def test_duplicate_attribute(self):
     validator = XMLFormatValidator(translator=FakeTranslator())
     request = FakeRequest(b'<a attr="value" attr="value"></a>')
     with pytest.raises(XMLFormatValidationError) as excinfo:
         validator.validate(request)
     exc = excinfo.value
     self.assertEqual(len(exc.details), 1)
     self.assertIn('Attribute attr redefined', exc.details[0].message)
 def test_empty_request(self):
     validator = XMLFormatValidator(translator=FakeTranslator())
     request = FakeRequest(b'')
     with pytest.raises(XMLFormatValidationError) as excinfo:
         validator.validate(request)
     exc = excinfo.value
     self.assertEqual(len(exc.details), 1)
     self.assertIn('Document is empty', exc.details[0].message)
 def test_not_xml(self):
     validator = XMLFormatValidator(translator=FakeTranslator())
     request = FakeRequest(b'{"this": "is JSON"}')
     with pytest.raises(XMLFormatValidationError) as excinfo:
         validator.validate(request)
     exc = excinfo.value
     self.assertEqual(len(exc.details), 1)
     self.assertIn(
         "Start tag expected, '<' not found", exc.details[0].message)
Exemple #4
0
 def test_tag_mismatch(self):
     validator = XMLFormatValidator(translator=FakeTranslator())
     request = FakeRequest(b'<a></b>')
     with pytest.raises(XMLFormatValidationError) as excinfo:
         validator.validate(request)
     exc = excinfo.value
     self.assertEqual(len(exc.details), 1)
     self.assertIn('Opening and ending tag mismatch: a line 1 and b',
                   exc.details[0].message)
 def test_valid_request(self):
     validator = XMLFormatValidator(translator=FakeTranslator())
     request = FakeRequest(b'<a></a>')
     self.assertIsNone(validator.validate(request))
 def test_xml_with_declarations(self):
     validator = XMLFormatValidator(translator=FakeTranslator())
     request = FakeRequest(b'<?xml version="1.0" encoding="utf-8" ?><a></a>')
     validator.validate(request)