本文整理汇总了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)
示例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])
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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"})
示例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"})