• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python xmlutil.validate_schema函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_create

    def test_create(self):
        serializer = common.MetadataTemplate()
        fixture = {
            'metadata': {
                'key9': 'value9',
                'key2': 'value2',
                'key1': 'value1',
            },
        }
        output = serializer.serialize(fixture)
        root = etree.XML(output)
        xmlutil.validate_schema(root, 'metadata')
        metadata_dict = fixture['metadata']
        metadata_elems = root.findall('{0}meta'.format(NS))
        self.assertEqual(len(metadata_elems), 3)
        for i, metadata_elem in enumerate(metadata_elems):
            (meta_key, meta_value) = metadata_dict.items()[i]
            self.assertEqual(str(metadata_elem.get('key')), str(meta_key))
            self.assertEqual(str(metadata_elem.text).strip(), str(meta_value))
        actual = minidom.parseString(output.replace("  ", ""))

        expected = minidom.parseString("""
            <metadata xmlns="http://docs.openstack.org/compute/api/v1.1">
                <meta key="key2">value2</meta>
                <meta key="key9">value9</meta>
                <meta key="key1">value1</meta>
            </metadata>
        """.replace("  ", "").replace("\n", ""))

        self.assertEqual(expected.toxml(), actual.toxml())
开发者ID:Charu-Sharma,项目名称:nova,代码行数:30,代码来源:test_common.py


示例2: test_create

    def test_create(self):
        serializer = common.MetadataXMLSerializer()
        fixture = {"metadata": {"key9": "value9", "key2": "value2", "key1": "value1"}}
        output = serializer.serialize(fixture, "create")
        print output
        root = etree.XML(output)
        xmlutil.validate_schema(root, "metadata")
        metadata_dict = fixture["metadata"]
        metadata_elems = root.findall("{0}meta".format(NS))
        self.assertEqual(len(metadata_elems), 3)
        for i, metadata_elem in enumerate(metadata_elems):
            (meta_key, meta_value) = metadata_dict.items()[i]
            self.assertEqual(str(metadata_elem.get("key")), str(meta_key))
            self.assertEqual(str(metadata_elem.text).strip(), str(meta_value))
        actual = minidom.parseString(output.replace("  ", ""))

        expected = minidom.parseString(
            """
            <metadata xmlns="http://docs.openstack.org/compute/api/v1.1">
                <meta key="key2">value2</meta>
                <meta key="key9">value9</meta>
                <meta key="key1">value1</meta>
            </metadata>
        """.replace(
                "  ", ""
            ).replace(
                "\n", ""
            )
        )

        self.assertEqual(expected.toxml(), actual.toxml())
开发者ID:rackerlabs,项目名称:reddwarf,代码行数:31,代码来源:test_common.py


示例3: test_list_extensions_xml

    def test_list_extensions_xml(self):
        app = v2.APIRouter()
        ext_midware = extensions.ExtensionMiddleware(app)
        ser_midware = wsgi.LazySerializationMiddleware(ext_midware)
        request = webob.Request.blank("/123/extensions")
        request.accept = "application/xml"
        response = request.get_response(ser_midware)
        self.assertEqual(200, response.status_int)
        print response.body

        root = etree.XML(response.body)
        self.assertEqual(root.tag.split('extensions')[0], NS)

        # Make sure we have all the extensions.
        exts = root.findall('{0}extension'.format(NS))
        self.assertEqual(len(exts), len(self.ext_list))

        # Make sure that at least Fox in Sox is correct.
        (fox_ext, ) = [x for x in exts if x.get('alias') == 'FOXNSOX']
        self.assertEqual(fox_ext.get('name'), 'Fox In Socks')
        self.assertEqual(fox_ext.get('namespace'),
            'http://www.fox.in.socks/api/ext/pie/v1.0')
        self.assertEqual(fox_ext.get('updated'), '2011-01-22T13:25:27-06:00')
        self.assertEqual(fox_ext.findtext('{0}description'.format(NS)),
            'The Fox In Socks Extension')

        xmlutil.validate_schema(root, 'extensions')
