10000 Migrated create_status from test_repos to tests/{integration, unit}/t… · kentr/github3.py@821566c · GitHub
[go: up one dir, main page]

Skip to content

Commit 821566c

Browse files
Migrated create_status from test_repos to tests/{integration, unit}/test_repos_repo
Migrated delete from test_repos to tests/unit
1 parent 4a90f83 commit 821566c

File tree

4 files changed

+58
-25
lines changed

4 files changed

+58
-25
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", "Authorization": "token <AUTH_TOKEN>"}, "method": "GET", "uri": "https://api.github.com/repos/itsmemattchung/github3.py"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA+2by27jNhRAf8XQto5l2c7EMVBMu2q7m8V0041By7RFjF4gKQceIf/ee0nZeiSUZFFFN9oEiUweXVF83WMmd9jR2W3Wr97aW32ZOzGJqLNzzkwG2WG9SK/O3DllYbgvPmBSRDQiUvpBFp/dWrnkLabc2eVOmJxZDJR6YSDhvV7Wz1tvuZo75EIk4fuMh1A0kDIVO9fVF8VCgzNBuZ/EksZy4SeRm7lF7a+XX9fAO/MCgmAHLjRgKStAujbQhPshqEBGYSMKfXdV6UPxUxKGyRuQmpF338y918VWVRwWnwdzoG7uJjKg0IjwaO/YIEzIIYGpejm8TiH37IgkAe+G0+OA4IqaEBr2h/fc5TRNFDI7CJ+zVLIkHhJkrT7wEn4mMftJhvKgvgAMhjckHFUP6tMLdM8hAF0xd1POLsS/YhNx6lN2gWYfDG0QgCmvKQ7pv6GL4Etgku7JMcIBeiKhoO9zRwUgoZC6MIfB2H9E1KeAI72/Ybjlt6sMkngWsgMn/Do7JXzGYDDzE/Gh787eYJKZQfed/cHkn9lh9vu3vy44qqHcD2cneQahtA5o9QYaI7Q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hHVZB7ENraKa3SWirMfUcQVUrCHiTOH09vDGRAPWzgTx9rBmcBjGTgT/2H/ZgINtW8m3gjuzYQeZt5MNEvvZsLaWDcT81HnZuJg2j7cuLVRB/u2Nugw29ZGHO7aTFQ702aiDvdsJqKVZTNBq7YOt/ePOTYTtYIpob0NWwdVcQD7gAYzEZsCDBO/EbA4SJvom6/q4znawkUzZWXWTPCRvJoJf3Nzw6yamarEnJVTM7GHGDUTaxyfZqIPs2kmmoVLMyEtTZoJO5JHM+H/C4tmupeNQzMxuwza6mm5fvLWyqBtd89KfTUN2l2PeeAQdiuv3aBBkedNh0EzRNvlz9qrddiz9sqizZ0ZqkJTDTNnm+32M3O22bx+dGfqYpc907oJPdlD8kxXq7kz78sKvovoY882G32mA7SXqlQTaPjhzQLCQTR8BqNDAx8mkoz74BQnH1YoWDw0V5G31Q4IvW7yYbCTUscsGrpn8mEfT0bWJq/Jh5kOpk0+TH+5pb9WNKx4tSNokIIMPpFm4k8+rO9JNFMLTj4MFkjM4fueQDM1JCbwkw8bdPLM1KSTD4NDcbBpmXyYPig6+TCbU2amUTbGGTMTe/JhtzPovc+WmZpy8mGR+h+iRgqns178HzV38mHQGLhWmM6TGbpWv9Nk7ZUnH6ZPs/0/Piym8g3+Qel2UE0FUf1arjjo5r3/Cykh8WPpOQAA", "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/\"c6c7f040562df1aeb41ace2aed831085\"", "cache-control": "private, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "4997", "x-served-by": "a6882e5cd2513376cb9481dbcd83f3a2", "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": "BCDE0E10:6396:163F54D:5691CA5C", "access-control-allow-credentials": "true", "last-modified": "Thu, 08 Oct 2015 19:57:33 GMT", "date": "Sun, 10 Jan 2016 03:05:01 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": "1452396600"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/itsmemattchung/github3.py"}, "recorded_at": "2016-01-10T03:05:01"}, {"request": {"body": {"string": "{\"state\": \"failure\", \"context\": \"default\"}", "encoding": "utf-8"}, "headers": {"Content-Length": "42", "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": "POST", "uri": "https://api.github.com/repos/itsmemattchung/github3.py/statuses/24893ec07db2a12073703258f0089f105906d2e4"}, "response": {"body": {"string": "{\"url\":\"https://api.github.com/repos/itsmemattchung/github3.py/statuses/24893ec07db2a12073703258f0089f105906d2e4\",\"id\":410823651,\"state\":\"failure\",\"description\":null,\"target_url\":null,\"context\":\"default\",\"created_at\":\"2016-01-10T03:05:01Z\",\"updated_at\":\"2016-01-10T03:05:01Z\",\"creator\":{\"login\":\"itsmemattchung\",\"id\":7358102,\"avatar_url\":\"https://avatars.githubusercontent.com/u/7358102?v=3\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/itsmemattchung\",\"html_url\":\"https://github.com/itsmemattchung\",\"followers_url\":\"https://api.github.com/users/itsmemattchung/followers\",\"following_url\":\"https://api.github.com/users/itsmemattchung/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/itsmemattchung/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/itsmemattchung/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/itsmemattchung/subscriptions\",\"organizations_url\":\"https://api.github.com/users/itsmemattchung/orgs\",\"repos_url\":\"https://api.github.com/users/itsmemattchung/repos\",\"events_url\":\"https://api.github.com/users/itsmemattchung/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/itsmemattchung/received_events\",\"type\":\"User\",\"site_admin\":false}}", "encoding": "utf-8"}, "headers": {"content-length": "1231", "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": "", "etag": "\"042be0c2a808f0f754f1d3bdf507d339\"", "location": "https://api.github.com/repos/itsmemattchung/github3.py/statuses/24893ec07db2a12073703258f0089f105906d2e4", "cache-control": "private, max-age=60, s-maxage=60", "status": "201 Created", "x-ratelimit-remaining": "4996", "x-served-by": "cee4c0729c8e9147e7abcb45b9d69689", "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": "BCDE0E10:6396:163F579:5691CA5D", "access-control-allow-credentials": "true", "date": "Sun, 10 Jan 2016 03:05:01 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "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": "1452396600"}, "status": {"message": "Created", "code": 201}, "url": "https://api.github.com/repos/itsmemattchung/github3.py/statuses/24893ec07db2a12073703258f0089f105906d2e4"}, "recorded_at": "2016-01-10T03:05:01"}], "recorded_with": "betamax/0.5.0"}

