8000 Migrated (3) struct test cases to tests/{unit/integration} · pythonthings/github3.py@fde1879 · GitHub
[go: up one dir, main page]

Skip to content

Commit fde1879

Browse files
Migrated (3) struct test cases to tests/{unit/integration}
Migrated test_str to tests/unit/test_struct.py Migrated test_stores_etag_properly to tests/unit/test_structs Created integration test to assert that StopIteration is raised
1 parent a7b0b88 commit fde1879

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed
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.0a2", "Accept-Charset": "utf-8", "Connection": "keep-alive", "Content-Type": "application/json"}, "method": "GET", "uri": "https://api.github.com/users?per_page=1"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA5WTwWrEIBCG38XzsrL0Fih9ip5KCSaZNVOMIzrJsg377h1j6NIcCp4ixu/zz6/5WJUji141aqIvmjpSJ4WDai4nZRbDJrZzdPJ2ZA6p0bpMprNFHuduThB78gyezz1NetaXt+X1RRw27niWKZk4aALuisKJJ+lngpEnd9i4bLitfq67knN0E/aY8h+9/oUkVRmjt/UCgVZNPIJUJPEf+aMxcVWUDVh1frQ4ZEWSyiMMNXF2RMLcvORYdYRAm2vuUh8xMJKvivUHFBFFazx+m2qRgEn4HKgqwAYICIvcrCqyEKsOERfT33MNEXrARTqttx1QkfE9gFzodznx3DAytGaY8g90NS7B4/MHKnTrqlIDAAA=", "encoding": "utf-8"}, "headers": {"vary": "Accept", "x-github-media-type": "github.v3; param=full; format=json", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "etag": "W/\"dc0259e89a34547cacf231a5b1fcb438\"", "cache-control": "public, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "59", "x-served-by": "318e55760cf7cdb40e61175a4d36cd32", "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": "97E45D32:A4EA:3D66357:56B3012E", "access-control-allow-credentials": "true", "link": "<https://api.github.com/users?per_page=1&since=1>; rel=\"next\", <https://api.github.com/users{?since}>; rel=\"first\"", "date": "Thu, 04 Feb 2016 07:43:42 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "content-encoding": "gzip", "strict-transport-security": "max-age=31536000; includeSubdomains; preload", "server": "GitHub.com", "x-ratelimit-limit": "60", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1454575422"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/users?per_page=1"}, "recorded_at": "2016-02-04T07:43:42"}], "recorded_with": "betamax/0.5.0"}

tests/integration/test_structs.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import github3
2+
import pytest
3+
14
from .helper import IntegrationHelper
25

36

@@ -11,3 +14,11 @@ def test_resets_etag(self):
1114
assert users_iter.etag is not None
1215
users_iter.refresh()
1316
assert users_iter.etag is None
17+
18+
def test_count_reaches_0(self):
19+
cassette_name = self.cassette_name('count_reaches_0')
20+
with self.recorder.use_cassette(cassette_name):
21+
users_iter = self.gh.all_users(number=1)
22+
assert isinstance(next(users_iter), github3.users.User)
23+
with pytest.raises(StopIteration):
24+
next(users_iter)

tests/test_structs.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@ def setUp(self):
1111
self.i = GitHubIterator(self.num, self.api_url, github3.users.User,
1212
self.g)
1313

14-
def test_headers(self):
15-
i = GitHubIterator(self.i.count, self.i.url, self.i.cls, self.g,
16-
etag='"foobarbogus"')
17-
assert i.headers.get('If-None-Match') == '"foobarbogus"'
18-
19-
def test_repr(self):
20-
assert repr(self.i) == '<GitHubIterator [{0}, /users]>'.format(
21-
self.num)
22-
2314
def test_nexts(self):
2415
self.response('user', _iter=True)
2516
self.get(self.api_url)
@@ -58,17 +49,6 @@ def test_entire_while_loop(self):
5849

5950
self.mock_assertions()
6051

61-
def test_count_reaches_0(self):
62-
self.response('user', _iter=True)
63-
self.get(self.api_url)
64-
self.conf = {'params': {'per_page': 1}, 'headers': {}}
65-
self.i = GitHubIterator(1, self.api_url, github3.users.User, self.g)
66-
67-
assert isinstance(next(self.i), github3.users.User)
68-
self.assertRaises(StopIteration, next, self.i)
69-
70-
self.mock_assertions()
71-
7252
def test_refresh(self):
7353
with mock.patch.object(GitHubIterator, '__iter__') as i:
7454
self.i.refresh()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,13 @@ def test_stores_headers_properly(self):
3939
i = GitHubIterator(count, url, cls, session, headers=headers)
4040
assert i.headers != {}
4141
assert i.headers.get('Accept') == 'foo'
42+
43+
def test_stores_etag_properly(self):
44+
session, url, count, cls = self.session, self.url, self.count, self.cls
45+
i = GitHubIterator(count, url, cls, session, etag='"foobarbogus"')
46+
assert i.headers != {}
47+
assert i.headers.get('If-None-Match') == '"foobarbogus"'
48+
49+
def test_str(self):
50+
"""Show that instance string is formatted correctly."""
51+
assert str(self.instance).startswith('<GitHubIterator')

0 commit comments

Comments
 (0)
0