def test_checksum(mock_checksum, mock_md5_hex): local_file_path = local_path + file_name mocked_gcs_client = MagicMock() mock_md5_hex.return_value = md5_hash_hex with patch( "datasetinsights.io.gcs.Client", MagicMock(return_value=mocked_gcs_client), ): client = GCSClient() mocked_bucket = MagicMock() mocked_blob = MagicMock() mocked_gcs_client.get_bucket = MagicMock(return_value=mocked_bucket) mocked_bucket.get_blob = MagicMock(return_value=mocked_blob) mocked_blob.md5_hash = md5_hash client._checksum(mocked_blob, local_file_path) mock_checksum.assert_called_with(local_file_path, md5_hash_hex, algorithm="MD5")
def test_checksum_error(mock_checksum, mock_remove): local_file_path = local_path + file_name mocked_gcs_client = MagicMock() with patch( "datasetinsights.io.gcs.Client", MagicMock(return_value=mocked_gcs_client), ): client = GCSClient() mocked_bucket = MagicMock() mocked_blob = MagicMock() mocked_gcs_client.get_bucket = MagicMock(return_value=mocked_bucket) mocked_bucket.get_blob = MagicMock(return_value=mocked_blob) mocked_blob.md5_hash = md5_hash client._MD5_hex = MagicMock(return_value=md5_hash_hex) client._checksum(mocked_blob, local_file_path) mock_checksum.side_effect = ChecksumError with pytest.raises(ChecksumError): client._checksum(mocked_blob, local_file_path) mock_remove.assert_called_once()