mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-04 16:11:11 -04:00
Make service API client do partial updates
The service API client was updating every attribute of a service. Which, while kinda clunky, is fine… …until something calling it doesn’t pass in every attribute of the current service. It was then defaulting optional parameters to `None`. Which resulted in a bug whereby every time a service was set to live, its `reply_to_address` and `sms_sender_name` got overwritten to be empty. This commit changes the `update` method to only require the service ID, and pass whatever other named arguments it received straight through to the API. The API handles partial updates just fine (I think).
This commit is contained in:
@@ -125,18 +125,20 @@ def mock_create_service(mocker):
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_update_service(mocker):
|
||||
def _update(service_id,
|
||||
service_name,
|
||||
active,
|
||||
message_limit,
|
||||
restricted,
|
||||
users,
|
||||
email_from,
|
||||
reply_to_email_address=None,
|
||||
sms_sender=None):
|
||||
def _update(service_id, **kwargs):
|
||||
service = service_json(
|
||||
service_id, service_name, users, message_limit=message_limit,
|
||||
active=active, restricted=restricted, email_from=email_from, reply_to_email_address=reply_to_email_address)
|
||||
service_id,
|
||||
**{key: kwargs.get(key) for key in [
|
||||
'name',
|
||||
'users',
|
||||
'message_limit',
|
||||
'active',
|
||||
'restricted',
|
||||
'email_from',
|
||||
'reply_to_email_address',
|
||||
'sms_sender'
|
||||
]}
|
||||
)
|
||||
return {'data': service}
|
||||
|
||||
return mocker.patch(
|
||||
@@ -145,14 +147,11 @@ def mock_update_service(mocker):
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_update_service_raise_httperror_duplicate_name(mocker):
|
||||
def _update(service_id,
|
||||
service_name,
|
||||
active,
|
||||
limit,
|
||||
restricted,
|
||||
users,
|
||||
email_from):
|
||||
json_mock = Mock(return_value={'message': {'name': ["Duplicate service name '{}'".format(service_name)]}})
|
||||
def _update(
|
||||
service_id,
|
||||
**kwargs
|
||||
):
|
||||
json_mock = Mock(return_value={'message': {'name': ["Duplicate service name '{}'".format(kwargs.get('name'))]}})
|
||||
resp_mock = Mock(status_code=400, json=json_mock)
|
||||
http_error = HTTPError(response=resp_mock, message="Default message")
|
||||
raise http_error
|
||||
|
||||
Reference in New Issue
Block a user