Exemplo n.º 1
0
def test_revert_create():
    res = DBResource.from_dict(
        "test1",
        {
            "name": "test1",
            "base_path": "x",
            "state": RESOURCE_STATE.created.name,
            "meta_inputs": {"a": {"value": None, "schema": "str"}},
        },
    )
    res.inputs["a"] = "9"
    res.save_lazy()
    ModelMeta.save_all_lazy()

    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    logitem = staged_log[0]
    operations.move_to_commited(logitem.log_action)
    assert logitem.diff == [["add", "", [["a", "9"]]]]

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

    change.revert(logitem.uid)

    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    for item in staged_log:
        operations.move_to_commited(item.log_action)
    assert resource.load_all() == []
Exemplo n.º 2
0
def test_discard_removed():
    res1 = DBResource.from_dict(
        "test1",
        {
            "name": "test1",
            "base_path": "x",
            "state": RESOURCE_STATE.created.name,
            "meta_inputs": {"a": {"value": None, "schema": "str"}},
        },
    )
    res1.inputs["a"] = "9"
    res1.save_lazy()
    ModelMeta.save_all_lazy()
    staged_log = change.stage_changes()
    for item in staged_log:
        operations.move_to_commited(item.log_action)
    res1 = resource.load("test1")
    res1.remove()
    assert len(change.stage_changes()) == 1
    assert res1.to_be_removed()

    change.discard_all()

    assert len(change.stage_changes()) == 0
    assert not resource.load("test1").to_be_removed()
Exemplo n.º 3
0
def test_revert_removed_child():
    res1 = orm.DBResource(id='test1', name='test1', base_path='x')
    res1.save()
    res1.add_input('a', 'str', '9')

    res2 = orm.DBResource(id='test2', name='test2', base_path='x')
    res2.save()
    res2.add_input('a', 'str', 0)

    res1 = resource.load('test1')
    res2 = resource.load('test2')
    signals.connect(res1, res2)

    staged_log = change.stage_changes()
    assert len(staged_log) == 2
    for item in staged_log:
        operations.move_to_commited(item.log_action)
    res2.remove()

    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    logitem = next(staged_log.collection())
    operations.move_to_commited(logitem.log_action)

    with mock.patch.object(resource, 'read_meta') as mread:
        mread.return_value = {'input': {'a': {'schema': 'str!'}}}
        change.revert(logitem.uid)

    res2 = resource.load('test2')
    assert res2.args == {'a': '9'}
Exemplo n.º 4
0
def test_revert_create():
    res = DBResource.from_dict('test1',
                               {'name': 'test1',
                                'base_path': 'x',
                                'state': RESOURCE_STATE.created.name,
                                'meta_inputs': {'a': {'value': None,
                                                      'schema': 'str'}}})
    res.inputs['a'] = '9'
    res.save_lazy()
    ModelMeta.save_all_lazy()

    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    logitem = staged_log[0]
    operations.move_to_commited(logitem.log_action)
    assert logitem.diff == [['add', '', [['a', '9']]]]

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

    change.revert(logitem.uid)

    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    for item in staged_log:
        operations.move_to_commited(item.log_action)
    assert resource.load_all() == []
Exemplo n.º 5
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
Exemplo n.º 6
0
def test_revert_create():
    res = DBResource.from_dict('test1',
                               {'name': 'test1',
                                'base_path': 'x',
                                'state': RESOURCE_STATE.created.name,
                                'meta_inputs': {'a': {'value': None,
                                                      'schema': 'str'}}})
    res.inputs['a'] = '9'
    res.save_lazy()
    ModelMeta.save_all_lazy()

    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    logitem = staged_log[0]
    operations.move_to_commited(logitem.log_action)
    assert logitem.diff == [['add', '', [['a', '9']]]]

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

    change.revert(logitem.uid)

    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    for item in staged_log:
        operations.move_to_commited(item.log_action)

    assert resource.load_all() == []
