Beispiel #1
0
    def test_process_main(self, fake_unit, fake_link, fake_model, fake_lib):
        remote_id = 'remote-1'
        commits = [Mock(), Mock()]
        refs = [
            Mock(path='branch:1', commit='commit:1', metadata='md:1'),
            Mock(path='branch:2', commit='commit:2', metadata='md:2'),
            Mock(path='branch:3', commit='commit:3', metadata='md:3')
        ]
        units = [
            Mock(key='key:1', metadata=refs[0].metadata,
                 storage_path='path:1'),
            Mock(key='key:2', metadata=refs[1].metadata, storage_path='path:2')
        ]
        pulp_units = [Mock(), Mock()]

        branches = [r.path for r in refs[:-1]]

        repository = Mock()
        repository.list_refs.return_value = refs
        fake_lib.Repository.return_value = repository

        fake_model.Commit.side_effect = commits
        fake_model.Unit.side_effect = units

        fake_unit.side_effect = pulp_units

        fake_conduit = Mock()

        # test
        step = Add()
        step.parent = Mock(remote_id=remote_id,
                           storage_path='/tmp/xyz',
                           branches=branches)
        step.get_conduit = Mock(return_value=fake_conduit)
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_path)
        self.assertEqual(fake_model.Commit.call_args_list, [
            (('commit:1', 'md:1'), {}),
            (('commit:2', 'md:2'), {}),
        ])
        self.assertEqual(fake_model.Unit.call_args_list, [
            ((remote_id, 'branch:1', commits[0]), {}),
            ((remote_id, 'branch:2', commits[1]), {}),
        ])
        self.assertEqual(fake_link.call_args_list, [
            ((units[0], ), {}),
            ((units[1], ), {}),
        ])
        self.assertEqual(fake_unit.call_args_list, [
            ((Unit.TYPE_ID, units[0].key, units[0].metadata,
              units[0].storage_path), {}),
            ((Unit.TYPE_ID, units[1].key, units[1].metadata,
              units[1].storage_path), {}),
        ])
        self.assertEqual(fake_conduit.save_unit.call_args_list, [
            ((pulp_units[0], ), {}),
            ((pulp_units[1], ), {}),
        ])
Beispiel #2
0
    def test_process_main(self, fake_associate, fake_model, fake_lib):
        repo_id = 'r-1234'
        remote_id = 'remote-1'
        refs = [
            Mock(path='branch:1', commit='commit:1', metadata='md:1'),
            Mock(path='branch:2', commit='commit:2', metadata='md:2'),
            Mock(path='branch:3', commit='commit:3', metadata='md:3'),
            Mock(path='branch:4', commit='commit:4', metadata='md:4'),
            Mock(path='branch:5', commit='commit:5', metadata='md:5'),
        ]
        units = [Mock(ref=r, unit_key={}) for r in refs]
        units[0].save.side_effect = NotUniqueError  # duplicate

        fake_model.Branch.side_effect = units
        fake_model.Branch.objects.get.return_value = units[0]

        branches = [r.path for r in refs[:-1]]

        repository = Mock()
        repository.list_refs.return_value = refs
        fake_lib.Repository.return_value = repository

        parent = Mock(remote_id=remote_id, storage_dir='/tmp/xyz', branches=branches)
        parent.get_repo.return_value = Mock(repo_id=repo_id)

        fake_conduit = Mock()

        # test
        step = Add()
        step.parent = parent
        step.get_conduit = Mock(return_value=fake_conduit)
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_dir)
        self.assertEqual(
            fake_model.Branch.call_args_list,
            [
                ((), dict(
                    remote_id=remote_id,
                    branch=r.path,
                    commit=r.commit,
                    metadata=r.metadata))
                for r in refs[:-1]
            ])
        self.assertEqual(
            fake_associate.call_args_list,
            [
                ((parent.get_repo.return_value, u), {}) for u in units[:-1]
            ])