开发者ID:geekontheway,项目名称:nova,代码行数:27,代码来源:test_extensions.py


示例4: test_get_version_2_detail_atom

    def test_get_version_2_detail_atom(self):
        req = webob.Request.blank('/v2/')
        req.accept = "application/atom+xml"
        res = req.get_response(fakes.wsgi_app())
        self.assertEqual(res.status_int, 200)
        self.assertEqual("application/atom+xml", res.content_type)

        xmlutil.validate_schema(etree.XML(res.body), 'atom')

        f = feedparser.parse(res.body)
        self.assertEqual(f.feed.title, 'About This Version')
        self.assertEqual(f.feed.updated, '2011-01-21T11:33:21Z')
        self.assertEqual(f.feed.id, 'http://localhost/v2/')
        self.assertEqual(f.feed.author, 'Rackspace')
        self.assertEqual(f.feed.author_detail.href,
                         'http://www.rackspace.com/')
        self.assertEqual(f.feed.links[0]['href'], 'http://localhost/v2/')
        self.assertEqual(f.feed.links[0]['rel'], 'self')

        self.assertEqual(len(f.entries), 1)
        entry = f.entries[0]
        self.assertEqual(entry.id, 'http://localhost/v2/')
        self.assertEqual(entry.title, 'Version v2.0')
        self.assertEqual(entry.updated, '2011-01-21T11:33:21Z')
        self.assertEqual(len(entry.content), 1)
        self.assertEqual(entry.content[0].value,
            'Version v2.0 CURRENT (2011-01-21T11:33:21Z)')
        self.assertEqual(len(entry.links), 2)
        self.assertEqual(entry.links[0]['href'], 'http://localhost/v2/')
        self.assertEqual(entry.links[0]['rel'], 'self')
        self.assertEqual(entry.links[1], {
            'href': EXP_LINKS['v2.0']['html'],
            'type': 'text/html',
            'rel': 'describedby'})
开发者ID:EdLeafe,项目名称:nova,代码行数:34,代码来源:test_versions.py


示例5: test_serialize_extensions

    def test_serialize_extensions(self):
        serializer = base_extensions.ExtensionsTemplate()
        data = {
            "extensions": [
                {
                    "name": "Public Image Extension",
                    "namespace": "http://foo.com/api/ext/pie/v1.0",
                    "alias": "RS-PIE",
                    "updated": "2011-01-22T13:25:27-06:00",
                    "description": "Adds the capability to share an image.",
                    "links": [
                        {
                            "rel": "describedby",
                            "type": "application/pdf",
                            "type": "application/vnd.sun.wadl+xml",
                            "href": "http://foo.com/api/ext/cs-pie.pdf",
                        },
                        {
                            "rel": "describedby",
                            "type": "application/vnd.sun.wadl+xml",
                            "href": "http://foo.com/api/ext/cs-pie.wadl",
                        },
                    ],
                },
                {
                    "name": "Cloud Block Storage",
                    "namespace": "http://foo.com/api/ext/cbs/v1.0",
                    "alias": "RS-CBS",
                    "updated": "2011-01-12T11:22:33-06:00",
                    "description": "Allows mounting cloud block storage.",
                    "links": [
                        {"rel": "describedby", "type": "application/pdf", "href": "http://foo.com/api/ext/cs-cbs.pdf"},
                        {
                            "rel": "describedby",
                            "type": "application/vnd.sun.wadl+xml",
                            "href": "http://foo.com/api/ext/cs-cbs.wadl",
                        },
                    ],
                },
            ]
        }

        xml = serializer.serialize(data)
        root = etree.XML(xml)
        ext_elems = root.findall("{0}extension".format(NS))
        self.assertEqual(len(ext_elems), 2)
        for i, ext_elem in enumerate(ext_elems):
            ext_dict = data["extensions"][i]
            self.assertEqual(ext_elem.findtext("{0}description".format(NS)), ext_dict["description"])

            for key in ["name", "namespace", "alias", "updated"]:
                self.assertEqual(ext_elem.get(key), ext_dict[key])

            link_nodes = ext_elem.findall("{0}link".format(ATOMNS))
            self.assertEqual(len(link_nodes), 2)
            for i, link in enumerate(ext_dict["links"]):
                for key, value in link.items():
                    self.assertEqual(link_nodes[i].get(key), value)

        xmlutil.validate_schema(root, "extensions")
