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


Python schema.Schema类代码示例

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


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

示例1: test_optional_list

 def test_optional_list(self):
     """
     The default value of an optional L{List} is C{[]}.
     """
     schema = Schema(List("names", Unicode(), optional=True))
     arguments, _ = schema.extract({})
     self.assertEqual([], arguments.names)
开发者ID:antisvin,项目名称:txAWS,代码行数:7,代码来源:test_schema.py

示例2: test_extract_with_single_numbered

 def test_extract_with_single_numbered(self):
     """
     L{Schema.extract} can handle a single parameter with a numbered value.
     """
     schema = Schema(Unicode("name.n"))
     arguments, _ = schema.extract({"name.0": "Joe"})
     self.assertEqual("Joe", arguments.name[0])
开发者ID:ArtRichards,项目名称:txaws,代码行数:7,代码来源:test_schema.py

示例3: test_add_single_extra_schema_item

 def test_add_single_extra_schema_item(self):
     """New Parameters can be added to the Schema."""
     schema = Schema(Unicode("name"))
     schema = schema.extend(Unicode("computer"))
     arguments, _ = schema.extract({"name": "value", "computer": "testing"})
     self.assertEqual(u"value", arguments.name)
     self.assertEqual("testing", arguments.computer)
开发者ID:antisvin,项目名称:txAWS,代码行数:7,代码来源:test_schema.py

示例4: test_bundle_with_numbered

 def test_bundle_with_numbered(self):
     """
     L{Schema.bundle} correctly handles numbered arguments.
     """
     schema = Schema(Unicode("name.n"))
     params = schema.bundle(name=["foo", "bar"])
     self.assertEqual({"name.1": "foo", "name.2": "bar"}, params)
开发者ID:antisvin,项目名称:txAWS,代码行数:7,代码来源:test_schema.py

示例5: test_bundle_with_empty_numbered

 def test_bundle_with_empty_numbered(self):
     """
     L{Schema.bundle} correctly handles an empty numbered arguments list.
     """
     schema = Schema(Unicode("name.n"))
     params = schema.bundle(name=[])
     self.assertEqual({}, params)
开发者ID:antisvin,项目名称:txAWS,代码行数:7,代码来源:test_schema.py

示例6: test_extend_with_additional_schema_attributes

    def test_extend_with_additional_schema_attributes(self):
        """
        The additional schema attributes can be passed to L{Schema.extend}.
        """
        result = {'id': Integer(), 'name': Unicode(), 'data': RawStr()}
        errors = [APIError]

        schema = Schema(
            name="GetStuff",
            parameters=[Integer("id")])

        schema2 = schema.extend(
            name="GetStuff2",
            doc="Get stuff 2",
            parameters=[Unicode("scope")],
            result=result,
            errors=errors)

        self.assertEqual("GetStuff2", schema2.name)
        self.assertEqual("Get stuff 2", schema2.doc)
        self.assertEqual(result, schema2.result)
        self.assertEqual(set(errors), schema2.errors)

        arguments, _ = schema2.extract({'id': '5', 'scope': u'foo'})
        self.assertEqual(5, arguments.id)
        self.assertEqual(u'foo', arguments.scope)
开发者ID:antisvin,项目名称:txAWS,代码行数:26,代码来源:test_schema.py

示例7: test_bundle_with_numbered_not_supplied

 def test_bundle_with_numbered_not_supplied(self):
     """
     L{Schema.bundle} ignores parameters that are not present.
     """
     schema = Schema(Unicode("name.n"))
     params = schema.bundle()
     self.assertEqual({}, params)
开发者ID:antisvin,项目名称:txAWS,代码行数:7,代码来源:test_schema.py

示例8: test_extract_complex

    def test_extract_complex(self):
        """L{Schema} can cope with complex schemas."""
        schema = Schema(
            Unicode("GroupName"),
            RawStr("IpPermissions.n.IpProtocol"),
            Integer("IpPermissions.n.FromPort"),
            Integer("IpPermissions.n.ToPort"),
            Unicode("IpPermissions.n.Groups.m.UserId", optional=True),
            Unicode("IpPermissions.n.Groups.m.GroupName", optional=True))

        arguments, _ = schema.extract(
            {"GroupName": "Foo",
             "IpPermissions.1.IpProtocol": "tcp",
             "IpPermissions.1.FromPort": "1234",
             "IpPermissions.1.ToPort": "5678",
             "IpPermissions.1.Groups.1.GroupName": "Bar",
             "IpPermissions.1.Groups.2.GroupName": "Egg"})

        self.assertEqual(u"Foo", arguments.GroupName)
        self.assertEqual(1, len(arguments.IpPermissions))
        self.assertEqual(1234, arguments.IpPermissions[0].FromPort)
        self.assertEqual(5678, arguments.IpPermissions[0].ToPort)
        self.assertEqual(2, len(arguments.IpPermissions[0].Groups))
        self.assertEqual("Bar", arguments.IpPermissions[0].Groups[0].GroupName)
        self.assertEqual("Egg", arguments.IpPermissions[0].Groups[1].GroupName)
