Exemplo n.º 1
0
 def test_link(self, fake_link):
     target = 'path-1'
     link_path = 'path-2'
     step = Add()
     unit = Mock(storage_path=link_path)
     step.parent = Mock(storage_path=target)
     step.link(unit)
     fake_link.assert_called_with(target, link_path)
Exemplo n.º 2
0
 def test_link(self, fake_link):
     target = 'path-1'
     link_path = 'path-2'
     step = Add()
     unit = Mock(storage_path=link_path)
     step.parent = Mock(storage_path=target)
     step.link(unit)
     fake_link.assert_called_with(target, link_path)
Exemplo n.º 3
0
    def test_link_exists(self, fake_link, fake_islink, fake_readlink):
        target = 'path-1'
        link_path = 'path-2'
        step = Add()
        unit = Mock(storage_path=link_path)
        step.parent = Mock(storage_path=target)
        fake_islink.return_value = True
        fake_readlink.return_value = target
        fake_link.side_effect = OSError(errno.EEXIST, link_path)

        # test
        step.link(unit)

        # validation
        fake_islink.assert_called_with(link_path)
        fake_readlink.assert_called_with(link_path)
Exemplo n.º 4
0
    def test_link_exists(self, fake_link, fake_islink, fake_readlink):
        target = 'path-1'
        link_path = 'path-2'
        step = Add()
        unit = Mock(storage_path=link_path)
        step.parent = Mock(storage_path=target)
        fake_islink.return_value = True
        fake_readlink.return_value = target
        fake_link.side_effect = OSError(errno.EEXIST, link_path)

        # test
        step.link(unit)

        # validation
        fake_islink.assert_called_with(link_path)
        fake_readlink.assert_called_with(link_path)
Exemplo n.º 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)