10000 Migrated TestComparison tests to tests/{unit/integration} · pythonthings/github3.py@d7a2907 · GitHub
[go: up one dir, main page]

Skip to content

Commit d7a2907

Browse files
Migrated TestComparison tests to tests/{unit/integration}
1 parent 66409c6 commit d7a2907

File tree

6 files changed

+301
-36
lines changed

6 files changed

+301
-36
lines changed

tests/cassettes/Comparison_diff.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/cassettes/Comparison_patch.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/integration/test_repos_repo.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,3 +1191,30 @@ def test_patch(self):
11911191
patch = commit.patch()
11921192

11931193
assert patch
1194+
1195+
1196+
class TestComparison(helper.IntegrationHelper):
1197+
1198+
"""Integration test for Comparison object."""
1199+
1200+
def test_diff(self):
1201+
"""Test the ability to retrieve a diff for a comparison."""
1202+
cassette_name = self.cassette_name('diff')
1203+
with self.recorder.use_cassette(cassette_name):
1204+
repository = self.gh.repository('sigmavirus24', 'github3.py')
1205+
comparison = repository.compare_commits(base='master',
1206+
head='develop')
1207+
diff = comparison.diff()
1208+
1209+
assert diff
1210+
1211+
def test_patch(self):
1212+
"""Test the ability to retrieve a diff for a comparison."""
1213+
cassette_name = self.cassette_name('patch')
1214+
with self.recorder.use_cassette(cassette_name):
1215+
repository = self.gh.repository('sigmavirus24', 'github3.py')
1216+
comparison = repository.compare_commits(base='master',
1217+
head='develop')
1218+
patch = comparison.patch()
1219+
1220+
assert patch

tests/test_repos.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,6 @@
55
from tests.utils import (BaseCase, load, mock)
66

77

8-
class TestComparison(BaseCase):
9-
def __init__(self, methodName='runTest'):
10-
super(TestComparison, self).__init__(methodName)
11-
self.comp = repos.comparison.Comparison(load('comparison'))
12-
self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/"
13-
"compare/a811e1a270f65eecb65755eca38d888cbefcb0a7..."
14-
"76dcc6cb4b9860034be81b7e58adc286a115aa97")
15-
16-
def test_repr(self):
17-
assert repr(self.comp).startswith('<Comparison ')
18-
19-
def test_equality(self):
20-
comp = repos.comparison.Comparison(load('comparison'))
21-
assert self.comp == comp
22-
comp.commits.pop(0)
23-
assert self.comp != comp
24-
25-
def test_diff(self):
26-
self.response('archive', 200)
27-
self.get(self.api)
28-
self.conf.update(headers={'Accept': 'application/vnd.github.diff'})
29-
30-
assert self.comp.diff().startswith(b'archive_data')
31-
self.mock_assertions()
32-
33-
def test_patch(self):
34-
self.response('archive', 200)
35-
self.get(self.api)
36-
self.conf.update(headers={'Accept': 'application/vnd.github.patch'})
37-
38-
assert self.comp.patch().startswith(b'archive_data')
39-
self.mock_assertions()
40-
41-
428
class TestAsset(BaseCase):
439
def __init__(self, methodName='runTest'):
4410
super(TestAsset, self).__init__(methodName)