Exemplo n.º 7
0
def test_revert_removed_child():
    res1 = orm.DBResource(id="test1", name="test1", base_path="x")  # NOQA
    res1.save()
    res1.add_input("a", "str", "9")

    res2 = orm.DBResource(id="test2", name="test2", base_path="x")  # NOQA
    res2.save()
    res2.add_input("a", "str", 0)

    res1 = resource.load("test1")
    res2 = resource.load("test2")
    signals.connect(res1, res2)

    staged_log = change.stage_changes()
    assert len(staged_log) == 2
    for item in staged_log:
        operations.move_to_commited(item.log_action)
    res2.remove()

    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    logitem = next(staged_log.collection())
    operations.move_to_commited(logitem.log_action)

    with mock.patch.object(resource, "read_meta") as mread:
        mread.return_value = {"input": {"a": {"schema": "str!"}}}
        change.revert(logitem.uid)

    res2 = resource.load("test2")
    assert res2.args == {"a": "9"}
Exemplo n.º 8
0
def test_discard_connection():
    res1 = DBResource.from_dict('test1',
                                {'name': 'test1',
                                 'base_path': 'x',
                                 'state': RESOURCE_STATE.created.name,
                                 'meta_inputs': {'a': {'value': None,
                                                       'schema': 'str'}}})
    res1.inputs['a'] = '9'
    res1.save_lazy()

    res2 = DBResource.from_dict('test2',
                                {'name': 'test2',
                                 'base_path': 'x',
                                 'state': RESOURCE_STATE.created.name,
                                 'meta_inputs': {'a': {'value': None,
                                                       'schema': 'str'}}})
    res2.inputs['a'] = '0'
    res2.save_lazy()
    ModelMeta.save_all_lazy()

    staged_log = change.stage_changes()
    for item in staged_log:
        operations.move_to_commited(item.log_action)

    res1 = resource.load('test1')
    res2 = resource.load('test2')
    res1.connect(res2, {'a': 'a'})
    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    assert res2.args == {'a': '9'}
    change.discard_all()
    assert res2.args == {'a': '0'}
    assert len(change.stage_changes()) == 0
Exemplo n.º 9
0
def test_revert_removed_child():
    res1 = orm.DBResource(id='test1', name='test1', base_path='x')  # NOQA
    res1.save()
    res1.add_input('a', 'str', '9')

    res2 = orm.DBResource(id='test2', name='test2', base_path='x')  # NOQA
    res2.save()
    res2.add_input('a', 'str', 0)

    res1 = resource.load('test1')
    res2 = resource.load('test2')
    signals.connect(res1, res2)

    staged_log = change.stage_changes()
    assert len(staged_log) == 2
    for item in staged_log:
        operations.move_to_commited(item.log_action)
    res2.remove()

    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    logitem = next(staged_log.collection())
    operations.move_to_commited(logitem.log_action)

    with mock.patch.object(resource, 'read_meta') as mread:
        mread.return_value = {'input': {'a': {'schema': 'str!'}}}
        change.revert(logitem.uid)

    res2 = resource.load('test2')
    assert res2.args == {'a': '9'}
Exemplo n.º 10
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
Exemplo n.º 11
0
def test_discard_connection():
    res1 = DBResource.from_dict('test1',
                                {'name': 'test1',
                                 'base_path': 'x',
                                 'state': RESOURCE_STATE.created.name,
                                 'meta_inputs': {'a': {'value': None,
                                                       'schema': 'str'}}})
    res1.inputs['a'] = '9'
    res1.save_lazy()

    res2 = DBResource.from_dict('test2',
                                {'name': 'test2',
                                 'base_path': 'x',
                                 'state': RESOURCE_STATE.created.name,
                                 'meta_inputs': {'a': {'value': None,
                                                       'schema': 'str'}}})
    res2.inputs['a'] = '0'
    res2.save_lazy()
    ModelMeta.save_all_lazy()

    staged_log = change.stage_changes()
    for item in staged_log:
        operations.move_to_commited(item.log_action)

    res1 = resource.load('test1')
    res2 = resource.load('test2')
    res1.connect(res2, {'a': 'a'})
    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    assert res2.args == {'a': '9'}
    change.discard_all()
    assert res2.args == {'a': '0'}
    assert len(change.stage_changes()) == 0
