8000 Add test for download feature on Release · pythonthings/github3.py@3865146 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3865146

Browse files
committed
Add test for download feature on Release
1 parent b7ca5a9 commit 3865146

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/test_repos.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,3 +951,50 @@ 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'))
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')

0 commit comments

Comments
 (0)
0