forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_structs.py
More file actions
63 lines (49 loc) · 2.27 KB
/
Copy pathtest_structs.py
File metadata and controls
63 lines (49 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from .helper import UnitHelper, mock
from github3.structs import GitHubIterator
class TestGitHubIterator(UnitHelper):
described_class = GitHubIterator
def after_setup(self):
self.count = self.instance.count = -1
self.cls = self.instance.cls = object
def create_instance_of_described_class(self):
self.url = 'https://api.github.com/users'
def _klass(*args):
return args
klass = _klass
instance = self.described_class(count=-1, url=self.url, cls=klass,
session=self.session)
return instance
def test_refresh(self):
"""Show that __iter__ is called when refreshing."""
with mock.patch.object(GitHubIterator, '__iter__') as i:
self.instance.refresh()
assert i.called is True
def test_refresh_conditional(self):
"""Show that __iter__ is called when refreshing."""
with mock.patch.object(GitHubIterator, '__iter__') as i:
self.instance.refresh(True)
assert i.called is True
def test_sets_per_page_to_100(self):
"""Test that the Iterator defaults the per_page parameter to 100"""
self.session.get.return_value = mock.Mock(status_code=200,
json=lambda: [],
links={})
for i in self.instance:
break
self.session.get.assert_called_once_with(
self.url, params={'per_page': 100}, headers={}
)
def test_stores_headers_properly(self):
headers = {'Accept': 'foo'}
session, url, count, cls = self.session, self.url, self.count, self.cls
i = GitHubIterator(count, url, cls, session, headers=headers)
assert i.headers != {}
assert i.headers.get('Accept') == 'foo'
def test_stores_etag_properly(self):
session, url, count, cls = self.session, self.url, self.count, self.cls
i = GitHubIterator(count, url, cls, session, etag='"foobarbogus"')
assert i.headers != {}
assert i.headers.get('If-None-Match') == '"foobarbogus"'
def test_str(self):
"""Show that instance string is formatted correctly."""
assert str(self.instance).startswith('<GitHubIterator')