开发者ID:fedoraKU,项目名称:nova,代码行数:60,代码来源:test_extensions.py


示例6: test_serialize_extension

    def test_serialize_extension(self):
        serializer = base_extensions.ExtensionTemplate()
        data = {'extension': {
          'name': 'ext1',
          'namespace': 'http://docs.rack.com/servers/api/ext/pie/v1.0',
          'alias': 'RS-PIE',
          'updated': '2011-01-22T13:25:27-06:00',
          'description': 'Adds the capability to share an image.',
          'links': [{'rel': 'describedby',
                     'type': 'application/pdf',
                     'href': 'http://docs.rack.com/servers/api/ext/cs.pdf'},
                    {'rel': 'describedby',
                     'type': 'application/vnd.sun.wadl+xml',
                     'href': 'http://docs.rack.com/servers/api/ext/cs.wadl'}]}}

        xml = serializer.serialize(data)
        root = etree.XML(xml)
        ext_dict = data['extension']
        self.assertEqual(root.findtext('{0}description'.format(NS)),
            ext_dict['description'])

        for key in ['name', 'namespace', 'alias', 'updated']:
            self.assertEqual(root.get(key), ext_dict[key])

        link_nodes = root.findall('{0}link'.format(ATOMNS))
        self.assertEqual(len(link_nodes), 2)
        for i, link in enumerate(ext_dict['links']):
            for key, value in link.items():
                self.assertEqual(link_nodes[i].get(key), value)

        xmlutil.validate_schema(root, 'extension')
开发者ID:674009287,项目名称:nova,代码行数:31,代码来源:test_extensions.py


示例7: test_versions_list_xml_serializer

    def test_versions_list_xml_serializer(self):
        versions_data = {
            "versions": [
                {
                    "id": "2.7",
                    "updated": "2011-07-18T11:30:00Z",
                    "status": "DEPRECATED",
                    "links": [{"rel": "self", "href": "http://test/v2"}],
                }
            ]
        }

        serializer = versions.VersionsTemplate()
        response = serializer.serialize(versions_data)

        root = etree.XML(response)
        xmlutil.validate_schema(root, "versions")

        self.assertTrue(root.xpath("/ns:versions", namespaces=NS))
        version_elems = root.xpath("ns:version", namespaces=NS)
        self.assertEqual(len(version_elems), 1)
        version = version_elems[0]
        self.assertEqual(version.get("id"), versions_data["versions"][0]["id"])
        self.assertEqual(version.get("status"), versions_data["versions"][0]["status"])

        (link,) = version.xpath("atom:link", namespaces=NS)
        self.assertTrue(
            common.compare_links(link, [{"rel": "self", "href": "http://test/v2", "type": "application/atom+xml"}])
        )
开发者ID:mygoda,项目名称:openstack,代码行数:29,代码来源:test_versions.py