Exemplo n.º 12
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
Exemplo n.º 13
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'}
Exemplo n.º 14
0
def test_discard_update():
    res1 = orm.DBResource(id='test1', name='test1', base_path='x')
    res1.save()
    res1.add_input('a', 'str', '9')
    staged_log = change.stage_changes()
    for item in staged_log:
        operations.move_to_commited(item.log_action)
    res1 = resource.load('test1')
    res1.update({'a': '11'})
    assert len(change.stage_changes()) == 1
    assert res1.args == {'a': '11'}

    change.discard_all()
    assert res1.args == {'a': '9'}
Exemplo n.º 15
0
def test_discard_removed():
    res1 = orm.DBResource(id='test1', name='test1', base_path='x')
    res1.save()
    res1.add_input('a', 'str', '9')
    staged_log = change.stage_changes()
    for item in staged_log:
        operations.move_to_commited(item.log_action)
    res1 = resource.load('test1')
    res1.remove()
    assert len(change.stage_changes()) == 1
    assert res1.to_be_removed()

    change.discard_all()

    assert len(change.stage_changes()) == 0
    assert not resource.load('test1').to_be_removed()
Exemplo n.º 16
0
def test_revert_removal():
    res = DBResource.from_dict('test1',
                               {'name': 'test1',
                                'base_path': 'x',
                                'state': RESOURCE_STATE.created.name,
                                'meta_inputs': {'a': {'value': None,
                                                      'schema': 'str'}}})
    res.inputs['a'] = '9'
    res.save_lazy()

    commited = CommitedResource.from_dict('test1', {'inputs': {'a': '9'},
                                                    'state': 'operational'})
    commited.save_lazy()

    resource_obj = resource.load(res.name)
    resource_obj.remove()
    ModelMeta.save_all_lazy()

    changes = change.stage_changes()
    assert len(changes) == 1
    assert changes[0].diff == [['remove', '', [['a', '9']]]]
    operations.move_to_commited(changes[0].log_action)

    clear_cache()
    assert DBResource._c.obj_cache == {}
    # assert DBResource.bucket.get('test1').siblings == []

    with mock.patch.object(repository.Repository, 'read_meta') as mread:
        mread.return_value = {
            'input': {'a': {'schema': 'str!'}},
            'id': 'mocked'
        }
        with mock.patch.object(repository.Repository, 'get_path') as mpath:
            mpath.return_value = 'x'

            change.revert(changes[0].uid)
    ModelMeta.save_all_lazy()
    # assert len(DBResource.bucket.get('test1').siblings) == 1

    resource_obj = resource.load('test1')
    assert resource_obj.args == {
        'a': '9',
        'location_id': '',
        'transports_id': ''
    }
Exemplo n.º 17
0
def test_revert_removal():
    res = DBResource.from_dict('test1',
                               {'name': 'test1',
                                'base_path': 'x',
                                'state': RESOURCE_STATE.created.name,
                                'meta_inputs': {'a': {'value': None,
                                                      'schema': 'str'}}})
    res.inputs['a'] = '9'
    res.save_lazy()

    commited = CommitedResource.from_dict('test1', {'inputs': {'a': '9'},
                                                    'state': 'operational'})
    commited.save_lazy()

    resource_obj = resource.load(res.name)
    resource_obj.remove()
    ModelMeta.save_all_lazy()

    changes = change.stage_changes()
    assert len(changes) == 1
    assert changes[0].diff == [['remove', '', [['a', '9']]]]
    operations.move_to_commited(changes[0].log_action)

    ModelMeta.session_start()
    assert DBResource._c.obj_cache == {}
    assert DBResource.bucket.get('test1').siblings == []

    with mock.patch.object(resource, 'read_meta') as mread:
        mread.return_value = {
            'input': {'a': {'schema': 'str!'}},
            'id': 'mocked'
        }
        change.revert(changes[0].uid)
    ModelMeta.save_all_lazy()
    assert len(DBResource.bucket.get('test1').siblings) == 1

    resource_obj = resource.load('test1')
    assert resource_obj.args == {
        'a': '9',
        'location_id': '',
        'transports_id': ''
    }
