Exemple #1
0
    def test_413_fault(self):
        metadata = {'attributes': {"overLimit": 'code'}}
        serializer = wsgi.XMLDictSerializer(metadata=metadata,
                                            xmlns=common.XML_NS_V1)

        fixture = {
            "overLimit": {
                "message": "sorry",
                "code": 413,
                "retryAfter": 4,
            },
        }

        output = serializer.serialize(fixture)
        result = minidom.parseString(self._prepare_xml(output))

        # result has 1 child - overLimit
        self.assertEqual(result.firstChild, result.lastChild)
        self.assertEqual(result.firstChild.tagName, 'overLimit')

        # overLimit has attrs code = '413' and xmlns = common.XML_NS_V1
        self.assertEqual(result.firstChild.getAttribute('code'), '413')
        self.assertEqual(result.firstChild.getAttribute('xmlns'),
                         common.XML_NS_V1)

        # overLimit has childs message = 'sorry' and retryAfter = '4'
        message = result.firstChild.getElementsByTagName('message')
        retry_after = result.firstChild.getElementsByTagName('retryAfter')
        self.assertEqual(len(message), 1)
        self.assertEqual(len(retry_after), 1)
        self.assertEqual(message[0].toxml(), '<message>sorry</message>')
        self.assertEqual(retry_after[0].toxml(), '<retryAfter>4</retryAfter>')
Exemple #2
0
 def test_xml(self):
     input_dict = dict(servers=dict(a=(2, 3)))
     expected_xml = '<serversxmlns="asdf"><a>(2,3)</a></servers>'
     serializer = wsgi.XMLDictSerializer(xmlns="asdf")
     result = serializer.serialize(input_dict)
     result = result.replace('\n', '').replace(' ', '')
     self.assertEqual(result, expected_xml)
Exemple #3
0
    def test_404_fault(self):
        metadata = {'attributes': {"itemNotFound": 'code'}}
        serializer = wsgi.XMLDictSerializer(metadata=metadata,
                                            xmlns=common.XML_NS_V1)

        fixture = {
            "itemNotFound": {
                "message": "sorry",
                "code": 404,
            },
        }

        output = serializer.serialize(fixture)
        actual = minidom.parseString(self._prepare_xml(output))

        expected = minidom.parseString(self._prepare_xml("""
                <itemNotFound code="404" xmlns="%s">
                    <message>sorry</message>
                </itemNotFound>
            """) % common.XML_NS_V1)

        self.assertEqual(expected.toxml(), actual.toxml())
Exemple #4
0
    def test_400_fault(self):
        metadata = {'attributes': {"badRequest": 'code'}}
        serializer = wsgi.XMLDictSerializer(metadata=metadata,
                                            xmlns=common.XML_NS_V1)

        fixture = {
            "badRequest": {
                "message": "scram",
                "code": 400,
            },
        }

        output = serializer.serialize(fixture)
        actual = minidom.parseString(self._prepare_xml(output))

        expected = minidom.parseString(self._prepare_xml("""
                <badRequest code="400" xmlns="%s">
                    <message>scram</message>
                </badRequest>
            """) % common.XML_NS_V1)

        self.assertEqual(expected.toxml(), actual.toxml())
Exemple #5
0
    def test_413_fault(self):
        metadata = {'attributes': {"overLimit": 'code'}}
        serializer = wsgi.XMLDictSerializer(metadata=metadata,
                                            xmlns=common.XML_NS_V1)

        fixture = {
            "overLimit": {
                "message": "sorry",
                "code": 413,
                "retryAfter": 4,
            },
        }

        output = serializer.serialize(fixture)
        actual = minidom.parseString(self._prepare_xml(output))

        expected = minidom.parseString(self._prepare_xml("""
                <overLimit code="413" xmlns="%s">
                    <message>sorry</message>
                    <retryAfter>4</retryAfter>
                </overLimit>
            """) % common.XML_NS_V1)

        self.assertEqual(expected.toxml(), actual.toxml())