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


Python json.fromjson函数代码示例

本文整理汇总了Python中wsme.rest.json.fromjson函数的典型用法代码示例。如果您正苦于以下问题:Python fromjson函数的具体用法?Python fromjson怎么用?Python fromjson使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_vip

 def test_vip(self):
     body = {"vip": {"ip_address": "10.0.0.1",
                     "net_port_id": uuidutils.generate_uuid(),
                     "subnet_id": uuidutils.generate_uuid(),
                     "floating_ip_id": uuidutils.generate_uuid(),
                     "floating_ip_network_id": uuidutils.generate_uuid()}}
     wsme_json.fromjson(self._type, body)
开发者ID:TrevorV,项目名称:octavia,代码行数:7,代码来源:test_load_balancers.py

示例2: valid_composite_rule

    def valid_composite_rule(rules):
        if isinstance(rules, dict) and len(rules) == 1:
            and_or_key = list(rules)[0]
            if and_or_key not in ('and', 'or'):
                raise base.ClientSideError(
                    _('Threshold rules should be combined with "and" or "or"'))
            if isinstance(rules[and_or_key], list):
                for sub_rule in rules[and_or_key]:
                    CompositeRule.valid_composite_rule(sub_rule)
            else:
                raise InvalidCompositeRule(rules)
        elif isinstance(rules, dict):
            rule_type = rules.pop('type', None)
            if not rule_type:
                raise base.ClientSideError(_('type must be set in every rule'))

            if rule_type not in CompositeRule.threshold_plugins:
                plugins = sorted(CompositeRule.threshold_plugins.names())
                err = _('Unsupported sub-rule type :%(rule)s in composite '
                        'rule, should be one of: %(plugins)s') % {
                            'rule': rule_type,
                            'plugins': plugins}
                raise base.ClientSideError(err)
            plugin = CompositeRule.threshold_plugins[rule_type].plugin
            wjson.fromjson(plugin, rules)
            rule_dict = plugin(**rules).as_dict()
            rules.update(rule_dict)
            rules.update(type=rule_type)
        else:
            raise InvalidCompositeRule(rules)
开发者ID:ISCAS-VDI,项目名称:aodh-base,代码行数:30,代码来源:composite.py

示例3: test_jsonObject

def test_jsonObject():
    # dictionaries work fine
    obj = AType()
    obj.data = {"a": 1}
    eq_(obj.data, {"a": 1})
    # other types don't
    assert_raises(wsme.exc.InvalidInput, lambda: setattr(obj, "data", ["a"]))
    # and un-JSONable Python data doesn't
    assert_raises(wsme.exc.InvalidInput, lambda: setattr(obj, "data", {"a": lambda: 1}))

    # valid JSON objects work fine
    obj = fromjson(AType, {"data": {"b": 2}})
    # other types don't
    assert_raises(wsme.exc.InvalidInput, lambda: fromjson(AType, {"data": ["b", 2]}))
开发者ID:acmiyaguchi,项目名称:build-relengapi,代码行数:14,代码来源:test_lib_api.py

示例4: test_l7policy

 def test_l7policy(self):
     body = {"action": constants.L7POLICY_ACTION_REJECT}
     l7policy = wsme_json.fromjson(self._type, body)
     self.assertEqual(sys.maxsize, l7policy.position)
     self.assertEqual(wsme_types.Unset, l7policy.redirect_url)
     self.assertEqual(wsme_types.Unset, l7policy.redirect_pool_id)
     self.assertTrue(l7policy.enabled)
开发者ID:evgenyfedoruk,项目名称:octavia,代码行数:7,代码来源:test_l7policies.py

示例5: test_l7rule

 def test_l7rule(self):
     body = {"type": constants.L7RULE_TYPE_PATH,
             "compare_type": constants.L7RULE_COMPARE_TYPE_STARTS_WITH,
             "value": "/api", "tags": ['test_tag']}
     l7rule = wsme_json.fromjson(self._type, body)
     self.assertEqual(wsme_types.Unset, l7rule.key)
     self.assertFalse(l7rule.invert)
开发者ID:openstack,项目名称:octavia,代码行数:7,代码来源:test_l7rules.py

示例6: test_max_weight

 def test_max_weight(self):
     body = {"weight": constants.MAX_WEIGHT + 1}
     self.assertRaises(
         exc.InvalidInput, wsme_json.fromjson, self._type, body)
     body = {"weight": constants.MAX_WEIGHT}
     member = wsme_json.fromjson(self._type, body)
     self.assertEqual(constants.MAX_WEIGHT, member.weight)
开发者ID:openstack,项目名称:octavia,代码行数:7,代码来源:test_members.py

示例7: test_non_uuid_project_id

 def test_non_uuid_project_id(self):
     body = {"loadbalancer_id": uuidutils.generate_uuid(),
             "protocol": constants.PROTOCOL_HTTP,
             "lb_algorithm": constants.LB_ALGORITHM_ROUND_ROBIN,
             "project_id": "non-uuid"}
     pool = wsme_json.fromjson(self._type, body)
     self.assertEqual(pool.project_id, body['project_id'])
