def test_fails_silently_on_empty_address_line(self): xml_address = ''' <Site> <MailingAddress> <Line1 /> </MailingAddress> </Site>''' root = etree.fromstring(xml_address) address_lines = parser.parse_address_lines(root.find('MailingAddress')) self.assertIsNone(address_lines)
def test_removes_doubly_escaped_strong_markup_from_optional_field(self): xml_address = ''' <Site> <MailingAddress> <Line1>&lt;strong&gt;Line1</Line1> </MailingAddress> </Site> ''' root = etree.fromstring(xml_address) address_lines = parser.parse_address_lines(root.find('MailingAddress')) self.assertEqual(address_lines, 'Line1')
def test_address_line_parser_returns_none_when_line_1_is_empty(self): xml_address = ''' <Site> <MailingAddress> <Line1 /> <Line2>Line2</Line2> <Line3>Line3</Line3> </MailingAddress> </Site>''' root = etree.fromstring(xml_address) address_lines = parser.parse_address_lines(root.find('MailingAddress')) self.assertEqual(address_lines, None)
def test_address_line_parser_sorts_address_lines(self): xml_address = ''' <Site> <MailingAddress> <Line3>Line3</Line3> <Line1>Line1</Line1> <Line2>Line2</Line2> </MailingAddress> </Site>''' root = etree.fromstring(xml_address) address_lines = parser.parse_address_lines(root.find('MailingAddress')) self.assertEqual(address_lines, 'Line1\nLine2\nLine3')
def test_ignores_invalid_lines(self): xml_address = ''' <Site> <MailingAddress> <Line0>Line0</Line0> <Line1>Line1</Line1> <Line2 /> </MailingAddress> </Site>''' root = etree.fromstring(xml_address) address_lines = parser.parse_address_lines(root.find('MailingAddress')) self.assertEqual(address_lines, 'Line1')
def test_address_line_parser_only_parses_lines_one_to_four(self): xml_address = ''' <Site> <MailingAddress> <Line1>Line1</Line1> <Line2>Line2</Line2> <Line3>Line3</Line3> <Line4>Line4</Line4> <Line5>Line5</Line5> </MailingAddress> </Site>''' root = etree.fromstring(xml_address) address_lines = parser.parse_address_lines(root.find('MailingAddress')) self.assertEqual(address_lines, 'Line1\nLine2\nLine3\nLine4')
def test_parses_lines_1_to_9(self): xml_address = ''' <Site> <MailingAddress> <Line1>Line1</Line1> <Line2>Line2</Line2> <Line3>Line3</Line3> <Line4>Line4</Line4> <Line5>Line5</Line5> <Line6>Line6</Line6> <Line7>Line7</Line7> <Line8>Line8</Line8> <Line9>Line9</Line9> </MailingAddress> </Site>''' root = etree.fromstring(xml_address) address_lines = parser.parse_address_lines(root.find('MailingAddress')) self.assertEqual( address_lines, 'Line1\nLine2\nLine3\nLine4\nLine5\nLine6\nLine7\nLine8\nLine9')