Exemplo n.º 18
0
def test_discard_connection():
    res1 = orm.DBResource(id='test1', name='test1', base_path='x')
    res1.save()
    res1.add_input('a', 'str', '9')

    res2 = orm.DBResource(id='test2', name='test2', base_path='x')
    res2.save()
    res2.add_input('a', 'str', '0')

    staged_log = change.stage_changes()
    for item in staged_log:
        operations.move_to_commited(item.log_action)

    res1 = resource.load('test1')
    res2 = resource.load('test2')
    signals.connect(res1, res2)
    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    assert res2.args == {'a': '9'}
    change.discard_all()
    assert res2.args == {'a': '0'}
    assert len(change.stage_changes()) == 0
Exemplo n.º 19
0
def test_discard_removed():
    res1 = DBResource.from_dict('test1',
                                {'name': 'test1',
                                 'base_path': 'x',
                                 'state': RESOURCE_STATE.created.name,
                                 'meta_inputs': {'a': {'value': None,
                                                       'schema': 'str'}}})
    res1.inputs['a'] = '9'
    res1.save_lazy()
    ModelMeta.save_all_lazy()
    staged_log = change.stage_changes()
    for item in staged_log:
        operations.move_to_commited(item.log_action)
    res1 = resource.load('test1')
    res1.remove()
    assert len(change.stage_changes()) == 1
    assert res1.to_be_removed()

    change.discard_all()

    assert len(change.stage_changes()) == 0
    assert not resource.load('test1').to_be_removed()
Exemplo n.º 20
0
def test_revert_create():
    res = orm.DBResource(id='test1', name='test1', base_path='x')
    res.save()
    res.add_input('a', 'str', '9')

    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    logitem = next(staged_log.collection())

    operations.move_to_commited(logitem.log_action)
    assert logitem.diff == [['add', '', [['a', '9']]]]

    commited = orm.DBCommitedState.load('test1')
    assert commited.inputs == {'a': '9'}

    change.revert(logitem.uid)

    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    for item in staged_log:
        operations.move_to_commited(item.log_action)
    assert orm.DBResource.load_all() == []
Exemplo n.º 21
0
def test_revert_update_connected():
    res1 = orm.DBResource(id='test1', name='test1', base_path='x')
    res1.save()
    res1.add_input('a', 'str', '9')

    res2 = orm.DBResource(id='test2', name='test2', base_path='x')
    res2.save()
    res2.add_input('a', 'str', 0)

    res3 = orm.DBResource(id='test3', name='test3', base_path='x')
    res3.save()
    res3.add_input('a', 'str', 0)

    res1 = resource.load('test1')
    res2 = resource.load('test2')
    res3 = resource.load('test3')
    signals.connect(res1, res2)
    signals.connect(res2, res3)

    staged_log = change.stage_changes()
    assert len(staged_log) == 3
    for item in staged_log:
        operations.move_to_commited(item.log_action)
    assert len(staged_log) == 0

    signals.disconnect(res1, res2)

    staged_log = change.stage_changes()
    assert len(staged_log) == 2
    to_revert = []
    for item in staged_log:
        operations.move_to_commited(item.log_action)
        to_revert.append(item.uid)

    change.revert_uids(sorted(to_revert, reverse=True))
    staged_log = change.stage_changes()
    assert len(staged_log) == 2
    for item in staged_log:
        assert item.diff == [['change', 'a', [0, '9']]]
Exemplo n.º 22
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
Exemplo n.º 23
0
def test_discard_removed():
    res1 = DBResource.from_dict('test1',
                                {'name': 'test1',
                                 'base_path': 'x',
                                 'state': RESOURCE_STATE.created.name,
                                 'meta_inputs': {'a': {'value': None,
                                                       'schema': 'str'}}})
    res1.inputs['a'] = '9'
    res1.save_lazy()
    ModelMeta.save_all_lazy()
    staged_log = change.stage_changes()
    for item in staged_log:
        operations.move_to_commited(item.log_action)
    res1 = resource.load('test1')
    res1.remove()
    assert len(change.stage_changes()) == 1
    assert res1.to_be_removed()

    change.discard_all()

    assert len(change.stage_changes()) == 0
    assert not resource.load('test1').to_be_removed()
