Skip to content

Commit

Permalink
test: remove redundant unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
helen-m-lin committed Jun 7, 2024
1 parent dc48a43 commit 1d2725f
Showing 1 changed file with 5 additions and 100 deletions.
105 changes: 5 additions & 100 deletions tests/test_aind_bucket_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,108 +193,27 @@ def test_process_docdb_record_same_md5_hash(
"aind_data_asset_indexer.aind_bucket_indexer."
"upload_metadata_json_str_to_s3"
)
@patch("aind_data_asset_indexer.utils.cond_copy_core_json_files")
@patch("aind_data_asset_indexer.utils.sync_core_json_files")
@patch("aind_data_asset_indexer.utils.does_s3_metadata_copy_exist")
@patch("aind_data_asset_indexer.aind_bucket_indexer.get_dict_of_file_info")
@patch("aind_data_asset_indexer.aind_bucket_indexer.does_s3_object_exist")
@patch("aind_data_asset_indexer.aind_bucket_indexer.MongoClient")
@patch("boto3.client")
@patch("logging.log")
@patch("logging.info")
def test_process_docdb_record_diff_md5_hash_copy_exists(
self,
mock_log_info: MagicMock,
mock_log: MagicMock,
mock_s3_client: MagicMock,
mock_docdb_client: MagicMock,
mock_does_s3_object_exist: MagicMock,
mock_get_dict_of_file_info: MagicMock,
mock_does_s3_metadata_copy_exist: MagicMock,
mock_sync_core_json_files: MagicMock,
mock_cond_copy_core_json_files: MagicMock,
mock_upload_metadata_json_str_to_s3: MagicMock,
):
"""Tests _process_docdb_record method when there is a metadata.nd.json
in s3, the md5 hashes are different, and /original_metadata exists.
"""
expected_prefix = "ecephys_642478_2023-01-17_13-56-29"
mock_does_s3_object_exist.return_value = True
mock_get_dict_of_file_info.return_value = {
f"{expected_prefix}/metadata.nd.json": {
"last_modified": datetime(
2024, 5, 15, 17, 41, 28, tzinfo=timezone.utc
),
"e_tag": '"2a2a2222aa2a2222a2a222a22a2aaaa2"',
"version_id": "version_id",
}
}
mock_does_s3_metadata_copy_exist.return_value = True
mock_upload_metadata_json_str_to_s3.return_value = (
self.example_put_object_response1
)

self.basic_job._process_docdb_record(
docdb_client=mock_docdb_client,
s3_client=mock_s3_client,
docdb_record=self.example_md_record,
)
mock_does_s3_metadata_copy_exist.assert_called_once_with(
bucket=self.basic_job.job_settings.s3_bucket,
prefix=expected_prefix,
copy_subdir="original_metadata",
s3_client=mock_s3_client,
)
mock_sync_core_json_files.assert_called_once_with(
metadata_json=json.dumps(self.example_md_record),
bucket=self.basic_job.job_settings.s3_bucket,
prefix=f"{expected_prefix}",
s3_client=mock_s3_client,
log_flag=True,
)
mock_cond_copy_core_json_files.assert_not_called()
mock_log.assert_called_once_with(
20,
"Copy of original metadata already exists at s3://"
f"aind-ephys-data-dev-u5u0i5/{expected_prefix}/original_metadata",
)
mock_log_info.assert_has_calls(
[
call(
"Uploading metadata record for: "
f"s3://aind-ephys-data-dev-u5u0i5/{expected_prefix}"
),
call(self.example_put_object_response1),
]
)

@patch(
"aind_data_asset_indexer.aind_bucket_indexer."
"upload_metadata_json_str_to_s3"
"cond_copy_then_sync_core_json_files"
)
@patch("aind_data_asset_indexer.utils.cond_copy_core_json_files")
@patch("aind_data_asset_indexer.utils.sync_core_json_files")
@patch("aind_data_asset_indexer.utils.does_s3_metadata_copy_exist")
@patch("aind_data_asset_indexer.aind_bucket_indexer.get_dict_of_file_info")
@patch("aind_data_asset_indexer.aind_bucket_indexer.does_s3_object_exist")
@patch("aind_data_asset_indexer.aind_bucket_indexer.MongoClient")
@patch("boto3.client")
@patch("logging.info")
def test_process_docdb_record_diff_md5_hash_copy_not_exist(
def test_process_docdb_record_diff_md5_hash(
self,
mock_log_info: MagicMock,
mock_s3_client: MagicMock,
mock_docdb_client: MagicMock,
mock_does_s3_object_exist: MagicMock,
mock_get_dict_of_file_info: MagicMock,
mock_does_s3_metadata_copy_exist: MagicMock,
mock_sync_core_json_files: MagicMock,
mock_cond_copy_core_json_files: MagicMock,
mock_cond_copy_then_sync_core_json_files: MagicMock,
mock_upload_metadata_json_str_to_s3: MagicMock,
):
"""Tests _process_docdb_record method when there is a metadata.nd.json
in s3, the md5 hashes are different, and /original_metadata does not
exist.
in s3, and the md5 hashes are different.
"""
expected_prefix = "ecephys_642478_2023-01-17_13-56-29"
mock_does_s3_object_exist.return_value = True
Expand All @@ -307,7 +226,6 @@ def test_process_docdb_record_diff_md5_hash_copy_not_exist(
"version_id": "version_id",
}
}
mock_does_s3_metadata_copy_exist.return_value = False
mock_upload_metadata_json_str_to_s3.return_value = (
self.example_put_object_response1
)
Expand All @@ -317,27 +235,14 @@ def test_process_docdb_record_diff_md5_hash_copy_not_exist(
s3_client=mock_s3_client,
docdb_record=self.example_md_record,
)
mock_does_s3_metadata_copy_exist.assert_called_once_with(
bucket=self.basic_job.job_settings.s3_bucket,
prefix=expected_prefix,
copy_subdir="original_metadata",
s3_client=mock_s3_client,
)
mock_sync_core_json_files.assert_called_once_with(
mock_cond_copy_then_sync_core_json_files.assert_called_once_with(
metadata_json=json.dumps(self.example_md_record),
bucket=self.basic_job.job_settings.s3_bucket,
prefix=expected_prefix,
s3_client=mock_s3_client,
log_flag=True,
)
mock_cond_copy_core_json_files.assert_called_once_with(
bucket=self.basic_job.job_settings.s3_bucket,
prefix=expected_prefix,
s3_client=mock_s3_client,
log_flag=True,
copy_original_md_subdir="original_metadata",
)

mock_log_info.assert_has_calls(
[
call(
Expand Down

0 comments on commit 1d2725f

Please sign in to comment.