Beispiel #1
0
    def test_xml_declaration(self):
        serializer = limits.LimitsTemplate()

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

        output = serializer.serialize(fixture)
        has_dec = output.startswith("<?xml version='1.0' encoding='UTF-8'?>")
        self.assertTrue(has_dec)
Beispiel #2
0
    def test_index_no_limits(self):
        serializer = limits.LimitsTemplate()

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

        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), 0)

        # verify rate limits
        rates = root.xpath('ns:rates/ns:rate', namespaces=NS)
        self.assertEqual(len(rates), 0)
Beispiel #3
0
    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]))