Skip to content

Commit 9346bde

Browse files
committed
100% test coverage
1 parent f9e40be commit 9346bde

11 files changed

Lines changed: 105 additions & 24 deletions

File tree

HISTORY.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,20 @@ History/Changelog
99
- Add ``check_authorization`` to the ``GitHub class`` to cover the `new part
1010
of the API <http://developer.github.com/v3/oauth/#check-an-authorization>`_.
1111

12-
- Add ``Repository.iter_contributor_statistics``,
13-
``Repository.iter_commit_activity``,
12+
- Add ``create_file``, ``iter_contributor_statistics``,
13+
``iter_commit_activity``, ``iter_code_frequency`` and
14+
``weekly_commit_count``.
1415

1516
- The signature of ``Hook.edit`` has changed since that endpoint has changed
1617
as well. See:
1718
github/developer.github.com@b95f291a47954154a6a8cd7c2296cdda9b610164
1819

1920
- ``github3.GitHub`` can now be used as a context manager, e.g.,
2021
::
21-
22+
2223
with github.GitHub() as gh:
2324
u = gh.user('sigmavirus24')
2425

25-
- Switch from expecter to unittest2 (python 2.6 only) and standard unittest (
26-
in progress)
27-
2826
0.6.1: 2013-04-06
2927
-----------------
3028

github3/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ def __init__(self, commit, session):
288288
self.message = commit.get('message')
289289
#: List of parents to this commit.
290290
self.parents = commit.get('parents', [])
291+
#: URL to view the commit on GitHub
292+
self.html_url = commit.get('html_url', '')
291293
if not self.sha:
292294
i = self._api.rfind('/')
293295
self.sha = self._api[i + 1:]

github3/repos/repo.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,18 @@ def create_file(self, path, message, content, branch=None,
401401
json = None
402402
if path and message and content:
403403
url = self._build_url('contents', path, base_url=self._api)
404-
data = {'message': message, 'content': b64encode(content)}
404+
data = {'message': message, 'content': b64encode(content),
405+
'branch': branch}
405406
if committer and committer.get('name') and committer.get('email'):
406407
data.update(committer=committer)
407408
if author and author.get('name') and author.get('email'):
408409
data.update(author=author)
409410

411+
self._remove_none(data)
410412
json = self._json(self._put(url, data=dumps(data)), 201)
411-
return Contents(json, self) if json else None
413+
json['content'] = Contents(json['content'])
414+
json['commit'] = Commit(json['commit'], self)
415+
return json
412416

413417
@requires_auth
414418
def create_fork(self, organization=None):
@@ -867,8 +871,10 @@ def iter_code_frequency(self, number=-1, etag=None):
867871
iterator and check the new ``last_status`` attribute. If it
868872
is a 202 you should wait before re-requesting.
869873
874+
.. versionadded:: 0.7
875+
870876
"""
871-
url = self._build_url('stats', 'code_frequecy', base_url=self._api)
877+
url = self._build_url('stats', 'code_frequency', base_url=self._api)
872878
return self._iter(int(number), url, list, etag=etag)
873879

874880
def iter_comments(self, number=-1, etag=None):
@@ -913,6 +919,8 @@ def iter_commit_activity(self, number=-1, etag=None):
913919
iterator and check the new ``last_status`` attribute. If it
914920
is a 202 you should wait before re-requesting.
915921
922+
.. versionadded:: 0.7
923+
916924
"""
917925
url = self._build_url('stats', 'commit_activity', base_url=self._api)
918926
return self._iter(int(number), url, dict, etag=etag)
@@ -972,6 +980,8 @@ def iter_contributor_statistics(self, number=-1, etag=None):
972980
iterator and check the new ``last_status`` attribute. If it
973981
is a 202 you should wait before re-requesting.
974982
983+
.. versionadded:: 0.7
984+
975985
"""
976986
url = self._build_url('stats', 'contributors', base_url=self._api)
977987
return self._iter(int(number), url, ContributorStats, etag=etag)
@@ -1478,11 +1488,16 @@ def weekly_commit_count(self):
14781488
You should give the API a moment to compose the data and then re
14791489
-request it via this method.
14801490
1491+
..versionadded:: 0.7
1492+
14811493
"""
14821494
url = self._build_url('stats', 'participation', base_url=self._api)
14831495
resp = self._get(url)
14841496
if resp.status_code == 202:
14851497
return {}
14861498
json = self._json(resp, 200)
1487-
del(json['Etag'], json['Last-Modified'])
1499+
if json.get('ETag'):
1500+
del json['ETag']
1501+
if json.get('Last-Modified'):
1502+
del json['Last-Modified']
14881503
return json

test.py

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

test_iterator.py

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

tests/json/code_frequency

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[1302998400, 1124, -435]

tests/json/commit_activity

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"week": 1337472000, "total": 25, "days": [6, 4, 3, 5, 3, 2, 2]}

