Skip to content

Commit 07a2d73

Browse files
Migrated several test cases to tests/{unit/integration}
Added defensive check on delete Contents.delete Migrated test_delete to tests/{unit/integration}. The test is no longer marked as xfail. Removed test_repr and added test_str to tests/unit.
1 parent 4199f56 commit 07a2d73

File tree

5 files changed

+65
-25
lines changed

5 files changed

+65
-25
lines changed

github3/repos/contents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ def delete(self, message, branch=None, committer=None, author=None):
116116
'author': validate_commmitter(author)}
117117
self._remove_none(data)
118118
json = self._json(self._delete(self._api, data=dumps(data)), 200)
119-
if 'commit' in json:
119+
if json and 'commit' in json:
120120
json['commit'] = Commit(json['commit'], self)
121-
if 'content' in json:
121+
if json and 'content' in json:
122122
json['content'] = self._instance_or_null(Contents,
123123
json['content'])
124124
return json

tests/cassettes/Contents_delete.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/github3py/delete_contents"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA+2YzW7bOhCFX8XQ9rqmnbRuYaDofYO76aobg5JoiQglCiRlwyHy7j0k9WffILLDLAMEgSxxPh4NOdTM2ITnye7b+uuP7cPjepnUtGLJLsmZYIbtM1kbVhudLJNDK8S+e1pwU7bpY3Mm/x8nTzVTyc4mQha8BmoYDIiba/P9x8Pm23aZ0CM1VO1bJTCqNKbRO0LCTb0KVq1mqtOwymRFWtJZ/zr+fASvUB3EgRPcuII1vAMFa9A0meopTSWuBITHfvx05EEKIU+wv9b75hRkMHMe9AheF+9BwMwSaUoGh+E1XtzLc23ul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/8jZgbbC7EPCjj1VUW3QG0N5zlSFN0CaATE26Yr38C5u9/SS3bETrlHTTxsin/21rv/42V8bO6dvdyI/+2uX3V+kMRfNOYTl7f21mpkTWkeTM2FaknQnyublLz1XlkZdFwAA", "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/\"f4de1d3e6758ef37ba4c516ec79ec972\"", "cache-control": "private, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "4993", "x-served-by": "7b641bda7ec2ca7cd9df72d2578baf75", "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": "97E45D32:135D3:6A62232:56A8616D", "access-control-allow-credentials": "true", "last-modified": "Wed, 27 Jan 2016 06:16:46 GMT", "date": "Wed, 27 Jan 2016 06:19:25 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": "1453878422"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/github3py/delete_contents"}, "recorded_at": "2016-01-27T06:19:25"}, {"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/github3py/delete_contents/readme"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA7WSXWvCMBSG/0uuxfTDj1UYYzJXq3jjQFEESfNhuyZpaFJcJ/73pVPEybzQsYuQ8EKe95z3nB2QSFDQA9PB88tk0BQENIBCJrmQdIKs4gU+8pnHsO/Hvuch6nYZ85wAd1wHEUa7rS4h7TayDJ1+WuyD2wBlwe3XxBilexAilTY3qUnKuIlzAQuqcg0Pgq8qSCinhq5xLg2VRsPT41TfU0HZo0Da0MLaJEbw9U+HM/p1bszzGB4o8Lx1++MCd2PBFgBruIY3hEXyreQ5IhfWBdoesyo1LY5RfMd2vbFfejKVqifMUk5tYkeMFaKqny3nH5yEM7bwgtLeJRlOxrMwUbjq18dZzt1t7I8SLLimb30Xe7MsCkftlYxCokiYuIv3SYmH2WYpgioKeU2RWLw6aB6U0XDKsT9VscDjlbTmVOKcpHJj3WOkaadltTVPZaZBbwc05ez/VsVmdj/8rrHWy3lm+YfF3O+/AFUXR1upAwAA", "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": "", "etag": "W/\"e61c42dbb02e81cf5d49f612ab0304ea\"", "cache-control": "private, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "4992", "x-served-by": "d594a23ec74671eba905bf91ef329026", "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": "97E45D32:135D3:6A62260:56A8616D", "access-control-allow-credentials": "true", "last-modified": "Wed, 27 Jan 2016 06:16:46 GMT", "date": "Wed, 27 Jan 2016 06:19:26 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": "1453878422"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/github3py/delete_contents/readme"}, "recorded_at": "2016-01-27T06:19:25"}, {"request": {"body": {"string": "{\"sha\": \"293a3f2fc33b322ae17ff209c610adfe747dd55a\", \"message\": \"Deleting readme from repository\"}", "encoding": "utf-8"}, "headers": {"Content-Length": "97", "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": "DELETE", "uri": "https://api.github.com/repos/github3py/delete_contents/contents/README.md"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA7WSwU7DMAyGX2XKeaNJ2qRdT0hw5cYJhFCSOm2lpq0a9zChvTsOYxIckJgYt9iO8/l3/jfmphFhRFaP6zBsKQyhp+iNxc6wmlmjpNGCOyWVdCBkDhUvfSWtVuCgorJvQAi2ZesyUEOHOMc6y8zc37Q9dqu9oTezBeYpZqdEPh+yBgZAeP2kf1SyEztmFzA7DMPrd/AX6M+4E+oSklmxm5a0mNEEIKEPBnFz161jS9ohmD6p7zEGOiO6VLhtUzrppyuNwdQmudA7LnayfOS6Fvta6id2PC8e4R8RuABNcP7ZwlZSNU4X0lkNdm+45qAK66tG72VVeQtQ7HlxjZ9N5Jj9mkjrCBCjadPC7pNT+rHdLGCaABu/TIHOZKcep+VA481mIQdHVj+ftZVO6Ebk3goyqjLO5xSXUhjpSl7k3BtV+TxX19B2du0FzD+69tek48vx+A5O0iMi4gMAAA==", "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": "", "etag": "W/\"dee69476834ba2605db71846bd15f8b0\"", "cache-control": "private, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "4991", "x-served-by": "a474937f3b2fa272558fa6dc951018ad", "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": "97E45D32:135D3:6A62286:56A8616E", "access-control-allow-credentials": "true", "date": "Wed, 27 Jan 2016 06:19:26 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": "1453878422"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/github3py/delete_contents/contents/README.md"}, "recorded_at": "2016-01-27T06:19:25"}], "recorded_with": "betamax/0.5.0"}

