8000 Migrated git_commit, is_collaborator to unit/integration · kentr/github3.py@461d0e6 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 461d0e6

Browse files
Migrated git_commit, is_collaborator to unit/integration
Updated is_collaborator to require Authentication since I received a 401 error when I did not login and called method
1 parent 55ad745 commit 461d0e6

File tree

6 files changed

+62
-16
lines changed

6 files changed

+62
-16
lines changed

github3/repos/repo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,7 @@ def is_assignee(self, username):
12761276
url = self._build_url('assignees', str(username), base_url=self._api)
12771277
return self._boolean(self._get(url), 204, 404)
12781278

1279+
@requires_auth
12791280
def is_collaborator(self, username):
12801281
"""Check to see if ``username`` is a collaborator on this repository.
12811282
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/repos/sigmavirus24/github3.py"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA62YTY/iOBCG/wrKdWlMAkz3RBrN7Gl3b3PovewFOYkhVidxZDsgOur/vq/tfMFo+WjvBUFwPX5drnKq3AY8C+LVc7h8DsN5UNGSBXGw5zpvktWiPgXzYNcUxbb7Q/F9SQ9cNipak7NR4lgxGcRtUIg9r8CYDgXFTBOtly+r5TygB6qp3DaywLhc61rFhLiHauGojWIyFZVmlV6koiQNccbfD99WoO1lxzDYAA8uWDXvOM4YMEUuBOW6LC4kuKmtycXgnSgKcQTlUvStichgaTxpKbzaf5ICy5YInTP4Dkv6MI7gSj8uylq12ECltzwzHIUNkSx7WFhnB1lm/z9aIlktLLBJVCp5rbmoHhd4Zg2akHta8Xf6ORqsFSBG2uNSrBWs2QGx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m0FtXT2MlGRqBQtRYSsX0EZ1gT7a4aRXSaYs2H/8Clg2hwjETAAA=", "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/\"c10696a3231778f2b4d52d390ab74bac\"", "cache-control": "public, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "53", "x-served-by": "5aeb3f30c9e3ef6ef7bcbcddfd9a68f7", "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": "3F91CA23:B794:469F977:5694FB08", "access-control-allow-credentials": "true", "last-modified": "Sun, 10 Jan 2016 01:24:21 GMT", "date": "Tue, 12 Jan 2016 13:09:29 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": "1452604405"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py"}, "recorded_at": "2016-01-12T13:09:29"}, {"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/repos/sigmavirus24/github3.py/git/commits/9ea7482560c9e70c66019f7981aa1727caf888e0"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA72TTY/bIBBA/wpyr0kwGAP2qdKeethbT+1WqzEebEv+WsCtVlH+e3HcSOmhUqKsejOeYR7zBo6JbyEpkwJBCc1zmZoCVWqkTFlhVaEZAFNcGbBaa0yTXbK4Pm5oQ5h9SSnM3aHpQrtUBzMN1OE8eeq7ZoCfnVs8F3SLZof5ff2kMWvogqd3ENsw9K9/Y6+Q/4JtoHs4sIR2ckl5TEYYMDb5BUbyNLkavJli5zhAt/Z+Tfy8eHT+ME6x8/79SkXMryGsVXjK5D5le8a/pqLksmTZt+S0S7YDBvx/xOAwHuj4Z+aomZEV4yloYBK4yXgujE5rAMGR51oobZXNH5/5yvX0Zl50M6D30Kz2ntE1SOal74nDtwV9IJ/yTBHrpoHEizTEqYRg2mVsaIhRT4eucdH8/nwXX8aX8Xn7UROLv8iaQwx49FuJdf16TiVhOkc9PXZjwLVIN407soxdOEUJMzgcg0/K7xeDAorU6qySVinIhcUKjIRCSJ6DzJBnlTGQV+Jxg5dXcwfxoVdzM+e0u8jQnOVSGmmtQhZFqAIrK7XFTAAark2NSknBPk7GHcSHZNzMOf04/Qb8a2mUUQUAAA==", "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/\"89f2c3d394b744f77fde2a91d3f3db9d\"", "cache-control": "public, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "52", "x-served-by": "76d9828c7e4f1d910f7ba069e90ce976", "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": "3F91CA23:B794:469FA3F:5694FB09", "access-control-allow-credentials": "true", "last-modified": "Tue, 12 Jan 2016 04:26:13 GMT", "date": "Tue, 12 Jan 2016 13:09:29 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": "1452604405"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py/git/commits/9ea7482560c9e70c66019f7981aa1727caf888e0"}, "recorded_at": "2016-01-12T13:09:29"}], "recorded_with": "betamax/0.5.0"}
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/sigmavirus24/github3.py"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA62YTY/iOBCG/wrKdWlMAkz3RBrN7Gl3b3PovewFOYkhVidxZDsgOur/vq/tfMFo+WjvBUFwPX5drnKq3AY8C+LVc7h8DsN5UNGSBXGw5zpvktWiPgXzYNcUxbb7Q/F9SQ9cNipak7NR4lgxGcRtUIg9r8CYDgXFTBOtly+r5TygB6qp3DaywLhc61rFhLiHauGojWIyFZVmlV6koiQNccbfD99WoO1lxzDYAA8uWDXvOM4YMEUuBOW6LC4kuKmtycXgnSgKcQTlUvStichgaTxpKbzaf5ICy5YInTP4Dkv6MI7gSj8uylq12ECltzwzHIUNkSx7WFhnB1lm/z9aIlktLLBJVCp5rbmoHhd4Zg2akHta8Xf6ORqsFSBG2uNSrBWs2QGx+Li5M2tJLfmBpifjGslSxg9w9ieRF/Yg6lNt0vZvBIVxPddsS7PSpOGOFop9zAM7vcYg+2COrLs3+s/TPGPDrmLCnyedi2pW8ERSeZrthJxx5Kzc0RSxOjviGJkhXGd/cP1nk8x+//nXwWQvxr0NSq5mrnX+WTKeyzGkG3tyFYH0BACS3tjJi2PsW4LPLp9SpDpNhKRa3Do0rgs8A7Vk+tPEkma09BJuAQDlQvh50gIA4ko17K7Qvr5wy1Gkz5+qKRN35N2TNdfRjgCtVOGcrxjz8uAAaUl/KiMdqjT3w/aMlrhvdrfp3kuqsQcmKUTixcGLklhIS1RO3XtIb33VGaphnEEl23lLNYwBqqXnfluZBjIg8RLU2HovnT2DtJ1HC1rtG7r3ow4Q7Lp5Ve/p+80i5nrujBQgTYUmedL4H3Ijxyh1tQPy3c+lI2aE2oLkeplzwwGTwsa6oCz5rbrgOrFDnIX9/4A1cXqJNr9vlzG35RpGS8Yz2R36Hd3Hu92p3+ucztG1A14h0TNI+1tNdW5OLkxVU8l8RHcI0iYUxdZisWhzRm1ZXTLpmcGOABSVaY6q0Udn2zNQ9ZRU22p9Z2RmqN4LQTMv3w4QAN02+mh1hOn+1+hDvQRawJRY8oIpLSq/M3akTNmV0HzH03s6luvpdgZqvytepWxOi2KOqNU85Yhj1NpmF1FwMj8POQKWgWsA16kUDCHt5XXJHKMlrtNMJUMjkm2pRgMRLcPoabl6Clev4dd48xJvVv9gJU2dnY358rQMn8Ll6zLEHUIchWZM3ah8gnFDotcwitcvcbQ0Q3ACdiGIb7hiwCeuNX7p7ycthbk1gKFS+Wj4YzSL/+P+ozNLC8TSRdDfP+fh8rV02xRSc1GyGmVCd5MyrHJVnxbwdIb2KxOpWqAHJmZl/B1Dn1cbXMNMCoJUNBX2Y73+Og+OVKN2xat3+rAvJIamz0xN1dalaRBr2ZiuEk/GY2Dy8Mjf+Nh7YpSRrHoz18V104VfIpybXErR3RBVSFvcANSs6mYbhG1cKwmONZoMwVLwZ7+SbmEZ29Gm0FtXT2MlGRqBQtQmmJgssRRzV2HusKbNs4u0Xqo5Q9x3NNUV00f0j70eK2Jau3QrijYf/wILLfFfZxMAAA==", "encoding": "utf-8"}, "headers": {"vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "x-github-media-type": "github.v3; param=full; format=json", "x-oauth-scopes": "admin:public_key, gist, repo, user", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "x-accepted-oauth-scopes": "repo", "etag": "W/\"5cb2601c68da9f413b72cd92e191c9e5\"", "cache-control": "private, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "4998", "x-served-by": "e183f7c661b1bbc2c987b3c4dc7b04e0", "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": "3F91CA23:6394:28C0A4F:5694F886", "access-control-allow-credentials": "true", "last-modified": "Sun, 10 Jan 2016 01:24:21 GMT", "date": "Tue, 12 Jan 2016 12:58:46 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": "1452606964"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py"}, "recorded_at": "2016-01-12T12:58:47"}, {"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/sigmavirus24/github3.py/collaborators/itsmemattchung"}, "response": {"body": {"string": "", "encoding": null}, "headers": {"status": "204 No Content", "x-ratelimit-remaining": "4997", "x-github-media-type": "github.v3; param=full; format=json", "x-content-type-options": "nosniff", "content-security-policy": "default-src 'none'", "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-github-request-id": "3F91CA23:6394:28C0AA7:5694F886", "strict-transport-security": "max-age=31536000; includeSubdomains; preload", "vary": "Accept-Encoding", "server": "GitHub.com", "x-ratelimit-limit": "5000", "x-oauth-scopes": "admin:public_key, gist, repo, user", "x-served-by": "7b641bda7ec2ca7cd9df72d2578baf75", "access-control-allow-credentials": "true", "date": "Tue, 12 Jan 2016 12:58:47 GMT", "x-frame-options": "deny", "access-control-allow-origin": "*", "x-accepted-oauth-scopes": "", "x-xss-protection": "1; mode=block", "x-ratelimit-reset": "1452606964"}, "status": {"message": "No Content", "code": 204}, "url": "https://api.github.com/repos/sigmavirus24/github3.py/collaborators/itsmemattchung"}, "recorded_at": "2016-01-12T12:58:47"}], "recorded_with": "betamax/0.5.0"}

tests/integration/test_repos_repo.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,16 @@ def test_forks(self):
500500
for fork in forks:
501501
assert isinstance(fork, github3.repos.Repository)
502502

503+
def test_git_commit(self):
504+
"""Test the ability to retrieve a commit from a repository."""
505+
cassette_name = self.cassette_name('git_commit')
506+
with self.recorder.use_cassette(cassette_name):
507+
repository = self.gh.repository('sigmavirus24', 'github3.py')
508+
commit = repository.git_commit(
509+
'9ea7482560c9e70c66019f7981aa1727caf888e0'
510+
)
511+
assert isinstance(commit, github3.git.Commit)
512+
503513
def test_hooks(self):
504514
"""Test that a user can iterate over the hooks of a repository."""
505515
self.basic_login()
@@ -524,6 +534,17 @@ def test_ignore(self):
524534
subscription = repository.ignore()
525535
assert subscription.ignored is True
526536

537+
def test_is_collaborator(self):
538+
"""
539+
Test the ability to check if a user is a collaborator on a
540+
repository.
541+
"""
542+
self.token_login()
543+
cassette_name = self.cassette_name('is_collaborator')
544+
with self.recorder.use_cassette(cassette_name):
545+
repository = self.gh.repository('sigmavirus24', 'github3.py')
546+
assert repository.is_collaborator('itsmemattchung') is True
547+
527548
def test_issue_events(self):
528549
"""Test that a user can iterate over issue events in a repo."""
529550
cassette_name = self.cassette_name('issue_events')

tests/test_repos.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,6 @@ def setUp(self):
1515
self.repo = repos.Repository(self.repo.as_dict(), self.g)
1616
self.api = 'https://api.github.com/repos/sigmavirus24/github3.py/'
1717

18-
def test_is_collaborator(self):
19-
self.response('', 204)
20-
self.get(self.api + 'collabora 57AE tors/user')
21-
22-
assert self.repo.is_collaborator(None) is False
23-
self.not_called()
24-
assert self.repo.is_collaborator('user')
25-
self.mock_assertions()
26-
27-
def test_git_commit(self):
28-
self.response('git_commit')
29-
self.get(self.api + 'git/commits/fakesha')
30-
31-
assert isinstance(self.repo.git_commit('fakesha'), github3.git.Commit)
32-
self.mock_assertions()
33-
3418
def test_hook(self):
3519
self.response('hook')
3620
self.get(self.api + 'hooks/2')

tests/unit/test_repos_repo.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,36 @@ def test_file_contents(self):
526526
params={'ref': 'some-sha'}
527527
)
528528

529+
def test_git_commit_required_sha(self):
530+
"""Verify the request for retrieving a git commit from a repository."""
531+
self.instance.git_commit('')
532+
assert self.session.get.called is False
533+
534+
def test_git_commit(self):
535+
"""Verify the request for retrieving a git commit from a repository."""
536+
self.instance.git_commit('fake-sha')
537+
self.session.get.assert_called_once_with(
538+
url_for('git/commits/fake-sha')
539+
)
540+
541+
def test_is_collaborator_required_username(self):
542+
"""
543+
Verify the request for checking if a user is a collaborator on a
544+
repository.
545+
"""
546+
assert self.instance.is_collaborator('') is False
547+
assert self.session.get.called is False
548+
549+
def test_is_collaborator(self):
550+
"""
551+
Verify the request for checking if a user is a collaborator on a
552+
repository.
553+
"""
554+
self.instance.is_collaborator('octocat')
555+
self.session.get.assert_called_once_with(
556+
url_for('collaborators/octocat')
557+
)
558+
529559
def test_key(self):
530560
"""Test the ability to fetch a deploy key."""
531561
self.instance.key(10)
@@ -1075,6 +1105,14 @@ def test_edit(self):
10751105
with pytest.raises(GitHubError):
10761106
self.instance.edit(name='Hello')
10771107

1108+
def test_is_collaborator(self):
1109+
"""
1110+
Show that checking if a user is collaborator on a repository requires
1111+
authentication.
1112+
"""
1113+
with pytest.raises(GitHubError):
1114+
self.instance.is_collaborator('octocat')
1115+
10781116
def test_hooks(self):
10791117
"""Show that a user must be authenticated to list hooks."""
10801118
with pytest.raises(GitHubError):

0 commit comments

Comments
 (0)
0