Exemple #1
0
    def test_clean_metadata(self):
        commit = 'abc'
        name = 'foo'
        metadata = {
            'a.b': '123',
            'a.b.c': '456',
            'created': '2016-02-23T22:49:05Z'
        }
        ref = {
            'commit': commit,
            'name': name,
            'metadata': metadata
        }

        cleaned = dict((k.replace('.', '-'), v) for k, v in metadata.items())

        # test
        Summary.clean_metadata(ref)

        # validation
        self.assertDictEqual(
            ref,
            {
                'commit': commit,
                'name': name,
                'metadata': cleaned
            })
    def test_process_main(self, fake_lib):
        refs = [
            Mock(),
            Mock(),
            Mock()
        ]
        remote = Mock()
        remote.list_refs.return_value = refs
        lib_repository = Mock()
        repository = Mock(id='1234')
        fake_lib.Remote.return_value = remote
        fake_lib.Repository.return_value = lib_repository
        parent = Mock(storage_dir='/tmp/xx', repo_id=repository.id)
        parent.get_repo.return_value = repository

        # test
        step = Summary()
        step.parent = parent
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_dir)
        fake_lib.Remote.assert_called_once_with(step.parent.repo_id, lib_repository)
        repository.scratchpad.update.assert_called_once_with(
            {
                constants.REMOTE: {
                    constants.SUMMARY: [r.dict() for r in remote.list_refs.return_value]
                }
            })
        repository.save.assert_called_once_with()
Exemple #3
0
    def test_convert_metadata_dict(self):
        ref_dict = {'commit': 'abc', 'name': 'foo', 'metadata': {'a.b': 'x'}}

        Summary.convert_metadata_dict(ref_dict)

        self.assertDictEqual(ref_dict,
                             {'commit': 'abc', 'name': 'foo', 'metadata': {'a-b': 'x'}})
Exemple #4
0
    def test_convert_metadata_dict(self):
        ref_dict = {'commit': 'abc', 'name': 'foo', 'metadata': {'a.b': 'x'}}

        Summary.convert_metadata_dict(ref_dict)

        self.assertDictEqual(ref_dict, {
            'commit': 'abc',
            'name': 'foo',
            'metadata': {
                'a-b': 'x'
            }
        })
Exemple #5
0
    def test_clean_metadata(self):
        commit = "abc"
        name = "foo"
        metadata = {"a.b": "123", "a.b.c": "456", "created": "2016-02-23T22:49:05Z"}
        ref = {"commit": commit, "name": name, "metadata": metadata}

        cleaned = dict((k.replace(".", "-"), v) for k, v in metadata.items())

        # test
        Summary.clean_metadata(ref)

        # validation
        self.assertDictEqual(ref, {"commit": commit, "name": name, "metadata": cleaned})
Exemple #6
0
    def test_process_main_fetch_failed(self, fake_lib):
        remote = Mock()
        remote.list_refs.side_effect = LibError
        lib_repository = Mock()
        repository = Mock(id='1234')
        fake_lib.Remote.return_value = remote
        fake_lib.Repository.return_value = lib_repository
        fake_lib.LibError = LibError
        parent = Mock(storage_dir='/tmp/xx', repo_id=repository.id)
        parent.get_repo.return_value = repository

        # test and validation
        step = Summary()
        step.parent = parent
        with self.assertRaises(PulpCodedException) as assertion:
            step.process_main()
            self.assertEqual(assertion.exception.error_code, errors.OST0005)
Exemple #7
0
    def test_process_main_fetch_failed(self, fake_lib):
        remote = Mock()
        remote.list_refs.side_effect = LibError
        lib_repository = Mock()
        repository = Mock(id='1234')
        fake_lib.Remote.return_value = remote
        fake_lib.Repository.return_value = lib_repository
        fake_lib.LibError = LibError
        parent = Mock(storage_dir='/tmp/xx', repo_id=repository.id)
        parent.get_repo.return_value = repository

        # test and validation
        step = Summary()
        step.parent = parent
        try:
            step.process_main()
            self.assertTrue(False, msg='Fetch exception expected')
        except PulpCodedException, pe:
            self.assertEqual(pe.error_code, errors.OST0005)
Exemple #8
0
    def test_process_main_fetch_failed(self, fake_lib):
        remote = Mock()
        remote.list_refs.side_effect = LibError
        lib_repository = Mock()
        repository = Mock(id="1234")
        fake_lib.Remote.return_value = remote
        fake_lib.Repository.return_value = lib_repository
        fake_lib.LibError = LibError
        parent = Mock(storage_dir="/tmp/xx", repo_id=repository.id)
        parent.get_repo.return_value = repository

        # test and validation
        step = Summary()
        step.parent = parent
        try:
            step.process_main()
            self.assertTrue(False, msg="Fetch exception expected")
        except PulpCodedException, pe:
            self.assertEqual(pe.error_code, errors.OST0005)