Exemplo n.º 24
0
def test_discard_connection():
    res1 = DBResource.from_dict(
        "test1",
        {
            "name": "test1",
            "base_path": "x",
            "state": RESOURCE_STATE.created.name,
            "meta_inputs": {"a": {"value": None, "schema": "str"}},
        },
    )
    res1.inputs["a"] = "9"
    res1.save_lazy()

    res2 = DBResource.from_dict(
        "test2",
        {
            "name": "test2",
            "base_path": "x",
            "state": RESOURCE_STATE.created.name,
            "meta_inputs": {"a": {"value": None, "schema": "str"}},
        },
    )
    res2.inputs["a"] = "0"
    res2.save_lazy()
    ModelMeta.save_all_lazy()

    staged_log = change.stage_changes()
    for item in staged_log:
        operations.move_to_commited(item.log_action)

    res1 = resource.load("test1")
    res2 = resource.load("test2")
    res1.connect(res2, {"a": "a"})
    staged_log = change.stage_changes()
    assert len(staged_log) == 1
    assert res2.args == {"a": "9"}
    change.discard_all()
    assert res2.args == {"a": "0"}
    assert len(change.stage_changes()) == 0
Exemplo n.º 25
0
def test_revert_removal():
    res = DBResource.from_dict(
        "test1",
        {
            "name": "test1",
            "base_path": "x",
            "state": RESOURCE_STATE.created.name,
            "meta_inputs": {"a": {"value": None, "schema": "str"}},
        },
    )
    res.inputs["a"] = "9"
    res.save_lazy()

    commited = CommitedResource.from_dict("test1", {"inputs": {"a": "9"}, "state": "operational"})
    commited.save_lazy()

    resource_obj = resource.load(res.name)
    resource_obj.remove()
    ModelMeta.save_all_lazy()

    changes = change.stage_changes()
    assert len(changes) == 1
    assert changes[0].diff == [["remove", "", [["a", "9"]]]]
    operations.move_to_commited(changes[0].log_action)

    ModelMeta.session_start()
    assert DBResource._c.obj_cache == {}
    assert DBResource.bucket.get("test1").siblings == []

    with mock.patch.object(resource, "read_meta") as mread:
        mread.return_value = {"input": {"a": {"schema": "str!"}}, "id": "mocked"}
        change.revert(changes[0].uid)
    ModelMeta.save_all_lazy()
    assert len(DBResource.bucket.get("test1").siblings) == 1

    resource_obj = resource.load("test1")
    assert resource_obj.args == {"a": "9", "location_id": "", "transports_id": ""}
Exemplo n.º 26
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
Exemplo n.º 27
0
def commit_logitem(task_uuid):
    return move_to_commited(task_uuid.rsplit(':', 1)[-1])
Exemplo n.º 28
0
def commit_all():
    """Helper mainly for ease of testing"""
    from solar.system_log.operations import move_to_commited
    for item in data.SL():
        move_to_commited(item.log_action)
Exemplo n.º 29
0
def test_revert_update_connected():
    res1 = DBResource.from_dict(
        "test1",
        {
            "name": "test1",
            "base_path": "x",
            "state": RESOURCE_STATE.created.name,
            "meta_inputs": {"a": {"value": None, "schema": "str"}},
        },
    )
    res1.inputs["a"] = "9"
    res1.save_lazy()

    res2 = DBResource.from_dict(
        "test2",
        {
            "name": "test2",
            "base_path": "x",
            "state": RESOURCE_STATE.created.name,
            "meta_inputs": {"a": {"value": None, "schema": "str"}},
        },
    )
    res2.inputs["a"] = ""
    res2.save_lazy()

    res3 = DBResource.from_dict(
        "test3",
        {
            "name": "test3",
            "base_path": "x",
            "state": RESOURCE_STATE.created.name,
            "meta_inputs": {"a": {"value": None, "schema": "str"}},
        },
    )
    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 = change.stage_changes()
    assert len(staged_log) == 3

    for item in staged_log:
        assert item.action == "run"
        operations.move_to_commited(item.log_action)
    assert len(change.stage_changes()) == 0

    res1.disconnect(res2)
    staged_log = change.stage_changes()
    assert len(staged_log) == 2
    to_revert = []

    for item in staged_log:
        assert item.action == "update"
        operations.move_to_commited(item.log_action)
        to_revert.append(item.uid)

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

    staged_log = change.stage_changes()

    assert len(staged_log) == 2
    for item in staged_log:
        assert item.diff == [["change", "a", ["", "9"]]]
