コード例 #1
0
ファイル: test_lib.py プロジェクト: bowlofeggs/pulp_ostree
    def test_pull_local(self, lib):
        path = '/tmp/path-2'
        path_in = '/tmp/path-1'
        url = 'file://%s' % path_in
        refs = ['branch-1']
        mirror = 'MIRROR'
        _lib = Mock()
        lib_repo = Mock()
        _lib.GLib.Variant.side_effect = Mock(side_effect=variant)
        _lib.OSTree.RepoPullFlags.MIRROR = mirror
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.open = Mock()
        repo.impl = lib_repo
        repo.pull_local(path_in, refs)

        # validation
        options = (
            'a{sv}', {
                'refs': ('as', ('branch-1',)),
                'flags': ('u', 'MIRROR')
            })
        lib.assert_called_with()
        repo.open.assert_called_once_with()
        lib_repo.pull_with_options.assert_called_once_with(url, options, None, None)
コード例 #2
0
ファイル: test_lib.py プロジェクト: pcreech/pulp_ostree
    def test_pull_all(self, lib):
        path = '/tmp/path-1'
        remote_id = 'remote-1'
        depth = 3
        refs = None
        mirror = 0xFF
        listener = Mock()
        _lib = Mock()
        lib_repo = Mock()
        progress = Mock()
        _lib.GLib.Variant.side_effect = Mock(side_effect=variant)
        _lib.OSTree.AsyncProgress.new.return_value = progress
        _lib.OSTree.RepoPullFlags.MIRROR = mirror
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.open = Mock()
        repo.impl = lib_repo
        repo.pull(remote_id, refs, listener, depth)

        # validation
        options = (
            'a{sv}', {
                'depth': ('i', depth),
                'flags': ('i', mirror)
            })
        lib.assert_called_with()
        repo.open.assert_called_once_with()
        progress.connect.assert_called_once_with('changed', ANY)
        lib_repo.pull_with_options.assert_called_once_with(remote_id, options, progress, None)
        progress.finish.assert_called_once_with()
コード例 #3
0
    def test_pull(self, lib):
        fp = Mock()
        path = '/tmp/path-1'
        remote_id = 'remote-1'
        refs = ['branch-1']
        mirror = 'MIRROR'
        listener = Mock()
        _lib = Mock()
        lib_repo = Mock()
        progress = Mock()
        _lib.Gio.File.new_for_path.return_value = fp
        _lib.OSTree.Repo.new.return_value = lib_repo
        _lib.OSTree.AsyncProgress.new.return_value = progress
        _lib.OSTree.RepoPullFlags.MIRROR = mirror
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.pull(remote_id, refs, listener)

        # validation
        lib.assert_called_with()
        _lib.OSTree.Repo.new.assert_called_once_with(fp)
        lib_repo.open.assert_called_once_with(None)
        progress.connect.assert_called_once_with('changed', ANY)
        lib_repo.pull.assert_called_once_with(remote_id, refs, mirror,
                                              progress, None)
        progress.finish.assert_called_once_with()
コード例 #4
0
    def test_pull_local(self, lib):
        fp = Mock()
        path = '/tmp/path-2'
        path_in = '/tmp/path-1'
        url = 'file://%s' % path_in
        refs = ['branch-1']
        mirror = 'MIRROR'
        _lib = Mock()
        lib_repo = Mock()
        _lib.GLib.Variant.side_effect = Mock(side_effect=variant)
        _lib.Gio.File.new_for_path.return_value = fp
        _lib.OSTree.Repo.new.return_value = lib_repo
        _lib.OSTree.RepoPullFlags.MIRROR = mirror
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.pull_local(path_in, refs)

        # validation
        options = ('a{sv}', {
            'refs': ('as', ('branch-1', )),
            'flags': ('u', 'MIRROR')
        })
        lib.assert_called_with()
        _lib.OSTree.Repo.new.assert_called_once_with(fp)
        lib_repo.open.assert_called_once_with(None)
        lib_repo.pull_with_options.assert_called_once_with(
            url, options, None, None)
