Example #1
0
 def test_validate_from_fail(self):
     xml_source = ('<?xml version="1.0" encoding="UTF-8" ?>'
                   '<feedback>'
                   '  <version>1.0</version>'
                   '  <record>'
                   '    <identifiers>'
                   '      <header_from>domain.org</header_from>'
                   '      <envelope_from>other.org</envelope_from>'
                   '    </identifiers>'
                   '  </record>'
                   '</feedback>')
     xml_tree = xml.etree.ElementTree.parse(io.StringIO(xml_source))
     report = RuaReport(xml_tree, set())
     report.validate_from()
     self.assertFalse(report.ok(),
                      msg='Header and Envelope domain match unexpectedly')
     self.assertEqual(len(report.errors), 1, msg='Incorrect error count')
     self.assertTrue('Mismatched from fields in header' in report.errors[0],
                     msg='Error text mismatch for "from" check')
Example #2
0
 def test_validate_from_pass(self):
     """Test two cases:
     1) a record with both fields (matching)
     2) a record with only one of the fields (ignored)"""
     xml_source = ('<?xml version="1.0" encoding="UTF-8" ?>'
                   '<feedback>'
                   '  <version>1.0</version>'
                   '  <record>'
                   '    <identifiers>'
                   '      <header_from>domain.org</header_from>'
                   '      <envelope_from>domain.org</envelope_from>'
                   '    </identifiers>'
                   '  </record>'
                   '  <record>'
                   '    <identifiers>'
                   '      <envelope_from>domain.org</envelope_from>'
                   '    </identifiers>'
                   '  </record>'
                   '</feedback>')
     xml_tree = xml.etree.ElementTree.parse(io.StringIO(xml_source))
     report = RuaReport(xml_tree, set())
     report.validate_from()
     self.assertTrue(report.ok(), msg='Header and Envelope domain mismatch')
     self.assertFalse(len(report.errors), msg='Unexpected errors')