예제 #1
0
def test_childs_added_on_stage():
    res_0, res_1 = [create_resource(str(n)) for n in range(2)]
    ModelMeta.save_all_lazy()
    for res in (res_0, res_1):
        change.create_run(res)
    res_0.connect(res_1, {'a': 'a'})
    change.staged_log()
    ModelMeta.save_all_lazy()
    change.commit_all()
    res_0.update({'a': '10'})
    ModelMeta.save_all_lazy()
    staged_log = change.staged_log()
    assert len(staged_log) == 2
    child_log_item = next(li for li in staged_log
                          if li.resource == res_1.name)
    assert child_log_item.action == 'update'
예제 #2
0
def test_revert_update_connected():
    res1 = create_resource('test1')
    res1.inputs['a'] = '9'
    res1.save_lazy()

    res2 = create_resource('test2')
    res2.inputs['a'] = ''
    res2.save_lazy()

    res3 = create_resource('test3')
    res3.inputs['a'] = ''
    res3.save_lazy()

    res1 = resource.load('test1')
    res2 = resource.load('test2')
    res3 = resource.load('test3')
    res1.connect(res2)
    res2.connect(res3)
    ModelMeta.save_all_lazy()

    staged_log = map(lambda res: change.create_run(res.name),
                     (res1, res2, res3))
    assert len(staged_log) == 3

    for item in staged_log:
        assert item.action == 'run'
        operations.commit_log_item(item)

    res1.disconnect(res2)
    staged_log = map(lambda res: change.create_run(res.name),
                     (res2, res3))
    to_revert = []

    for item in staged_log:
        assert item.action == 'run'
        to_revert.append(item.uid)
        operations.commit_log_item(item)

    change.revert_uids(sorted(to_revert, reverse=True))
    ModelMeta.save_all_lazy()

    staged_log = map(lambda res: change.create_run(res.name),
                     (res2, res3))

    for item in staged_log:
        assert item.diff == [['change', 'a', ['', '9']]]
예제 #3
0
def test_revert_update_connected():
    res1 = create_resource('test1')
    res1.inputs['a'] = '9'
    res1.save_lazy()

    res2 = create_resource('test2')
    res2.inputs['a'] = ''
    res2.save_lazy()

    res3 = create_resource('test3')
    res3.inputs['a'] = ''
    res3.save_lazy()

    res1 = resource.load('test1')
    res2 = resource.load('test2')
    res3 = resource.load('test3')
    res1.connect(res2)
    res2.connect(res3)
    ModelMeta.save_all_lazy()

    staged_log = map(lambda res: change.create_run(res.name),
                     (res1, res2, res3))
    assert len(staged_log) == 3

    for item in staged_log:
        assert item.action == 'run'
        operations.commit_log_item(item)

    res1.disconnect(res2)
    staged_log = map(lambda res: change.create_run(res.name), (res2, res3))
    to_revert = []

    for item in staged_log:
        assert item.action == 'run'
        to_revert.append(item.uid)
        operations.commit_log_item(item)

    change.revert_uids(sorted(to_revert, reverse=True))
    ModelMeta.save_all_lazy()

    staged_log = map(lambda res: change.create_run(res.name), (res2, res3))

    for item in staged_log:
        assert item.diff == [['change', 'a', ['', '9']]]
예제 #4
0
def test_discard_update():
    res1 = create_resource('test1')
    res1.db_obj.inputs['a'] = '9'
    operations.commit_log_item(change.create_run(res1))
    res1.update({'a': '11'})
    ModelMeta.save_all_lazy()
    assert len(change.staged_log()) == 1
    assert res1.args == {'a': '11'}

    change.discard_single(change.staged_log()[0])
    assert res1.args == {'a': '9'}
예제 #5
0
def test_discard_update():
    res1 = create_resource('test1')
    res1.inputs['a'] = '9'
    res1.save_lazy()
    operations.commit_log_item(change.create_run(res1.name))
    res1 = resource.load('test1')
    res1.update({'a': '11'})
    ModelMeta.save_all_lazy()
    assert len(change.staged_log()) == 1
    assert res1.args == {'a': '11'}

    change.discard_all()
    assert res1.args == {'a': '9'}
예제 #6
0
def test_discard_update():
    res1 = create_resource('test1')
    res1.inputs['a'] = '9'
    res1.save_lazy()
    operations.commit_log_item(change.create_run(res1.name))
    res1 = resource.load('test1')
    res1.update({'a': '11'})
    ModelMeta.save_all_lazy()
    assert len(change.staged_log()) == 1
    assert res1.args == {'a': '11'}

    change.discard_all()
    assert res1.args == {'a': '9'}
예제 #7
0
def test_revert_create():
    res = create_resource('test1')
    res.db_obj.inputs['a'] = '9'
    logitem = change.create_run(res)
    assert logitem.diff == [['add', '', [['a', '9']]]]
    uid = logitem.uid
    operations.commit_log_item(logitem)

    commited = CommitedResource.get('test1')
    assert commited.inputs == {'a': '9'}

    change.revert(uid)
    ModelMeta.save_all_lazy()
    staged_log = change.staged_log()
    assert len(staged_log) == 1
    for item in staged_log:
        operations.commit_log_item(item)

    assert resource.load_all() == []
예제 #8
0
def test_revert_create():
    res = create_resource('test1')
    res.inputs['a'] = '9'
    res.save_lazy()

    logitem = change.create_run(res.name)
    assert logitem.diff == [['add', '', [['a', '9']]]]
    uid = logitem.uid
    operations.commit_log_item(logitem)

    commited = CommitedResource.get('test1')
    assert commited.inputs == {'a': '9'}

    change.revert(uid)
    ModelMeta.save_all_lazy()
    staged_log = change.staged_log()
    assert len(staged_log) == 1
    for item in staged_log:
        operations.commit_log_item(item)

    assert resource.load_all() == []