コード例 #5
0
    def test_history(self, lib):
        commit_id = '123'
        parents = ['456', '789', None]
        variants = [
            (True, ({
                'version': 1
            }, )),
            (True, ({
                'version': 2
            }, )),
            (True, ({
                'version': 3
            }, )),
        ]
        _repo = Mock()
        _repo.load_variant.side_effect = variants
        _lib = Mock()
        _lib.OSTree.Repo.new.return_value = _repo
        _lib.GLib.GError = GError
        _lib.OSTree.ObjectType.COMMIT = 'COMMIT'
        _lib.OSTree.commit_get_parent.side_effect = parents
        lib.return_value = _lib

        # test
        repo = Repository('')
        history = repo.history(commit_id)

        # validation
        self.assertEqual(history, [
            Commit('123', {'version': 1}),
            Commit('456', {'version': 2}),
            Commit('789', {'version': 3}),
        ])
コード例 #6
0
    def test_add_remote(self, lib):
        fp = Mock()
        path = '/tmp/path-1'
        remote_id = 'remote-1'
        url = 'http://free-trees.com'
        lib_repo = Mock()
        _lib = Mock()
        _lib.GLib.Variant.side_effect = ['v1', 'v2']
        _lib.Gio.File.new_for_path.return_value = fp
        _lib.OSTree.Repo.new.return_value = lib_repo
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.add_remote(remote_id, url)

        # validation
        lib.assert_called_with()
        _lib.OSTree.Repo.new.assert_called_once_with(fp)
        lib_repo.open.assert_called_once_with(None)
        lib_repo.remote_add.assert_called_once_with(remote_id, url, 'v2', None)
        self.assertEqual(_lib.GLib.Variant.call_args_list,
                         [(('s', 'false'), {}),
                          (('a{sv}', {
                              'gpg-verify': 'v1'
                          }), {})])
コード例 #7
0
    def test_history_not_pulled(self, lib):
        # Depending on tree traversal depth, the entire commit
        # hierarchy may not have been pulled.
        commit_id = '123'
        parents = ['456', '789', None]
        variants = [
            (True, ({
                'version': 1
            }, )),
            (True, ({
                'version': 2
            }, )),
            GError,
        ]
        _repo = Mock()
        _repo.load_variant.side_effect = variants
        _lib = Mock()
        _lib.OSTree.Repo.new.return_value = _repo
        _lib.GLib.GError = GError
        _lib.OSTree.ObjectType.COMMIT = 'COMMIT'
        _lib.OSTree.commit_get_parent.side_effect = parents
        lib.return_value = _lib

        # test
        repo = Repository('')
        history = repo.history(commit_id)

        # validation
        self.assertEqual(history, [
            Commit('123', {'version': 1}),
            Commit('456', {'version': 2}),
        ])
コード例 #8
0
ファイル: test_lib.py プロジェクト: beav/pulp_ostree
    def test_pull(self, lib):
        fp = Mock()
        path = '/tmp/path-1'
        remote_id = 'remote-1'
        refs = ['branch-1']
        mirror = 'MIRROR'
        listener = Mock()
        _lib = Mock()
        lib_repo = Mock()
        progress = Mock()
        _lib.Gio.File.new_for_path.return_value = fp
        _lib.OSTree.Repo.new.return_value = lib_repo
        _lib.OSTree.AsyncProgress.new.return_value = progress
        _lib.OSTree.RepoPullFlags.MIRROR = mirror
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.pull(remote_id, refs, listener)

        # validation
        lib.assert_called_with()
        _lib.OSTree.Repo.new.assert_called_once_with(fp)
        lib_repo.open.assert_called_once_with(None)
        progress.connect.assert_called_once_with('changed', ANY)
        lib_repo.pull.assert_called_once_with(remote_id, refs, mirror, progress, None)
        progress.finish.assert_called_once_with()
