def test_send_not_configured_properly(mocker): """Should fail without config file.""" mocker.patch("builtins.open", side_effect=FileNotFoundError) with pytest.raises(FileNotFoundError): transfer.send([], dict(filename="this.yaml", path=Path("/doesnt/exist")), 0)
def test_send_no_client(mocker): """Should re-raise exception if config is not parseable.""" mocked_s3_fs = mocker.patch("solgate.transfer.S3FileSystem") mocked_s3_fs.from_config_file.side_effect = ValueError with pytest.raises(ValueError): transfer.send([], {}, 0)
def test_send_no_key(mocker, file_list, mocked_solgate_s3_file_system, exception): """Should fail to transfer files where the key is missing.""" mocker.patch("solgate.transfer._transfer_single_file") with pytest.raises(exception): transfer.send(file_list, {})
def test_send_unable_to_transfer(mocker, mocked_solgate_s3_file_system): """Should log failures.""" mocker.patch("solgate.transfer._transfer_single_file", return_value=False) with pytest.raises(IOError) as e: transfer.send([dict(relpath="a/b/file.csv")], {}) assert e.args[1] == dict(failed_files=[dict(relpath="a/b/file.csv")])
def test_send(mocker, file_list, dry_run, mocked_solgate_s3_file_system): """Should request files to be sent to clients.""" mocked_transfer_single_file = mocker.patch( "solgate.transfer._transfer_single_file") transfer.send(file_list, {}, dry_run) for f in file_list: mocked_transfer_single_file.assert_any_call( f["key"], [mocked_solgate_s3_file_system], dry_run)
def test_send_unable_to_transfer(mocker, mocked_solgate_s3_file_system): """Should log failures.""" mocker.patch("solgate.transfer._transfer_single_file", side_effect=transfer.TransferFailed()) logger_spy = mocker.spy(transfer.logger, "error") with pytest.raises(IOError) as e: transfer.send([dict(key="a/b/file.csv")], {}, 1) assert e.args[1] == dict(failed_files=[dict(key="a/b/file.csv")]) logger_spy.assert_called_once_with("Max retries reached", mocker.ANY, exc_info=True)