def test_precompiled_sanitise_pdf_without_notify_tag(client, auth_header): assert not is_notify_tag_present(BytesIO(blank_with_address)) response = client.post( url_for('precompiled_blueprint.sanitise_precompiled_letter'), data=blank_with_address, headers={ 'Content-type': 'application/json', **auth_header }) assert response.status_code == 200 assert response.json == { "message": None, "file": ANY, "page_count": 1, "recipient_address": "Queen Elizabeth\nBuckingham Palace\nLondon\nSW1 1AA", "invalid_pages": None, 'redaction_failed_message': None } pdf = BytesIO(base64.b64decode(response.json["file"].encode())) assert is_notify_tag_present(pdf) assert extract_address_block(pdf).normalised == ('Queen Elizabeth\n' 'Buckingham Palace\n' 'London\n' 'SW1 1AA')
def test_is_notify_tag_calls_extract_with_wider_numbers(mocker): mock_extract = mocker.patch( 'app.precompiled._extract_text_from_first_page_of_pdf') pdf = MagicMock() is_notify_tag_present(pdf) mock_extract.assert_called_once_with( ANY, x1=pytest.approx(6.8031496), y1=pytest.approx(3.685039), x2=pytest.approx(58.149606), y2=pytest.approx(26.692913), )
def test_is_notify_tag_present(): assert is_notify_tag_present(BytesIO(blank_page)) is False
def test_is_notify_tag_present_finds_notify_tag(): assert is_notify_tag_present(BytesIO(example_dwp_pdf)) is True