Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for selector_fn #3394

Merged
merged 3 commits into from
Apr 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions api/python/tests/integration/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,73 @@ def test_push_dest_fn(self):
BytesIO(push_manifest_mock.call_args[0][2])
)[lk].physical_key == PhysicalKey(dest_bucket, dest_key, version)

@patch('quilt3.workflows.validate', mock.MagicMock(return_value=None))
@patch('quilt3.Package._calculate_top_hash', mock.MagicMock(return_value=mock.sentinel.top_hash))
def test_push_selector_fn_false(self):
pkg_name = 'foo/bar'
lk = 'foo'
src_bucket = 'src-bucket'
src_key = 'foo.txt'
src_version = '1'
dst_bucket = 'dst-bucket'
pkg = Package()
with patch('quilt3.packages.get_size_and_version', return_value=(0, src_version)):
pkg.set(lk, f's3://{src_bucket}/{src_key}')

selector_fn = mock.MagicMock(return_value=False)
push_manifest_mock = self.patch_s3_registry('push_manifest')
self.patch_s3_registry('shorten_top_hash', return_value='7a67ff4')
with patch('quilt3.packages.calculate_sha256', return_value=["a" * 64]):
pkg.push(pkg_name, registry=f's3://{dst_bucket}', selector_fn=selector_fn, force=True)

selector_fn.assert_called_once_with(lk, pkg[lk])
push_manifest_mock.assert_called_once_with(pkg_name, mock.sentinel.top_hash, ANY)
assert Package.load(
BytesIO(push_manifest_mock.call_args[0][2])
)[lk].physical_key == PhysicalKey(src_bucket, src_key, src_version)

@patch('quilt3.workflows.validate', mock.MagicMock(return_value=None))
@patch('quilt3.Package._calculate_top_hash', mock.MagicMock(return_value=mock.sentinel.top_hash))
def test_push_selector_fn_true(self):
pkg_name = 'foo/bar'
lk = 'foo'
src_bucket = 'src-bucket'
src_key = 'foo.txt'
src_version = '1'
dst_bucket = 'dst-bucket'
dst_key = f'{pkg_name}/{lk}'
dst_version = '2'
pkg = Package()
with patch('quilt3.packages.get_size_and_version', return_value=(0, src_version)):
pkg.set(lk, f's3://{src_bucket}/{src_key}')

selector_fn = mock.MagicMock(return_value=True)
self.s3_stubber.add_response(
method='copy_object',
service_response={
'VersionId': dst_version,
},
expected_params={
'Bucket': dst_bucket,
'Key': dst_key,
'CopySource': {
'Bucket': src_bucket,
'Key': src_key,
'VersionId': src_version,
},
}
)
push_manifest_mock = self.patch_s3_registry('push_manifest')
self.patch_s3_registry('shorten_top_hash', return_value='7a67ff4')
with patch('quilt3.packages.calculate_sha256', return_value=["a" * 64]):
pkg.push(pkg_name, registry=f's3://{dst_bucket}', selector_fn=selector_fn, force=True)

selector_fn.assert_called_once_with(lk, pkg[lk])
push_manifest_mock.assert_called_once_with(pkg_name, mock.sentinel.top_hash, ANY)
assert Package.load(
BytesIO(push_manifest_mock.call_args[0][2])
)[lk].physical_key == PhysicalKey(dst_bucket, dst_key, dst_version)

def test_package_dump_file_mode(self):
"""
Package.dump() works with both files opened in binary and text mode.
Expand Down