tests/json/contributor_statistics

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"weeks": [{"a": 0, "c": 0, "d": 0, "w": 1331424000}, {"a": 0, "c": 0, "d": 0, "w": 1332028800}, {"a": 0, "c": 0, "d": 0, "w": 1332633600}, {"a": 0, "c": 0, "d": 0, "w": 1333238400}, {"a": 0, "c": 0, "d": 0, "w": 1333843200}, {"a": 0, "c": 0, "d": 0, "w": 1334448000}, {"a": 0, "c": 0, "d": 0, "w": 1335052800}, {"a": 0, "c": 0, "d": 0, "w": 1335657600}, {"a": 0, "c": 0, "d": 0, "w": 1336262400}, {"a": 0, "c": 0, "d": 0, "w": 1336867200}, {"a": 0, "c": 0, "d": 0, "w": 1337472000}, {"a": 0, "c": 0, "d": 0, "w": 1338076800}, {"a": 0, "c": 0, "d": 0, "w": 1338681600}, {"a": 0, "c": 0, "d": 0, "w": 1339286400}, {"a": 0, "c": 0, "d": 0, "w": 1339891200}, {"a": 0, "c": 0, "d": 0, "w": 1340496000}, {"a": 0, "c": 0, "d": 0, "w": 1341100800}, {"a": 0, "c": 0, "d": 0, "w": 1341705600}, {"a": 0, "c": 0, "d": 0, "w": 1342310400}, {"a": 0, "c": 0, "d": 0, "w": 1342915200}, {"a": 0, "c": 0, "d": 0, "w": 1343520000}, {"a": 0, "c": 0, "d": 0, "w": 1344124800}, {"a": 49, "c": 1, "d": 45, "w": 1344729600}, {"a": 0, "c": 0, "d": 0, "w": 1345334400}, {"a": 0, "c": 0, "d": 0, "w": 1345939200}, {"a": 0, "c": 0, "d": 0, "w": 1346544000}, {"a": 0, "c": 0, "d": 0, "w": 1347148800}, {"a": 0, "c": 0, "d": 0, "w": 1347753600}, {"a": 0, "c": 0, "d": 0, "w": 1348358400}, {"a": 0, "c": 0, "d": 0, "w": 1348963200}, {"a": 0, "c": 0, "d": 0, "w": 1349568000}, {"a": 0, "c": 0, "d": 0, "w": 1350172800}, {"a": 0, "c": 0, "d": 0, "w": 1350777600}, {"a": 0, "c": 0, "d": 0, "w": 1351382400}, {"a": 0, "c": 0, "d": 0, "w": 1351987200}, {"a": 0, "c": 0, "d": 0, "w": 1352592000}, {"a": 0, "c": 0, "d": 0, "w": 1353196800}, {"a": 0, "c": 0, "d": 0, "w": 1353801600}, {"a": 0, "c": 0, "d": 0, "w": 1354406400}, {"a": 0, "c": 0, "d": 0, "w": 1355011200}, {"a": 0, "c": 0, "d": 0, "w": 1355616000}, {"a": 0, "c": 0, "d": 0, "w": 1356220800}, {"a": 0, "c": 0, "d": 0, "w": 1356825600}, {"a": 0, "c": 0, "d": 0, "w": 1357430400}, {"a": 0, "c": 0, "d": 0, "w": 1358035200}, {"a": 0, "c": 0, "d": 0, "w": 1358640000}, {"a": 0, "c": 0, "d": 0, "w": 1359244800}, {"a": 0, "c": 0, "d": 0, "w": 1359849600}, {"a": 0, "c": 0, "d": 0, "w": 1360454400}, {"a": 0, "c": 0, "d": 0, "w": 1361059200}, {"a": 0, "c": 0, "d": 0, "w": 1361664000}, {"a": 0, "c": 0, "d": 0, "w": 1362268800}, {"a": 0, "c": 0, "d": 0, "w": 1362873600}, {"a": 0, "c": 0, "d": 0, "w": 1363478400}, {"a": 0, "c": 0, "d": 0, "w": 1364083200}, {"a": 0, "c": 0, "d": 0, "w": 1364688000}, {"a": 0, "c": 0, "d": 0, "w": 1365292800}, {"a": 0, "c": 0, "d": 0, "w": 1365897600}, {"a": 0, "c": 0, "d": 0, "w": 1366502400}, {"a": 0, "c": 0, "d": 0, "w": 1367107200}, {"a": 0, "c": 0, "d": 0, "w": 1367712000}, {"a": 0, "c": 0, "d": 0, "w": 1368316800}], "total": 1, "author": {"following_url": "https://api.github.com/users/davelxmos/following{/other_user}", "events_url": "https://api.github.com/users/davelxmos/events{/privacy}", "organizations_url": "https://api.github.com/users/davelxmos/orgs", "url": "https://api.github.com/users/davelxmos", "gists_url": "https://api.github.com/users/davelxmos/gists{/gist_id}", "html_url": "https://github.com/davelxmos", "subscriptions_url": "https://api.github.com/users/davelxmos/subscriptions", "avatar_url": "https://secure.gravatar.com/avatar/141a5d39eb35f0fb9fd55fca63bacbc1?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", "repos_url": "https://api.github.com/users/davelxmos/repos", "received_events_url": "https://api.github.com/users/davelxmos/received_events", "gravatar_id": "141a5d39eb35f0fb9fd55fca63bacbc1", "starred_url": "https://api.github.com/users/davelxmos/starred{/owner}{/repo}", "login": "davelxmos", "type": "User", "id": 483686, "followers_url": "https://api.github.com/users/davelxmos/followers"}}

