10000 Migrated tests cases to tests/{unit, integration} · pythonthings/github3.py@4199f56 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4199f56

Browse files
Migrated tests cases to tests/{unit, integration}
Migrated test_test_weekly_commit_count to test/{unit/integration} Created tests/unit/content_example from test/json/readme. I tried to use the octocat/hello-world example data however the content attribute is not base64 encoded. Therefore, creating the instance would raise a b64decode exception. Migrated test_git_url and test_html_url to tests/unit
1 parent 35932cf commit 4199f56

File tree

6 files changed

+53
-45
lines changed

6 files changed

+53
-45
lines changed

github3/repos/repo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,12 +1935,12 @@ def weekly_commit_count(self):
19351935
"""
19361936
url = self._build_url('stats', 'participation', base_url=self._api)
19371937
resp = self._get(url)
1938-
if resp.status_code == 202:
1938+
if resp and resp.status_code == 202:
19391939
return {}
19401940
json = self._json(resp, 200)
1941-
if json.get('ETag'):
1941+
if json and json.get('ETag'):
19421942
del json['ETag']
1943-
if json.get('Last-Modified'):
1943+
if json and json.get('Last-Modified'):
19441944
del json['Last-Modified']
19451945
return json
19461946

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+jOBCG/0rEddNxIOlOD9JoZk+7e5vD7GUvkQEnWA0Y2SZRGvV/39c2EMho89HeS5QQ1+PXZVdR5TbgWRCvNuFyE4bzoKIlC+Jgz3XeJKtFfQrmwa4pim33h+L7kh64bFS0JpNR4lgxGcRtUIg9r8AYDwXFTBOtl6+r5TygB6qp3DaywLhc61rFhLiHauGojWI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Iun/Ow+W77rYppOaiZDVqj+56Zljlqj4t4OkMPV0mUrVAY03Myvg7hm7Wr+tJlZGKpsJ+rF+ieXCkGgUx3ufjh311MnSSZmqqti72g1jLxrSqeHLOLaOHR/7Gzw0tRhnJqjdzrWE3XfiyQTLmUoru2qlCLsC1Qs2qbrZB2BfXn4JjjUZDsBT82a+kW1jGdrQp9NYV6VhJhu6iEDWWUjF9RHvZky1uXNp02qLNx79dsvZ8hhMAAA==", "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/\"eea9c6b902a54f69403bc3d31368cf6e\"", "cache-control": "public, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "59", "x-served-by": "ef96c2e493b28ffea49b891b085ed2dd", "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:2075:91E4D0A:56A71B85", "access-control-allow-credentials": "true", "last-modified": "Mon, 25 Jan 2016 14:32:21 GMT", "date": "Tue, 26 Jan 2016 07:08:53 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": "1453795733"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py"}, "recorded_at": "2016-01-26T07:08:53"}, {"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/stats/participation"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA01Ouw6DQAz7l5s9kIS7cv2VioGhGyoSS4eq/147FAlFcp6O/SnLupb7Y4BjhBmTypq5cjRkbxmNNU8iVxzy+lgLzwjub7BAR/CgwyZ9dnhDOFcBZ89PbUbZ3q/nftU3aTCkH399zRQSJps4EuXyKnxaSWOToFNNDJo9yI3EOn9/ovZ2SfUAAAA=", "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/\"2f25f55f3c8deb081262470b972b3304\"", "cache-control": "public, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "58", "x-served-by": "a7f8a126c9ed3f1c4715a34c0ddc7290", "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:2075:91E4D3D:56A71B85", "access-control-allow-credentials": "true", "date": "Tue, 26 Jan 2016 07:08:53 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": "1453795733"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py/stats/participation"}, "recorded_at": "2016-01-26T07:08:53"}], "recorded_with": "betamax/0.5.0"}

tests/integration/test_repos_repo.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,3 +1036,17 @@ def test_tree(self):
10361036
tree = repository.tree('52a3f30e05cf434285e775979f01f1a8355049a7')
10371037

10381038
assert isinstance(tree, github3.git.Tree)
1039+
1040+
def test_weekly_commit_count(self):
1041+
"""
1042+
Test the ability to retrieve the weekly commit count on a
1043+
repository.
1044+
"""
1045+
cassette_name = self.cassette_name('weekly_commit_count')
1046+
with self.recorder.use_cassette(cassette_name):
1047+
repository = self.gh.repository('sigmavirus24', 'github3.py')
1048+
weekly_commit_count = repository.weekly_commit_count()
1049+
1050+
assert isinstance(weekly_commit_count, dict)
1051+
assert len(weekly_commit_count.get('owner')) == 52
1052+
assert len(weekly_commit_count.get('all')) == 52

tests/test_repos.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,6 @@
44
from github3 import repos
55
from tests.utils import (BaseCase, load, mock)
66

7-
8-
class TestRepository(BaseCase):
9-
def __init__(self, methodName='runTest'):
10-
super(TestRepository, self).__init__(methodName)
11-
self.repo = repos.Repository(load('repo'))
12-
13-
def setUp(self):
14-
super(TestRepository, self).setUp()
15-
self.repo = repos.Repository(self.repo.as_dict(), self.g)
16-
self.api = 'https://api.github.com/repos/sigmavirus24/github3.py/'
17-
18-
def test_repr(self):
19-
assert repr(self.repo) == '<Repository [sigmavirus24/github3.py]>'
20-
21-
22-
def test_equality(self):
23-
assert self.repo == repos.Repository(load('repo'))
24-
25-
def test_weekly_commit_count(self):
26-
self.response('weekly_commit_count', ETag='"foobarbogus"')
27-
self.request.return_value.headers['Last-Modified'] = 'foo'
28-
self.get(self.api + 'stats/participation')
29-
30-
w = self.repo.weekly_commit_count()
31-
self.assertTrue(w.get('owner') is not None)
32-
self.assertTrue(w.get('all') is not None)
33-
34-
self.mock_assertions()
35-
36-
self.response('', 202)
37-
w = self.repo.weekly_commit_count()
38-
self.assertEqual(w, {})
39-
self.mock_assertions()
40-
41-
427
class TestContents(BaseCase):
438
def __init__(self, methodName='runTest'):
449
super(TestContents, self).__init__(methodName)
@@ -56,12 +21,6 @@ def test_equality(self):
5621
contents.sha = 'fakesha'
5722
assert self.contents != contents
5823

59-
def test_git_url(self):
60-
assert self.contents.links['git'] == self.contents.git_url
61-
62-
def test_html_url(self):
63-
assert self.contents.links['html'] == self.contents.html_url
64-
6524
def test_repr(self):
6625
assert repr(self.contents) == '<Content [{0}]>'.format('README.rst')
6726

tests/unit/json/content_example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name": "README.rst", "encoding": "base64", "url": "https://api.github.com/repos/github3py/github3.py/contents/README.rst?ref=master", "html_url": "https://github.com/github3py/github3.py/blob/master/README.rst", "content": "Z2l0aHViMy5weQo9PT09PT09PT09CgouLiBpbWFnZTo6CiAgICBodHRwczov\nL3NlY3VyZS50cmF2aXMtY2kub3JnL3NpZ21hdmlydXMyNC9naXRodWIzLnB5\nLnBuZz9icmFuY2g9bW9jawogICAgOmFsdDogQnVpbGQgU3RhdHVzCiAgICA6\ndGFyZ2V0OiBodHRwOi8vdHJhdmlzLWNpLm9yZy9zaWdtYXZpcnVzMjQvZ2l0\naHViMy5weQoKLi4gaW1hZ2U6OiBodHRwczovL3B5cGlwLmluL2QvZ2l0aHVi\nMy5weS9iYWRnZS5wbmcKICAgIDphbHQ6IERvd25sb2FkcwogICAgOnRhcmdl\ndDogaHR0cHM6Ly9jcmF0ZS5pby9wYWNrYWdlcy9naXRodWIzLnB5CgpnaXRo\ndWIzLnB5IGlzIGEgY29tcHJlaGVuc2l2ZSwgYWN0aXZlbHkgZGV2ZWxvcGVk\nIGFuZCBleHRyYW9yZGluYXJpbHkgc3RhYmxlIAp3cmFwcGVyIGFyb3VuZCB0\naGUgR2l0SHViIEFQSSAodjMpLgoKU2VlIEhJU1RPUlkucnN0IGZvciBhbnkg\nImJyZWFraW5nIiBjaGFuZ2VzLgoKSW5zdGFsbGF0aW9uCi0tLS0tLS0tLS0t\nLQoKOjoKCiAgICAkIHBpcCBpbnN0YWxsIGdpdGh1YjMucHkKCkRlcGVuZGVu\nY2llcwotLS0tLS0tLS0tLS0KCi0gcmVxdWVzdHNfICBieSBLZW5uZXRoIFJl\naXR6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v\ncmcvZW4vbGF0ZXN0L2luZGV4Lmh0bWwjbW9yZS1leGFtcGxlcwoKVGVzdGlu\nZwp+fn5+fn5+CgpJbnN0YWxsIHRoZSBkZXBlbmRlbmNpZXMgZnJvbSByZXF1\naXJlbWVudHMudHh0IGUuZy46Cgo6OgoKICAgIHBpcCBpbnN0YWxsIC1yIHJl\ncXVpcmVtZW50cy50eHQKICAgICMgb3IgbWFrZSB0ZXN0LWRlcHMKCjo6Cgog\nICAgbWFrZSB0ZXN0cwoKQXV0aG9yCi0tLS0tLQoKSWFuIENvcmRhc2NvIChz\naWdtYXZpcnVzMjQpCgpDb250YWN0IE9wdGlvbnMKLS0tLS0tLS0tLS0tLS0t\nCgotIEl0IGlzIHByZWZlcnJlZCB0aGF0IHlvdSBzZW5kIGFuIGVtYWlsIHRv\nIGdpdGh1YjMucHlAbGlicmVsaXN0LmNvbQotIFlvdSBtYXkgYWxzbyBjb250\nYWN0ICh2aWEgZW1haWwpIHRoZSBhdXRob3IgZGlyZWN0bHkgd2l0aCAKICBx\ndWVzdGlvbnMvc3VnZ2VzdGlvbnMvY29tbWVudHMK\n", "sha": "3f4f0b9a43d13376679ee5710958ca88baa7c421", "_links": {"self": "https://api.github.com/repos/github3py/github3.py/contents/README.rst?ref=master", "git": "https://api.github.com/repos/github3py/github3.py/git/blobs/3f4f0b9a43d13376679ee5710958ca88baa7c421", "html": "https://github.com/github3py/github3.py/blob/master/README.rst"}, "git_url": "https://api.github.com/repos/github3py/github3.py/git/blobs/3f4f0b9a43d13376679ee5710958ca88baa7c421", "path": "README.rst", "type": "file", "size": 1785}

tests/unit/test_repos_repo.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from base64 import b64encode
77
from github3 import GitHubError
88
from github3.null import NullObject
9-
from github3.repos.repo import Repository
9+
from github3.repos.repo import Repository, Contents
1010
from github3.models import GitHubCore
1111

1212
from . import helper
@@ -18,9 +18,13 @@
1818
get_repo_example_data = helper.create_example_data_helper(
1919
'repos_repo_example'
2020
)
21+
get_content_example_data = helper.create_example_data_helper(
22+
'content_example'
23+
)
2124
create_file_contents_example_data = helper.create_example_data_helper(
2225
'create_file_contents_example'
2326
)
27+
content_example_data = get_content_example_data()
2428
create_file_contents_example_data = create_file_contents_example_data()
2529
repo_example_data = get_repo_example_data()
2630

@@ -919,6 +923,20 @@ def test_tree_required_sha(self):
919923

920924
assert self.session.get.called is False
921925

926+
def test_str(self):
927+
"""Verify instance string is formatted correctly."""
928+
owner = self.instance.owner
929+
repository = self.instance.name
930+
assert str(self.instance) == '{0}/{1}'.format(owner, repository)
931+
932+
def test_weekly_commit_count(self):
933+
"""Verify the request for retrieving total commit counts."""
934+
self.instance.weekly_commit_count()
935+
936+
self.session.get.assert_called_once_with(
937+
url_for('stats/participation')
938+
)
939+
922940

923941
class TestRepositoryIterator(helper.UnitIteratorHelper):
924942

@@ -1503,3 +1521,18 @@ def test_teams(self):
15031521
"""Show that a user must be authenticated to list teams on a repo."""
15041522
with pytest.raises(GitHubError):
15051523
self.instance.teams()
1524+
1525+
1526+
class TestContents(helper.UnitHelper):
1527+
"Unit tests for content methods."""
1528+
1529+
described_class = Contents
1530+
example_data = content_example_data
1531+
1532+
def test_git_url(self):
1533+
"""Veriy instance contains git url."""
1534+
assert self.instance.links['git'] == self.instance.git_url
1535+
1536+
def test_html_url(self):
1537+
"""Verify instance contains html url."""
1538+
assert self.instance.links['html'] == self.instance.html_url

0 commit comments

Comments
 (0)
0