コード例 #1
0
ファイル: test_cli.py プロジェクト: quiltdata/quilt
def test_push_with_meta_data(
    meta_data,
    expected_meta,
):
    name = 'test/name'
    dir_path = 'test/dir/path'

    with patch_package_class as mocked_package_class, \
         mock.patch('quilt3.main.parse_arg_json', wraps=main.parse_arg_json) as mocked_parse_json_arg:
        mocked_package_class.browse.side_effect = FileNotFoundError()

        # '--registry' defaults to configured remote registry hence optional.
        if meta_data:
            main.main(('push', '--dir', dir_path, name, '--meta', meta_data))
            mocked_parse_json_arg.assert_called_once_with(meta_data)
        else:
            main.main(('push', '--dir', dir_path, name))
            mocked_parse_json_arg.assert_not_called()
        mocked_package_class.browse.assert_called_once_with(name, None)
        mocked_package_class.assert_called_once_with()
        mocked_package = mocked_package_class.return_value
        mocked_package.set_dir.assert_called_once_with('.',
                                                       dir_path,
                                                       meta=expected_meta)
        mocked_package.push.assert_called_once_with(name,
                                                    dest=None,
                                                    message=None,
                                                    registry=None,
                                                    workflow=...,
                                                    force=False)
コード例 #2
0
ファイル: test_cli.py プロジェクト: ltirrell/quilt
def test_push_with_meta_data(meta_arg, meta_data, expected_set_dir_count,
                             expected_push_count, expected_meta,
                             expected_stderr, capsys):
    name = 'test/name'
    pkg = quilt3.Package()

    with tempfile.TemporaryDirectory() as tmp_dir:
        (Path(tmp_dir) / 'foo').touch()
        (Path(tmp_dir) / 'bar').mkdir()
        (Path(tmp_dir) / 'bar' / 'baz')

        with mock.patch('quilt3.Package.__new__', return_value=pkg) as mocked_package_class,\
             mock.patch.object(pkg, 'set_dir', wraps=pkg.set_dir) as mocked_set_dir, \
             mock.patch.object(pkg, 'push') as mocked_push:

            # '--registry' defaults to configured remote registry hence optional.
            if meta_arg:
                main.main(
                    ('push', '--dir', tmp_dir, name, meta_arg, meta_data))
            else:
                main.main(('push', '--dir', tmp_dir, name))
            mocked_package_class.assert_called_once_with(quilt3.Package)
            assert mocked_set_dir.call_count == expected_set_dir_count
            assert mocked_push.call_count == expected_push_count
            assert pkg.meta == expected_meta
            # check for expected stderr exception message
            captured = capsys.readouterr()
            assert expected_stderr in captured.err
コード例 #3
0
def test_list_packages(capsys):
    registry = 's3://my_test_bucket/'
    pkg_names = ['foo/bar', 'foo/bar1', 'foo1/bar']
    with patch('quilt3.backends.s3.S3PackageRegistryV1.list_packages') as list_packages_mock:
        list_packages_mock.return_value = pkg_names
        main.main(('list-packages', registry))

        list_packages_mock.assert_called_once_with()
        captured = capsys.readouterr()
        assert captured.out.split() == pkg_names
コード例 #4
0
    def test_push(self):
        name = 'test/name'
        dir_path = 'test/dir/path'

        with patch_package_class as mocked_package_class:
            main.main(('push', '--dir', dir_path, name))

            mocked_package_class.assert_called_once_with()
            mocked_package = mocked_package_class.return_value
            mocked_package.set_dir.assert_called_once_with('.', dir_path, meta=None)
            mocked_package.push.assert_called_once_with(name, registry=None, dest=None, message=None, workflow=...)
コード例 #5
0
def test_push_workflow(workflow_input, expected_workflow):
    name = 'test/name'
    dir_path = 'test/dir/path'

    with patch_package_class as mocked_package_class:
        workflow_args = () if workflow_input is None else ('--workflow', workflow_input)
        main.main(('push', '--dir', dir_path, *workflow_args, name))

        mocked_package_class.assert_called_once_with()
        mocked_package = mocked_package_class.return_value
        mocked_package.set_dir.assert_called_once_with('.', dir_path, meta=None)
        mocked_package.push.assert_called_once_with(
            name, dest=None, message=None, registry=None, workflow=expected_workflow,
        )
コード例 #6
0
ファイル: test_cli.py プロジェクト: quiltdata/quilt
def test_push_with_meta_data_error(meta_data, capsys):
    name = 'test/name'

    with patch_package_class as mocked_package_class, \
         mock.patch('quilt3.main.parse_arg_json', wraps=main.parse_arg_json) as mocked_parse_json_arg:

        mocked_package_class.browse.side_effect = FileNotFoundError()

        with pytest.raises(SystemExit):
            main.main(('push', '--dir', '.', name, '--meta', meta_data))
        # check for expected stderr exception message
        captured = capsys.readouterr()
        assert 'is not a valid json string' in captured.err
        mocked_parse_json_arg.assert_called_once_with(meta_data)
        mocked_package_class.browse.assert_not_called()
        mocked_package_class.assert_not_called()
コード例 #7
0
ファイル: test_cli.py プロジェクト: ltirrell/quilt
    def test_push(self):
        name = 'test/name'
        pkg = quilt3.Package()

        with tempfile.TemporaryDirectory() as tmp_dir:
            (Path(tmp_dir) / 'foo').touch()
            (Path(tmp_dir) / 'bar').mkdir()
            (Path(tmp_dir) / 'bar' / 'baz')

            with mock.patch('quilt3.Package.__new__', return_value=pkg) as mocked_package_class, \
                 mock.patch.object(pkg, 'set_dir', wraps=pkg.set_dir) as mocked_set_dir, \
                 mock.patch.object(pkg, 'push') as mocked_push:
                main.main(('push', '--dir', tmp_dir, name))

                mocked_package_class.assert_called_once_with(quilt3.Package)
                mocked_set_dir.assert_called_once_with('.', tmp_dir, meta=None)
                mocked_push.assert_called_once_with(name,
                                                    registry=None,
                                                    dest=None,
                                                    message=None)
コード例 #8
0
ファイル: test_cli.py プロジェクト: quiltdata/quilt
    def test_push_force(self):
        name = 'test/name'
        dir_path = 'test/dir/path'

        with patch_package_class as mocked_package_class:
            mocked_package_class.browse.side_effect = FileNotFoundError()

            main.main(('push', '--dir', dir_path, name, '--force'))

            mocked_package_class.browse.assert_called_once_with(name, None)
            mocked_package_class.assert_called_once_with()
            mocked_package = mocked_package_class.return_value
            mocked_package.set_dir.assert_called_once_with('.',
                                                           dir_path,
                                                           meta=None)
            mocked_package.push.assert_called_once_with(name,
                                                        registry=None,
                                                        dest=None,
                                                        message=None,
                                                        workflow=...,
                                                        force=True)