示例8: test_get_version_3_detail_atom

    def test_get_version_3_detail_atom(self):
        req = webob.Request.blank("/v3/")
        req.accept = "application/atom+xml"
        res = req.get_response(fakes.wsgi_app_v3())
        self.assertEqual(res.status_int, 200)
        self.assertEqual("application/atom+xml", res.content_type)

        xmlutil.validate_schema(etree.XML(res.body), "atom")

        f = feedparser.parse(res.body)
        self.assertEqual(f.feed.title, "About This Version")
        self.assertEqual(f.feed.updated, "2013-07-23T11:33:21Z")
        self.assertEqual(f.feed.id, "http://localhost/v3/")
        self.assertEqual(f.feed.author, "Rackspace")
        self.assertEqual(f.feed.author_detail.href, "http://www.rackspace.com/")
        self.assertEqual(f.feed.links[0]["href"], "http://localhost/v3/")
        self.assertEqual(f.feed.links[0]["rel"], "self")

        self.assertEqual(len(f.entries), 1)
        entry = f.entries[0]
        self.assertEqual(entry.id, "http://localhost/v3/")
        self.assertEqual(entry.title, "Version v3.0")
        self.assertEqual(entry.updated, "2013-07-23T11:33:21Z")
        self.assertEqual(len(entry.content), 1)
        self.assertEqual(entry.content[0].value, "Version v3.0 EXPERIMENTAL (2013-07-23T11:33:21Z)")
        self.assertEqual(len(entry.links), 3)
        self.assertEqual(entry.links[0]["href"], "http://localhost/v3/")
        self.assertEqual(entry.links[0]["rel"], "self")
        self.assertEqual(
            entry.links[1], {"href": EXP_LINKS["v3.0"]["pdf"], "type": "application/pdf", "rel": "describedby"}
        )
        self.assertEqual(
            entry.links[2],
            {"href": EXP_LINKS["v3.0"]["wadl"], "type": "application/vnd.sun.wadl+xml", "rel": "describedby"},
        )
开发者ID:slagle,项目名称:nova,代码行数:35,代码来源:test_versions.py


示例9: test_show_image_no_metadata_key

    def test_show_image_no_metadata_key(self):
        serializer = images.ImageTemplate()

        fixture = {
            'image': {
                'id': 1,
                'name': 'Image1',
                'created': self.TIMESTAMP,
                'updated': self.TIMESTAMP,
                'status': 'ACTIVE',
                'server': {
                    'id': self.SERVER_UUID,
                    'links': [
                        {
                            'href': self.SERVER_HREF,
                            'rel': 'self',
                        },
                        {
                            'href': self.SERVER_BOOKMARK,
                            'rel': 'bookmark',
                        },
                    ],
                },
                'links': [
                    {
                        'href': self.IMAGE_HREF % 1,
                        'rel': 'self',
                    },
                    {
                        'href': self.IMAGE_BOOKMARK % 1,
                        'rel': 'bookmark',
                    },
                ],
            },
        }

        output = serializer.serialize(fixture)
        root = etree.XML(output)
        xmlutil.validate_schema(root, 'image')
        image_dict = fixture['image']

        for key in ['name', 'id', 'updated', 'created', 'status']:
            self.assertEqual(root.get(key), str(image_dict[key]))

        link_nodes = root.findall('{0}link'.format(ATOMNS))
        self.assertEqual(len(link_nodes), 2)
        for i, link in enumerate(image_dict['links']):
            for key, value in link.items():
                self.assertEqual(link_nodes[i].get(key), value)

        meta_nodes = root.findall('{0}meta'.format(ATOMNS))
        self.assertEqual(len(meta_nodes), 0)

        server_root = root.find('{0}server'.format(NS))
        self.assertEqual(server_root.get('id'), image_dict['server']['id'])
        link_nodes = server_root.findall('{0}link'.format(ATOMNS))
        self.assertEqual(len(link_nodes), 2)
        for i, link in enumerate(image_dict['server']['links']):
            for key, value in link.items():
                self.assertEqual(link_nodes[i].get(key), value)
开发者ID:Krylon360,项目名称:nova,代码行数:60,代码来源:test_images.py


