Example #1
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', {})
Example #2
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'), {})
Example #3
0
def test_tophash_changes(tmpdir):
    test_file = tmpdir / 'test.txt'
    test_file.write_text('asdf', 'utf-8')

    pkg = Package()
    th1 = pkg.top_hash()
    pkg.set('asdf', test_file)
    pkg.build()
    th2 = pkg.top_hash()
    assert th1 != th2

    test_file.write_text('jkl', 'utf-8')
    pkg.set('jkl', test_file)
    pkg.build()
    th3 = pkg.top_hash()
    assert th1 != th3
    assert th2 != th3

    pkg.delete('jkl')
    th4 = pkg.top_hash()
    assert th2 == th4
Example #4
0
def test_browse_package_from_registry():
    """ Verify loading manifest locally and from s3 """
    with patch('t4.Package._from_path') as pkgmock:
        registry = BASE_PATH.as_uri()
        pkg = Package()
        pkgmock.return_value = pkg
        pkghash = pkg.top_hash()

        # default registry load
        pkg = Package.browse(pkg_hash=pkghash)
        assert '{}/.quilt/packages/{}'.format(registry, pkghash) \
                in [x[0][0] for x in pkgmock.call_args_list]

        pkgmock.reset_mock()

        pkg = Package.browse('Quilt/nice-name', pkg_hash=pkghash)
        assert '{}/.quilt/packages/{}'.format(registry, pkghash) \
                in [x[0][0] for x in pkgmock.call_args_list]

        pkgmock.reset_mock()

        with patch('t4.packages.get_bytes') as dl_mock:
            dl_mock.return_value = (pkghash.encode('utf-8'), None)
            pkg = Package.browse('Quilt/nice-name')
            assert registry + '/.quilt/named_packages/Quilt/nice-name/latest' \
                    == dl_mock.call_args_list[0][0][0]

        assert '{}/.quilt/packages/{}'.format(registry, pkghash) \
                in [x[0][0] for x in pkgmock.call_args_list]
        pkgmock.reset_mock()

        remote_registry = 's3://asdf/foo'
        # remote load
        pkg = Package.browse('Quilt/nice-name',
                             registry=remote_registry,
                             pkg_hash=pkghash)
        assert '{}/.quilt/packages/{}'.format(remote_registry, pkghash) \
                in [x[0][0] for x in pkgmock.call_args_list]
        pkgmock.reset_mock()
        pkg = Package.browse(pkg_hash=pkghash, registry=remote_registry)
        assert '{}/.quilt/packages/{}'.format(remote_registry, pkghash) \
                in [x[0][0] for x in pkgmock.call_args_list]

        pkgmock.reset_mock()
        with patch('t4.packages.get_bytes') as dl_mock:
            dl_mock.return_value = (pkghash.encode('utf-8'), None)
            pkg = Package.browse('Quilt/nice-name', registry=remote_registry)
        assert '{}/.quilt/packages/{}'.format(remote_registry, pkghash) \
                in [x[0][0] for x in pkgmock.call_args_list]