Skip to content

Commit e260c58

Browse files
committed
Rename Repository#iter_notifications
1 parent 8e2fc9d commit e260c58

6 files changed

Lines changed: 57 additions & 40 deletions

File tree

HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Old name New name
8484
``Repository#iter_languages`` ``Repository#languages``
8585
``Repository#iter_milestones`` ``Repository#milestones``
8686
``Repository#iter_network_events`` ``Repository#network_events``
87+
``Repository#iter_notifications`` ``Repository#notifications``
8788

8889
========================================== ==============================================
8990

github3/repos/repo.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,34 +1410,6 @@ def latest_pages_build(self):
14101410
json = self._json(self._get(url), 200)
14111411
return PagesBuild(json) if json else None
14121412

1413-
@requires_auth
1414-
def iter_notifications(self, all=False, participating=False, since=None,
1415-
number=-1, etag=None):
1416-
r"""Iterate over the notifications for this repository.
1417-
1418-
:param bool all: (optional), show all notifications, including ones
1419-
marked as read
1420-
:param bool participating: (optional), show only the notifications the
1421-
user is participating in directly
1422-
:param since: (optional), filters out any notifications updated
1423-
before the given time. This can be a `datetime` or an `ISO8601`
1424-
formatted date string, e.g., 2012-05-20T23:10:27Z
1425-
:type since: datetime or string
1426-
:param str etag: (optional), ETag from a previous request to the same
1427-
endpoint
1428-
:returns: generator of :class:`Thread <github3.notifications.Thread>`
1429-
"""
1430-
url = self._build_url('notifications', base_url=self._api)
1431-
params = {
1432-
'all': all,
1433-
'participating': participating,
1434-
'since': timestamp_parameter(since)
1435-
}
1436-
for (k, v) in list(params.items()):
1437-
if not v:
1438-
del params[k]
1439-
return self._iter(int(number), url, Thread, params, etag)
1440-
14411413
@requires_auth
14421414
def iter_pages_builds(self, number=-1, etag=None):
14431415
"""Iterate over pages builds of this repository.
@@ -1671,6 +1643,32 @@ def network_events(self, number=-1, etag=None):
16711643
url = self._build_url('events', base_url=base)
16721644
return self._iter(int(number), url, Event, etag)
16731645

1646+
@requires_auth
1647+
def notifications(self, all=False, participating=False, since=None,
1648+
number=-1, etag=None):
1649+
r"""Iterate over the notifications for this repository.
1650+
1651+
:param bool all: (optional), show all notifications, including ones
1652+
marked as read
1653+
:param bool participating: (optional), show only the notifications the
1654+
user is participating in directly
1655+
:param since: (optional), filters out any notifications updated
1656+
before the given time. This can be a `datetime` or an `ISO8601`
1657+
formatted date string, e.g., 2012-05-20T23:10:27Z
1658+
:type since: datetime or string
1659+
:param str etag: (optional), ETag from a previous request to the same
1660+
endpoint
1661+
:returns: generator of :class:`Thread <github3.notifications.Thread>`
1662+
"""
1663+
url = self._build_url('notifications', base_url=self._api)
1664+
params = {
1665+
'all': all,
1666+
'participating': participating,
1667+
'since': timestamp_parameter(since)
1668+
}
1669+
self._remove_none(params)
1670+
return self._iter(int(number), url, Thread, params, etag)
1671+
16741672
@requires_auth
16751673
def pages(self):
16761674
"""Get information about this repository's pages site.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions": [{"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "User-Agent": "github3.py/1.0.0", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "Basic <BASIC_AUTH>"}, "method": "GET", "uri": "https://api.github.com/repos/sigmavirus24/github3.py"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA62YXY+rNhCG/0rEbbNxCNlsglSd9qrt3bk4velNZMAEawEj2yTKov3vfY2BQI6aj3WlVZSwnsevxzNmxo3HEy8M3vzlm+/PvZIWzAu9A9dZHQWL6uzNvbTO8333D8UPBT1yWavVmkxGiVPJpBc2Xi4OvARjPBQUM81qvdwGy7lHj1RTua9ljnGZ1pUKCbEP1cJSa8VkLErNSr2IRUFqYo2/HX9dgXaQHcNgvdhfb4PXTbLdpbvVK9vsVv7bNmLMT3YBjdM3GFzNVfFuHgvHZIpcCc50kV9JtNJak6vBqchzcQLlel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XfHqHT/sC4mh6TNTU7W3aeqFWtamq8STyzEwenji73zo+GzT1tE3O5ySXErR3ReVSFL0+xUrO/YgY2sbR+WFxmY0Arrxv152t4qEpbTO9d4Wz5CdoOrPRWUih8kCus3FhLnQ6jpluwITVf1qzHlhv6OBLpk+oVfs1RgJ4zKl99X2819he1kIchMAAA==", "encoding": "utf-8"}, "headers": {"vary": "Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding", "x-served-by": "971af40390ac4398fcdd45c8dab0fbe7", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "etag": "\"d788d2d447e1f828e4e0672c124149ef\"", "access-control-allow-credentials": "true", "status": "200 OK", "x-ratelimit-remaining": "4987", "x-github-media-type": "github.v3; param=full; format=json", "access-control-expose-headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "transfer-encoding": "chunked", "x-github-request-id": "48A0C4D3:7B5D:26B4A60:53E6DCD0", "cache-control": "private, max-age=60, s-maxage=60", "last-modified": "Fri, 08 Aug 2014 17:22:50 GMT", "date": "Sun, 10 Aug 2014 02:45:36 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "content-encoding": "gzip", "strict-transport-security": "max-age=31536000; includeSubdomains", "server": "GitHub.com", "x-ratelimit-limit": "5000", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1407641433"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py"}, "recorded_at": "2014-08-10T02:45:37"}, {"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "User-Agent": "github3.py/1.0.0", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "Basic <BASIC_AUTH>"}, "method": "GET", "uri": "https://api.github.com/repos/sigmavirus24/github3.py/notifications?participating=False&per_page=100&all=False"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA62YXY/iNhSG/wrKbVkMAWaGkapV1Yt2b6rRqr3pqkJO4iTuJHFqOyA2mv/e9zgBAlUzw3huEBCfx+fbx/nWBjIJHoPlarXehJv7YBo0lRYc/1ndiGmA70ZVWGGayMRaRiKhNXXCrUi23OJJOF+sPs3vPi0Wv4fh43L1uF79iTUFN3ZLKLeqaopiSpC/RYyfbWClLQSkfxP7CbcW5MYKM0mVnjxh7VfxTyOM/Sp2Uux/VmUpKjsRO3wa2l8XEM2trc0jY7yWs0zavIlmsSqZFrUyzMis5DupGxOuWPd0OasPTBoDMAvXZGsBK6AlpIi//SisPdRk2hfaKnghJ0IjaZU+kOXk8OX9Yn6/WEyDipe09KwgtEph/7Z/8D9mYJXaV0ITr1CZdBEaWIzntE24mj8s59OA77jl+to+96fpXdcYoWNVWfjBebFhnfDn3Y8haJnuGS5d4sXqYbm+Sx426SZci7tNuLh/iIRYJJslj1OXRmMhos0uQwSJ3JbFlYqDqF5Zl6qiUHtQro26zIX/bsROkuRpR5FV9k4KJFumbC7gW5j0Qo6Sxt6ulJNqkafIRpkQxyA2GiV2ox9ZLwe1KD9eWlcODtgVcG2lqm5X8EIaNKUzXsnv/H00SFMZu7q42UInBemuG9ws3om1rNZyx+MDuUaLWMgdnP1O5JU8iH0H+ANJQa6XVmx5UlKZprwwAj3BbW9R++6PW7J/0M3ATgS1ZRdVFObTweaqmhQy0lwfXDeVqGmd8hi5OtmjS06QrpNfpP21iSY/PX3ZLQHBuueTJqMZN9pce9IrIR1FoDz1M0X3WRy8OCTfMnz29RSj1HmkNEcb9gJfgFo2/Em5ZAUvvfgOAFCu1LMXyAEAcifem1J7PDL9yXmsn6opo67lvaVqxtGng50b9PlKCC/DT5CWHbsyyqGKcz/skdGy7puLNs+8VCV5YKJCRV4cHJTMQVpmct6dQ3brqx1RiXEB1SL1VpUYJ6jVnvF2ahLkhMQhaBF6Lz2PDNb2Hi14lTU886OeIIg6HdUZ//7qEDNeO2cKkDTBuVHau8mdOaTpcfj3a50DzBnqjq7xU/wVBwwGG+eCspSvjWDjxB5xkfYfgKU8vUb3Vw+vTD0yWnbuyV3T/7iLzXEP1p736K8Lnrq7K4dh7Q81tzl1LmxVcy18UqJHsDbiGLZms1mb4yJK8FJozwruCEBxHeeYGn30bI8MTD0lt25aT0nNBNN7oXji5dsTBMDu8PbRtSMMc6zGPdVLQQcYEktZ4D6uKr8ee6YM2ZWyMpXxW24s493hAtR+NrKKxZTj9Qay1spYIo8xa1MUMXAKPw91BJiB1wTdTaXACxk/92jRMVpGN01cRUYH/gtrmc3pjY5hg/dFw5vheH6No9gQFLz89S/mnOF4mxIAAA==", "encoding": "utf-8"}, "headers": {"vary": "Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding", "x-served-by": "6d7de9e645814cac34ea2a8d72ba3141", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "etag": "nil", "access-control-allow-credentials": "true", "x-poll-interval": "60", "status": "200 OK", "x-ratelimit-remaining": "4986", "x-github-media-type": "github.v3; param=full; format=json", "access-control-expose-headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "transfer-encoding": "chunked", "x-github-request-id": "48A0C4D3:7B5D:26B4A89:53E6DCD0", "cache-control": "private, max-age=60, s-maxage=60", "last-modified": "Wed, 11 Jun 2014 22:34:54 GMT", "date": "Sun, 10 Aug 2014 02:45:36 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "content-encoding": "gzip", "strict-transport-security": "max-age=31536000; includeSubdomains", "server": "GitHub.com", "x-ratelimit-limit": "5000", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1407641433"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py/notifications?participating=False&per_page=100&all=False"}, "recorded_at": "2014-08-10T02:45:37"}], "recorded_with": "betamax/0.4.0"}