tests/unit/json/compare_example

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
{
2+
"url": "https://api.github.com/repos/octocat/Hello-World/compare/master...topic",
3+
"html_url": "https://github.com/octocat/Hello-World/compare/master...topic",
4+
"permalink_url": "https://github.com/octocat/Hello-World/compare/octocat:bbcd538c8e72b8c175046e27cc8f907076331401...octocat:0328041d1152db8ae77652d1618a02e57f745f17",
5+
"diff_url": "https://github.com/octocat/Hello-World/compare/master...topic.diff",
6+
"patch_url": "https://github.com/octocat/Hello-World/compare/master...topic.patch",
7+
"base_commit": {
8+
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
9+
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
10+
"html_url": "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e",
11+
"comments_url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments",
12+
"commit": {
13+
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
14+
"author": {
15+
"name": "Monalisa Octocat",
16+
"email": "support@github.com",
17+
"date": "2011-04-14T16:00:49Z"
18+
},
19+
"committer": {
20+
"name": "Monalisa Octocat",
21+
"email": "support@github.com",
22+
"date": "2011-04-14T16:00:49Z"
23+
},
24+
"message": "Fix all the bugs",
25+
"tree": {
26+
"url": & 10000 quot;https://api.github.com/repos/octocat/Hello-World/tree/6dcb09b5b57875f334f61aebed695e2e4193db5e",
27+
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
28+
},
29+
"comment_count": 0
30+
},
31+
"author": {
32+
"login": "octocat",
33+
"id": 1,
34+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
35+
"gravatar_id": "",
36+
"url": "https://api.github.com/users/octocat",
37+
"html_url": "https://github.com/octocat",
38+
"followers_url": "https://api.github.com/users/octocat/followers",
39+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
40+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
41+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
42+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
43+
"organizations_url": "https://api.github.com/users/octocat/orgs",
44+
"repos_url": "https://api.github.com/users/octocat/repos",
45+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
46+
"received_events_url": "https://api.github.com/users/octocat/received_events",
47+
"type": "User",
48+
"site_admin": false
49+
},
50+
"committer": {
51+
"login": "octocat",
52+
"id": 1,
53+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
54+
"gravatar_id": "",
55+
"url": "https://api.github.com/users/octocat",
56+
"html_url": "https://github.com/octocat",
57+
"followers_url": "https://api.github.com/users/octocat/followers",
58+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
59+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
60+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
61+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
62+
"organizations_url": "https://api.github.com/users/octocat/orgs",
63+
"repos_url": "https://api.github.com/users/octocat/repos",
64+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
65+
"received_events_url": "https://api.github.com/users/octocat/received_events",
66+
"type": "User",
67+
"site_admin": false
68+
},
69+
"parents": [
70+
{
71+
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193 10000 db5e",
72+
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
73+
}
74+
]
75+
},
76+
"merge_base_commit": {
77+
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
78+
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
79+
"html_url": "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e",
80+
"comments_url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments",
81+
"commit": {
82+
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
83+
"author": {
84+
"name": "Monalisa Octocat",
85+
"email": "support@github.com",
86+
"date": "2011-04-14T16:00:49Z"
87+
},
88+
"committer": {
89+
"name": "Monalisa Octocat",
90+
"email": "support@github.com",
91+
"date": "2011-04-14T16:00:49Z"
92+
},
93+
"message": "Fix all the bugs",
94+
"tree": {
95+
"url": "https://api.github.com/repos/octocat/Hello-World/tree/6dcb09b5b57875f334f61aebed695e2e4193db5e",
96+
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
97+
},
98+
"comment_count": 0
99+
},
100+
"author": {
101+
"login": "octocat",
102+
"id": 1,
103+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
104+
"gravatar_id": "",
105+
"url": "https://api.github.com/users/octocat",
106+
"html_url": "https://github.com/octocat",
107+
"followers_url": "https://api.github.com/users/octocat/followers",
108+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
109+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
110+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
111+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
112+
"organizations_url": "https://api.github.com/users/octocat/orgs",
113+
"repos_url": "https://api.github.com/users/octocat/repos",
114+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
115+
"received_events_url": "https://api.github.com/users/octocat/received_events",
116+
"type": "User",
117+
"site_admin": false
118+
},
119+
"committer": {
120+
"login": "octocat",
121+
"id": 1,
122+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
123+
"gravatar_id": "",
124+
"url": "https://api.github.com/users/octocat",
125+
"html_url": "https://github.com/octocat",
126+
"followers_url": "https://api.github.com/users/octocat/followers",
127+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
128+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
129+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
130+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
131+
"organizations_url": "https://api.github.com/users/octocat/orgs",
132+
"repos_url": "https://api.github.com/users/octocat/repos",
133+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
134+
"received_events_url": "https://api.github.com/users/octocat/received_events",
135+
"type": "User",
136+
"site_admin": false
137+
},
138+
"parents": [
139+
{
140+
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
141+
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
142+
}
143+
]
144+
},
145+
"status": "behind",
146+
"ahead_by": 1,
147+
"behind_by": 2,
148+
"total_commits": 1,
149+
"commits": [
150+
{
151+
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
152+
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
153+
"html_url": "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e",
154+
"comments_url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments",
155+
"commit": {
156+
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
157+
"author": {
158+
"name": "Monalisa Octocat",
159+
"email": "support@github.com",
160+
"date": "2011-04-14T16:00:49Z"
161+
},
162+
"committer": {
163+
"name": "Monalisa Octocat",
164+
"email": "support@github.com",
165+
"date": "2011-04-14T16:00:49Z"
166+
},
167+
"message": "Fix all the bugs",
168+
"tree": {
169+
"url": "https://api.github.com/repos/octocat/Hello-World/tree/6dcb09b5b57875f334f61aebed695e2e4193db5e",
170+
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
171+
},
172+
"comment_count": 0
173+
},
174+
"author": {
175+
"login": "octocat",
176+
"id": 1,
177+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
178+
"gravatar_id": "",
179+
"url": "https://api.github.com/users/octocat",
180+
"html_url": "https://github.com/octocat",
181+
"followers_url": "https://api.github.com/users/octocat/followers",
182+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
183+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
184+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
185+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
186+
"organizations_url": "https://api.github.com/users/octocat/orgs",
187+
"repos_url": "https://api.github.com/users/octocat/repos",
188+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
189+
"received_events_url": "https://api.github.com/users/octocat/received_events",
190+
"type": "User",
191+
"site_admin": false
192+
},
193+
"committer": {
194+
"login": "octocat",
195+
"id": 1,
196+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
197+
"gravatar_id": "",
198+
"url": "https://api.github.com/users/octocat",
199+
"html_url": "https://github.com/octocat",
200+
"followers_url": "https://api.github.com/users/octocat/followers",
201+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
202+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
203+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
204+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
205+
"organizations_url": "https://api.github.com/users/octocat/orgs",
206+
"repos_url": "https://api.github.com/users/octocat/repos",
207+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
208+
"received_events_url": "https://api.github.com/users/octocat/received_events",
209+
"type": "User",
210+
"site_admin": false
211+
},
212+
"parents": [
213+
{
214+
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
215+
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
216+
}
217+
]
218+
}
219+
],
220+
"files": [
221+
{
222+
"sha": "bbcd538c8e72b8c175046e27cc8f907076331401",
223+
"filename": "file1.txt",
224+
"status": "added",
225+
"additions": 103,
226+
"deletions": 21,
227+
"changes": 124,
228+
"blob_url": "https://github.com/octocat/Hello-World/blob/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt",
229+
"raw_url": "https://github.com/octocat/Hello-World/raw/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt",
230+
"contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e",
231+
"patch": "@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test"
232+
}
233+
]
234+
}

