8000 100% coverage everywhere! · davidmoss/github3.py@444ca6f · GitHub
[go: up one dir, main page]

Skip to content

Commit 444ca6f

Browse files
committed
100% coverage everywhere!
1 parent 99d635b commit 444ca6f

File tree

7 files changed

+50
-22
lines changed

7 files changed

+50
-22
lines changed

github3/models.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ def _json(self, response, status_code):
9090
ret['ETag'] = response.headers.get('ETag', '')
9191
return ret
9292

93-
def _boolean(self, request, true_code, false_code):
94-
if request:
95-
status_code = request.status_code
93+
def _boolean(self, response, true_code, false_code):
94+
if response is not None:
95+
status_code = response.status_code
9696
if status_code == true_code:
9797
return True
9898
if status_code != false_code and status_code >= 400:
99-
raise GitHubError(request)
99+
raise GitHubError(response)
100100
return False
101101

102102
def _delete(self, url, **kwargs):
@@ -132,11 +132,11 @@ def _build_url(self, *args, **kwargs):
132132
return __url_cache__[key]
133133

134134
@property
135-
def api(self):
135+
def _api(self):
136136
return "{0.scheme}://{0.netloc}{0.path}".format(self._uri)
137137

138-
@api.setter
139-
def api(self, uri):
138+
@_api.setter
139+
def _api(self, uri):
140140
self._uri = urlparse(uri)
141141

142142
def _iter(self, count, url, cls, params=None, etag=None):
@@ -345,14 +345,14 @@ def __init__(self, resp):
345345
self.response = resp
346346
self.code = resp.status_code
347347
self.errors = []
348-
if resp.json(): # GitHub Error
348+
try:
349349
error = resp.json()
350350
#: Message associated with the error
351351
self.msg = error.get('message')
352352
#: List of errors provided by GitHub
353353
if error.get('errors'):
354354
self.errors = error.get('errors')
355-
else: # Amazon S3 error
355+
except: # Amazon S3 error
356356
self.msg = resp.content or '[No message]'
357357

358358
def __repr__(self):

github3/orgs.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ def __init__(self, org, session=None):
152152
#: Number of private repositories.
153153
self.private_repos = org.get('private_repos', 0)
154154