示例10: test_index

    def test_index(self):
        serializer = flavors.MinimalFlavorsTemplate()

        fixture = {
            "flavors": [
                next(self.flavors),
                next(self.flavors),
            ],
        }

        output = serializer.serialize(fixture)
        root = etree.XML(output)
        xmlutil.validate_schema(root, 'flavors_index')
        flavor_elems = root.findall('{0}flavor'.format(NS))
        self.assertEqual(len(flavor_elems), 2)
        for i, flavor_elem in enumerate(flavor_elems):
            flavor_dict = fixture['flavors'][i]

            for key in ['name', 'id']:
                self.assertEqual(flavor_elem.get(key), str(flavor_dict[key]))

            link_nodes = flavor_elem.findall('{0}link'.format(ATOMNS))
            self.assertEqual(len(link_nodes), 2)
            for i, link in enumerate(flavor_dict['links']):
                for key, value in link.items():
                    self.assertEqual(link_nodes[i].get(key), value)
开发者ID:Charu-Sharma,项目名称:nova,代码行数:26,代码来源:test_flavors.py


示例11: test_show_handles_integers

    def test_show_handles_integers(self):
        serializer = flavors.FlavorTemplate()

        fixture = {
            "flavor": {
                "id": 12,
                "name": "asdf",
                "ram": 256,
                "disk": 10,
                "vcpus": "",
                "links": [
                    {"rel": "self", "href": "http://localhost/v2/fake/flavors/12"},
                    {"rel": "bookmark", "href": "http://localhost/fake/flavors/12"},
                ],
            }
        }

        output = serializer.serialize(fixture)
        root = etree.XML(output)
        xmlutil.validate_schema(root, "flavor")
        flavor_dict = fixture["flavor"]

        for key in ["name", "id", "ram", "disk"]:
            self.assertEqual(root.get(key), str(flavor_dict[key]))

        link_nodes = root.findall("{0}link".format(ATOMNS))
        self.assertEqual(len(link_nodes), 2)
        for i, link in enumerate(flavor_dict["links"]):
            for key, value in link.items():
                self.assertEqual(link_nodes[i].get(key), value)
开发者ID:polettix,项目名称:nova,代码行数:30,代码来源:test_flavors.py


示例12: test_detail

    def test_detail(self):
        serializer = flavors.FlavorsTemplate()

        fixture = {
            "flavors": [
                {
                    "id": "23",
                    "name": "flavor 23",
                    "ram": "512",
                    "disk": "20",
                    "vcpus": "",
                    'extra_specs': {'ecus_per_vcpu:': '1', 'nbs': 'true'},
                    "links": [
                        {
                            "rel": "self",
                            "href": "http://localhost/v2/fake/flavors/23",
                        },
                        {
                            "rel": "bookmark",
                            "href": "http://localhost/fake/flavors/23",
                        },
                    ],
                },
                {
                    "id": "13",
                    "name": "flavor 13",
                    "ram": "256",
                    "disk": "10",
                    "vcpus": "",
                    'extra_specs': {'ecus_per_vcpu:': '1', 'nbs': 'true'},
                    "links": [
                        {
                            "rel": "self",
                            "href": "http://localhost/v2/fake/flavors/13",
                        },
                        {
                            "rel": "bookmark",
                            "href": "http://localhost/fake/flavors/13",
                        },
                    ],
                },
            ],
        }

        output = serializer.serialize(fixture)
        root = etree.XML(output)
        xmlutil.validate_schema(root, 'flavors')
        flavor_elems = root.findall('{0}flavor'.format(NS))
        self.assertEqual(len(flavor_elems), 2)
        for i, flavor_elem in enumerate(flavor_elems):
            flavor_dict = fixture['flavors'][i]

            for key in ['name', 'id', 'ram', 'disk']:
                self.assertEqual(flavor_elem.get(key), str(flavor_dict[key]))

            link_nodes = flavor_elem.findall('{0}link'.format(ATOMNS))
            self.assertEqual(len(link_nodes), 2)
            for i, link in enumerate(flavor_dict['links']):
                for key, value in link.items():
                    self.assertEqual(link_nodes[i].get(key), value)
开发者ID:xww,项目名称:nova-old,代码行数:60,代码来源:test_flavors.py


