예제 #1
0
def test_revert_update():
    commit = {'a': '10'}
    previous = {'a': '9'}
    res = DBResource.from_dict('test1',
                               {'name': 'test1',
                                'base_path': 'x',
                                'meta_inputs': {'a': {'value': None,
                                                      'schema': 'str'}}})
    res.save()
    action = 'update'
    res.inputs['a'] = '9'
    resource_obj = resource.load(res.name)

    assert resource_obj.args == previous

    log = data.SL()
    logitem = change.create_logitem(res.name,
                                    action,
                                    change.create_diff(commit, previous),
                                    [],
                                    base_path=res.base_path)
    log.append(logitem)
    resource_obj.update(commit)
    operations.move_to_commited(logitem.log_action)

    assert logitem.diff == [('change', 'a', ('9', '10'))]
    assert resource_obj.args == commit

    change.revert(logitem.uid)
    assert resource_obj.args == previous
예제 #2
0
def test_revert_removal():
    res = orm.DBResource(id='test1', name='test1', base_path='x')
    res.save()
    res.add_input('a', 'str', '9')
    res.add_input('location_id', 'str', '1')
    res.add_input('transports_id', 'str', '1')

    commited = orm.DBCommitedState.get_or_create('test1')
    commited.inputs = {'a': '9', 'location_id': '1', 'transports_id': '1'}
    commited.save()

    logitem =change.create_logitem(
        res.name, 'remove', change.create_diff({}, {'a': '9'}), [],
        base_path=res.base_path)
    log = data.SL()
    log.append(logitem)
    resource_obj = resource.load(res.name)
    resource_obj.remove()
    operations.move_to_commited(logitem.log_action)

    resources = orm.DBResource.load_all()

    assert resources == []
    assert logitem.diff == [('remove', '', [('a', '9')])]

    with mock.patch.object(resource, 'read_meta') as mread:
        mread.return_value = {'input': {'a': {'schema': 'str!'}}, 'id': 'mocked'}
        change.revert(logitem.uid)
    resource_obj = resource.load('test1')
    assert resource_obj.args == {'a': '9', 'location_id': '1', 'transports_id': '1'}
예제 #3
0
def test_revert_update():
    commit = {'a': '10'}
    previous = {'a': '9'}
    res = orm.DBResource(id='test1', name='test1', base_path='x')
    res.save()
    res.add_input('a', 'str', '9')
    action = 'update'

    resource_obj = resource.load(res.name)

    assert resource_obj.args == previous

    log = data.SL()
    logitem =change.create_logitem(
        res.name, action, change.create_diff(commit, previous), [],
        base_path=res.base_path)
    log.append(logitem)
    resource_obj.update(commit)
    operations.move_to_commited(logitem.log_action)

    assert logitem.diff == [('change', 'a', ('9', '10'))]
    assert resource_obj.args == commit

    change.revert(logitem.uid)
    assert resource_obj.args == previous
예제 #4
0
def test_revert_update():
    commit = {'a': '10'}
    previous = {'a': '9'}
    res = DBResource.from_dict('test1',
                               {'name': 'test1',
                                'base_path': 'x',
                                'meta_inputs': {'a': {'value': None,
                                                      'schema': 'str'}}})
    res.save()
    action = 'update'
    res.inputs['a'] = '9'
    resource_obj = resource.load(res.name)

    assert resource_obj.args == previous

    log = data.SL()
    logitem = change.create_logitem(res.name,
                                    action,
                                    change.create_diff(commit, previous),
                                    [],
                                    base_path=res.base_path)
    log.append(logitem)
    resource_obj.update(commit)
    operations.move_to_commited(logitem.log_action)

    assert logitem.diff == [['change', 'a', ['9', '10']]]
    assert resource_obj.args == commit

    change.revert(logitem.uid)
    assert resource_obj.args == previous
예제 #5
0
def test_revert_update():
    prev = {'a': '9'}
    new = {'a': '10'}
    res = create_resource('test1')
    res.save()
    action = 'run'
    resource_obj = resource.load(res.name)

    resource_obj.update(prev)
    logitem = change.create_logitem(res.name, action)
    operations.commit_log_item(logitem)
    resource_obj.update(new)

    logitem = change.create_logitem(res.name, action)
    uid = logitem.uid
    assert logitem.diff == [['change', 'a', ['9', '10']]]
    operations.commit_log_item(logitem)
    assert resource_obj.args == new

    change.revert(uid)
    assert resource_obj.args == {'a': '9'}
예제 #6
0
def test_revert_update():
    prev = {'a': '9'}
    new = {'a': '10'}
    res = create_resource('test1')
    res.save()
    action = 'run'
    resource_obj = resource.load(res.name)

    resource_obj.update(prev)
    logitem = change.create_logitem(res.name, action)
    operations.commit_log_item(logitem)
    resource_obj.update(new)

    logitem = change.create_logitem(res.name, action)
    uid = logitem.uid
    assert logitem.diff == [['change', 'a', ['9', '10']]]
    operations.commit_log_item(logitem)
    assert resource_obj.args == new

    change.revert(uid)
    assert resource_obj.args == {'a': '9'}
예제 #7
0
def test_revert_update():
    commit = {"a": "10"}
    previous = {"a": "9"}
    res = orm.DBResource(id="test1", name="test1", base_path="x")
    res.save()
    res.add_input("a", "str", "9")
    action = "update"

    resource_obj = resource.load(res.name)

    assert resource_obj.args == previous

    log = data.SL()
    logitem = change.create_logitem(res.name, action, change.create_diff(commit, previous))
    log.append(logitem)
    resource_obj.update(commit)
    operations.move_to_commited(logitem.log_action)

    assert resource_obj.args == commit

    change.revert(logitem.uid)
    assert resource_obj.args == previous
예제 #8
0
def test_revert_update():
    commit = {"a": "10"}
    previous = {"a": "9"}
    res = DBResource.from_dict(
        "test1", {"name": "test1", "base_path": "x", "meta_inputs": {"a": {"value": None, "schema": "str"}}}
    )
    res.save()
    action = "update"
    res.inputs["a"] = "9"
    resource_obj = resource.load(res.name)

    assert resource_obj.args == previous

    log = data.SL()
    logitem = change.create_logitem(res.name, action, change.create_diff(commit, previous), [], base_path=res.base_path)
    log.append(logitem)
    resource_obj.update(commit)
    operations.move_to_commited(logitem.log_action)

    assert logitem.diff == [("change", "a", ("9", "10"))]
    assert resource_obj.args == commit

    change.revert(logitem.uid)
    assert resource_obj.args == previous