155-
def __repr__(self):
156-
return '<Organization [{0}:{1}]>'.format(self.login, self.name)
157-
158155
@requires_auth
159156
def add_member(self, login, team):
160157
"""Add ``login`` to ``team`` and thereby to this organization.

github3/users.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ def __init__(self, user, session=None):
120120
#: Which plan this user is on
121121
self.plan = Plan(user.get('plan', {}))
122122

123-
def __repr__(self):
124-
return '<User [{0}:{1}]>'.format(self.login, self.name)
125-
126123
def __str__(self):
127124
return self.login
128125

tests/json/gist_comment

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"files": {"gistfile1.txt": {"raw_url": "https://gist.github.com/raw/3623733/ba0e162e1c47469e3fe4b393a8bf8c569f302116/gistfile1.txt", "language": null, "filename": "gistfile1.txt", "content": "bar", "type": "text/plain", "size": 3}}, "commits_url": "https://api.github.com/gists/3623733/commits", "forks_url": "https://api.github.com/gists/3623733/forks", "description": "Testing github3.py edit", "url": "https://api.github.com/gists/3623733", "created_at": "2012-09-04T17:20:08Z", "comments_url": "https://api.github.com/gists/3623733/comments", "html_url": "https://gist.github.com/3623733", "comments": 1, "updated_at": "2012-09-08T03:14:57Z", "git_pull_url": "https://gist.github.com/3623733.git", "fork_of": null, "id": "3623733", "user": null, "owner": {"following_url": "https://api.github.com/users/sigmavirus24/following", "events_url": "https://api.github.com/users/sigmavirus24/events{/privacy}", "organizations_url": "https://api.github.com/users/sigmavirus24/orgs", "url": "https://api.github.com/users/sigmavirus24", "gists_url": "https://api.github.com/users/sigmavirus24/gists{/gist_id}", "subscriptions_url": "https://api.github.com/users/sigmavirus24/subscriptions", "avatar_url": "https://secure.gravatar.com/avatar/c148356d89f925e692178bee1d93acf7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", "repos_url": "https://api.github.com/users/sigmavirus24/repos", "received_events_url": "https://api.github.com/users/sigmavirus24/received_events", "gravatar_id": "c148356d89f925e692178bee1d93acf7", "starred_url": "https://api.github.com/users/sigmavirus24/starred{/owner}{/repo}", "login": "sigmavirus24", "type": "User", "id": 240830, "followers_url": "https://api.github.com/users/sigmavirus24/followers"}, "git_push_url": "https://gist.github.com/3623733.git", "forks": [], "public": true, "history": [{"url": "https://api.github.com/gists/3623733/18b44579c6cd37d868d10fa06c8bc46728c44b47", "change_status": {"deletions": 0, "additions": 0, "total": 0}, "committed_at": "2012-09-08T03:14:57Z", "version": "18b44579c6cd37d868d10fa06c8bc46728c44b47", "user": {"following_url": "https://api.github.com/users/sigmavirus24/following", "events_url": "https://api.github.com/users/sigmavirus24/events{/privacy}", "organizations_url": "https://api.github.com/users/sigmavirus24/orgs", "url": "https://api.github.com/users/sigmavirus24", "gists_url": "https://api.github.com/users/sigmavirus24/gists{/gist_id}", "subscriptions_url": "https://api.github.com/users/sigmavirus24/subscriptions", "avatar_url": "https://secure.gravatar.com/avatar/c148356d89f925e692178bee1d93acf7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", "repos_url": "https://api.github.com/users/sigmavirus24/repos", "received_events_url": "https://api.github.com/users/sigmavirus24/received_events", "gravatar_id": "c148356d89f925e692178bee1d93acf7", "starred_url": "https://api.github.com/users/sigmavirus24/starred{/owner}{/repo}", "login": "sigmavirus24", "type": "User", "id": 240830, "followers_url": "https://api.github.com/users/sigmavirus24/followers"}}, {"url": "https://api.github.com/gists/3623733/4a4cb8cfdda98870a15a5d30c59a2a0656bd2506", "change_status": {"deletions": 1, "additions": 1, "total": 2}, "committed_at": "2012-09-07T16:29:49Z", "version": "4a4cb8cfdda98870a15a5d30c59a2a0656bd2506", "user": {"following_url": "https://api.github.com/users/sigmavirus24/following", "events_url": "https://api.github.com/users/sigmavirus24/events{/privacy}", "organizations_url": "https://api.github.com/users/sigmavirus24/orgs", "url": "https://api.github.com/users/sigmavirus24", "gists_url": "https://api.github.com/users/sigmavirus24/gists{/gist_id}", "subscriptions_url": "https://api.github.com/users/sigmavirus24/subscriptions", "avatar_url": "https://secure.gravatar.com/avatar/c148356d89f925e692178bee1d93acf7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", "repos_url": "https://api.github.com/users/sigmavirus24/repos", "received_events_url": "https://api.github.com/users/sigmavirus24/received_events", "gravatar_id": "c148356d89f925e692178bee1d93acf7", "starred_url": "https://api.github.com/users/sigmavirus24/starred{/owner}{/repo}", "login": "sigmavirus24", "type": "User", "id": 240830, "followers_url": "https://api.github.com/users/sigmavirus24/followers"}}, {"url": "https://api.github.com/gists/3623733/64b1e8bd8552a865c94a3deedef4e14ac902842f", "change_status": {"deletions": 0, "additions": 0, "total": 0}, "committed_at": "2012-09-04T17:20:08Z", "version": "64b1e8bd8552a865c94a3deedef4e14ac902842f", "user": {"following_url": "https://api.github.com/users/sigmavirus24/following", "events_url": "https://api.github.com/users/sigmavirus24/events{/privacy}", "organizations_url": "https://api.github.com/users/sigmavirus24/orgs", "url": "https://api.github.com/users/sigmavirus24", "gists_url": "https://api.github.com/users/sigmavirus24/gists{/gist_id}", "subscriptions_url": "https://api.github.com/users/sigmavirus24/subscriptions", "avatar_url": "https://secure.gravatar.com/avatar/c148356d89f925e692178bee1d93acf7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", "repos_url": "https://api.github.com/users/sigmavirus24/repos", "received_events_url": "https://api.github.com/users/sigmavirus24/received_events", "gravatar_id": "c148356d89f925e692178bee1d93acf7", "starred_url": "https://api.github.com/users/sigmavirus24/starred{/owner}{/repo}", "login": "sigmavirus24", "type": "User", "id": 240830, "followers_url": "https://api.github.com/users/sigmavirus24/followers"}}, {"url": "https://api.github.com/gists/3623733/10f1b9b519632ba10e3c304afcdba48df1312968", "change_status": {"deletions": 0, "additions": 1, "total": 1}, "committed_at": "2012-09-04T17:19:03Z", "version": "10f1b9b519632ba10e3c304afcdba48df1312968", "user": null}]}
1+
{"body": "I was using curl, but this is awesome, too :)\r\n\r\n`curl -u <username> -XDELETE https://api.github.com/gists/<gist_id>/comments/<comment_id>`", "body_text": "I was using curl, but this is awesome, too :)\n\ncurl -u <username> -XDELETE https://api.github.com/gists/<gist_id>/comments/<comment_id>", "url": "https://api.github.com/gists/4321394/comments/655725", "created_at": "2012-12-17T19:56:05Z", "body_html": "<p>I was using curl, but this is awesome, too :)</p>\n\n<p><code>curl -u &lt;username&gt; -XDELETE https://api.github.com/gists/&lt;gist_id&gt;/comments/&lt;comment_id&gt;</code></p>", "updated_at": "2012-12-17T19:56:05Z", "user": {"following_url": "https://api.github.com/users/bradmontgomery/following", "events_url": "https://api.github.com/users/bradmontgomery/events{/privacy}", "organizations_url": "https://api.github.com/users/bradmontgomery/orgs", "url": "https://api.github.com/users/bradmontgomery", "gists_url": "https://api.github.com/users/bradmontgomery/gists{/gist_id}", "subscriptions_url": "https://api.github.com/users/bradmontgomery/subscriptions", "avatar_url": "https://secure.gravatar.com/avatar/d57aec10399cbb252bd890c2bb3fe1c9?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", "repos_url": "https://api.github.com/users/bradmontgomery/repos", "received_events_url": "https://api.github.com/users/bradmontgomery/received_events", "gravatar_id": "d57aec10399cbb252bd890c2bb3fe1c9", "starred_url": "https://api.github.com/users/bradmontgomery/starred{/owner}{/repo}", "login": "bradmontgomery", "type": "User", "id": 103113, "followers_url": "https://api.github.com/users/bradmontgomery/followers"}, "id": 655725}

tests/test_gists.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,27 @@ def test_history(self):
156156

157157

158158
class TestGistComment(BaseCase):
159-
def test(self):
160-
json = load('gist_comment')
161-
json['user'] = load('user')
162-
comment = github3.gists.GistComment(json)
163-
expect(repr(comment).startswith('<Gist Comment')).is_True()
159+
def __init__(self, methodName='runTest'):
160+
super(TestGistComment, self).__init__(methodName)
161+
self.comment = github3.gists.GistComment(load('gist_comment'))
162+
self.api = "https://api.github.com/gists/4321394/comments/655725"
163+
164+
def setUp(self):
165+
super(TestGistComment, self).setUp()
166+
self.comment = github3.gists.GistComment(self.comment.to_json(),
167+
self.g)
168+
169+
def test_edit(self):
170+
self.response('gist_comment', 200)
171+
self.patch(self.api)
172+
self.conf = {'data': {'body': 'body'}}
173+
174+
with expect.githuberror():
175+
self.comment.edit(None)
176+
177+
self.login()
178+
expect(self.comment.edit(None)).is_False()
179+
self.not_called()
180+
181+
expect(self.comment.edit('body')).is_True()
182+
self.mock_assertions()

tests/test_repos.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,19 @@ def setUp(self):
11601160
self.comment = github3.repos.RepoComment(self.comment.to_json(),
11611161
self.g)
11621162

1163+
def test_delete(self):
1164+
self.response('', 204)
1165+
self.delete(self.api)
1166+
1167+
with expect.githuberror():
1168+
self.comment.delete()
1169+
1170+
self.not_called()
1171+
self.login()
1172+
1173+
expect(self.comment.delete()).is_True()
1174+
self.mock_assertions()
1175+
11631176
def test_repr(self):
11641177
expect(repr(self.comment).startswith('<Repository Comment'))
11651178

tests/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from unittest import TestCase
99
from requests.structures import CaseInsensitiveDict
1010

11+
is_py3 = sys.version_info > (3, 0)
12+
1113

1214
def load(name):
1315
return json.load(path(name))
@@ -107,7 +109,7 @@ def response(self, path_name, status_code=200, enc='utf-8',
107109
if _iter:
108110
content = '[{0}]'.format(content)
109111
r.raw = BytesIO(content.encode())
110-
elif sys.version_info > (3, 0):
112+
elif is_py3:
111113
r.raw = BytesIO(content.encode())
112114
else:
113115
r.raw = BytesIO(content)

0 commit comments

Comments
 (0)
0