Esempio n. 1
0
 def setUp(self):
     self.pkg = Package()
     self.entry_with_hash = PackageEntry(
         PhysicalKey('test-bucket', 'with-hash', 'with-hash'),
         42,
         {
             'type': 'SHA256',
             'value': '0' * 64
         },
         {},
     )
     self.entry_without_hash = PackageEntry(
         PhysicalKey('test-bucket', 'without-hash', 'without-hash'),
         42,
         None,
         {},
     )
     self.pkg.set('with-hash', self.entry_with_hash)
     self.pkg.set('without-hash', self.entry_without_hash)
Esempio n. 2
0
 def get_pkg_entry(cls, path):
     pk = PhysicalKey.from_url(
         f's3://{cls.parent_bucket}/{path}?versionId=obj{path}Version')
     return PackageEntry(
         pk,
         cls.file_size,
         {
             'type': 'SHA256',
             'value': cls.get_file_hash(pk)
         },
         cls.get_file_meta(pk),
     )
Esempio n. 3
0
    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,
        )