Exemple #9
0
    def test_process_main(self, fake_lib):
        refs = [
            Mock(),
            Mock(),
            Mock(),
        ]
        ref_dicts = [
            {'commit': 'abc', 'name': 'foo', 'metadata': {'a.b': 'x'}},
            {'commit': 'def', 'name': 'bar', 'metadata': {'a.b': 'y'}},
            {'commit': 'hij', 'name': 'baz', 'metadata': {'a.b': 'z'}},
        ]
        for ref, d in zip(refs, ref_dicts):
            ref.dict.return_value = d
        remote = Mock()
        remote.list_refs.return_value = refs
        lib_repository = Mock()
        repository = Mock(id='1234')
        fake_lib.Remote.return_value = remote
        fake_lib.Repository.return_value = lib_repository
        parent = Mock(storage_dir='/tmp/xx', repo_id=repository.id)
        parent.get_repo.return_value = repository

        # test
        step = Summary()
        step.parent = parent
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_dir)
        fake_lib.Remote.assert_called_once_with(step.parent.repo_id, lib_repository)
        repository.repo_obj.scratchpad.update.assert_called_once_with(
            {
                constants.REMOTE: {
                    constants.SUMMARY: [
                        {'commit': 'abc', 'name': 'foo', 'metadata': {'a-b': 'x'}},
                        {'commit': 'def', 'name': 'bar', 'metadata': {'a-b': 'y'}},
                        {'commit': 'hij', 'name': 'baz', 'metadata': {'a-b': 'z'}},
                    ]
                }
            })
        repository.repo_obj.save.assert_called_once_with()
Exemple #10
0
    def test_clean_metadata(self):
        commit = 'abc'
        name = 'foo'
        metadata = {
            'a.b': '123',
            'a.b.c': '456',
            'created': '2016-02-23T22:49:05Z'
        }
        ref = {'commit': commit, 'name': name, 'metadata': metadata}

        cleaned = dict((k.replace('.', '-'), v) for k, v in metadata.items())

        # test
        Summary.clean_metadata(ref)

        # validation
        self.assertDictEqual(ref, {
            'commit': commit,
            'name': name,
            'metadata': cleaned
        })
Exemple #11
0
    def test_process_main(self, fake_lib):
        refs = [Mock(), Mock(), Mock()]
        ref_dicts = [
            {"commit": "abc", "name": "foo", "metadata": {"a.b": "x"}},
            {"commit": "def", "name": "bar", "metadata": {"a.b": "y"}},
            {"commit": "hij", "name": "baz", "metadata": {"a.b": "z"}},
        ]
        for ref, d in zip(refs, ref_dicts):
            ref.dict.return_value = d
        remote = Mock()
        remote.list_refs.return_value = refs
        lib_repository = Mock()
        repository = Mock(id="1234")
        fake_lib.Remote.return_value = remote
        fake_lib.Repository.return_value = lib_repository
        parent = Mock(storage_dir="/tmp/xx", repo_id=repository.id)
        parent.get_repo.return_value = repository

        # test
        step = Summary()
        step.parent = parent
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_dir)
        fake_lib.Remote.assert_called_once_with(step.parent.repo_id, lib_repository)
        repository.repo_obj.scratchpad.update.assert_called_once_with(
            {
                constants.REMOTE: {
                    constants.SUMMARY: [
                        {"commit": "abc", "name": "foo", "metadata": {"a-b": "x"}},
                        {"commit": "def", "name": "bar", "metadata": {"a-b": "y"}},
                        {"commit": "hij", "name": "baz", "metadata": {"a-b": "z"}},
                    ]
                }
            }
        )
        repository.repo_obj.save.assert_called_once_with()
Exemple #12
0
    def test_process_main(self, fake_lib):
        refs = [
            Mock(),
            Mock(),
            Mock(),
        ]
        ref_dicts = [
            {
                'commit': 'abc',
                'name': 'foo',
                'metadata': {
                    'a.b': 'x'
                }
            },
            {
                'commit': 'def',
                'name': 'bar',
                'metadata': {
                    'a.b': 'y'
                }
            },
            {
                'commit': 'hij',
                'name': 'baz',
                'metadata': {
                    'a.b': 'z'
                }
            },
        ]
        for ref, d in zip(refs, ref_dicts):
            ref.dict.return_value = d
        remote = Mock()
        remote.list_refs.return_value = refs
        lib_repository = Mock()
        repository = Mock(id='1234')
        fake_lib.Remote.return_value = remote
        fake_lib.Repository.return_value = lib_repository
        parent = Mock(storage_dir='/tmp/xx', repo_id=repository.id)
        parent.get_repo.return_value = repository

        # test
        step = Summary()
        step.parent = parent
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_dir)
        fake_lib.Remote.assert_called_once_with(step.parent.repo_id,
                                                lib_repository)
        repository.repo_obj.scratchpad.update.assert_called_once_with({
            constants.REMOTE: {
                constants.SUMMARY: [
                    {
                        'commit': 'abc',
                        'name': 'foo',
                        'metadata': {
                            'a-b': 'x'
                        }
                    },
                    {
                        'commit': 'def',
                        'name': 'bar',
                        'metadata': {
                            'a-b': 'y'
                        }
                    },
                    {
                        'commit': 'hij',
                        'name': 'baz',
                        'metadata': {
                            'a-b': 'z'
                        }
                    },
                ]
            }
        })
        repository.repo_obj.save.assert_called_once_with()