def test_upload_called_before_run(self): self.mock_data['uploads'] = MagicMock() self.instantiate() calls = [ call.upload(ANY, ANY, ANY), call.run(self.plugin_id, self.run_id, ANY) ] self.mock_host.assert_has_calls(calls)
def test_with_large_file(self, fake): data = fake.binary() mime_type = fake.mime_type() chunk_size = fake.random_int(len(data) // 20, len(data) // 2) document = Document( self.client, { 'uri': 'https://rest.interfax.net/outbound/documents/{0}'.format( fake.random_number()) }) self.client.documents.create.return_value = document with patch('interfax.files.uuid4') as m: m.return_value = UUID('8fbaaaaf-87bb-4bd0-9d82-823c3eb38e49') f = File(self.client, data, mime_type=mime_type, chunk_size=chunk_size) assert f.headers == {'Content-Location': document.uri} assert f.mime_type is None assert f.body is None assert f.file_tuple() == (None, '', None, { 'Content-Location': document.uri }) filename = 'upload-8fbaaaaf-87bb-4bd0-9d82-823c3eb38e49{0}'.format( guess_extension(mime_type)) calls = [call.create(filename, len(data))] cursor = 0 while cursor < len(data): chunk = data[cursor:cursor + chunk_size] calls.append( call.upload(document.id, cursor, cursor + len(chunk) - 1, chunk)) cursor += len(chunk) self.client.documents.assert_has_calls(calls)
def test_upload_call_ok(caplog, store_mock): """Simple upload, success result.""" caplog.set_level(logging.INFO, logger="charmcraft.commands") store_response = Uploaded(ok=True, status=200, revision=7) store_mock.upload.return_value = store_response args = Namespace(charm_file='whatever-cmd-arg') with patch('charmcraft.commands.store.UploadCommand._discover_charm') as mock_discover: mock_discover.return_value = ('discovered-name', 'discovered-path') UploadCommand('group').run(args) # check it called self discover helper with correct args mock_discover.assert_called_once_with('whatever-cmd-arg') assert store_mock.mock_calls == [ call.upload('discovered-name', 'discovered-path') ] expected = "Revision 7 of 'discovered-name' created" assert [expected] == [rec.message for rec in caplog.records]
async def test_submit_calls_methods_and_callbacks_in_correct_order( job, mocker): mocks = Mock() mocks.attach_mock(job._tracker.login, 'login') mocks.attach_mock(job._tracker.logout, 'logout') mocks.attach_mock(job._tracker.upload, 'upload') job.signal.register('logging_in', mocks.logging_in_cb) job.signal.register('logged_in', mocks.logged_in_cb) job.signal.register('uploading', mocks.uploading_cb) job.signal.register('uploaded', mocks.uploaded_cb) job.signal.register('logging_out', mocks.logging_out_cb) job.signal.register('logged_out', mocks.logged_out_cb) await job._submit() assert mocks.method_calls == [ call.logging_in_cb(), call.login(), call.logged_in_cb(), call.uploading_cb(), call.upload(job._tracker_jobs), call.uploaded_cb(), call.logging_out_cb(), call.logout(), call.logged_out_cb(), ]