示例13: test_index

    def test_index(self):
        serializer = limits.LimitsTemplate()
        fixture = {
            "limits": {
                "rate": [
                    {
                        "uri": "*",
                        "regex": ".*",
                        "limit": [
                            {
                                "value": 10,
                                "verb": "POST",
                                "remaining": 2,
                                "unit": "MINUTE",
                                "next-available": "2011-12-15T22:42:45Z",
                            }
                        ],
                    },
                    {
                        "uri": "*/servers",
                        "regex": "^/servers",
                        "limit": [
                            {
                                "value": 50,
                                "verb": "POST",
                                "remaining": 10,
                                "unit": "DAY",
                                "next-available": "2011-12-15T22:42:45Z",
                            }
                        ],
                    },
                ],
                "absolute": {"maxServerMeta": 1, "maxImageMeta": 1, "maxPersonality": 5, "maxPersonalitySize": 10240},
            }
        }

        output = serializer.serialize(fixture)
        root = etree.XML(output)
        xmlutil.validate_schema(root, "limits")

        # verify absolute limits
        absolutes = root.xpath("ns:absolute/ns:limit", namespaces=NS)
        self.assertEqual(len(absolutes), 4)
        for limit in absolutes:
            name = limit.get("name")
            value = limit.get("value")
            self.assertEqual(value, str(fixture["limits"]["absolute"][name]))

        # verify rate limits
        rates = root.xpath("ns:rates/ns:rate", namespaces=NS)
        self.assertEqual(len(rates), 2)
        for i, rate in enumerate(rates):
            for key in ["uri", "regex"]:
                self.assertEqual(rate.get(key), str(fixture["limits"]["rate"][i][key]))
            rate_limits = rate.xpath("ns:limit", namespaces=NS)
            self.assertEqual(len(rate_limits), 1)
            for j, limit in enumerate(rate_limits):
                for key in ["verb", "value", "remaining", "unit", "next-available"]:
                    self.assertEqual(limit.get(key), str(fixture["limits"]["rate"][i]["limit"][j][key]))
开发者ID:VinceOnGit,项目名称:nova,代码行数:59,代码来源:test_limits.py


示例14: test_index_zero_images

 def test_index_zero_images(self):
     serializer = images.MinimalImagesTemplate()
     del self.fixture_dict['images']
     output = serializer.serialize(self.fixture_dict)
     root = etree.XML(output)
     xmlutil.validate_schema(root, 'images_index')
     image_elems = root.findall('{0}image'.format(NS))
     self.assertEqual(len(image_elems), 0)
开发者ID:ChaosCloud,项目名称:nova,代码行数:8,代码来源:test_images.py


示例15: test_validate_schema

    def test_validate_schema(self):
        xml = '''<?xml version='1.0' encoding='UTF-8'?>
<metadata xmlns="http://docs.openstack.org/compute/api/v1.1">
<meta key="key6">value6</meta><meta key="key4">value4</meta>
</metadata>
'''
        xmlutil.validate_schema(xml, 'metadata')
        # No way to test the return value of validate_schema.
        # It just raises an exception when something is wrong.
        self.assertTrue(True)
开发者ID:AsherBond,项目名称:nova,代码行数:10,代码来源:test_xmlutil.py


示例16: test_index_empty

    def test_index_empty(self):
        serializer = flavors.MinimalFlavorsTemplate()

        fixture = {"flavors": []}

        output = serializer.serialize(fixture)
        root = etree.XML(output)
        xmlutil.validate_schema(root, "flavors_index")
        flavor_elems = root.findall("{0}flavor".format(NS))
        self.assertEqual(len(flavor_elems), 0)
开发者ID:polettix,项目名称:nova,代码行数:10,代码来源:test_flavors.py