tests/integration/test_repos_repo.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,19 @@ def test_create_release(self):
366366

367367
assert isinstance(release, github3.repos.release.Release)
368368

369+
def test_create_status(self):
370+
"""Test the ability to create a status object on a commit."""
371+
self.token_login()
372+
cassette_name = self.cassette_name('create_status')
373+
with self.recorder.use_cassette(cassette_name):
374+
repository = self.gh.repository('itsmemattchung', 'github3.py')
375+
status = repository.create_status(
376+
sha='24893ec07db2a12073703258f0089f105906d2e4',
377+
state='failure'
378+
)
379+
380+
assert isinstance(status, github3.repos.status.Status)
381+
369382
def test_create_tag(self):
370383
"""Test the ability to create an annotated tag on a repository."""
371384
self.basic_login()

tests/test_repos.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +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_create_status(self):
19-
self.response('status', 201)
20-
self.post(self.api + 'statuses/fakesha')
21-
self.conf = {'data': {'state': 'success'}}
22-
23-
self.assertRaises(github3.GitHubError, self.repo.create_status,
24-
'fakesha', 'success')
25-
26-
self.login()
27-
s = self.repo.create_status('fakesha', 'success')
28-
assert isinstance(s, repos.status.Status)
29-
assert repr(s) > ''
30-
self.mock_assertions()
31-
32-
def test_delete(self):
33-
self.response('', 204)
34-
self.delete(self.api[:-1])
35-
self.conf = {}
36-
37-
self.assertRaises(github3.GitHubError, self.repo.delete)
38-
39-
self.login()
40-
assert self.repo.delete()
41-
self.mock_assertions()
42-
4318
def test_delete_key(self):
4419
self.response('', 204)
4520
self.delete(self.api + 'keys/2')

tests/unit/test_repos_repo.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,37 @@ def test_create_ref_requires_a_truthy_sha(self):
344344

345345
assert self.session.post.called is False
346346

347+
def test_create_status(self):
348+
"""Verify the request for creating a status on a commit."""
349+
data = {
350+
'state': 'success',
351+
'target_url': 'foo',
352+
'description': 'bar',
353+
'context': 'default'
354+
}
355+
with helper.mock.patch.object(GitHubCore, '_remove_none') as rm_none:
356+
self.instance.create_status(sha='fake-sha', **data)
357+
rm_none.assert_called_once_with(data)
358+
self.post_called_with(
359+
url_for('statuses/fake-sha'),
360+
data=data
361+
)
362+
363+
def test_create_status_required_sha(self):
364+
"""Verify the request for creating a status on a commit."""
365+
self.instance.create_status(sha='', state='success')
366+
assert self.session.post.called is False
367+
368+
def test_create_status_required_state(self):
369+
"""Verify the request for creating a status on a commit."""
370+
self.instance.create_status(sha='fake-sha', state='')
371+
assert self.session.post.called is False
372+
373+
def test_create_status_required_sha_and_state(self):
374+
"""Verify the request for creating a status on a commit."""
375+
self.instance.create_status(sha='', state='')
376+
assert self.session.post.called is False
377+
347378
def test_create_tag_that_is_not_lightweight(self):
348379
"""Verify we can create an annotated tag."""
349380
self.instance.create_tag(
@@ -401,6 +432,12 @@ def test_create_tree_rejects_invalid_trees(self):
401432

402433
assert self.session.post.called is False
403434

435+
def test_delete(self):
436+
"""Verify the request for deleting a repository."""
437+
self.instance.delete()
438+
439+
assert self.session.delete.called is True
440+
404441
def test_directory_contents(self):
405442
"""Verify the request made to retrieve a directory's contents."""
406443
self.instance.directory_contents('path/to/directory')
@@ -961,6 +998,13 @@ def test_create_pull_from_issue(self):
961998
base='master'
962999
)
9631000

1001+
def test_create_status(self):
1002+
"""Verify the request for creating a status object on a commit."""
1003+
with pytest.raises(GitHubError):
1004+
self.instance.create_status(
1005+
sha='fake-sha'
1006+
)
1007+
9641008
def test_hooks(self):
9651009
"""Show that a user must be authenticated to list hooks."""
9661010
with pytest.raises(GitHubError):

0 commit comments

Comments
 (0)
0