Пример #1
0
    def test_list_refs(self, lib, ref):
        remote_id = '123'

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

        _lib = Mock()
        lib_repo = Mock()
        lib_repo.remote_list_refs.return_value = (1, summary)
        lib_repo.load_variant.side_effect = commits
        _lib.OSTree.ObjectType.COMMIT = 'COMMIT'
        _lib.OSTree.RepoPullFlags.COMMIT_ONLY = 'COMMIT_ONLY'
        lib.return_value = _lib

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

        # test
        remote = Remote(remote_id, Mock(impl=lib_repo))
        remote.open = Mock()
        listed = remote.list_refs(required=True)

        # validation
        lib.assert_called_with()
        remote.open.assert_called_once_with()
        lib_repo.remote_list_refs.assert_called_once_with(remote_id, None)
        lib_repo.pull.assert_called_once_with(
            remote_id,
            sorted(summary.keys()),
            _lib.OSTree.RepoPullFlags.COMMIT_ONLY,
            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,
            [
                ((_lib.OSTree.ObjectType.COMMIT, 'commit:1'), {}),
                ((_lib.OSTree.ObjectType.COMMIT, 'commit:2'), {}),
            ])
        self.assertEqual(listed, ref_objects)
Пример #2
0
    def test_list_refs_no_summary(self, lib):
        remote_id = '123'

        _lib = Mock()
        _lib.GLib.GError = GError
        lib_repo = Mock()
        lib_repo.remote_list_refs.side_effect = GError()
        lib.return_value = _lib

        # test
        remote = Remote(remote_id, Mock(impl=lib_repo))
        remote.open = Mock()
        listed = remote.list_refs()

        # validation
        lib.assert_called_with()
        remote.open.assert_called_once_with()
        lib_repo.remote_list_refs.assert_called_once_with(remote_id, None)
        self.assertEqual(listed, [])
Пример #3
0
    def test_list_refs_no_summary(self, lib):
        remote_id = '123'

        _lib = Mock()
        _lib.GLib.GError = GError
        lib_repo = Mock()
        lib_repo.remote_list_refs.side_effect = GError()
        lib.return_value = _lib

        # test
        remote = Remote(remote_id, Mock(impl=lib_repo))
        remote.open = Mock()
        listed = remote.list_refs()

        # validation
        lib.assert_called_with()
        remote.open.assert_called_once_with()
        lib_repo.remote_list_refs.assert_called_once_with(remote_id, None)
        self.assertEqual(listed, [])