Exemplo n.º 30
0
 def commit(self, ctxt, *args, **kwargs):
     return move_to_commited(ctxt['task_id'].rsplit(':', 1)[-1])
Exemplo n.º 31
0
def commit_all():
    """Helper mainly for ease of testing"""
    from solar.system_log.operations import move_to_commited
    for item in data.SL():
        move_to_commited(item.log_action)
Exemplo n.º 32
0
def test_revert_update_connected():
    res1 = DBResource.from_dict('test1',
                                {'name': 'test1',
                                 'base_path': 'x',
                                 'state': RESOURCE_STATE.created.name,
                                 'meta_inputs': {'a': {'value': None,
                                                       'schema': 'str'}}})
    res1.inputs['a'] = '9'
    res1.save_lazy()

    res2 = DBResource.from_dict('test2',
                                {'name': 'test2',
                                 'base_path': 'x',
                                 'state': RESOURCE_STATE.created.name,
                                 'meta_inputs': {'a': {'value': None,
                                                       'schema': 'str'}}})
    res2.inputs['a'] = ''
    res2.save_lazy()

    res3 = DBResource.from_dict('test3',
                                {'name': 'test3',
                                 'base_path': 'x',
                                 'state': RESOURCE_STATE.created.name,
                                 'meta_inputs': {'a': {'value': None,
                                                       'schema': 'str'}}})
    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 = change.stage_changes()
    assert len(staged_log) == 3

    for item in staged_log:
        assert item.action == 'run'
        operations.move_to_commited(item.log_action)
    assert len(change.stage_changes()) == 0

    res1.disconnect(res2)
    staged_log = change.stage_changes()
    assert len(staged_log) == 2
    to_revert = []

    for item in staged_log:
        assert item.action == 'update'
        operations.move_to_commited(item.log_action)
        to_revert.append(item.uid)

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

    staged_log = change.stage_changes()

    assert len(staged_log) == 2
    for item in staged_log:
        assert item.diff == [['change', 'a', ['', '9']]]
Exemplo n.º 33
0
def test_revert_update_connected():
    res1 = DBResource.from_dict('test1',
                                {'name': 'test1',
                                 'base_path': 'x',
                                 'state': RESOURCE_STATE.created.name,
                                 'meta_inputs': {'a': {'value': None,
                                                       'schema': 'str'}}})
    res1.inputs['a'] = '9'
    res1.save_lazy()

    res2 = DBResource.from_dict('test2',
                                {'name': 'test2',
                                 'base_path': 'x',
                                 'state': RESOURCE_STATE.created.name,
                                 'meta_inputs': {'a': {'value': None,
                                                       'schema': 'str'}}})
    res2.inputs['a'] = ''
    res2.save_lazy()

    res3 = DBResource.from_dict('test3',
                                {'name': 'test3',
                                 'base_path': 'x',
                                 'state': RESOURCE_STATE.created.name,
                                 'meta_inputs': {'a': {'value': None,
                                                       'schema': 'str'}}})
    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 = change.stage_changes()
    assert len(staged_log) == 3

    for item in staged_log:
        assert item.action == 'run'
        operations.move_to_commited(item.log_action)
    assert len(change.stage_changes()) == 0

    res1.disconnect(res2)
    staged_log = change.stage_changes()
    assert len(staged_log) == 2
    to_revert = []

    for item in staged_log:
        assert item.action == 'update'
        operations.move_to_commited(item.log_action)
        to_revert.append(item.uid)

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

    staged_log = change.stage_changes()

    assert len(staged_log) == 2
    for item in staged_log:
        assert item.diff == [['change', 'a', ['', '9']]]
Exemplo n.º 34
0
 def commit(self, ctxt, *args, **kwargs):
     return move_to_commited(ctxt['task_id'].rsplit(':', 1)[-1])