当前位置: 首页>>代码示例>>Python>>正文


Python Resource.from_dict方法代码示例

本文整理汇总了Python中solar.dblayer.solar_models.Resource.from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Resource.from_dict方法的具体用法?Python Resource.from_dict怎么用?Python Resource.from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在solar.dblayer.solar_models.Resource的用法示例。


在下文中一共展示了Resource.from_dict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_discard_connection

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
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
开发者ID:pigmej,项目名称:solar,代码行数:35,代码来源:test_system_log_api.py

示例2: test_discard_all_pending_changes_resources_created

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
def test_discard_all_pending_changes_resources_created():
    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()
    assert len(staged_log) == 2

    change.discard_all()
    staged_log = change.stage_changes()
    assert len(staged_log) == 0
    assert resource.load_all() == []
开发者ID:pigmej,项目名称:solar,代码行数:29,代码来源:test_system_log_api.py

示例3: test_discard_all_pending_changes_resources_created

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
def test_discard_all_pending_changes_resources_created():
    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()
    assert len(staged_log) == 2

    change.discard_all()
    staged_log = change.stage_changes()
    assert len(staged_log) == 0
    assert resource.load_all() == []
开发者ID:aglarendil,项目名称:solar,代码行数:35,代码来源:test_system_log_api.py

示例4: tagged_resources

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
def tagged_resources():
    tags = ['n1', 'n2', 'n3']
    t1 = Resource.from_dict('t1',
                            {'name': 't1', 'tags': tags, 'base_path': 'x'})
    t1.save_lazy()
    t2 = Resource.from_dict('t2',
                            {'name': 't2', 'tags': tags, 'base_path': 'x'})
    t2.save_lazy()
    t3 = Resource.from_dict('t3',
                            {'name': 't3', 'tags': tags, 'base_path': 'x'})
    t3.save_lazy()
    ModelMeta.save_all_lazy()
    return [t1, t2, t3]
开发者ID:aglarendil,项目名称:solar,代码行数:15,代码来源:test_operations_with_tags.py

示例5: test_remove_events

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
def test_remove_events(events_example):
    r = Resource.from_dict(dict(key='e1', name='e1', base_path='x'))
    r.save()
    to_be_removed = events_example[2]
    evapi.add_events('e1', events_example)
    evapi.remove_event(to_be_removed)
    assert to_be_removed not in evapi.all_events('e1')
开发者ID:loles,项目名称:solar-1,代码行数:9,代码来源:test_events.py

示例6: test_riak

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
def test_riak():

    events = {
        'riak_service1': [
            evapi.React('riak_service1', 'run', 'success', 'riak_service2',
                        'run'),
            evapi.React('riak_service1', 'run', 'success',
                        'riak_service3', 'run')
        ],
        'riak_service3': [
            evapi.React('riak_service3', 'join', 'success', 'riak_service1',
                        'commit'),
            evapi.React('riak_service3', 'run', 'success', 'riak_service3',
                        'join')
        ],
        'riak_service2': [
            evapi.React('riak_service2', 'run', 'success', 'riak_service2',
                        'join'),
            evapi.React('riak_service2', 'join', 'success', 'riak_service1',
                        'commit')
        ],
    }
    for name in events:
        res = Resource.from_dict({'key': name, 'name': name})
        res.save()
        res.inputs.add_new('location_id', '1')
        evapi.add_events(name, events[name])

    changes_graph = nx.MultiDiGraph()
    changes_graph.add_node('riak_service1.run')
    evapi.build_edges(changes_graph, events)
    assert set(changes_graph.predecessors('riak_service1.commit')) == {
        'riak_service2.join', 'riak_service3.join'
    }
开发者ID:loles,项目名称:solar-1,代码行数:36,代码来源:test_events.py

示例7: test_revert_create

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
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() == []
开发者ID:aglarendil,项目名称:solar,代码行数:32,代码来源:test_system_log_api.py

示例8: test_revert_update

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
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
开发者ID:pigmej,项目名称:solar,代码行数:32,代码来源:test_system_log_api.py

示例9: test_revert_create

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
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() == []
开发者ID:pigmej,项目名称:solar,代码行数:30,代码来源:test_system_log_api.py

示例10: test_discard_removed

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
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()
开发者ID:aglarendil,项目名称:solar,代码行数:27,代码来源:test_system_log_api.py

示例11: test_events

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
def test_events(rk):
    k = next(rk)
    r1 = Resource.from_dict(k, {'events': ['event1', 'event2']})
    r1.save()
    assert r1.events == ['event1', 'event2']
    r1.events.pop()

    assert r1.events == ['event1']
开发者ID:aglarendil,项目名称:solar,代码行数:10,代码来源:test_real.py

示例12: tagged_resources

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
def tagged_resources():
    base_tags = ['n1=x', 'n2']
    tags = base_tags + ['node=t1']
    t1 = Resource.from_dict('t1',
                            {'name': 't1', 'tags': tags, 'base_path': 'x'})
    t1.save_lazy()
    tags = base_tags + ['node=t2']
    t2 = Resource.from_dict('t2',
                            {'name': 't2', 'tags': tags, 'base_path': 'x'})
    t2.save_lazy()
    tags = base_tags + ['node=t3']
    t3 = Resource.from_dict('t3',
                            {'name': 't3', 'tags': tags, 'base_path': 'x'})
    t3.save_lazy()
    tags = ['node=t3']
    t4 = Resource.from_dict('t4',
                            {'name': 't4', 'tags': tags, 'base_path': 'x'})
    t4.save_lazy()
    ModelMeta.save_all_lazy()
    return [t1, t2, t3]
开发者ID:loles,项目名称:solar-1,代码行数:22,代码来源:test_operations_with_tags.py

示例13: create_resource

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
def create_resource(name, tags=None):
    resource = DBResource.from_dict(
        name,
        {'name': name,
         'base_path': 'x',
         'state': '',
         'tags': tags or [],
         'meta_inputs': {'a': {'value': None,
                               'schema': 'str'}}})
    resource.save_lazy()
    return resource
开发者ID:pigmej,项目名称:solar-1,代码行数:13,代码来源:test_system_log_api.py

示例14: nova_deps

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
def nova_deps():
    for name in ['nova', 'nova_api', 'nova_sch']:
        r = Resource.from_dict(dict(key=name, name=name))
        r.inputs.add_new('location_id', '1')
        r.save()
    nova = [
        evapi.Dep('nova', 'run', 'success', 'nova_sch', 'run'),
        evapi.React('nova', 'run', 'success', 'nova_api', 'update')]
    nova_api = [
        evapi.React('nova_api', 'update', 'success', 'nova', 'reboot')]
    evapi.add_events('nova', nova)
    evapi.add_events('nova_api', nova_api)
    return {'nova': nova}
开发者ID:loles,项目名称:solar-1,代码行数:15,代码来源:test_events.py

示例15: test_discard_connection

# 需要导入模块: from solar.dblayer.solar_models import Resource [as 别名]
# 或者: from solar.dblayer.solar_models.Resource import from_dict [as 别名]
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
开发者ID:aglarendil,项目名称:solar,代码行数:41,代码来源:test_system_log_api.py


注:本文中的solar.dblayer.solar_models.Resource.from_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。