tests/integration/test_repos_repo.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,19 @@ def test_network_events(self):
311311
for event in events:
312312
assert isinstance(event, github3.events.Event)
313313

314+
def test_notifications(self):
315+
"""Test that a user can retrieve their repo notifications."""
316+
self.basic_login()
317+
cassette_name = self.cassette_name('notifications')
318+
with self.recorder.use_cassette(cassette_name):
319+
repository = self.gh.repository('sigmavirus24', 'github3.py')
320+
assert repository is not None
321+
notifications = list(repository.notifications())
322+
323+
assert len(notifications) > 0
324+
for notification in notifications:
325+
assert isinstance(notification, github3.notifications.Thread)
326+
314327
def test_iter_pulls_accepts_sort_and_direction(self):
315328
"""Test that iter_pulls now takes a sort parameter."""
316329
cassette_name = self.cassette_name('pull_requests_accept_sort')

tests/test_repos.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -536,18 +536,6 @@ def test_label(self):
536536
assert isinstance(self.repo.label('name'), github3.issues.label.Label)
537537
self.mock_assertions()
538538

539-
def test_iter_notifications(self):
540-
self.response('notification', _iter=True)
541-
self.get(self.api + 'notifications')
542-
self.conf.update(params={'per_page': 100})
543-
544-
self.assertRaises(github3.GitHubError, self.repo.iter_notifications)
545-
546-
self.login()
547-
n = next(self.repo.iter_notifications())
548-
assert isinstance(n, github3.notifications.Thread)
549-
self.mock_assertions()
550-
551539
def test_iter_pulls(self):
552540
self.response('pull', _iter=True)
553541
self.get(self.api + 'pulls')

tests/unit/test_repos_repo.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,17 @@ def test_network_events(self):
469469
headers={}
470470
)
471471

472+
def test_notifications(self):
473+
"""Test the ability to iterate over the notifications for a repo."""
474+
i = self.instance.notifications()
475+
self.get_next(i)
476+
477+
self.session.get.assert_called_once_with(
478+
url_for('notifications'),
479+
params={'per_page': 100, 'participating': False, 'all': False},
480+
headers={}
481+
)
482+
472483

473484
class TestRepositoryRequiresAuth(UnitHelper):
474485

@@ -495,3 +506,8 @@ def test_keys(self):
495506
"""Show that a user must be authenticated to list keys."""
496507
with pytest.raises(GitHubError):
497508
self.instance.keys()
509+
510+
def test_notifications(self):
511+
"""Show that a user must be authenticated to list notifications."""
512+
with pytest.raises(GitHubError):
513+
self.instance.notifications()

0 commit comments

Comments
 (0)