flake8 fixes

a stricter flake8 bump. mostly things around f strings and format
strings, but a couple of bad placeholder names in loops
This commit is contained in:
Leo Hemsted
2020-12-07 15:15:50 +00:00
parent d6555d887c
commit 9502f17d84
8 changed files with 23 additions and 21 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

@@ -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

@@ -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):