tests/integration/test_repos_repo.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,3 +1050,19 @@ def test_weekly_commit_count(self):
10501050
assert isinstance(weekly_commit_count, dict)
10511051
assert len(weekly_commit_count.get('owner')) == 52
10521052
assert len(weekly_commit_count.get('all')) == 52
1053+
1054+
1055+
class TestContents(helper.IntegrationHelper):
1056+
1057+
"""Integration test for Contents object."""
1058+
1059+
def test_delete(self):
1060+
"""Test the ability to delete content from a repository."""
1061+
self.token_login()
1062+
cassette_name = self.cassette_name('delete')
1063+
with self.recorder.use_cassette(cassette_name):
1064+
repository = self.gh.repository('github3py', 'delete_contents')
1065+
content = repository.readme()
1066+
deleted = content.delete('Deleting readme from repository')
1067+
1068+
assert deleted

tests/test_repos.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,6 @@ def test_equality(self):
2121
contents.sha = 'fakesha'
2222
assert self.contents != contents
2323

24-
def test_repr(self):
25-
assert repr(self.contents) == '<Content [{0}]>'.format('README.rst')
26-
27-
@pytest.mark.xfail
28-
def test_delete(self):
29-
self.response('create_content', 200)
30-
self.delete(self.api)
31-
self.conf = {
32-
'data': {
33-
'message': 'foo',
34-
'sha': self.contents.sha,
35-
}
36-
}
37-
38-
self.assertRaises(github3.GitHubError, self.contents.delete, None)
39-
40-
self.not_called()
41-
self.login()
42-
43-
c = self.contents.delete('foo')
44-
assert isinstance(c, github3.git.Commit)
45-
self.mock_assertions()
46-
4724
@pytest.mark.xfail
4825
def test_update(self):
4926
self.response('create_content', 200)

tests/unit/test_repos_repo.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
from . import helper
1313

14+
contents_url_for = helper.create_url_helper(
15+
'https://api.github.com/repos/github3py/github3.py/contents/README.rst'
16+
)
1417
url_for = helper.create_url_helper(
1518
'https://api.github.com/repos/octocat/Hello-World'
1619
)
@@ -1529,10 +1532,53 @@ class TestContents(helper.UnitHelper):
15291532
described_class = Contents
15301533
example_data = content_example_data
15311534

1535+
def test_delete(self):
1536+
"""Verify the request for deleting content from a repository."""
1537+
data = {
1538+
'message': 'Deleting file from repository',
1539+
'branch': 'featureA',
1540+
'committer': {
1541+
'name': 'Octocat',
1542+
'email': 'octocat@github.com'
1543+
},
1544+
'author': {
1545+
'name': 'Octocat',
1546+
'email': 'octocat@github.com'
1547+
}
1548+
}
1549+
self.instance.delete(**data)
1550+
data.update({
1551+
'sha': '3f4f0b9a43d13376679ee5710958ca88baa7c421'
1552+
})
1553+
self.delete_called_with(
1554+
contents_url_for(),
1555+
data=data
1556+
)
1557+
15321558
def test_git_url(self):
15331559
"""Veriy instance contains git url."""
15341560
assert self.instance.links['git'] == self.instance.git_url
15351561

15361562
def test_html_url(self):
15371563
"""Verify instance contains html url."""
15381564
assert self.instance.links['html'] == self.instance.html_url
1565+
1566+
def test_str(self):
1567+
"""Verify that instance string is formatted properly."""
1568+
assert str(self.instance) == '<Content [{0}]>'.format(
1569+
self.instance.path
1570+
)
1571+
1572+
1573+
class TestContentsRequiresAuth(helper.UnitRequiresAuthenticationHelper):
1574+
1575+
"""Unit test for Content methods that require Auth."""
1576+
1577+
described_class = Contents
1578+
example_data = content_example_data
1579+
1580+
def test_delete(self):
1581+
"""
1582+
Show that deleting content from a repository requires authentication.
1583+
"""
1584+
self.assert_requires_auth(self.instance.delete)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy