8000 Add all_organizations to GitHub · pythonthings/github3.py@8b5dacf · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b5dacf

Browse files
committed
Add all_organizations to GitHub
- New method - Integration test - Add the cassette JSON - Unit tests
1 parent 95b8f36 commit 8b5dacf

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

github3/github.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ def all_events(self, number=-1, etag=None):
7878
url = self._build_url('events')
7979
return self._iter(int(number), url, Event, etag=etag)
8080

81+
def all_organizations(self, number=-1, since=None, etag=None,
82+
per_page=None):
83+
"""Iterate over every organization in the order they were created.
84+
85+
:param int number: (optional), number of organizations to return.
86+
Default: -1, returns all of them
87+
:param int since: (optional), last organization id seen (allows
88+
restarting this iteration)
89+
:param str etag: (optional), ETag from a previous request to the same
90+
endpoint
91+
:param int per_page: (optional), number of organizations to list per
92+
request
93+
:returns: generator of :class:`Organization
94+
<github3.orgs.Organization>`
95+
"""
96+
url = self._build_url('organizations')
97+
return self._iter(int(number), url, Organization,
98+
params={'since': since, 'per_page': per_page},
99+
etag=etag)
100+
81101
def all_repositories(self, number=-1, since=None, etag=None,
82102
per_page=None):
83103
"""Iterate over every repository in the order they were created.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions": [{"request": {"uri": "https://api.github.com/organizations?per_page=25", "method": "GET", "headers": {"Accept": "application/vnd.github.v3.full+json", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "User-Agent": "github3.py/1.0.0a2"}, "body": {"string": "", "encoding": "utf-8"}}, "recorded_at": "2015-07-27T16:50:16", "response": {"url": "https://api.github.com/organizations?per_page=25", "headers": {"x-github-media-type": "github.v3; param=full; format=json", "content-type": "application/json; charset=utf-8", "x-github-request-id": "3EBD09C7:4121:BE664F4:55B66147", "x-served-by": "065b43cd9674091fec48a221b420fbb3", "x-ratelimit-remaining": "58", "transfer-encoding": "chunked", "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", "x-frame-options": "deny", "content-security-policy": "default-src 'none'", "status": "200 OK", "x-xss-protection": "1; mode=block", "date": "Mon, 27 Jul 2015 16:50:16 GMT", "x-ratelimit-limit": "60", "etag": "W/\"467f85325c09d7c93ffa03581d0b7de5\"", "cache-control": "public, max-age=60, s-maxage=60", "content-encoding": "gzip", "access-control-allow-origin": "*", "link": "<https://api.github.com/organizations?per_page=25&since=2595>; rel=\"next\", <https://api.github.com/organizations{?since}>; rel=\"first\"", "x-ratelimit-reset": "1438017277", "access-control-allow-credentials": "true", "vary": "Accept", "x-content-type-options": "nosniff", "server": "GitHub.com", "strict-transport-security": "max-age=31536000; includeSubdomains; preload"}, "status": {"message": "OK", "code": 200}, "body": {"base64_string": "H4sIAAAAAAAAA63ay27jNhSA4VcR1G0QX+JbAhRdzKqLAsV00UVRDGiZlomhRIGi7BqDefceySJFyRrMIXF2gyD/yYQfaElU/vmWSpWLMv1IudZnzXn6kopT+rHZvKSNlvD1izFV/bFYsEq85sJcmuNrpoqF0nm9GBrNK1V/QReL7vvhZ/ErL01I+AigLHhx5Dok7Ytvi8c/vsOQqjlKkX0JnzUO/ZHsygzT06Xovlj3C9jUXGeqNPCrd2vZLDab366/vsF/6MTrTIvKCAUmZSPl9xePqAQqfmf61CsdViglP0NDuSjCamhjuIaaRGwYR4x2WM2hpalPVohS1EbfM7Dmmlu41eodIzdTY/2mabji04QIy6cZFKJPQ4ldAWcOdrobMyUlz4y4cnHirN+Rq/UBA/vUYlnHYTjqpI8gnUygAJ2MpOZcH+Y40795cmyEPCW1Opsb0zwxCv4trzzRnMmk0uooeVG/jja0yjNLjbtGPgKsL3x3OGobRUi2GQVfO4faDHdBrNvf+ia0vWtZbZeY3ednW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uy3593+CzYb+GisAAA==", "string": "", "encoding": "utf-8"}}}], "recorded_with": "betamax/0.4.2"}

tests/integration/test_github.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ def test_issue(self):
169169

170170
assert isinstance(i, github3.issues.Issue)
171171

172+
def test_all_organizations(self):
173+
"""Test the ability to iterate over all of the organizations."""
174+
cassette_name = self.cassette_name('all_organizations')
175+
with self.recorder.use_cassette(cassette_name):
176+
for r in self.gh.all_organizations(number=25):
177+
assert isinstance(r, github3.orgs.Organization)
178+
172179
def test_all_repositories(self):
173180
"""Test the ability to iterate over all of the repositories."""
174181
cassette_name = self.cassette_name('iter_all_repos')

tests/unit/test_github.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,40 @@ def test_all_events(self):
317317
headers={}
318318
)
319319

320+
def test_all_organizations(self):
321+
"""Show that one can iterate over all organizations."""
322+
i = self.instance.all_organizations()
323+
self.get_next(i)
324+
325+
self.session.get.assert_called_once_with(
326+
url_for('organizations'),
327+
params={'per_page': 100},
328+
headers={}
329+
)
330+
331+
def test_all_organizations_per_page(self):
332+
"""Show that one can iterate over all organizations with per_page."""
333+
i = self.instance.all_organizations(per_page=25)
334+
self.get_next(i)
335+
336+
self.session.get.assert_called_once_with(
337+
url_for('organizations'),
338+
params={'per_page': 25},
339+
headers={}
340+
)
341+
342+
def test_all_organizations_since(self):
343+
"""Show that one can limit the organizations returned."""
344+
since = 100000
345+
i = self.instance.all_organizations(since=since)
346+
self.get_next(i)
347+
348+
self.session.get.assert_called_once_with(
349+
url_for('organizations'),
350+
params={'per_page': 100, 'since': since},
351+
headers={}
352+
)
353+
320354
def test_all_repositories(self):
321355
"""Show that one can iterate over all repositories."""
322356
i = self.instance.all_repositories()

0 commit comments

Comments
 (0)
0