예제 #1
0
def test_local_push(tmpdir):
    """ Verify loading local manifest and data into S3. """
    with patch('t4.packages.put_bytes') as bytes_mock, \
         patch('t4.data_transfer._copy_local_file') as file_mock, \
         patch('t4.packages.get_remote_registry') as config_mock:
        config_mock.return_value = tmpdir / 'package_contents'
        new_pkg = Package()
        contents = 'blah'
        test_file = pathlib.Path(tmpdir) / 'bar'
        test_file.write_text(contents)
        new_pkg = new_pkg.set('foo', test_file)
        new_pkg.push('Quilt/package', tmpdir / 'package_contents')

        push_uri = pathlib.Path(tmpdir, 'package_contents').as_uri()

        # Manifest copied
        top_hash = new_pkg.top_hash()
        bytes_mock.assert_any_call(
            top_hash.encode(),
            push_uri + '/.quilt/named_packages/Quilt/package/latest')
        bytes_mock.assert_any_call(ANY,
                                   push_uri + '/.quilt/packages/' + top_hash)

        # Data copied
        file_mock.assert_called_once_with(
            ANY, len(contents), str(test_file),
            str(tmpdir / 'package_contents/Quilt/package/foo'), {})
예제 #2
0
def test_load_into_t4(tmpdir):
    """ Verify loading local manifest and data into S3. """
    with patch('t4.packages.put_bytes') as bytes_mock, \
         patch('t4.data_transfer._upload_file') as file_mock, \
         patch('t4.packages.get_remote_registry') as config_mock:
        config_mock.return_value = 's3://my_test_bucket'
        new_pkg = Package()
        # Create a dummy file to add to the package.
        contents = 'blah'
        test_file = pathlib.Path(tmpdir) / 'bar'
        test_file.write_text(contents)
        new_pkg = new_pkg.set('foo', test_file)
        new_pkg.push('Quilt/package', 's3://my_test_bucket/')

        # Manifest copied
        top_hash = new_pkg.top_hash()
        bytes_mock.assert_any_call(
            top_hash.encode(),
            's3://my_test_bucket/.quilt/named_packages/Quilt/package/latest')
        bytes_mock.assert_any_call(
            ANY, 's3://my_test_bucket/.quilt/packages/' + top_hash)

        # Data copied
        file_mock.assert_called_once_with(ANY, len(contents), str(test_file),
                                          'my_test_bucket',
                                          'Quilt/package/foo', {})
예제 #3
0
    def test_load_into_t4(self):
        """ Verify loading local manifest and data into S3. """
        top_hash = '5333a204bbc6e21607c2bc842f4a77d2e21aa6147cf2bf493dbf6282188d01ca'

        self.s3_stubber.add_response(method='put_object',
                                     service_response={'VersionId': 'v1'},
                                     expected_params={
                                         'Body': ANY,
                                         'Bucket': 'my_test_bucket',
                                         'Key': 'Quilt/package/foo',
                                         'Metadata': {
                                             'helium': '{}'
                                         }
                                     })

        self.s3_stubber.add_response(method='put_object',
                                     service_response={'VersionId': 'v2'},
                                     expected_params={
                                         'Body': ANY,
                                         'Bucket': 'my_test_bucket',
                                         'Key': '.quilt/packages/' + top_hash,
                                         'Metadata': {
                                             'helium': 'null'
                                         }
                                     })

        self.s3_stubber.add_response(
            method='put_object',
            service_response={'VersionId': 'v3'},
            expected_params={
                'Body': top_hash.encode(),
                'Bucket': 'my_test_bucket',
                'Key': '.quilt/named_packages/Quilt/package/1234567890',
                'Metadata': {
                    'helium': 'null'
                }
            })

        self.s3_stubber.add_response(
            method='put_object',
            service_response={'VersionId': 'v4'},
            expected_params={
                'Body': top_hash.encode(),
                'Bucket': 'my_test_bucket',
                'Key': '.quilt/named_packages/Quilt/package/latest',
                'Metadata': {
                    'helium': 'null'
                }
            })

        new_pkg = Package()
        # Create a dummy file to add to the package.
        contents = 'blah'
        test_file = Path('bar')
        test_file.write_text(contents)
        new_pkg = new_pkg.set('foo', test_file)

        with patch('time.time', return_value=1234567890):
            new_pkg.push('Quilt/package', 's3://my_test_bucket/')
예제 #4
0
    def test_default_registry(self):
        new_pkg = Package()

        # Create a dummy file to add to the package.
        test_file_name = 'bar'
        with open(test_file_name, "w") as fd:
            fd.write('test_file_content_string')
            test_file = Path(fd.name)

        # Build a new package into the local registry.
        new_pkg = new_pkg.set('foo', test_file_name)
        top_hash = new_pkg.build("Quilt/Test").top_hash

        # Verify manifest is registered by hash.
        out_path = Path(BASE_PATH, ".quilt/packages", top_hash)
        with open(out_path) as fd:
            pkg = Package.load(fd)
            assert test_file.resolve().as_uri() == pkg['foo'].physical_keys[0]

        # Verify latest points to the new location.
        named_pointer_path = Path(BASE_PATH,
                                  ".quilt/named_packages/Quilt/Test/latest")
        with open(named_pointer_path) as fd:
            assert fd.read().replace('\n', '') == top_hash

        # Test unnamed packages.
        new_pkg = Package()
        new_pkg = new_pkg.set('bar', test_file_name)
        top_hash = new_pkg.build().top_hash
        out_path = Path(BASE_PATH, ".quilt/packages", top_hash)
        with open(out_path) as fd:
            pkg = Package.load(fd)
            assert test_file.resolve().as_uri() == pkg['bar'].physical_keys[0]

        new_base_path = Path(BASE_PATH, ".quilttest")
        with patch('t4.packages.get_from_config') as mock_config:
            mock_config.return_value = new_base_path
            top_hash = new_pkg.build("Quilt/Test").top_hash
            out_path = Path(new_base_path, ".quilt/packages",
                            top_hash).resolve()
            with open(out_path) as fd:
                pkg = Package.load(fd)
                assert test_file.resolve().as_uri(
                ) == pkg['bar'].physical_keys[0]

        with patch('t4.packages.get_from_config') as mock_config:
            mock_config.return_value = new_base_path
            new_pkg.push("Quilt/Test")
            with open(out_path) as fd:
                pkg = Package.load(fd)
                assert pkg['bar'].physical_keys[0].endswith(
                    '.quilttest/Quilt/Test/bar')
예제 #5
0
    def test_local_push(self):
        """ Verify loading local manifest and data into a local dir. """
        top_hash = '5333a204bbc6e21607c2bc842f4a77d2e21aa6147cf2bf493dbf6282188d01ca'

        new_pkg = Package()
        contents = 'blah'
        test_file = Path('bar')
        test_file.write_text(contents)
        new_pkg = new_pkg.set('foo', test_file)
        new_pkg.push('Quilt/package', 'package_contents')

        push_dir = Path('package_contents')

        assert (push_dir / '.quilt/named_packages/Quilt/package/latest'
                ).read_text() == top_hash
        assert (push_dir / ('.quilt/packages/' + top_hash)).exists()
        assert (push_dir / 'Quilt/package/foo').read_text() == contents