Ejemplo 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() == []
Ejemplo n.º 2
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
Ejemplo n.º 3
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'}
Ejemplo n.º 4
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'}
Ejemplo 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
Ejemplo n.º 6
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
Ejemplo 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"}
Ejemplo n.º 8
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() == []
Ejemplo n.º 9
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() == []
Ejemplo n.º 10
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'}
Ejemplo n.º 11
0
def test_revert_removal():
    res = create_resource('test1')
    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()

    log_item = change.create_remove(resource_obj.name)
    log_item.save()
    uid = log_item.uid
    assert log_item.diff == [['remove', '', [['a', '9']]]]
    operations.commit_log_item(log_item)

    ModelMeta.save_all_lazy()

    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(uid)

    ModelMeta.save_all_lazy()

    resource_obj = resource.load('test1')
    assert resource_obj.args == {
        'a': '9',
        'location_id': '',
        'transports_id': ''
    }
Ejemplo n.º 12
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': ''
    }
Ejemplo n.º 13
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() == []
Ejemplo n.º 14
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': ''
    }
Ejemplo n.º 15
0
def test_revert_update():
    prev = {'a': '9'}
    new = {'a': '10'}
    res = create_resource('test1')
    ModelMeta.save_all_lazy()

    res.update(prev)
    ModelMeta.save_all_lazy()
    logitem = change.staged_log()[0]
    operations.commit_log_item(logitem)
    res.update(new)
    ModelMeta.save_all_lazy()
    logitem = change.staged_log()[0]
    uid = logitem.uid
    assert logitem.diff == [['change', 'a', ['9', '10']]]
    operations.commit_log_item(logitem)
    assert res.args == new

    change.revert(uid)
    assert res.args == {'a': '9'}
Ejemplo n.º 16
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() == []
Ejemplo n.º 17
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'}
Ejemplo n.º 18
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'}
Ejemplo n.º 19
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
Ejemplo 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() == []
Ejemplo n.º 21
0
def test_revert_removal():
    res = create_resource('test1')
    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()

    log_item = change.create_remove(resource_obj.name)
    log_item.save()
    uid = log_item.uid
    assert log_item.diff == [['remove', '', [['a', '9']]]]
    operations.commit_log_item(log_item)

    ModelMeta.save_all_lazy()

    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(uid)

    ModelMeta.save_all_lazy()

    resource_obj = resource.load('test1')
    assert resource_obj.args == {
        'a': '9',
        'location_id': '',
        'transports_id': ''
    }
Ejemplo n.º 22
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": ""}
Ejemplo n.º 23
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
Ejemplo n.º 24
0
def revert(uid):
    try:
        change.revert(uid)
    except errors.SolarError as er:
        raise click.BadParameter(str(er))
Ejemplo n.º 25
0
def revert(uid):
    change.revert(uid)
Ejemplo n.º 26
0
def revert(uid):
    try:
        change.revert(uid)
    except errors.SolarError as er:
        raise click.BadParameter(str(er))