示例17: test_show_no_server

    def test_show_no_server(self):
        del self.fixture['image']['server']
        output = self.serializer.serialize(self.fixture)
        root = etree.XML(output)
        xmlutil.validate_schema(root, 'image')
        image_dict = self.fixture['image']

        server_root = root.find('{0}server'.format(NS))
        self.assertIsNone(server_root)
        self._assertElementAndLinksEquals(root, image_dict, ['name', 'id',
                                          'updated', 'created', 'status'])
        self._assertMetadataEquals(root, image_dict)
开发者ID:ChaosCloud,项目名称:nova,代码行数:12,代码来源:test_images.py


示例18: test_index

    def test_index(self):
        serializer = images.MinimalImagesTemplate()
        output = serializer.serialize(self.fixture_dict)
        root = etree.XML(output)
        xmlutil.validate_schema(root, 'images_index')
        image_elems = root.findall('{0}image'.format(NS))
        self.assertEqual(len(image_elems), 2)
        for i, image_elem in enumerate(image_elems):
            image_dict = self.fixture_dict['images'][i]

            self._assertElementAndLinksEquals(image_elem, image_dict, ['name',
                                                                       'id'])
开发者ID:ChaosCloud,项目名称:nova,代码行数:12,代码来源:test_images.py


示例19: test_index_no_limits

    def test_index_no_limits(self):
        serializer = limits.LimitsTemplate()

        fixture = {"limits": {"rate": []}}

        output = serializer.serialize(fixture)
        root = etree.XML(output)
        xmlutil.validate_schema(root, 'limits', version='v3')

        #verify rate limits
        rates = root.xpath('ns:rates/ns:rate', namespaces=NS)
        self.assertEqual(len(rates), 0)
开发者ID:BATYD-Turksat,项目名称:nova_servo,代码行数:12,代码来源:test_limits.py


示例20: test_index

    def test_index(self):
        serializer = limits.LimitsXMLSerializer()
        fixture = {
            "limits": {
                   "rate": [{
                         "uri": "*",
                         "regex": ".*",
                         "limit": [{
                              "value": 10,
                              "verb": "POST",
                              "remaining": 2,
                              "unit": "MINUTE",
                              "next-available": "2011-12-15T22:42:45Z"}]},
                          {"uri": "*/servers",
                           "regex": "^/servers",
                           "limit": [{
                              "value": 50,
                              "verb": "POST",
                              "remaining": 10,
                              "unit": "DAY",
                              "next-available": "2011-12-15T22:42:45Z"}]}],
                    "absolute": {"maxServerMeta": 1,
                                 "maxImageMeta": 1,
                                 "maxPersonality": 5,
                                 "maxPersonalitySize": 10240}}}

        output = serializer.serialize(fixture, 'index')
        print output
        root = etree.XML(output)
        xmlutil.validate_schema(root, 'limits')

        #verify absolute limits
        absolutes = root.xpath('ns:absolute/ns:limit', namespaces=NS)
        self.assertEqual(len(absolutes), 4)
        for limit in absolutes:
            name = limit.get('name')
            value = limit.get('value')
            self.assertEqual(value, str(fixture['limits']['absolute'][name]))

        #verify rate limits
        rates = root.xpath('ns:rates/ns:rate', namespaces=NS)
        self.assertEqual(len(rates), 2)
        for i, rate in enumerate(rates):
            for key in ['uri', 'regex']:
                self.assertEqual(rate.get(key),
                                 str(fixture['limits']['rate'][i][key]))
            rate_limits = rate.xpath('ns:limit', namespaces=NS)
            self.assertEqual(len(rate_limits), 1)
            for j, limit in enumerate(rate_limits):
                for key in ['verb', 'value', 'remaining', 'unit',
                            'next-available']:
                    self.assertEqual(limit.get(key),
                         str(fixture['limits']['rate'][i]['limit'][j][key]))
开发者ID:Oneiroi,项目名称:nova,代码行数:53,代码来源:test_limits.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python validator.validate函数代码示例发布时间:2022-05-27
下一篇:
Python xmlutil.safe_minidom_parse_string函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap