Ejemplo n.º 1
0
    def test_find_branches(self, fake_walk, fake_open, fake_head):
        fp = Mock()
        fp.__enter__ = Mock(return_value=fp)
        fp.__exit__ = Mock()
        fp.read.side_effect = ['hash-1', 'hash-2']
        fake_open.return_value = fp
        path = '/path-1'
        step = Add()
        step.parent = Mock(storage_path=path)
        heads = [Mock(), Mock()]
        fake_head.side_effect = heads
        tree = [
            ('/path-1/refs/heads', ['fedora'], []),
            ('/path-1/refs/heads/fedora', ['f21'], []),
            ('/path-1/refs/heads/fedora/f21', ['i386', 'x86_64'], []),
            ('/path-1/refs/heads/fedora/f21/i386', [], ['os']),
            ('/path-1/refs/heads/fedora/f21/x86_64', [], ['os']),
        ]
        fake_walk.return_value = tree

        # test
        branches = list(step.find_branches())

        # validation
        self.assertEqual(
            fake_open.call_args_list,
            [
                (('/path-1/refs/heads/fedora/f21/i386/os',), {}),
                (('/path-1/refs/heads/fedora/f21/x86_64/os',), {})
            ])
        fake_walk.assert_called_once_with(os.path.join(path, 'refs', 'heads'))
        self.assertEqual(
            fake_head.call_args_list,
            [
                (('fedora/f21/i386/os', 'hash-1'), {}),
                (('fedora/f21/x86_64/os', 'hash-2'), {})
            ])
        self.assertEqual(len(branches), 2)
        self.assertEqual(branches, heads)
Ejemplo n.º 2
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)