Beispiel #3
0
    def test_process_main(self, fake_associate, fake_model, fake_lib):
        repo_id = 'r-1234'
        remote_id = 'remote-1'
        refs = [
            Mock(path='branch:1', commit='commit:1', metadata='md:1'),
            Mock(path='branch:2', commit='commit:2', metadata='md:2'),
            Mock(path='branch:3', commit='commit:3', metadata='md:3'),
            Mock(path='branch:4', commit='commit:4', metadata='md:4'),
            Mock(path='branch:5', commit='commit:5', metadata='md:5'),
        ]
        units = [Mock(ref=r, unit_key={}) for r in refs]
        units[0].save.side_effect = NotUniqueError  # duplicate

        fake_model.Branch.side_effect = units
        fake_model.Branch.objects.get.return_value = units[0]

        branches = [r.path.split(':')[-1] for r in refs[:-1]]

        repository = Mock()
        repository.list_refs.return_value = refs
        fake_lib.Repository.return_value = repository

        parent = Mock(remote_id=remote_id,
                      storage_dir='/tmp/xyz',
                      branches=branches)
        parent.get_repo.return_value = Mock(id=repo_id)

        fake_conduit = Mock()

        # test
        step = Add()
        step.parent = parent
        step.get_conduit = Mock(return_value=fake_conduit)
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_dir)
        self.assertEqual(fake_model.Branch.call_args_list,
                         [((),
                           dict(remote_id=remote_id,
                                branch=r.path.split(':')[-1],
                                commit=r.commit,
                                metadata=r.metadata)) for r in refs[:-1]])
        self.assertEqual(fake_associate.call_args_list,
                         [((parent.get_repo.return_value.repo_obj, u), {})
                          for u in units[:-1]])
Beispiel #4
0
    def test_process_main(self, fake_associate, fake_model, fake_lib):
        repo_id = "r-1234"
        remote_id = "remote-1"
        refs = [
            Mock(path="branch:1", commit="commit:1", metadata="md:1"),
            Mock(path="branch:2", commit="commit:2", metadata="md:2"),
            Mock(path="branch:3", commit="commit:3", metadata="md:3"),
            Mock(path="branch:4", commit="commit:4", metadata="md:4"),
            Mock(path="branch:5", commit="commit:5", metadata="md:5"),
        ]
        units = [Mock(ref=r, unit_key={}) for r in refs]
        units[0].save.side_effect = NotUniqueError  # duplicate

        fake_model.Branch.side_effect = units
        fake_model.Branch.objects.get.return_value = units[0]

        branches = [r.path.split(":")[-1] for r in refs[:-1]]

        repository = Mock()
        repository.list_refs.return_value = refs
        fake_lib.Repository.return_value = repository

        parent = Mock(remote_id=remote_id, storage_dir="/tmp/xyz", branches=branches)
        parent.get_repo.return_value = Mock(id=repo_id)

        fake_conduit = Mock()

        # test
        step = Add()
        step.parent = parent
        step.get_conduit = Mock(return_value=fake_conduit)
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_dir)
        self.assertEqual(
            fake_model.Branch.call_args_list,
            [
                ((), dict(remote_id=remote_id, branch=r.path.split(":")[-1], commit=r.commit, metadata=r.metadata))
                for r in refs[:-1]
            ],
        )
        self.assertEqual(
            fake_associate.call_args_list, [((parent.get_repo.return_value.repo_obj, u), {}) for u in units[:-1]]
        )
Beispiel #5
0
    def test_process_main(self, fake_refs, fake_repo, dt, fake_unit):
        utc_now = 'utc-now'
        dt.utcnow.return_value = utc_now
        refs = Mock()
        fake_refs.return_value = refs
        heads = [Mock(), Mock()]
        remote_id = 'remote-1'
        repo = Mock(TYPE_ID='type-id',
                    unit_key='unit-key',
                    metadata='md',
                    storage_path='storage-path')
        fake_repo.return_value = repo
        unit = Mock()
        fake_unit.return_value = unit
        fake_conduit = Mock()

        # test
        step = Add()
        step.find_branches = Mock(return_value=heads)
        step.parent = Mock(remote_id=remote_id)
        step.link = Mock()
        step.get_conduit = Mock(return_value=fake_conduit)
        step.process_main()

        # validation
        dt.utcnow.assert_called_once_with()
        fake_refs.assert_called_once_with()
        step.find_branches.assert_called_once_with()
        self.assertEqual(
            refs.add_head.call_args_list,
            [
                ((heads[0],), {}),
                ((heads[1],), {}),
            ])
        fake_repo.assert_called_once_with(remote_id, fake_refs.return_value, utc_now)
        step.link.assert_called_once_with(repo)
        fake_unit.assert_called_once_with(
            repo.TYPE_ID, repo.unit_key, repo.metadata, repo.storage_path)
        fake_conduit.save_unit.assert_called_once_with(unit)
