Commit 15ff4c46 authored by Florian Pritz's avatar Florian Pritz
Browse files

Handle file upload results individually per file


Signed-off-by: Florian Pritz's avatarFlorian Pritz <bluewind@xinu.at>
parent f2aea6a2
......@@ -39,7 +39,43 @@ class TestUploader(unittest.TestCase):
'./test-data/archive/packages/f/fb-client/fb-client-2.0.4-1-any.pkg.tar.xz.sig',],
metadata=mock.ANY)
def test_upload_pkg_error(self):
mock_uploader = MagicMock()
app = upload_pkg_internetarchive.ArchiveUploader(mock_uploader,
DB.DB(':memory:'))
response_ok = MagicMock(status_code=200)
response_error = MagicMock(status_code=500)
mock_uploader.upload.side_effect = [
[response_ok, response_ok, response_error, response_ok]
]
self.assertFalse(app.db.exists('fb-client-2.0.4-1-any.pkg.tar.xz'))
self.assertFalse(app.db.exists('fb-client-2.0.3-2-any.pkg.tar.xz'))
app.main('./test-data/archive/packages/f/fb-client')
mock_uploader.upload.assert_called_once_with('archlinux_pkg_fb-client',
files=['./test-data/archive/packages/f/fb-client/fb-client-2.0.3-2-any.pkg.tar.xz',
'./test-data/archive/packages/f/fb-client/fb-client-2.0.3-2-any.pkg.tar.xz.sig',
'./test-data/archive/packages/f/fb-client/fb-client-2.0.4-1-any.pkg.tar.xz',
'./test-data/archive/packages/f/fb-client/fb-client-2.0.4-1-any.pkg.tar.xz.sig',],
metadata=mock.ANY)
self.assertFalse(app.db.exists('fb-client-2.0.4-1-any.pkg.tar.xz'))
self.assertTrue(app.db.exists('fb-client-2.0.3-2-any.pkg.tar.xz'))
mock_uploader.reset_mock()
mock_uploader.upload.side_effect = [[response_ok]]
app.main('./test-data/archive/packages/f/fb-client')
mock_uploader.upload.assert_called_once_with('archlinux_pkg_fb-client',
files=['./test-data/archive/packages/f/fb-client/fb-client-2.0.4-1-any.pkg.tar.xz'],
metadata=mock.ANY)
self.assertTrue(app.db.exists('fb-client-2.0.4-1-any.pkg.tar.xz'))
self.assertTrue(app.db.exists('fb-client-2.0.3-2-any.pkg.tar.xz'))
if __name__ == '__main__':
unittest.main()
......@@ -70,16 +70,16 @@ class ArchiveUploader:
#print(metadata)
try:
res = self.ia.upload(identifier, files=files, metadata=metadata)
if all([x.status_code == 200 for x in res]):
for f in files:
file_status = zip(files, res)
for status in file_status:
f = status[0]
code = status[1].status_code
if code == 200:
filename = os.path.basename(f)
self.db.add_file(filename)
else:
ok = len([x for x in res if x.status_code == 200])
nok = len([x for x in res if x.status_code != 200])
codes = set([x.status_code for x in res])
print("{}: only {}/{} files uploaded, status codes: {}".format(identifier, ok, ok+nok, codes), file=sys.stderr)
print(directory)
else:
print("Upload failed with status code '{}' for directory '{}' and file: {}"
.format(code, directory, f))
except Exception as e:
print("{}: exception raised".format(identifier), file=sys.stderr)
print(e, file=sys.stderr)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment