示例#1
0
def test_get_bucket_name_and_prefix_for_notification_templated_letter_using_test_key(sample_letter_notification):
    sample_letter_notification.key_type = KEY_TYPE_TEST

    bucket, bucket_prefix = get_bucket_name_and_prefix_for_notification(sample_letter_notification)

    assert bucket == current_app.config['TEST_LETTERS_BUCKET_NAME']
    assert bucket_prefix == 'NOTIFY.{}'.format(sample_letter_notification.reference).upper()
示例#2
0
def test_get_bucket_name_and_prefix_for_failed_validation(sample_precompiled_letter_notification):
    sample_precompiled_letter_notification.status = NOTIFICATION_VALIDATION_FAILED
    bucket, bucket_prefix = get_bucket_name_and_prefix_for_notification(sample_precompiled_letter_notification)

    assert bucket == current_app.config['INVALID_PDF_BUCKET_NAME']
    assert bucket_prefix == 'NOTIFY.{}'.format(
        sample_precompiled_letter_notification.reference).upper()
def test_get_bucket_name_and_prefix_for_notification_precompiled_letter_using_test_key(
    sample_precompiled_letter_notification_using_test_key, ):
    bucket, bucket_prefix = get_bucket_name_and_prefix_for_notification(
        sample_precompiled_letter_notification_using_test_key)

    assert bucket == current_app.config["TEST_LETTERS_BUCKET_NAME"]
    assert bucket_prefix == "NOTIFY.{}".format(
        sample_precompiled_letter_notification_using_test_key.reference).upper(
        )
def test_get_bucket_name_and_prefix_for_test_noti_with_failed_validation(
    sample_precompiled_letter_notification_using_test_key, ):
    sample_precompiled_letter_notification_using_test_key.status = NOTIFICATION_VALIDATION_FAILED
    bucket, bucket_prefix = get_bucket_name_and_prefix_for_notification(
        sample_precompiled_letter_notification_using_test_key)

    assert bucket == current_app.config["INVALID_PDF_BUCKET_NAME"]
    assert bucket_prefix == "NOTIFY.{}".format(
        sample_precompiled_letter_notification_using_test_key.reference).upper(
        )
def test_get_bucket_name_and_prefix_for_notification_get_from_sent_at_date(
    sample_notification, ):
    sample_notification.created_at = datetime(2019, 8, 1, 17, 35)
    sample_notification.sent_at = datetime(2019, 8, 2, 17, 45)

    bucket, bucket_prefix = get_bucket_name_and_prefix_for_notification(
        sample_notification)

    assert bucket == current_app.config["LETTERS_PDF_BUCKET_NAME"]
    assert (bucket_prefix == "{folder}/NOTIFY.{reference}".format(
        folder="2019-08-02", reference=sample_notification.reference).upper())
def test_get_bucket_name_and_prefix_for_notification_valid_notification(
        sample_notification, created_at, folder):
    sample_notification.created_at = created_at
    sample_notification.updated_at = created_at

    bucket, bucket_prefix = get_bucket_name_and_prefix_for_notification(
        sample_notification)

    assert bucket == current_app.config["LETTERS_PDF_BUCKET_NAME"]
    assert bucket_prefix == "{folder}/NOTIFY.{reference}".format(
        folder=folder, reference=sample_notification.reference).upper()
示例#7
0
def test_get_bucket_name_and_prefix_for_notification_is_tomorrow_after_17_30(sample_notification):
    sample_notification.created_at = datetime(2019, 8, 1, 17, 35)
    sample_notification.sent_at = datetime(2019, 8, 2, 17, 45)

    bucket, bucket_prefix = get_bucket_name_and_prefix_for_notification(sample_notification)

    assert bucket == current_app.config['LETTERS_PDF_BUCKET_NAME']
    assert bucket_prefix == '{folder}/NOTIFY.{reference}'.format(
        folder='2019-08-02',
        reference=sample_notification.reference
    ).upper()
示例#8
0
def test_get_bucket_name_and_prefix_for_notification_from_created_at_date(
        sample_notification):
    sample_notification.created_at = datetime(2019, 8, 1, 12, 00)
    sample_notification.updated_at = datetime(2019, 8, 2, 12, 00)
    sample_notification.sent_at = datetime(2019, 8, 3, 12, 00)

    bucket, bucket_prefix = get_bucket_name_and_prefix_for_notification(
        sample_notification)

    assert bucket == current_app.config['LETTERS_PDF_BUCKET_NAME']
    assert bucket_prefix == '{folder}/NOTIFY.{reference}'.format(
        folder='2019-08-03', reference=sample_notification.reference).upper()
示例#9
0
def test_find_letter_pdf_in_s3_returns_object(sample_notification):
    bucket_name = current_app.config['LETTERS_PDF_BUCKET_NAME']
    s3 = boto3.client('s3', region_name='eu-west-1')
    s3.create_bucket(
        Bucket=bucket_name,
        CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'})

    _, prefix = get_bucket_name_and_prefix_for_notification(
        sample_notification)
    s3.put_object(Bucket=bucket_name, Key=f'{prefix}-and-then-some', Body=b'f')

    assert find_letter_pdf_in_s3(
        sample_notification).key == f'{prefix}-and-then-some'
def test_get_bucket_name_and_prefix_for_notification_invalid_notification():
    with pytest.raises(AttributeError):
        get_bucket_name_and_prefix_for_notification(None)