mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 14:29:25 -04:00
Do extra code style checks with flake8-bugbear
Flake8 Bugbear checks for some extra things that aren’t code style errors, but are likely to introduce bugs or unexpected behaviour. A good example is having mutable default function arguments, which get shared between every call to the function and therefore mutating a value in one place can unexpectedly cause it to change in another. This commit enables all the extra warnings provided by Flake8 Bugbear, except for: - the line length one (because we already lint for that separately) - B903 Data class should either be immutable or use `__slots__` because this seems to false-positive on some of our custom exceptions - B902 Invalid first argument 'cls' used for instance method because some SQLAlchemy decorators (eg `declared_attr`) make things that aren’t formally class methods take a class not an instance as their first argument It disables: - _B306: BaseException.message is removed in Python 3_ because I think our exceptions have a custom structure that means the `.message` attribute is still present Matches the work done in other repos: - https://github.com/alphagov/notifications-admin/pull/3172/files
This commit is contained in:
@@ -463,14 +463,24 @@ def test_returns_a_429_limit_exceeded_if_rate_limit_exceeded(
|
||||
assert not persist_mock.called
|
||||
|
||||
|
||||
@pytest.mark.parametrize('service_args', [
|
||||
{'service_permissions': [EMAIL_TYPE, SMS_TYPE]},
|
||||
{'restricted': True}
|
||||
@pytest.mark.parametrize('service_args, expected_status, expected_message', [
|
||||
(
|
||||
{'service_permissions': [EMAIL_TYPE, SMS_TYPE]},
|
||||
400,
|
||||
'Service is not allowed to send letters',
|
||||
),
|
||||
(
|
||||
{'restricted': True},
|
||||
403,
|
||||
'Cannot send letters when service is in trial mode',
|
||||
)
|
||||
])
|
||||
def test_post_letter_notification_returns_403_if_not_allowed_to_send_notification(
|
||||
client,
|
||||
notify_db_session,
|
||||
service_args
|
||||
service_args,
|
||||
expected_status,
|
||||
expected_message,
|
||||
):
|
||||
service = create_service(**service_args)
|
||||
template = create_template(service, template_type=LETTER_TYPE)
|
||||
@@ -480,10 +490,10 @@ def test_post_letter_notification_returns_403_if_not_allowed_to_send_notificatio
|
||||
'personalisation': test_address
|
||||
}
|
||||
|
||||
error_json = letter_request(client, data, service_id=service.id, _expected_status=400)
|
||||
assert error_json['status_code'] == 400
|
||||
error_json = letter_request(client, data, service_id=service.id, _expected_status=expected_status)
|
||||
assert error_json['status_code'] == expected_status
|
||||
assert error_json['errors'] == [
|
||||
{'error': 'BadRequestError', 'message': 'Service is not allowed to send letters'}
|
||||
{'error': 'BadRequestError', 'message': expected_message}
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ def test_should_cache_template_lookups_in_memory(mocker, client, sample_template
|
||||
'template_id': str(sample_template.id),
|
||||
}
|
||||
|
||||
for i in range(5):
|
||||
for _ in range(5):
|
||||
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
||||
client.post(
|
||||
path='/v2/notifications/sms',
|
||||
|
||||
Reference in New Issue
Block a user