8000 Merge pull request #488 from itsmemattchung/migrate-tests/git · pythonthings/github3.py@3ee5c15 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ee5c15

Browse files
committed
Merge pull request sigmavirus24#488 from itsmemattchung/migrate-tests/git
Migrated commit/reference tests into tests/unit/test_git and tests/integration/test_git
2 parents 9fc6672 + 03e8e5c commit 3ee5c15

File tree

6 files changed

+172
-68
lines changed

6 files changed

+172
-68
lines changed

tests/cassettes/Reference_update.json

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", "Authorization": "token <AUTH_TOKEN>"}, "method": "GET", "uri": "https://api.github.com/repos/itsmemattchung/github3.py"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA+2bS3OrNhSA/0rG2zrGGDsPZjq3XbXd3cXtphuPjGWjCa+RhDO+TP57z5HABhIZjOh0wyaTYOnjIPQ6n5VixvYzf+29up67eprPEhLTmT87MhnmO2+RnWfz2SGPom35AZMipjGRMgjz5Og0yqXvCeUzv5hF6ZElQGkWBhLe69nbvLjL1XxGTkQSvs15BEVDKTPhO46+KBYanAvKgzSRNJGLII2d3Clrfzv96gHvyEsIgmdwoQXLWAnStYEmnE9BhTKOWlHou6tKn4of0ihK34HUjrz7Zs6lLraq4rDkOJgDdQsnlSGFRoRH+8AGYUIOCUzVK+B1CrlleyQJeDec7gcEV9aE0LA/fBQOp1mqkPlOBJxlkqXJkCAb9YGX8iNJ2E8ylAf1BWAwvCHhqHpQn56gew4B6IqFk3F2IsEZm4jTgLITNPtgaIsATHnOcEj/DV0EXwKTdEv2MQ7QA4kE/ZjPVAASCqkLcxiM/UdEcwrY08sbhlt+P8swTR4ituOEnx8OKX9gMJj5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BsvFzrzVlYuQZpPCfXxNaNHvSeu41cg3avj2tUVoschNAn48e0WziN6uO4uFZEDZcHsY1t4lqdpabsR/RwpRPsIeLM4fTWcAbE3RLOxLFWcCbwWALOxL9bv5lAQ+WbiTeCejOhh4k3E81Su5mwNtLNxLxXuZk4mLUPF263qIN12y3oMNl2izhctZmodqLNRB2u2UxEK8lmgtZlHe7u71NsJmoNc4X2FmwdVMUB7B0WzERs+y/M+0bA4iBtoytd1Udz3AoXxZSVWDPBR9JqJnyl5oZJNTNVeTkrpWZiDxFqJtY4Os1EHybTTDQLlWZCWoo0E3YkjWbC/xcSzXQvG4VmYnYJtNXj0nt0PSXQXvyNkmNfCDT30X394a78leevnowCbYkCzXN9d90h0AzRdumz29U65NntyuKWOjNUhaYaJs5eluuvxNl6tfmsztTFLnmmdRNqMlt35m5e4KuIPvZsDQVLfaYqNQQaflhJQDiHhs9gdGjgw0Sa8wCU4uTDamfmau623gGh100+DHZS6pRFS/dMPuzzwcjG5DX5MNO5tMmH6e+29LeKhhWvcQINUpDBB9JM/MmH9T2IZmrByYfBAok5fN8DaKaGxAR+8mGDDp6ZmnTyYXAmDjYtkw/T50QnH2ZzyMw0ysY4YmZiTz6sOoLe+2iZqSknHxarfyFqpXA668V/UXMmHwaNgWuF6TiZoWv1O0x2u/Lkw/Rhtv/HhyVUvsP/J1UH1VQQ9a/lyoNu7se/nAJb4eg5AAA=", "encoding": "utf-8"}, "headers": {"vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "x-github-media-type": "github.v3; param=full; format=json", "x-oauth-scopes": "gist, repo, user", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "x-accepted-oauth-scopes": "repo", "etag": "W/\"297a1659cea558ddd9f39d992544c186\"", "cache-control": "private, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "4973", "x-served-by": "474556b853193c38f1b14328ce2d1b7d", "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": "97E1C718:146C4:CA866EF:5651F442", "access-control-allow-credentials": "true", "last-modified": "Thu, 08 Oct 2015 19:57:33 GMT", "date": "Sun, 22 Nov 2015 16:58: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": "5000", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1448212583"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/itsmemattchung/github3.py"}, "recorded_at": "2015-11-22T16:58:42"}, {"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", "Authorization": "token <AUTH_TOKEN>"}, "method": "GET", "uri": "https://api.github.com/repos/itsmemattchung/github3.py/git/refs/heads/migrate-tests/git-integration-test"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA62OXQ6DIAzH78LzlIlKnLeprAjLEGLrgzHefbBdYEv20jTt/+N3iBWtGMsk6RDuJIOfV2CsGIlJzp4rvzCWm4/L+youYluf2eWYE41SQvJ1Frptqk0McsUUSXqmgAGYjduWuQTlf1unvaxZ81thnB5oWIyHIAe5+qpbZTUo7AdrG3VD0BYb3Q6d6UGbbjBKq0Z1mZX3hNmRyYL/C/snieTXDOf5AoILiMZoAQAA", "encoding": "utf-8"}, "headers": {"vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "x-github-media-type": "github.v3; param=full; format=json", "x-oauth-scopes": "gist, repo, user", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "x-accepted-oauth-scopes": "", "etag": "W/\"e585c4db5d6c5f23bb487f90d2ddc27c\"", "cache-control": "private, max-age=60, s-maxage=60", "x-poll-interval": "300", "status": "200 OK", "x-ratelimit-remaining": "4972", "x-served-by": "4c8b2d4732c413f4b9aefe394bd65569", "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": "97E1C718:146C4:CA86700:5651F442", "access-control-allow-credentials": "true", "last-modified": "Thu, 08 Oct 2015 19:57:33 GMT", "date": "Sun, 22 Nov 2015 16:58: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": "5000", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1448212583"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/itsmemattchung/github3.py/git/refs/heads/migrate-tests/git-integration-test"}, "recorded_at": "2015-11-22T16:58:42"}, {"request": {"body": {"string": "{\"sha\": \"b8bcee4db99325949c4171590b8fbcc8354d54d8\", \"force\": false}", "encoding": "utf-8"}, "headers": {"Content-Length": "67", "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", "Authorization": "token <AUTH_TOKEN> 10000 "}, "method": "PATCH", "uri": "https://api.github.com/repos/itsmemattchung/github3.py/git/refs/heads/migrate-tests/git-integration-test"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA61OXQ6DIAy+C89T5sQMvA1gFZahxNYHY7z7ynaBLVnSNM3X7+8QK4yiLxtlADugTHFaLUFFgIRyilTFmaBgcZnfqLiIbX2yKhBl7KW0OdZMDJur/ZLkCnlBGQkTJEvkwzZPxYj/bZ33cjLnt8DFPcCT6A+BwXK0084DqMEZ0946o4xXzb3pzNXp0Xmv204NPJq70p6BFdwsxb90/zih/LrDeb4AfUKXbWgBAAA=", "encoding": "utf-8"}, "headers": {"vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "x-github-media-type": "github.v3; param=full; format=json", "x-oauth-scopes": "gist, repo, user", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "x-accepted-oauth-scopes": "", "etag": "W/\"ca19f03884b12efde6f1bfaf0eac6b28\"", "cache-control": "private, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "4971", "x-served-by": "a241e1a8264a6ace03db946c85b92db3", "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": "97E1C718:146C4:CA86708:5651F442", "access-control-allow-credentials": "true", "date": "Sun, 22 Nov 2015 16:58:43 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": "5000", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1448212583"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/itsmemattchung/github3.py/git/refs/heads/migrate-tests/git-integration-test"}, "recorded_at": "2015-11-22T16:58:43"}], "recorded_with": "betamax/0.5.0"}

