Skip to content

Commit

Permalink
get tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
lmossman committed Sep 19, 2023
1 parent 08abd62 commit c5556dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def validate(metadata_file_path: pathlib.Path, doc_path: pathlib.Path):
@click.option("--prerelease", type=click.STRING, required=False, default=None, help="The prerelease tag of the connector.")
def upload(metadata_file_path: pathlib.Path, doc_path: pathlib.Path, bucket_name: str, prerelease: str):
metadata_file_path = metadata_file_path if not metadata_file_path.is_dir() else metadata_file_path / METADATA_FILE_NAME
validator_opts = ValidatorOptions(doc_path=doc_path, prerelease_tag=prerelease)
validator_opts = ValidatorOptions(doc_path=str(doc_path), prerelease_tag=prerelease)
try:
upload_info = upload_metadata_to_gcs(bucket_name, metadata_file_path, validator_opts)
log_metadata_upload_info(upload_info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def upload_file_if_changed(
print(f"Remote {blob_path} md5_hash: {remote_blob_md5_hash}")

if local_file_md5_hash != remote_blob_md5_hash:
print(f"~~~~ Uploading {local_file_path} to {blob_path}...")
uploaded = _save_blob_to_gcs(remote_blob, local_file_path, disable_cache=disable_cache)
return uploaded, remote_blob.id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def setup_upload_mocks(mocker, version_blob_md5_hash, latest_blob_md5_hash, loca

# Mock md5 hash
def side_effect_compute_gcs_md5(file_path):
if file_path == metadata_file_path:
if str(file_path) == str(metadata_file_path):
return local_file_md5_hash
elif file_path == doc_file_path:
elif str(file_path) == str(doc_file_path):
return doc_local_file_md5_hash
else:
raise ValueError(f"Unexpected path: {file_path}")
Expand Down Expand Up @@ -165,6 +165,8 @@ def test_upload_metadata_to_gcs_valid_metadata(
metadata_file_path = Path(valid_metadata_upload_file)
metadata = ConnectorMetadataDefinitionV0.parse_obj(yaml.safe_load(metadata_file_path.read_text()))

doc_file_path = Path(valid_doc_file)

mocks = setup_upload_mocks(mocker, version_blob_md5_hash, latest_blob_md5_hash, local_file_md5_hash, local_doc_file_md5_hash, doc_version_blob_md5_hash, doc_latest_blob_md5_hash, metadata_file_path, valid_doc_file)

expected_version_key = f"metadata/{metadata.data.dockerRepository}/{metadata.data.dockerImageTag}/{METADATA_FILE_NAME}"
Expand Down Expand Up @@ -216,11 +218,11 @@ def test_upload_metadata_to_gcs_valid_metadata(
assert upload_info.metadata_uploaded

if not doc_version_blob_exists:
mocks["mock_doc_version_blob"].upload_from_filename.assert_called_with(valid_doc_file)
mocks["mock_doc_version_blob"].upload_from_filename.assert_called_with(doc_file_path)
assert doc_version_uploaded_file.uploaded

if not doc_latest_blob_exists:
mocks["mock_doc_latest_blob"].upload_from_filename.assert_called_with(valid_doc_file)
mocks["mock_doc_latest_blob"].upload_from_filename.assert_called_with(doc_file_path)
assert doc_latest_uploaded_file.uploaded

if version_blob_md5_hash != local_file_md5_hash:
Expand All @@ -232,11 +234,11 @@ def test_upload_metadata_to_gcs_valid_metadata(
assert upload_info.metadata_uploaded

if doc_version_blob_md5_hash != local_doc_file_md5_hash:
mocks["mock_doc_version_blob"].upload_from_filename.assert_called_with(valid_doc_file)
mocks["mock_doc_version_blob"].upload_from_filename.assert_called_with(doc_file_path)
assert doc_version_uploaded_file.uploaded

if doc_latest_blob_md5_hash != local_doc_file_md5_hash:
mocks["mock_doc_latest_blob"].upload_from_filename.assert_called_with(valid_doc_file)
mocks["mock_doc_latest_blob"].upload_from_filename.assert_called_with(doc_file_path)
assert doc_latest_uploaded_file.uploaded

# clear the call count
Expand Down

0 comments on commit c5556dc

Please sign in to comment.