10000 Add new-style tests for Release#archive · pythonthings/github3.py@1dadd2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 1dadd2e

Browse files
committed
Add new-style tests for Release#archive
1 parent a4cd241 commit 1dadd2e

File tree

4 files changed

+42
-47
lines changed

4 files changed

+42
-47
lines changed

tests/cassettes/Release_archive.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/integration/test_repos_release.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66

77

88
class TestRelease(IntegrationHelper):
9+
def test_archive(self):
10+
"""Test the ability to download a release archive."""
11+
cassette_name = self.cassette_name('archive')
12+
with self.recorder.use_cassette(cassette_name,
13+
preserve_exact_body_bytes=True):
14+
repository = self.gh.repository('sigmavirus24', 'github3.py')
15+
release = repository.release(76677)
16+
_, filename = tempfile.mkstemp()
17+
release.archive('tarball', path=filename)
18+
19+
with open(filename, 'rb') as fd:
20+
assert len(fd.read(1024)) > 0
21+
22+
os.unlink(filename)
23+
924
def test_asset(self):
1025
"""Test the ability to retrieve a single asset from a release."""
1126
cassette_name = self.cassette_name('asset')

tests/test_repos.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -951,50 +951,3 @@ def test_download(self):
951951
self.response('', 404)
952952
self.request.side_effect = None
953953
assert self.asset.download() is False
954-
955-
956-
class TestRelease(BaseCase):
957-
def __init__(self, methodName='runTest'):
958-
super(TestRelease, self).__init__(methodName)
959-
self.release = repos.release.Release(load('release'))
10000
960-
961-
def test_archive(self):
962-
headers = {'content-disposition': 'filename=foo'}
963-
self.response('archive', 200, **headers)
964-
self.get('https://api.github.com/repos/sigmavirus24/github3.py/tarball/v0.7.1')
965-
self.conf.update({'stream': True})
966-
967-
assert self.release.archive(None) is False
968-
969-
assert os.path.isfile('foo') is False
970-
assert self.release.archive('tarball')
971-
assert os.path.isfile('foo')
972-
os.unlink('foo')
973-
self.mock_assertions()
974-
975-
self.request.return_value.raw.seek(0)
976-
self.request.return_value._content_consumed = False
977-
978-
assert os.path.isfile('path_to_file') is False
979-
assert self.release.archive('tarball', 'path_to_file')
980-
assert os.path.isfile('path_to_file')
981-
os.unlink('path_to_file')
982-
983-
self.request.return_value.raw.seek(0)
984-
self.request.return_value._content_consumed = False
985-
986-
self.get('https://api.github.com/repos/sigmavirus24/github3.py/zipball/v0.7.1')
987-
assert self.release.archive('zipball')
988-
os.unlink('foo')
989-
990-
self.request.return_value.raw.seek(0)
991-
self.request.return_value._content_consumed = False
992-
993-
o = mock.mock_open()
994-
with mock.patch('{0}.open'.format(__name__), o, create=True):
995-
with open('archive', 'wb+') as fd:
996-
self.release.archive('tarball', fd)
997-
998-
o.assert_called_once_with('archive', 'wb+')
999-
fd = o()
1000-
fd.write.assert_called_once_with(b'archive_data')

tests/unit/test_repos_release.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,32 @@ def test_has_upload_urlt(self):
4949
assert self.instance.upload_urlt is not None
5050

5151
# Method tests
52+
def test_tarball_archive(self):
53+
"""Verify that we generate the correct URL for a tarball archive."""
54+
self.instance.archive(format='tarball')
55+
56+
self.session.get.assert_called_once_with(
57+
'https://api.github.com/repos/octocat/Hello-World/tarball/v1.0.0',
58+
allow_redirects=True,
59+
stream=True
60+
)
61+
62+
def test_zipball_archive(self):
63+
"""Verify that we generate the correct URL for a zipball archive."""
64+
self.instance.archive(format='zipball')
65+
66+
self.session.get.assert_called_once_with(
67+
'https://api.github.com/repos/octocat/Hello-World/zipball/v1.0.0',
68+
allow_redirects=True,
69+
stream=True
70+
)
71+
72+
def test_unsupported_archive(self):
73+
"""Do not make a request if the archive format is unsupported."""
74+
self.instance.archive(format='clearly fake')
75+
76+
assert self.session.get.called is False
77+
5278
def test_delete(self):
5379
self.instance.delete()
5480
self.session.delete.assert_called_once_with(

0 commit comments

Comments
 (0)
0