tests/integration/test_git.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Integration tests for Tree."""
1+
"""Integration tests for Git."""
22
import github3
33
from .helper import IntegrationHelper
44

@@ -15,3 +15,17 @@ def test_recurse(self):
1515
t = repository.tree('75b347329e3fc87ac78895ca1be58daff78872a1').recurse()
1616
assert isinstance(t.tree[0], github3.git.Hash)
1717
assert repr(t.tree[0]).startswith('<Hash')
18+
19+
20+
class TestReference(IntegrationHelper):
21+
22+
"""Integration tests for methods on the Reference class."""
23+
24+
def test_update(self):
25+
"""Show that user can update a reference."""
26+
self.token_login()
27+
cassette_name = self.cassette_name('update')
28+
with self.recorder.use_cassette(cassette_name):
29+
repository = self.gh.repository('itsmemattchung', 'github3.py')
30+
reference = repository.ref('heads/migrate-tests/git-integration-test')
31+
assert reference.update('b8bcee4db99325949c4171590b8fbcc8354d54d8') is True

tests/test_git.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

tests/unit/commit_example

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
3+
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
4+
"html_url": "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e",
5+
"comments_url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments",
6+
"commit": {
7+
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
8+
"author": {
9+
"name": "Monalisa Octocat",
10+
"email": "support@github.com",
11+
"date": "2011-04-14T16:00:49Z"
12+
},
13+
"committer": {
14+
"name": "Monalisa Octocat",
15+
"email": "support@github.com",
16+
"date": "2011-04-14T16:00:49Z"
17+
},
18+
"message": "Fix all the bugs",
19+
"tree": {
20+
"url": "https://api.github.com/repos/octocat/Hello-World/tree/6dcb09b5b57875f334f61aebed695e2e4193db5e",
21+
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
22+
},
23+
"comment_count": 0
24+
},
25+
"author": {
26+
"login": "octocat",
27+
"id": 1,
28+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
29+
"gravatar_id": "",
30+
"url": "https://api.github.com/users/octocat",
31+
"html_url": "https://github.com/octocat",
32+
"followers_url": "https://api.github.com/users/octocat/followers",
33+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
34+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
35+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
36+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
37+
"organizations_url": "https://api.github.com/users/octocat/orgs",
38+
"repos_url": "https://api.github.com/users/octocat/repos",
39+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
40+
"received_events_url": "https://api.github.com/users/octocat/received_events",
41+
"type": "User",
42+
"site_admin": false
43+
},
44+
"committer": {
45+
"login": "octocat",
46+
"id": 1,
47+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
48+
"gravatar_id": "",
49+
"url": "https://api.github.com/users/octocat",
50+
"html_url": "https://github.com/octocat",
51+
"followers_url": "https://api.github.com/users/octocat/followers",
52+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
53+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
54+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
55+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
56+
"organizations_url": "https://api.github.com/users/octocat/orgs",
57+
"repos_url": "https://api.github.com/users/octocat/repos",
58+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
59+
"received_events_url": "https://api.github.com/users/octocat/received_events",
60+
"type": "User",
61+
"site_admin": false
62+
},
63+
"parents": [
64+
{
65+
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
66+
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
67+
}
68+
],
69+
"stats": {
70+
"additions": 104,
71+
"deletions": 4,
72+
"total": 108
73+
},
74+
"files": [
75+
{
76+
"filename": "file1.txt",
77+
"additions": 10,
78+
"deletions": 2,
79+
"changes": 12,
80+
"status": "modified",
81+
"raw_url": "https://github.com/octocat/Hello-World/raw/7ca483543807a51b6079e54ac4cc392bc29ae284/file1.txt",
82+
"blob_url": "https://github.com/octocat/Hello-World/blob/7ca483543807a51b6079e54ac4cc392bc29ae284/file1.txt",
83+
"patch": "@@ -29,7 +29,7 @@\n....."
84+
}
85+
]
86+
}

tests/unit/reference_example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"ref": "refs/heads/featureA",
3+
"url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/featureA",
4+
"object": {
5+
"type": "commit",
6+
"sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
7+
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"
8+
}
9+
}

tests/unit/test_git.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
url_for = create_url_helper('https://api.github.com/repos/octocat/Hello-World/'
77
'trees/9fb037999f264ba9a7fc6274d15fa3ae2ab98312')
88

9+
reference_url_for = create_url_helper('https://api.github.com/repos/'
10+
'octocat/Hello-World/'
11+
'git/refs/heads/featureA')
12+
13+
get_commit_example_data = create_example_data_helper('commit_example')
14+
get_reference_example_data = create_example_data_helper('reference_example')
15+
916

1017
class TestTree(UnitHelper):
1118
"""Tree unit test"""
@@ -25,3 +32,57 @@ def test_recurse(self):
2532
url_for(),
2633
params={'recursive': '1'}
2734
)
35+
36+
37+
class TestCommit(UnitHelper):
38+
39+
"Commit unit test."""
40+
41+
described_class = github3.git.Commit
42+
example_data = get_commit_example_data()
43+
44+
def test_repr(self):
45+
assert repr(self.instance).startswith('<Commit')
46+
47+
def test_committer_as_User(self):
48+
"""Show that commit_as_User() returns instance of User."""
49+
user = self.instance.committer_as_User()
50+
assert isinstance(user, github3.users.User)
51+
52+
def test_author_as_User(self):
53+
"""Show that commit_as_Author() returns instance of User."""
54+
user = self.instance.author_as_User()
55+
assert isinstance(user, github3.users.User)
56+
57+
58+
class TestReference(UnitHelper):
59+
60+
"""Reference unit test."""
61+
62+
described_class = github3.git.Reference
63+
example_data = get_reference_example_data()
64+
65+
def test_delete(self):
66+
self.instance.delete()
67+
self.session.delete.assert_called_once_with(
68+
reference_url_for()
69+
)
70+
71+
def test_repr(self):
72+
assert repr(self.instance).startswith('<Reference')
73+
assert repr(self.instance.object).startswith('<Git Object')
74+
75+
def test_update(self):
76+
"""Show that a user can update the reference."""
77+
78+
self.instance.update('fakesha', True)
79+
try:
80+
self.session.patch.assert_called_once_with(
81+
reference_url_for(),
82+
data='{"force": true, "sha": "fakesha"}'
83+
)
84+
except AssertionError:
85+
self.session.patch.assert_called_once_with(
86+
reference_url_for(),
87+
data='{"sha": "fakesha", "force": true}'
88+
)

0 commit comments

Comments
 (0)
0