def setUpClass(cls): super().setUpClass() pkg = Package() pkg._set_commit_message(cls.parent_commit_message) pkg._workflow = { 'config': f's3://{cls.parent_bucket}/.quilt/workflows/config.yml?versionId=configVersion', 'id': 'gamma', 'schemas': { 'top-secret': f's3://{cls.parent_bucket}/top-secret.schema.json?versionId=schemaVersion' }, } pkg.set_meta({'meta': 'old meta'}) cls.entries = cls.get_pkg_entries() for lk, entry in cls.entries.items(): pkg.set(lk, entry) manifest_buf = io.BytesIO() pkg._dump(manifest_buf) cls.parent_manifest = manifest_buf.getvalue() cls.parent_top_hash = pkg.top_hash cls.src_params = { 'parent': { 'registry': cls.src_registry, 'name': cls.parent_pkg_name, 'top_hash': cls.parent_top_hash, }, }
def _mock_package_build(self, entries, *, message=..., expected_workflow=...): if message is ...: message = self.dst_commit_message # Use a test package to verify manifest entries test_pkg = Package() test_pkg.set_meta(self.meta) # Mock hashing package objects for entry in entries: pkey = PhysicalKey.from_url(entry['physical_key']) hash_obj = {'type': 'SHA256', 'value': entry['hash']} test_entry = PackageEntry(pkey, entry['size'], hash_obj, entry.get('meta')) test_pkg.set(entry['logical_key'], entry=test_entry) mocked_workflow_data = 'some-workflow-data' test_pkg._workflow = mocked_workflow_data # build the manifest from the test_package test_pkg._set_commit_message(message) manifest = io.BytesIO() test_pkg.dump(manifest) manifest.seek(0) self.s3_stubber.add_response( 'put_object', service_response={}, expected_params={ 'Body': manifest.read(), 'Bucket': self.dst_bucket, 'Key': f'.quilt/packages/{test_pkg.top_hash}', }, ) self.s3_stubber.add_response( 'put_object', service_response={}, expected_params={ 'Body': str.encode(test_pkg.top_hash), 'Bucket': self.dst_bucket, 'Key': f'.quilt/named_packages/{self.dst_pkg_name}/{str(int(self.mock_timestamp))}', }, ) self.s3_stubber.add_response( 'put_object', service_response={}, expected_params={ 'Body': str.encode(test_pkg.top_hash), 'Bucket': self.dst_bucket, 'Key': f'.quilt/named_packages/{self.dst_pkg_name}/latest', }, ) with mock.patch( 'quilt3.workflows.validate', return_value=mocked_workflow_data) as workflow_validate_mock: yield workflow_validate_mock.assert_called_once_with( registry=get_package_registry(self.dst_registry), workflow=expected_workflow, name=self.dst_pkg_name, pkg=mock.ANY, # TODO: probably this should be more specific. message=message, )