コード例 #9
0
ファイル: test_lib.py プロジェクト: beav/pulp_ostree
    def test_add_remote(self, lib):
        fp = Mock()
        path = '/tmp/path-1'
        remote_id = 'remote-1'
        url = 'http://free-trees.com'
        lib_repo = Mock()
        _lib = Mock()
        _lib.GLib.Variant.side_effect = ['v1', 'v2']
        _lib.Gio.File.new_for_path.return_value = fp
        _lib.OSTree.Repo.new.return_value = lib_repo
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.add_remote(remote_id, url)

        # validation
        lib.assert_called_with()
        _lib.OSTree.Repo.new.assert_called_once_with(fp)
        lib_repo.open.assert_called_once_with(None)
        lib_repo.remote_add.assert_called_once_with(remote_id, url, 'v2', None)
        self.assertEqual(
            _lib.GLib.Variant.call_args_list,
            [
                (('s', 'false'), {}),
                (('a{sv}', {'gpg-verify': 'v1'}), {})
            ])
コード例 #10
0
ファイル: test_lib.py プロジェクト: pcreech/pulp_ostree
    def test_pull_local_all(self, lib):
        path = '/tmp/path-2'
        path_in = '/tmp/path-1'
        url = 'file://%s' % path_in
        refs = None
        mirror = 0xFF
        depth = 3
        _lib = Mock()
        lib_repo = Mock()
        _lib.GLib.Variant.side_effect = Mock(side_effect=variant)
        _lib.OSTree.RepoPullFlags.MIRROR = mirror
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.open = Mock()
        repo.impl = lib_repo
        repo.pull_local(path_in, refs, depth)

        # validation
        options = (
            'a{sv}', {
                'depth': ('i', depth),
                'flags': ('i', mirror)
            })
        lib.assert_called_with()
        repo.open.assert_called_once_with()
        lib_repo.pull_with_options.assert_called_once_with(url, options, None, None)
コード例 #11
0
ファイル: test_lib.py プロジェクト: pcreech/pulp_ostree
    def test_close(self):
        repository = Repository('')
        repository.impl = Mock()

        # test
        repository.close()

        # validation
        self.assertEqual(repository.impl, None)
コード例 #12
0
    def test_close(self):
        repository = Repository('')
        repository.impl = Mock()

        # test
        repository.close()

        # validation
        self.assertEqual(repository.impl, None)
コード例 #13
0
ファイル: test_lib.py プロジェクト: pcreech/pulp_ostree
    def test_already_created(self, lib):
        path = '/tmp/path-1'
        _lib = Mock()
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.impl = Mock()
        repo.create()

        # validation
        self.assertFalse(_lib.OSTree.Repo.new.called)
コード例 #14
0
    def test_already_created(self, lib):
        path = '/tmp/path-1'
        _lib = Mock()
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.impl = Mock()
        repo.create()

        # validation
        self.assertFalse(_lib.OSTree.Repo.new.called)
コード例 #15
0
ファイル: test_lib.py プロジェクト: bmbouter/pulp_ostree
    def test_list_refs(self, lib, ref):
        fp = Mock()
        path = '/tmp/path-1'

        commits = [
            (1, [{'version': 1}]),
            (2, [{'version': 2}])
        ]
        refs = (
            2,
            {
                'branch:1': 'commit:1',
                'branch:2': 'commit:2'
            }
        )

        _lib = Mock()
        lib_repo = Mock()
        lib_repo.list_refs.return_value = refs
        lib_repo.load_variant.side_effect = commits
        _lib.Gio.File.new_for_path.return_value = fp
        _lib.OSTree.ObjectType.COMMIT = 'COMMIT'
        _lib.OSTree.Repo.new.return_value = lib_repo
        lib.return_value = _lib

        ref_objects = [Mock(), Mock()]
        ref.side_effect = ref_objects

        # test
        repo = Repository(path)
        listed = repo.list_refs()

        # validation
        lib.assert_called_with()
        _lib.OSTree.Repo.new.assert_called_once_with(fp)
        lib_repo.open.assert_called_once_with(None)
        lib_repo.list_refs.assert_called_once_with(None, None)
        self.assertEqual(
            ref.call_args_list,
            [
                (('branch:1', 'commit:1', {'version': 1}), {}),
                (('branch:2', 'commit:2', {'version': 2}), {}),
            ])
        self.assertEqual(
            lib_repo.load_variant.call_args_list,
            [
                (('COMMIT', 'commit:1'), {}),
                (('COMMIT', 'commit:2'), {}),
            ])
        self.assertEqual(listed, ref_objects)
