mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-02 03:41:08 +00:00
Move get_notification(s) to AuthenticatedUser (pull #148)
This commit is contained in:
@@ -617,6 +617,44 @@ class AuthenticatedUser(github.GithubObject.GithubObject):
|
||||
None
|
||||
)
|
||||
|
||||
def get_notification(self, id):
|
||||
"""
|
||||
:calls: `GET /notifications/threads/:id <http://developer.github.com/v3/activity/notifications/#view-a-single-thread>`_
|
||||
: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 <http://developer.github.com/v3/activity/notifications/#list-your-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 <http://developer.github.com/v3/todo>`_
|
||||
|
||||
@@ -167,44 +167,6 @@ class Github(object):
|
||||
None
|
||||
)
|
||||
|
||||
def get_notification(self, id):
|
||||
"""
|
||||
:calls: `GET /notifications/threads/:id <http://developer.github.com/v3/todo>`_
|
||||
: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 <http://developer.github.com/v3/todo>`_
|
||||
: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 <http://developer.github.com/v3/todo>`_
|
||||
|
||||
@@ -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"])
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
+1
-1
@@ -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}}]
|
||||
Reference in New Issue
Block a user