开发者ID:antisvin,项目名称:txAWS,代码行数:25,代码来源:test_schema.py

示例9: test_extend_maintains_existing_attributes

    def test_extend_maintains_existing_attributes(self):
        """
        If additional schema attributes aren't passed to L{Schema.extend}, they
        stay the same.
        """
        result = {'id': Integer(), 'name': Unicode(), 'data': RawStr()}
        errors = [APIError]

        schema = Schema(
            name="GetStuff",
            doc="""Get the stuff.""",
            parameters=[Integer("id")],
            result=result,
            errors=errors)

        schema2 = schema.extend(parameters=[Unicode("scope")])

        self.assertEqual("GetStuff", schema2.name)
        self.assertEqual("Get the stuff.", schema2.doc)
        self.assertEqual(result, schema2.result)
        self.assertEqual(set(errors), schema2.errors)

        arguments, _ = schema2.extract({'id': '5', 'scope': u'foo'})
        self.assertEqual(5, arguments.id)
        self.assertEqual(u'foo', arguments.scope)
开发者ID:antisvin,项目名称:txAWS,代码行数:25,代码来源:test_schema.py

示例10: test_schema_conversion_optional_list

 def test_schema_conversion_optional_list(self):
     """
     Backwards-compatibility conversions maintains optional-ness of lists.
     """
     schema = Schema(Unicode("foos.N", optional=True))
     arguments, _ = schema.extract({})
     self.assertEqual([], arguments.foos)
开发者ID:antisvin,项目名称:txAWS,代码行数:7,代码来源:test_schema.py

示例11: test_extend_errors

 def test_extend_errors(self):
     """
     Errors can be extended with L{Schema.extend}.
     """
     schema = Schema(parameters=[], errors=[APIError])
     schema2 = schema.extend(errors=[ZeroDivisionError])
     self.assertEqual(set([APIError, ZeroDivisionError]), schema2.errors)
开发者ID:antisvin,项目名称:txAWS,代码行数:7,代码来源:test_schema.py

示例12: test_default_list

 def test_default_list(self):
     """
     The default of a L{List} can be specified as a list.
     """
     schema = Schema(List("names", Unicode(), optional=True,
                          default=[u"foo", u"bar"]))
     arguments, _ = schema.extract({})
     self.assertEqual([u"foo", u"bar"], arguments.names)
开发者ID:antisvin,项目名称:txAWS,代码行数:8,代码来源:test_schema.py

示例13: test_bundle_with_arguments

 def test_bundle_with_arguments(self):
     """L{Schema.bundle} can bundle L{Arguments} too."""
     schema = Schema(Unicode("name.n"), Integer("count"))
     arguments = Arguments({"name": Arguments({1: "Foo", 7: "Bar"}),
                            "count": 123})
     params = schema.bundle(arguments)
     self.assertEqual({"name.1": "Foo", "name.7": "Bar", "count": "123"},
                      params)
开发者ID:antisvin,项目名称:txAWS,代码行数:8,代码来源:test_schema.py

示例14: test_extract_with_mixed

 def test_extract_with_mixed(self):
     """
     L{Schema.extract} stores in the rest result all numbered parameters
     given without an index.
     """
     schema = Schema(Unicode("name.n"))
     _, rest = schema.extract({"name": "foo", "name.1": "bar"})
     self.assertEqual(rest, {"name": "foo"})
开发者ID:ArtRichards,项目名称:txaws,代码行数:8,代码来源:test_schema.py

示例15: test_extract_with_rest

 def test_extract_with_rest(self):
     """
     L{Schema.extract} stores unknown parameters in the 'rest' return
     dictionary.
     """
     schema = Schema()
     _, rest = schema.extract({"name": "value"})
     self.assertEqual(rest, {"name": "value"})
开发者ID:antisvin,项目名称:txAWS,代码行数:8,代码来源:test_schema.py


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