コード例 #16
0
ファイル: test_lib.py プロジェクト: daviddavis/pulp_ostree
    def test_list_refs(self, lib, ref):
        path = '/tmp/path-1'

        commits = [
            (1, [{'version': 1}]),
            (2, [{'version': 2}])
        ]
        refs = (
            2,
            {
                'branch:1': 'commit:1',
                'branch:2': 'commit:2'
            }
        )

        _lib = Mock()
        lib_repo = Mock()
        lib_repo.list_refs.return_value = refs
        lib_repo.load_variant.side_effect = commits
        _lib.OSTree.ObjectType.COMMIT = 'COMMIT'
        lib.return_value = _lib

        ref_objects = [Mock(), Mock()]
        ref.side_effect = ref_objects

        # test
        repo = Repository(path)
        repo.open = Mock()
        repo.impl = lib_repo
        listed = repo.list_refs()

        # validation
        lib.assert_called_with()
        repo.open.assert_called_once_with()
        lib_repo.list_refs.assert_called_once_with(None, None)
        self.assertEqual(
            ref.call_args_list,
            [
                (('branch:1', 'commit:1', {'version': 1}), {}),
                (('branch:2', 'commit:2', {'version': 2}), {}),
            ])
        self.assertEqual(
            lib_repo.load_variant.call_args_list,
            [
                (('COMMIT', 'commit:1'), {}),
                (('COMMIT', 'commit:2'), {}),
            ])
        self.assertEqual(listed, ref_objects)
コード例 #17
0
ファイル: test_lib.py プロジェクト: beav/pulp_ostree
    def test_open(self, lib):
        fp = Mock()
        path = '/tmp/path-1'
        lib_repo = Mock()
        _lib = Mock()
        _lib.Gio.File.new_for_path.return_value = fp
        _lib.OSTree.Repo.new.return_value = lib_repo
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.create()

        # validation
        lib.assert_called_with()
        _lib.Gio.File.new_for_path.assert_called_once_with(path)
        _lib.OSTree.Repo.new.assert_called_once_with(fp)
        lib_repo.open.assert_called_once_with(None)
        self.assertFalse(lib_repo.create.called)
コード例 #18
0
    def test_open(self, lib):
        fp = Mock()
        path = '/tmp/path-1'
        lib_repo = Mock()
        _lib = Mock()
        _lib.Gio.File.new_for_path.return_value = fp
        _lib.OSTree.Repo.new.return_value = lib_repo
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.open()

        # validation
        lib.assert_called_with()
        _lib.Gio.File.new_for_path.assert_called_once_with(path)
        _lib.OSTree.Repo.new.assert_called_once_with(fp)
        lib_repo.open.assert_called_once_with(None)
        self.assertFalse(lib_repo.create.called)
コード例 #19
0
ファイル: test_lib.py プロジェクト: daviddavis/pulp_ostree
    def test_create(self, lib):
        fp = Mock()
        path = '/tmp/path-1'
        lib_repo = Mock()
        _lib = Mock()
        _lib.GLib.GError = GError
        _lib.Gio.File.new_for_path.return_value = fp
        _lib.OSTree.Repo.new.return_value = lib_repo
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.create()

        # validation
        lib.assert_called_with()
        _lib.Gio.File.new_for_path.assert_called_once_with(path)
        _lib.OSTree.Repo.new.assert_called_once_with(fp)
        lib_repo.create.assert_called_once_with(_lib.OSTree.RepoMode.ARCHIVE_Z2, None)
