provide a location for create_bucket

this is required when the boto3.resource itself is given a region
This commit is contained in:
Leo Hemsted
2020-12-07 15:03:41 +00:00
parent 45cc74bcc0
commit d6555d887c
2 changed files with 64 additions and 16 deletions

View File

@@ -747,9 +747,18 @@ def test_process_sanitised_letter_with_valid_letter(
destination_bucket_name = current_app.config[destination_bucket]
conn = boto3.resource('s3', region_name='eu-west-1')
scan_bucket = conn.create_bucket(Bucket=scan_bucket_name)
template_preview_bucket = conn.create_bucket(Bucket=template_preview_bucket_name)
destination_bucket = conn.create_bucket(Bucket=destination_bucket_name)
scan_bucket = conn.create_bucket(
Bucket=scan_bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
template_preview_bucket = conn.create_bucket(
Bucket=template_preview_bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
destination_bucket = conn.create_bucket(
Bucket=destination_bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
s3 = boto3.client('s3', region_name='eu-west-1')
s3.put_object(Bucket=scan_bucket_name, Key=filename, Body=b'original_pdf_content')
@@ -802,9 +811,18 @@ def test_process_sanitised_letter_sets_postage_international(
template_preview_bucket_name = current_app.config['LETTER_SANITISE_BUCKET_NAME']
destination_bucket_name = current_app.config['LETTERS_PDF_BUCKET_NAME']
conn = boto3.resource('s3', region_name='eu-west-1')
conn.create_bucket(Bucket=scan_bucket_name)
conn.create_bucket(Bucket=template_preview_bucket_name)
conn.create_bucket(Bucket=destination_bucket_name)
conn.create_bucket(
Bucket=scan_bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
conn.create_bucket(
Bucket=template_preview_bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
conn.create_bucket(
Bucket=destination_bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
s3 = boto3.client('s3', region_name='eu-west-1')
s3.put_object(Bucket=scan_bucket_name, Key=filename, Body=b'original_pdf_content')
@@ -842,9 +860,18 @@ def test_process_sanitised_letter_with_invalid_letter(sample_letter_notification
invalid_letter_bucket_name = current_app.config['INVALID_PDF_BUCKET_NAME']
conn = boto3.resource('s3', region_name='eu-west-1')
scan_bucket = conn.create_bucket(Bucket=scan_bucket_name)
template_preview_bucket = conn.create_bucket(Bucket=template_preview_bucket_name)
invalid_letter_bucket = conn.create_bucket(Bucket=invalid_letter_bucket_name)
scan_bucket = conn.create_bucket(
Bucket=scan_bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
template_preview_bucket = conn.create_bucket(
Bucket=template_preview_bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
invalid_letter_bucket = conn.create_bucket(
Bucket=invalid_letter_bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
s3 = boto3.client('s3', region_name='eu-west-1')
s3.put_object(Bucket=scan_bucket_name, Key=filename, Body=b'original_pdf_content')

View File

@@ -191,7 +191,10 @@ def test_get_letter_pdf_gets_pdf_from_correct_bucket(
bucket_name = current_app.config[bucket_config_name]
filename = datetime.utcnow().strftime(filename_format)
conn = boto3.resource('s3', region_name='eu-west-1')
conn.create_bucket(Bucket=bucket_name)
conn.create_bucket(
Bucket=bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
s3 = boto3.client('s3', region_name='eu-west-1')
s3.put_object(Bucket=bucket_name, Key=filename, Body=b'pdf_content')
@@ -265,7 +268,10 @@ def test_move_failed_pdf_error(notify_api):
bucket_name = current_app.config['LETTERS_SCAN_BUCKET_NAME']
conn = boto3.resource('s3', region_name='eu-west-1')
bucket = conn.create_bucket(Bucket=bucket_name)
bucket = conn.create_bucket(
Bucket=bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
s3 = boto3.client('s3', region_name='eu-west-1')
s3.put_object(Bucket=bucket_name, Key=filename, Body=b'pdf_content')
@@ -283,7 +289,10 @@ def test_move_failed_pdf_scan_failed(notify_api):
bucket_name = current_app.config['LETTERS_SCAN_BUCKET_NAME']
conn = boto3.resource('s3', region_name='eu-west-1')
bucket = conn.create_bucket(Bucket=bucket_name)
bucket = conn.create_bucket(
Bucket=bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
s3 = boto3.client('s3', region_name='eu-west-1')
s3.put_object(Bucket=bucket_name, Key=filename, Body=b'pdf_content')
@@ -323,8 +332,14 @@ def test_move_sanitised_letter_to_live_pdf_bucket(notify_api, mocker):
target_bucket_name = current_app.config['LETTERS_PDF_BUCKET_NAME']
conn = boto3.resource('s3', region_name='eu-west-1')
source_bucket = conn.create_bucket(Bucket=source_bucket_name)
target_bucket = conn.create_bucket(Bucket=target_bucket_name)
source_bucket = conn.create_bucket(
Bucket=source_bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
target_bucket = conn.create_bucket(
Bucket=target_bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
s3 = boto3.client('s3', region_name='eu-west-1')
s3.put_object(Bucket=source_bucket_name, Key=filename, Body=b'pdf_content')
@@ -347,8 +362,14 @@ def test_move_sanitised_letter_to_test_pdf_bucket(notify_api, mocker):
target_bucket_name = current_app.config['TEST_LETTERS_BUCKET_NAME']
conn = boto3.resource('s3', region_name='eu-west-1')
source_bucket = conn.create_bucket(Bucket=source_bucket_name)
target_bucket = conn.create_bucket(Bucket=target_bucket_name)
source_bucket = conn.create_bucket(
Bucket=source_bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
target_bucket = conn.create_bucket(
Bucket=target_bucket_name,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
s3 = boto3.client('s3', region_name='eu-west-1')
s3.put_object(Bucket=source_bucket_name, Key=filename, Body=b'pdf_content')