XHTML responses are handled by the XML formatter.
()
| 56 | |
| 57 | @responses.activate |
| 58 | def test_xml_xhtml(): |
| 59 | """XHTML responses are handled by the XML formatter.""" |
| 60 | file = XML_FILES_PATH / 'xhtml' / 'xhtml_raw.xml' |
| 61 | xml_data = file.read_text(encoding=UTF8) |
| 62 | |
| 63 | # Python < 3.8 was sorting attributes (https://bugs.python.org/issue34160) |
| 64 | # so we have 2 different output expected given the Python version. |
| 65 | expected_file_name = ( |
| 66 | 'xhtml_formatted_python_less_than_3.8.xml' |
| 67 | if sys.version_info < (3, 8) |
| 68 | else 'xhtml_formatted.xml' |
| 69 | ) |
| 70 | expected_xml_file = file.with_name(expected_file_name) |
| 71 | expected_xml_output = expected_xml_file.read_text(encoding=UTF8) |
| 72 | responses.add( |
| 73 | responses.GET, |
| 74 | DUMMY_URL, |
| 75 | body=xml_data, |
| 76 | content_type='application/xhtml+xml', |
| 77 | ) |
| 78 | |
| 79 | r = http(DUMMY_URL) |
| 80 | assert expected_xml_output in r |
| 81 | |
| 82 | |
| 83 | @pytest.mark.parametrize('file', XML_FILES_INVALID) |