diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 6665c669..0e3d52cf 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -617,6 +617,44 @@ class AuthenticatedUser(github.GithubObject.GithubObject): None ) + def get_notification(self, id): + """ + :calls: `GET /notifications/threads/:id `_ + :rtype: :class:`github.Notification.Notification` + """ + + assert isinstance(id, (str, unicode)), id + headers, data = self._requester.requestJsonAndCheck( + "GET", + "/notifications/threads/" + id, + None, + None + ) + return github.Notification.Notification(self._requester, data, completed=True) + + def get_notifications(self, all=github.GithubObject.NotSet, participating=github.GithubObject.NotSet): + """ + :calls: `GET /notifications `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Notification.Notification` + """ + + assert all is github.GithubObject.NotSet or isinstance(all, bool), all + assert participating is github.GithubObject.NotSet or isinstance(participating, bool), participating + + params = dict() + if all is not github.GithubObject.NotSet: + params["all"] = all + if participating is not github.GithubObject.NotSet: + params["participating"] = participating + # TODO: implement parameter "since" + + return github.PaginatedList.PaginatedList( + github.Notification.Notification, + self._requester, + "/notifications", + params + ) + def get_organization_events(self, org): """ :calls: `GET /users/:user/events/orgs/:org `_ diff --git a/github/MainClass.py b/github/MainClass.py index 8783701b..d0a97aec 100644 --- a/github/MainClass.py +++ b/github/MainClass.py @@ -167,44 +167,6 @@ class Github(object): None ) - def get_notification(self, id): - """ - :calls: `GET /notifications/threads/:id `_ - :rtype: :class:`github.Notification.Notification` - """ - - assert isinstance(id, (str, unicode)), id - headers, data = self.__requester.requestJsonAndCheck( - "GET", - "/notifications/threads/" + id, - None, - None - ) - return github.Notification.Notification(self.__requester, data, completed=True) - - def get_notifications(self, all=False, participating=True): - """ - :calls: `GET /notifications `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Notification.Notification` - """ - - assert isinstance(all, (bool, )), all - assert isinstance(participating, (bool,)), participating - - params = dict() - if all: - params["all"] = "true" - if participating: - params["participating"] = "true" - # TODO: implement parameter "since" - - return github.PaginatedList.PaginatedList( - github.Notification.Notification, - self.__requester, - "/notifications", - params - ) - def legacy_search_repos(self, keyword, language=github.GithubObject.NotSet): """ :calls: `GET /legacy/repos/search/:keyword `_ diff --git a/github/tests/AuthenticatedUser.py b/github/tests/AuthenticatedUser.py index 8ae20d7a..77bcae4d 100644 --- a/github/tests/AuthenticatedUser.py +++ b/github/tests/AuthenticatedUser.py @@ -185,3 +185,15 @@ class AuthenticatedUser(Framework.TestCase): def testCreateFork(self): repo = self.user.create_fork(self.g.get_user("nvie").get_repo("gitflow")) self.assertEqual(repo.source.full_name, "nvie/gitflow") + + def testGetNotification(self): + notification = self.user.get_notification("8406712") + self.assertEqual(notification.id, "8406712") + self.assertEqual(notification.unread, False) + self.assertEqual(notification.reason, "author") + self.assertEqual(notification.subject.title, "Feature/coveralls") + self.assertEqual(notification.subject.type, "PullRequest") + self.assertEqual(notification.repository.id, 8432784) + + def testGetNotifications(self): + self.assertListKeyBegin(self.user.get_notifications(participating=True), lambda n: n.id, ["8406712"]) diff --git a/github/tests/Github_.py b/github/tests/Github_.py index 46da42c7..149af2b8 100644 --- a/github/tests/Github_.py +++ b/github/tests/Github_.py @@ -93,25 +93,6 @@ class Github(Framework.TestCase): self.assertEqual(hook.events, ["push"]) self.assertEqual(hook.schema, [["string", "url"], ["string", "token"], ["string", "project_id"], ["string", "milestone_id"], ["string", "category_id"]]) - def testGetNotification(self): - notification = self.g.get_notification("8406712") - self.assertEqual(notification.id, "8406712") - self.assertEqual(notification.unread, False) - self.assertEqual(notification.reason, "author") - self.assertEqual(notification.subject.title, "Feature/coveralls") - self.assertEqual(notification.subject.type, "PullRequest") - self.assertEqual(notification.repository.id, 8432784) - - def testGetNotifications(self): - notifications = self.g.get_notifications() - notification = notifications[0] - self.assertEqual(notification.id, "8406712") - self.assertEqual(notification.unread, False) - self.assertEqual(notification.reason, "author") - self.assertEqual(notification.subject.title, "Feature/coveralls") - self.assertEqual(notification.subject.type, "PullRequest") - self.assertEqual(notification.repository.id, 8432784) - def testGetRepoFromFullName(self): self.assertEqual(self.g.get_repo("jacquev6/PyGithub").description, "Python library implementing the full Github API v3") diff --git a/github/tests/ReplayData/Github.testGetNotification.txt b/github/tests/ReplayData/AuthenticatedUser.testGetNotification.txt similarity index 100% rename from github/tests/ReplayData/Github.testGetNotification.txt rename to github/tests/ReplayData/AuthenticatedUser.testGetNotification.txt diff --git a/github/tests/ReplayData/Github.testGetNotifications.txt b/github/tests/ReplayData/AuthenticatedUser.testGetNotifications.txt similarity index 92% rename from github/tests/ReplayData/Github.testGetNotifications.txt rename to github/tests/ReplayData/AuthenticatedUser.testGetNotifications.txt index 81aa7eed..150f872a 100644 --- a/github/tests/ReplayData/Github.testGetNotifications.txt +++ b/github/tests/ReplayData/AuthenticatedUser.testGetNotifications.txt @@ -1,4 +1,4 @@ -https GET api.github.com None /notifications?participating=true {'Authorization': 'Basic login_and_password_removed'} null +https GET api.github.com None /notifications?participating=True {'Authorization': 'Basic login_and_password_removed'} null 200 [('status', '200 OK'), ('x-ratelimit-remaining', '4999'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('x-ratelimit-limit', '5000'), ('vary', 'Accept, Authorization, Cookie'), ('content-length', '16567'), ('server', 'nginx'), ('last-modified', 'Fri, 24 Aug 2012 07:05:12 GMT'), ('connection', 'keep-alive'), ('etag', '"eb52c03081d2fc22f26ed2718921e500"'), ('cache-control', 'private, max-age=60, s-maxage=60'), ('date', 'Sat, 08 Sep 2012 17:26:28 GMT'), ('content-type', 'application/json; charset=utf-8')] [{"id": "8406712","unread": false,"reason": "author","updated_at": "2013-03-15T05:43:11Z","last_read_at": "2013-03-15T06:06:34Z","subject": {"title": "Feature/coveralls","type": "PullRequest"},"repository": {"id": 8432784}}]