|
7 | 7 | from mock import patch, Mock |
8 | 8 |
|
9 | 9 | from pygithub3.services.repos import (Repo, Collaborator, Commits, Downloads, |
10 | | - Forks, Keys) |
| 10 | + Forks, Keys, Watchers) |
11 | 11 | from pygithub3.resources.base import json |
12 | 12 | from pygithub3.tests.utils.base import (mock_response, mock_response_result, |
13 | 13 | mock_json) |
@@ -325,3 +325,46 @@ def test_DELETE(self, request_method): |
325 | 325 | self.ks.delete(1) |
326 | 326 | self.assertEqual(request_method.call_args[0], |
327 | 327 | ('delete', _('repos/oct/re_oct/keys/1'))) |
| 328 | + |
| 329 | + |
| 330 | +@patch.object(requests.sessions.Session, 'request') |
| 331 | +class TestWatchersService(TestCase): |
| 332 | + |
| 333 | + def setUp(self): |
| 334 | + self.ws = Watchers(user='oct', repo='re_oct') |
| 335 | + |
| 336 | + def test_LIST(self, request_method): |
| 337 | + request_method.return_value = mock_response_result() |
| 338 | + self.ws.list().all() |
| 339 | + self.assertEqual(request_method.call_args[0], |
| 340 | + ('get', _('repos/oct/re_oct/watchers'))) |
| 341 | + |
| 342 | + def test_LIST_repos(self, request_method): |
| 343 | + request_method.return_value = mock_response_result() |
| 344 | + self.ws.list_repos().all() |
| 345 | + self.assertEqual(request_method.call_args[0], |
| 346 | + ('get', _('users/oct/watched'))) |
| 347 | + |
| 348 | + def test_LIST_repos_without_user(self, request_method): |
| 349 | + request_method.return_value = mock_response_result() |
| 350 | + self.ws.set_user(None) |
| 351 | + self.ws.list_repos().all() |
| 352 | + self.assertEqual(request_method.call_args[0], |
| 353 | + ('get', _('user/watched'))) |
| 354 | + |
| 355 | + def test_IS_watching(self, request_method): |
| 356 | + request_method.return_value = mock_response() |
| 357 | + self.assertTrue(self.ws.is_watching()) |
| 358 | + self.assertEqual(request_method.call_args[0], |
| 359 | + ('head', _('user/watched/oct/re_oct'))) |
| 360 | + |
| 361 | + def test_WATCH(self, request_method): |
| 362 | + self.ws.watch() |
| 363 | + self.assertEqual(request_method.call_args[0], |
| 364 | + ('put', _('user/watched/oct/re_oct'))) |
| 365 | + |
| 366 | + def test_UNWATCH(self, request_method): |
| 367 | + request_method.return_value = mock_response('delete') |
| 368 | + self.ws.unwatch() |
| 369 | + self.assertEqual(request_method.call_args[0], |
| 370 | + ('delete', _('user/watched/oct/re_oct'))) |
0 commit comments