コード例 #20
0
ファイル: test_lib.py プロジェクト: beav/pulp_ostree
    def test_pull_progress_listener_exception(self, lib, progress_report):
        _lib = Mock()
        listener = Mock(side_effect=ValueError)
        progress = Mock()
        _lib.OSTree.AsyncProgress.new.return_value = progress
        lib.return_value = _lib
        report = Mock()

        def connect(unused, fn):
            fn(report)

        progress.connect.side_effect = connect

        # test
        repo = Repository('')
        repo.pull('', [], listener)

        # validation
        progress_report.assert_called_once_with(report)
        listener.assert_called_once_with(progress_report.return_value)
コード例 #21
0
    def test_pull_progress_listener_exception(self, lib, progress_report):
        _lib = Mock()
        listener = Mock(side_effect=ValueError)
        progress = Mock()
        _lib.OSTree.AsyncProgress.new.return_value = progress
        lib.return_value = _lib
        report = Mock()

        def connect(unused, fn):
            fn(report)

        progress.connect.side_effect = connect

        # test
        repo = Repository('')
        repo.pull('', [], listener)

        # validation
        progress_report.assert_called_once_with(report)
        listener.assert_called_once_with(progress_report.return_value)
コード例 #22
0
    def test_pull_local_all(self, lib):
        path = '/tmp/path-2'
        path_in = '/tmp/path-1'
        url = 'file://%s' % path_in
        refs = None
        mirror = 0xFF
        depth = 3
        _lib = Mock()
        lib_repo = Mock()
        _lib.GLib.Variant.side_effect = Mock(side_effect=variant)
        _lib.OSTree.RepoPullFlags.MIRROR = mirror
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.open = Mock()
        repo.impl = lib_repo
        repo.pull_local(path_in, refs, depth)

        # validation
        options = ('a{sv}', {'depth': ('i', depth), 'flags': ('i', mirror)})
        lib.assert_called_with()
        repo.open.assert_called_once_with()
        lib_repo.pull_with_options.assert_called_once_with(
            url, options, None, None)
コード例 #23
0
    def test_pull_all(self, lib):
        path = '/tmp/path-1'
        remote_id = 'remote-1'
        depth = 3
        refs = None
        mirror = 0xFF
        listener = Mock()
        _lib = Mock()
        lib_repo = Mock()
        progress = Mock()
        _lib.GLib.Variant.side_effect = Mock(side_effect=variant)
        _lib.OSTree.AsyncProgress.new.return_value = progress
        _lib.OSTree.RepoPullFlags.MIRROR = mirror
        lib.return_value = _lib

        # test
        repo = Repository(path)
        repo.open = Mock()
        repo.impl = lib_repo
        repo.pull(remote_id, refs, listener, depth)

        # validation
        options = ('a{sv}', {'depth': ('i', depth), 'flags': ('i', mirror)})
        lib.assert_called_with()
        repo.open.assert_called_once_with()
        progress.connect.assert_called_once_with('changed', ANY)
        lib_repo.pull_with_options.assert_called_once_with(
            remote_id, options, progress, None)
        progress.finish.assert_called_once_with()
コード例 #24
0
    def test_history_failed(self, lib):
        commit_id = '123'
        _repo = Mock()
        _repo.load_variant.side_effect = GError
        _lib = Mock()
        _lib.OSTree.Repo.new.return_value = _repo
        _lib.GLib.GError = GError
        _lib.OSTree.ObjectType.COMMIT = 'COMMIT'
        lib.return_value = _lib

        # test
        repo = Repository('')
        self.assertRaises(GError, repo.history, commit_id)
コード例 #25
0
    def test_pull_finished_always_called(self, lib):
        _lib = Mock()
        _lib.GLib.GError = GError
        _repo = Mock()
        _repo.pull.side_effect = GError
        progress = Mock()
        _lib.OSTree.Repo.new.return_value = _repo
        _lib.OSTree.AsyncProgress.new.return_value = progress
        lib.return_value = _lib

        # test
        repo = Repository('')

        # validation
        self.assertRaises(LibError, repo.pull, '', [], None)
        progress.finish.assert_called_once_with()
コード例 #26
0
 def test_init(self):
     path = '/tmp/path-1'
     repo = Repository(path)
     self.assertEqual(repo.path, path)
     self.assertEqual(repo.impl, None)