Exemplo n.º 1
0
def test_get_letters_pdf_calls_notifications_template_preview_service_correctly(
        notify_api, mocker, client, sample_letter_template, personalisation):
    contact_block = 'Mr Foo,\n1 Test Street,\nLondon\nN1'
    filename = 'opg'

    with set_config_values(notify_api, {
        'TEMPLATE_PREVIEW_API_HOST': 'http://localhost/notifications-template-preview',
        'TEMPLATE_PREVIEW_API_KEY': 'test-key'
    }):
        with requests_mock.Mocker() as request_mock:
            mock_post = request_mock.post(
                'http://localhost/notifications-template-preview/print.pdf', content=b'\x00\x01', status_code=200)

            get_letters_pdf(
                sample_letter_template,
                contact_block=contact_block,
                filename=filename,
                values=personalisation)

    assert mock_post.last_request.json() == {
        'values': personalisation,
        'letter_contact_block': contact_block,
        'filename': filename,
        'template': {
            'subject': sample_letter_template.subject,
            'content': sample_letter_template.content,
            'template_type': sample_letter_template.template_type
        }
    }
Exemplo n.º 2
0
def test_get_letters_pdf_calculates_billing_units(
    notify_api,
    mocker,
    client,
    sample_letter_template,
    page_count,
    expected_billable_units,
):
    contact_block = "Mr Foo,\n1 Test Street,\nLondon\nN1"
    filename = "opg"

    with set_config_values(
            notify_api,
        {
            "TEMPLATE_PREVIEW_API_HOST":
            "http://localhost/notifications-template-preview",
            "TEMPLATE_PREVIEW_API_KEY": "test-key",
        },
    ):
        with requests_mock.Mocker() as request_mock:
            request_mock.post(
                "http://localhost/notifications-template-preview/print.pdf",
                content=b"\x00\x01",
                headers={"X-pdf-page-count": page_count},
                status_code=200,
            )

            _, billable_units = get_letters_pdf(
                sample_letter_template,
                contact_block=contact_block,
                filename=filename,
                values=None,
            )

    assert billable_units == expected_billable_units
Exemplo n.º 3
0
def test_get_letters_pdf_calculates_billing_units(notify_api, mocker, client,
                                                  sample_letter_template,
                                                  page_count,
                                                  expected_billable_units):
    contact_block = 'Mr Foo,\n1 Test Street,\nLondon\nN1'
    filename = 'opg'

    with set_config_values(
            notify_api, {
                'TEMPLATE_PREVIEW_API_HOST':
                'http://localhost/notifications-template-preview',
                'TEMPLATE_PREVIEW_API_KEY': 'test-key'
            }):
        with requests_mock.Mocker() as request_mock:
            request_mock.post(
                'http://localhost/notifications-template-preview/print.pdf',
                content=b'\x00\x01',
                headers={'X-pdf-page-count': page_count},
                status_code=200)

            _, billable_units = get_letters_pdf(sample_letter_template,
                                                contact_block=contact_block,
                                                filename=filename,
                                                values=None)

    assert billable_units == expected_billable_units
Exemplo n.º 4
0
def test_get_letters_pdf_calls_notifications_template_preview_service_correctly(
        notify_api, mocker, client, sample_letter_template, personalisation):
    contact_block = "Mr Foo,\n1 Test Street,\nLondon\nN1"
    filename = "opg"

    with set_config_values(
            notify_api,
        {
            "TEMPLATE_PREVIEW_API_HOST":
            "http://localhost/notifications-template-preview",
            "TEMPLATE_PREVIEW_API_KEY": "test-key",
        },
    ):
        with requests_mock.Mocker() as request_mock:
            mock_post = request_mock.post(
                "http://localhost/notifications-template-preview/print.pdf",
                content=b"\x00\x01",
                status_code=200,
            )

            get_letters_pdf(
                sample_letter_template,
                contact_block=contact_block,
                filename=filename,
                values=personalisation,
            )

    assert mock_post.last_request.json() == {
        "values": personalisation,
        "letter_contact_block": contact_block,
        "filename": filename,
        "template": {
            "subject": sample_letter_template.subject,
            "content": sample_letter_template.content,
        },
    }