开发者ID:openstack,项目名称:octavia,代码行数:7,代码来源:test_pools.py

示例8: test_member

 def test_member(self):
     body = {"name": "member1", "address": "10.0.0.1",
             "protocol_port": 80, "tags": ['test_tag']}
     member = wsme_json.fromjson(self._type, body)
     self.assertTrue(member.admin_state_up)
     self.assertEqual(1, member.weight)
     self.assertEqual(wsme_types.Unset, member.subnet_id)
开发者ID:openstack,项目名称:octavia,代码行数:7,代码来源:test_members.py

示例9: test_l7policy_max_position

 def test_l7policy_max_position(self):
     body = {"position": constants.MAX_POLICY_POSITION + 1}
     self.assertRaises(
         exc.InvalidInput, wsme_json.fromjson, self._type, body)
     body = {"position": constants.MAX_POLICY_POSITION}
     l7policy = wsme_json.fromjson(self._type, body)
     self.assertEqual(constants.MAX_POLICY_POSITION, l7policy.position)
开发者ID:openstack,项目名称:octavia,代码行数:7,代码来源:test_l7policies.py

示例10: test_date_formatting

def test_date_formatting():
    """ISO 8601 formatted dates with timezones are correctly translated to
    datetime instances and back"""
    d = TypeWithDate()
    d.when = datetime(2015, 2, 28, 1, 2, 3, tzinfo=UTC)
    j = {'when': '2015-02-28T01:02:03+00:00'}
    eq_(tojson(TypeWithDate, d), j)
    eq_(fromjson(TypeWithDate, j).when, d.when)
开发者ID:lundjordan,项目名称:build-relengapi,代码行数:8,代码来源:test_lib_api.py

示例11: test_with_redirect_url

 def test_with_redirect_url(self):
     url = "http://www.example.com/"
     body = {"action": constants.L7POLICY_ACTION_REDIRECT_TO_URL,
             "redirect_url": url}
     l7policy = wsme_json.fromjson(self._type, body)
     self.assertEqual(sys.maxsize, l7policy.position)
     self.assertEqual(url, l7policy.redirect_url)
     self.assertEqual(wsme_types.Unset, l7policy.redirect_pool_id)
开发者ID:evgenyfedoruk,项目名称:octavia,代码行数:8,代码来源:test_l7policies.py

示例12: test_jsonObject

def test_jsonObject():
    # dictionaries work fine
    obj = AType()
    obj.data = {'a': 1}
    eq_(obj.data, {'a': 1})
    # other types don't
    assert_raises(wsme.exc.InvalidInput, lambda:
                  setattr(obj, 'data', ['a']))
    # and un-JSONable Python data doesn't
    assert_raises(wsme.exc.InvalidInput, lambda:
                  setattr(obj, 'data', {'a': lambda: 1}))

    # valid JSON objects work fine
    obj = fromjson(AType, {'data': {'b': 2}})
    # other types don't
    assert_raises(wsme.exc.InvalidInput, lambda:
                  fromjson(AType, {'data': ['b', 2]}))
开发者ID:lundjordan,项目名称:build-relengapi,代码行数:17,代码来源:test_lib_api.py

示例13: test_listener

 def test_listener(self):
     body = {"name": "test", "description": "test", "connection_limit": 10,
             "protocol": constants.PROTOCOL_HTTP, "protocol_port": 80,
             "default_pool_id": uuidutils.generate_uuid(),
             "loadbalancer_id": uuidutils.generate_uuid(),
             "tags": ['test_tag']}
     listener = wsme_json.fromjson(self._type, body)
     self.assertTrue(listener.admin_state_up)
开发者ID:openstack,项目名称:octavia,代码行数:8,代码来源:test_listeners.py

示例14: test_non_uuid_project_id

 def test_non_uuid_project_id(self):
     body = {"name": "test", "description": "test", "connection_limit": 10,
             "protocol": constants.PROTOCOL_HTTP, "protocol_port": 80,
             "default_pool_id": uuidutils.generate_uuid(),
             "loadbalancer_id": uuidutils.generate_uuid(),
             "project_id": "non-uuid"}
     listener = wsme_json.fromjson(self._type, body)
     self.assertEqual(listener.project_id, body['project_id'])
开发者ID:openstack,项目名称:octavia,代码行数:8,代码来源:test_listeners.py

示例15: test_pool

 def test_pool(self):
     body = {
         "loadbalancer_id": uuidutils.generate_uuid(),
         "listener_id": uuidutils.generate_uuid(),
         "protocol": constants.PROTOCOL_HTTP,
         "lb_algorithm": constants.LB_ALGORITHM_ROUND_ROBIN,
         "tags": ['test_tag']}
     pool = wsme_json.fromjson(self._type, body)
     self.assertTrue(pool.admin_state_up)
开发者ID:openstack,项目名称:octavia,代码行数:9,代码来源:test_pools.py


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