Merge pull request #3054 from alphagov/utils-bump

bump utils
This commit is contained in:
Leo Hemsted
2020-12-07 16:07:44 +00:00
committed by GitHub
13 changed files with 111 additions and 59 deletions

View File

@@ -339,7 +339,7 @@ def save_api_email_or_sms(self, encrypted_notification):
try:
self.retry(queue=QueueNames.RETRY)
except self.MaxRetriesExceededError:
current_app.logger.error('Max retry failed' + f"Failed to persist notification {notification['id']}")
current_app.logger.error(f"Max retry failed Failed to persist notification {notification['id']}")
@notify_celery.task(bind=True, name="save-letter", max_retries=5, default_retry_delay=300)
@@ -604,7 +604,7 @@ def send_inbound_sms_to_service(self, inbound_sms_id, service_id):
self.retry(queue=QueueNames.RETRY)
except self.MaxRetriesExceededError:
current_app.logger.error(
f"Retry: send_inbound_sms_to_service has retried the max number of" +
"Retry: send_inbound_sms_to_service has retried the max number of" +
f"times for service: {service_id} and inbound_sms {inbound_sms_id}"
)
else:

View File

@@ -60,8 +60,8 @@ class AwsSesClient(EmailClient):
# events are generally undocumented, but some that might be of interest are:
# before-call, after-call, after-call-error, request-created, response-received
self._client.meta.events.register(f'request-created.ses.SendEmail', self.ses_request_created_hook)
self._client.meta.events.register(f'response-received.ses.SendEmail', self.ses_response_received_hook)
self._client.meta.events.register('request-created.ses.SendEmail', self.ses_request_created_hook)
self._client.meta.events.register('response-received.ses.SendEmail', self.ses_response_received_hook)
def ses_request_created_hook(self, **kwargs):
# request created may be called multiple times if the request auto-retries. We want to count all these as the

View File

@@ -244,7 +244,7 @@ def validate_address(service, letter_data):
if not address.has_valid_last_line:
if address.allow_international_letters:
raise ValidationError(
message=f'Last line of address must be a real UK postcode or another country'
message='Last line of address must be a real UK postcode or another country'
)
raise ValidationError(
message='Must be a real UK postcode'

View File

@@ -84,21 +84,21 @@ def get_usage_for_all_services():
}
combined[s.service_id] = entry
for l in letter_costs:
if l.service_id in combined:
combined[l.service_id].update({'letter_cost': float(l.letter_cost)})
for letter_cost in letter_costs:
if letter_cost.service_id in combined:
combined[letter_cost.service_id].update({'letter_cost': float(letter_cost.letter_cost)})
else:
letter_entry = {
"organisation_id": str(l.organisation_id) if l.organisation_id else "",
"organisation_name": l.organisation_name or "",
"service_id": str(l.service_id),
"service_name": l.service_name,
"organisation_id": str(letter_cost.organisation_id) if letter_cost.organisation_id else "",
"organisation_name": letter_cost.organisation_name or "",
"service_id": str(letter_cost.service_id),
"service_name": letter_cost.service_name,
"sms_cost": 0,
"sms_fragments": 0,
"letter_cost": float(l.letter_cost),
"letter_cost": float(letter_cost.letter_cost),
"letter_breakdown": ""
}
combined[l.service_id] = letter_entry
combined[letter_cost.service_id] = letter_entry
for service_id, breakdown in lb_by_service:
combined[service_id]['letter_breakdown'] += (breakdown + '\n')

View File

@@ -27,9 +27,9 @@ cachetools==4.1.1
notifications-python-client==5.7.0
# PaaS
awscli-cwlogs>=1.4,<1.5
awscli-cwlogs==1.4.6
git+https://github.com/alphagov/notifications-utils.git@43.5.2#egg=notifications-utils==43.5.2
git+https://github.com/alphagov/notifications-utils.git@43.5.4#egg=notifications-utils==43.5.4
# gds-metrics requires prometheseus 0.2.0, override that requirement as 0.7.1 brings significant performance gains
prometheus-client==0.8.0

View File