tests/json/create_content

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"content": {"name": "Makefile", "encoding": "base64", "url": "https://api.github.com/repos/sigmavirus24/github3.py/contents/Makefile", "html_url": "https://github.com/sigmavirus24/github3.py/blob/develop/Makefile", "content": "IyBNYWtlZmlsZSBmb3IgZ2l0aHViMy5weQojCiMgQ29weXJpZ2h0IDIwMTIs\nIElhbiBDb3JkYXNjbwoKQ09WRVJBR0VfSU5DTFVERSA6PSBnaXRodWIzLyou\ncHkKVEVTVF9SVU5ORVIgOj0gcnVuX3Rlc3RzLnB5CgpjbGVhbjoKCWdpdCBj\nbGVhbiAtWGRmCglybSAtcmYgYnVpbGQvIGRpc3QvCgp0cmF2aXM6CglweXRo\nb24gJChURVNUX1JVTk5FUikKCnRlc3RzOiB0cmF2aXMKCmRvY3M6CgltYWtl\nIC1DIGRvY3MvIGh0bWwK\n", "sha": "a90d97d108bd8d844dbf2b9cadd521d8b70f56f8", "_links": {"git": "https://api.github.com/repos/sigmavirus24/github3.py/git/blobs/a90d97d108bd8d844dbf2b9cadd521d8b70f56f8", "self": "https://api.github.com/repos/sigmavirus24/github3.py/contents/Makefile", "html": "https://github.com/sigmavirus24/github3.py/blob/develop/Makefile"}, "git_url": "https://api.github.com/repos/sigmavirus24/github3.py/git/blobs/a90d97d108bd8d844dbf2b9cadd521d8b70f56f8", "path": "Makefile", "type": "file", "size": 240}, "commit": {"committer": {"date": "2013-01-07T05:35:34Z", "email": "graffatcolmingov@gmail.com", "name": "Ian Cordasco"}, "author": {"date": "2013-01-07T05:35:34Z", "email": "graffatcolmingov@gmail.com", "name": "Ian Cordasco"}, "url": "https://api.github.com/repos/sigmavirus24/github3.py/git/commits/9923038a9521b57fb6e7729129783b6108ae9964", "tree": {"url": "https://api.github.com/repos/sigmavirus24/github3.py/git/trees/0d95629f911fc4a7e168c073876323e4474a423c", "sha": "0d95629f911fc4a7e168c073876323e4474a423c"}, "sha": "9923038a9521b57fb6e7729129783b6108ae9964", "parents": [{"url": "https://api.github.com/repos/sigmavirus24/github3.py/git/commits/092913d1dbf599205c1bb10e48220ab995d1818a", "sha": "092913d1dbf599205c1bb10e48220ab995d1818a"}], "message": "test_download\n\nAlso < 900 lines to test\n"}}

tests/json/weekly_commit_count

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"owner": [23, 22, 6, 21, 15, 21, 10, 59, 19, 29, 17, 9, 0, 17, 23, 30, 35, 39, 30, 45, 31, 25, 11, 7, 1, 16, 10, 10, 14, 16, 4, 2, 9, 28, 30, 33, 12, 26, 9, 18, 2, 4, 0, 8, 12, 14, 14, 4, 3, 2, 4, 3, 1], "all": [23, 22, 6, 21, 15, 21, 10, 61, 19, 29, 17, 9, 2, 17, 23, 32, 35, 39, 30, 65, 37, 25, 11, 11, 3, 20, 16, 11, 16, 21, 4, 2, 9, 32, 31, 33, 12, 32, 10, 18, 3, 6, 0, 11, 18, 28, 23, 4, 3, 7, 14, 3, 1]}

0 commit comments

Comments
 (0)