def test_view_precompiled_letter_message_log_delivered(
        driver, login_seeded_user, seeded_client_using_test_key):

    reference = "functional_tests_precompiled_" + str(
        uuid.uuid1()) + "_delivered"

    send_precompiled_letter_via_api(reference, seeded_client_using_test_key,
                                    BytesIO(base64.b64decode(correct_letter)))

    api_integration_page = ApiIntegrationPage(driver)
    api_integration_page.go_to_api_integration_for_service(
        service_id=config['service']['id'])

    retry_call(_check_status_of_notification,
               fargs=[
                   api_integration_page, config['service']['id'], reference,
                   "received"
               ],
               tries=config['notification_retry_times'],
               delay=config['notification_retry_interval'])

    ref_link = config['service'][
        'id'] + "/notification/" + api_integration_page.get_notification_id()
    link = api_integration_page.get_view_letter_link()
    assert ref_link in link
def test_view_precompiled_letter_message_log_virus_scan_failed(
        driver, login_seeded_user, seeded_client_using_test_key):

    reference = "functional_tests_precompiled_" + str(
        uuid.uuid1()) + "_virus_scan_failed"

    send_precompiled_letter_via_api(reference, seeded_client_using_test_key,
                                    BytesIO(base64.b64decode(pdf_with_virus)))

    api_integration_page = ApiIntegrationPage(driver)

    retry_call(_check_status_of_notification,
               fargs=[
                   api_integration_page, config['service']['id'], reference,
                   NotificationStatuses.VIRUS_SCAN_FAILED
               ],
               tries=config['notification_retry_times'],
               delay=config['notification_retry_interval'])

    ref_link = config['service'][
        'id'] + "/notification/" + api_integration_page.get_notification_id()
    link = api_integration_page.get_view_letter_link()
    assert ref_link not in link
def test_view_precompiled_letter_preview_delivered(
        driver, login_seeded_user, seeded_client_using_test_key):

    reference = "functional_tests_precompiled_letter_preview_" + str(
        uuid.uuid1()) + "_delivered"

    notification_id = send_precompiled_letter_via_api(
        reference, seeded_client_using_test_key,
        BytesIO(base64.b64decode(correct_letter)))

    api_integration_page = ApiIntegrationPage(driver)
    api_integration_page.go_to_api_integration_for_service(
        service_id=config['service']['id'])

    retry_call(_check_status_of_notification,
               fargs=[
                   api_integration_page, config['service']['id'], reference,
                   "received"
               ],
               tries=config['notification_retry_times'],
               delay=config['notification_retry_interval'])

    api_integration_page.go_to_preview_letter()

    letter_preview_page = PreviewLetterPage(driver)
    assert letter_preview_page.is_text_present_on_page("Provided as PDF")

    # Check the pdf link looks valid
    pdf_download_link = letter_preview_page.get_download_pdf_link()

    link = config['service']['id'] + "/notification/" + notification_id + ".pdf"

    assert link in pdf_download_link

    # Check the link has a file at the end of it
    with urllib.request.urlopen(pdf_download_link) as url:
        pdf_file_data = url.read()

    assert pdf_file_data

    # check the image isn't the error page (we can't do much else)
    image_src = letter_preview_page.get_image_src()
    with urllib.request.urlopen(image_src) as url:
        image_data = url.read()

    assert base64.b64encode(image_data) != preview_error
Example #4
0
def test_send_precompiled_letter_notification_via_api(
        seeded_client_using_test_key):

    reference = config['service_name'].replace(" ", "_") + "_delivered"

    notification_id = send_precompiled_letter_via_api(
        reference, seeded_client_using_test_key,
        BytesIO(base64.b64decode(correct_letter)))

    notification = retry_call(get_notification_by_id_via_api,
                              fargs=[
                                  seeded_client_using_test_key,
                                  notification_id,
                                  NotificationStatuses.RECEIVED
                              ],
                              tries=config['notification_retry_times'],
                              delay=config['notification_retry_interval'])

    assert reference == notification['reference']
Example #5
0
def test_send_precompiled_letter_with_virus_notification_via_api(
        seeded_client_using_test_key):

    # This uses a file which drops the Eicar test virus into the temp directory
    # The dropper code _should_ be detected before the eicar virus

    reference = config['service_name'].replace(" ", "_") + "_virus_scan_failed"

    notification_id = send_precompiled_letter_via_api(
        reference, seeded_client_using_test_key,
        BytesIO(base64.b64decode(pdf_with_virus)))

    notification = retry_call(get_notification_by_id_via_api,
                              fargs=[
                                  seeded_client_using_test_key,
                                  notification_id,
                                  NotificationStatuses.VIRUS_SCAN_FAILED
                              ],
                              tries=config['notification_retry_times'],
                              delay=config['notification_retry_interval'])

    assert reference == notification['reference']