@@ -29,9 +29,9 @@ cachetools==4.1.1
notifications-python-client==5.7.0
# PaaS
awscli-cwlogs>=1.4,<1.5
awscli-cwlogs==1.4.6
git+https://github.com/alphagov/notifications-utils.git@43.5.2#egg=notifications-utils==43.5.2
git+https://github.com/alphagov/notifications-utils.git@43.5.4#egg=notifications-utils==43.5.4
# gds-metrics requires prometheseus 0.2.0, override that requirement as 0.7.1 brings significant performance gains
prometheus-client==0.8.0
@@ -42,15 +42,15 @@ alembic==1.4.3
amqp==1.4.9
anyjson==0.3.3
attrs==20.3.0
awscli==1.18.185
awscli==1.18.190
bcrypt==3.2.0
billiard==3.3.0.23
bleach==3.1.4
bleach==3.2.1
blinker==1.4
boto==2.49.0
boto3==1.10.38
botocore==1.19.25
certifi==2020.11.8
boto3==1.16.30
botocore==1.19.30
certifi==2020.12.5
chardet==3.0.4
click==7.1.2
colorama==0.4.3
@@ -59,10 +59,10 @@ docutils==0.15.2
flask-redis==0.4.0
future==0.18.2
geojson==2.5.0
govuk-bank-holidays==0.6
govuk-bank-holidays==0.8
greenlet==0.4.17
idna==2.10
importlib-metadata==3.1.0
importlib-metadata==3.1.1
Jinja2==2.11.2
jmespath==0.10.0
kombu==3.0.37
@@ -70,15 +70,17 @@ Mako==1.1.3
MarkupSafe==1.1.1
mistune==0.8.4
monotonic==1.5
orderedset==2.0.1
phonenumbers==8.11.2
orderedset==2.0.3
packaging==20.7
phonenumbers==8.12.14
pyasn1==0.4.8
pycparser==2.20
pyparsing==2.4.7
PyPDF2==1.26.0
pyrsistent==0.17.3
python-dateutil==2.8.1
python-editor==1.0.4
python-json-logger==0.1.11
python-json-logger==2.0.1
pytz==2020.4
PyYAML==5.3.1
redis==3.5.3

View File

@@ -1,12 +1,12 @@
-r requirements.txt
flake8==3.7.9
moto==1.3.14
pytest==5.3.2
flake8==3.8.4
moto==1.3.16
pytest==6.1.2
pytest-env==0.6.2
pytest-mock==2.0.0
pytest-cov==2.8.1
pytest-xdist==1.31.0
freezegun==0.3.12
requests-mock==1.7.0
pytest-mock==3.3.1
pytest-cov==2.10.1
pytest-xdist==2.1.0
freezegun==1.0.0
requests-mock==1.8.0
# used for creating manifest file locally
jinja2-cli[yaml]==0.7.0

View File

@@ -253,7 +253,7 @@ def test_should_allow_valid_token_when_service_has_multiple_keys(client, sample_
save_model_api_key(api_key)
token = __create_token(sample_api_key.service_id)
response = client.get(
'/notifications'.format(str(sample_api_key.service_id)),
'/notifications',
headers={'Authorization': 'Bearer {}'.format(token)})
assert response.status_code == 200

View File

@@ -412,7 +412,7 @@ def test_update_broadcast_message_status_rejects_approval_from_creator(
)
assert mock_task.called is False
assert f'cannot approve their own broadcast' in response['message']
assert 'cannot approve their own broadcast' in response['message']
def test_update_broadcast_message_status_rejects_approval_of_broadcast_with_no_areas(
@@ -523,7 +523,7 @@ def test_update_broadcast_message_status_rejects_approval_from_user_not_on_that_
)
assert mock_task.called is False
assert f'cannot approve broadcast' in response['message']
assert 'cannot approve broadcast' in response['message']
@pytest.mark.parametrize('current_status, new_status', [

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')

View File

@@ -354,9 +354,11 @@ def test_check_is_message_too_long_passes_for_long_email(sample_service):
with pytest.raises(BadRequestError) as e:
check_is_message_too_long(template_with_content)
assert e.value.status_code == 400
expected_message = f'Your message is too long. ' \
f'Emails cannot be longer than 1000000 bytes. ' \
f'Your message is 1000084 bytes.'
expected_message = (
'Your message is too long. ' +
'Emails cannot be longer than 1000000 bytes. ' +
'Your message is 1000084 bytes.'
)
assert e.value.message == expected_message
assert e.value.fields == []

View File

@@ -25,7 +25,7 @@ def test_url_for_get_service_by_id(notify_api):
def test_url_for_create_service(notify_api):
with notify_api.test_request_context():
url = url_for('service.create_service')
assert str(url) == '/service'.format(service_id)
assert str(url) == '/service'
def test_url_for_update_service(notify_api):