tests/unit/test_repos_repo.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from base64 import b64encode
77
from github3 import GitHubError
88
from github3.null import NullObject
9-
from github3.repos.repo import (Repository, Contents, Hook, RepoComment,
10-
RepoCommit)
9+
from github3.repos.repo import (Comparison, Contents, Hook, RepoComment,
10+
RepoCommit, Repository)
1111
from github3.models import GitHubCore
1212

1313
from . import helper
@@ -19,6 +19,9 @@
1919
('https://api.github.com/repos/octocat/Hello-World/'
2020
'commits/6dcb09b5b57875f334f61aebed695e2e4193db5e')
2121
)
22+
compare_url_for = helper.create_url_helper(
23+
'https://api.github.com/repos/octocat/Hello-World/compare/master...topic'
24+
)
2225
contents_url_for = helper.create_url_helper(
2326
'https://api.github.com/repos/github3py/github3.py/contents/README.rst'
2427
)
@@ -38,6 +41,9 @@
3841
get_commit_example_data = helper.create_example_data_helper(
3942
'commit_example'
4043
)
44+
get_compare_example_data = helper.create_example_data_helper(
45+
'compare_example'
46+
)
4147
get_content_example_data = helper.create_example_data_helper(
4248
'content_example'
4349
)
@@ -49,6 +55,7 @@
4955
)
5056
comment_example_data = get_comment_example_data()
5157
commit_example_data = get_commit_example_data()
58+
compare_example_data = get_compare_example_data()
5259
content_example_data = get_content_example_data()
5360
create_file_contents_example_data = create_file_contents_example_data()
5461
hook_example_data = get_hook_example_data()
@@ -1828,3 +1835,32 @@ def test_patch(self):
18281835
def test_str(self):
18291836
"""Show that instance string is formatted correctly."""
18301837
assert str(self.instance).startswith('<Repository Commit')
1838+
1839+
1840+
class TestComparison(helper.UnitHelper):
1841+
1842+
"""Unit test for Comparison object."""
1843+
described_class = Comparison
1844+
example_data = compare_example_data
1845+
1846+
def test_diff(self):
1847+
"""Verify the request for retrieving a diff for this comparison."""
1848+
self.instance.diff()
1849+
1850+
self.session.get.assert_called_once_with(
1851+
compare_url_for(),
1852+
headers={'Accept': 'application/vnd.github.diff'}
1853+
)
1854+
1855+
def test_patch(self):
1856+
"""Verify the request for retrieving a diff for this comparison."""
1857+
self.instance.patch()
1858+
1859+
self.session.get.assert_called_once_with(
1860+
compare_url_for(),
1861+
headers={'Accept': 'application/vnd.github.patch'}
1862+
)
1863+
1864+
def test_str(self):
1865+
"""Show that instance string is formatted correctly."""
1866+
assert str(self.instance).startswith('<Comparison')

0 commit comments

Comments
 (0)
0