Beispiel #6
0
    def test_process_main(self, fake_unit, fake_link, fake_model, fake_lib):
        remote_id = 'remote-1'
        commits = [
            Mock(),
            Mock()
        ]
        refs = [
            Mock(path='branch:1', commit='commit:1', metadata='md:1'),
            Mock(path='branch:2', commit='commit:2', metadata='md:2')
        ]
        units = [
            Mock(key='key:1', metadata=refs[0].metadata, storage_path='path:1'),
            Mock(key='key:2', metadata=refs[1].metadata, storage_path='path:2')
        ]
        pulp_units = [
            Mock(),
            Mock()
        ]

        repository = Mock()
        repository.list_refs.return_value = refs
        fake_lib.Repository.return_value = repository

        fake_model.Commit.side_effect = commits
        fake_model.Unit.side_effect = units

        fake_unit.side_effect = pulp_units

        fake_conduit = Mock()

        # test
        step = Add()
        step.parent = Mock(remote_id=remote_id, storage_path='/tmp/xyz')
        step.get_conduit = Mock(return_value=fake_conduit)
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_path)
        self.assertEqual(
            fake_model.Commit.call_args_list,
            [
                (('commit:1', 'md:1'), {}),
                (('commit:2', 'md:2'), {}),
            ])
        self.assertEqual(
            fake_model.Unit.call_args_list,
            [
                ((remote_id, 'branch:1', commits[0]), {}),
                ((remote_id, 'branch:2', commits[1]), {}),
            ])
        self.assertEqual(
            fake_link.call_args_list,
            [
                ((units[0],), {}),
                ((units[1],), {}),
            ])
        self.assertEqual(
            fake_unit.call_args_list,
            [
                ((Unit.TYPE_ID, units[0].key, units[0].metadata, units[0].storage_path), {}),
                ((Unit.TYPE_ID, units[1].key, units[1].metadata, units[1].storage_path), {}),
            ])
        self.assertEqual(
            fake_conduit.save_unit.call_args_list,
            [
                ((pulp_units[0],), {}),
                ((pulp_units[1],), {}),
            ])
Beispiel #7
0
    def test_process_main(self, fake_associate, fake_model, fake_lib):
        def history(commit_id):
            return [
                Commit(id='{}head'.format(commit_id), metadata={'md': 0}),
                Commit(id='{}parent-1'.format(commit_id), metadata={'md': 1}),
                Commit(id='{}parent-2'.format(commit_id), metadata={'md': 2}),
            ]

        repo_id = 'r-1234'
        remote_id = 'remote-1'
        refs = [
            Mock(path='branch:1', commit='commit:1', metadata='md:1'),
            Mock(path='branch:2', commit='commit:2', metadata='md:2'),
            Mock(path='branch:3', commit='commit:3', metadata='md:3'),
            Mock(path='branch:4', commit='commit:4', metadata='md:4'),
            Mock(path='branch:5', commit='commit:5', metadata='md:5'),
        ]

        units = [
            Mock(remote_id=remote_id,
                 branch=r.path.split(':')[-1],
                 commit=c.id,
                 metadata=c.metadata,
                 unit_key={}) for r in refs[:-1]
            for c in reversed(history(r.commit))
        ]

        units[0].save.side_effect = NotUniqueError  # duplicate

        fake_model.Branch.side_effect = units
        fake_model.Branch.objects.get.return_value = units[0]

        branches = [r.path.split(':')[-1] for r in refs[:-1]]

        repository = Mock()
        repository.list_refs.return_value = refs
        repository.history.side_effect = history
        fake_lib.Repository.return_value = repository

        parent = Mock(remote_id=remote_id,
                      storage_dir='/tmp/xyz',
                      branches=branches)
        parent.get_repo.return_value = Mock(id=repo_id)

        fake_conduit = Mock()

        # test
        step = Add()
        step.parent = parent
        step.get_conduit = Mock(return_value=fake_conduit)
        step.process_main()

        # validation
        fake_lib.Repository.assert_called_once_with(step.parent.storage_dir)
        self.assertEqual(fake_model.Branch.call_args_list, [
            call(remote_id=u.remote_id,
                 branch=u.branch,
                 commit=u.commit,
                 metadata=u.metadata) for u in units
        ])
        self.assertEqual(fake_associate.call_args_list,
                         [((parent.get_repo.return_value.repo_obj, u), {})
                          for u in units])