mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 21:48:49 -04:00
Update add_user_to_service endoint to only handle new data format
Updated the add_user_to_service endpoint to only handle data in the
'new' format (`{"permissions": [...]}` instead of `[permission_1, permission_2]`)
since Admin has been updated to send data the new way.
This change means that we no longer need the Marshmallow Permission
schema, so it can be deleted.
This commit is contained in:
@@ -1080,81 +1080,7 @@ def test_default_permissions_are_added_for_user_service(notify_api,
|
||||
assert sorted(default_service_permissions) == sorted(service_permissions)
|
||||
|
||||
|
||||
def test_add_existing_user_to_another_service_with_all_permissions(notify_api,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_service,
|
||||
sample_user):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
# check which users part of service
|
||||
user_already_in_service = sample_service.users[0]
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.get(
|
||||
'/service/{}/users'.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
)
|
||||
|
||||
assert resp.status_code == 200
|
||||
result = resp.json
|
||||
assert len(result['data']) == 1
|
||||
assert result['data'][0]['email_address'] == user_already_in_service.email_address
|
||||
|
||||
# add new user to service
|
||||
user_to_add = User(
|
||||
name='Invited User',
|
||||
email_address='invited@digital.cabinet-office.gov.uk',
|
||||
password='password',
|
||||
mobile_number='+4477123456'
|
||||
)
|
||||
# they must exist in db first
|
||||
save_model_user(user_to_add)
|
||||
|
||||
data = [{"permission": "send_emails"},
|
||||
{"permission": "send_letters"},
|
||||
{"permission": "send_texts"},
|
||||
{"permission": "manage_users"},
|
||||
{"permission": "manage_settings"},
|
||||
{"permission": "manage_api_keys"},
|
||||
{"permission": "manage_templates"},
|
||||
{"permission": "view_activity"}]
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}/users/{}'.format(sample_service.id, user_to_add.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
data=json.dumps(data)
|
||||
)
|
||||
|
||||
assert resp.status_code == 201
|
||||
|
||||
# check new user added to service
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.get(
|
||||
'/service/{}'.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
json_resp = resp.json
|
||||
assert str(user_to_add.id) in json_resp['data']['users']
|
||||
|
||||
# check user has all permissions
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.get(url_for('user.get_user', user_id=user_to_add.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
|
||||
assert resp.status_code == 200
|
||||
json_resp = resp.json
|
||||
permissions = json_resp['data']['permissions'][str(sample_service.id)]
|
||||
expected_permissions = ['send_texts', 'send_emails', 'send_letters', 'manage_users',
|
||||
'manage_settings', 'manage_templates', 'manage_api_keys', 'view_activity']
|
||||
assert sorted(expected_permissions) == sorted(permissions)
|
||||
|
||||
|
||||
def test_add_existing_user_to_another_service_with_all_permissions_with_new_data_format(
|
||||
def test_add_existing_user_to_another_service_with_all_permissions(
|
||||
notify_api,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
@@ -1250,9 +1176,13 @@ def test_add_existing_user_to_another_service_with_send_permissions(notify_api,
|
||||
)
|
||||
save_model_user(user_to_add)
|
||||
|
||||
data = [{"permission": "send_emails"},
|
||||
data = {
|
||||
"permissions": [
|
||||
{"permission": "send_emails"},
|
||||
{"permission": "send_letters"},
|
||||
{"permission": "send_texts"}]
|
||||
{"permission": "send_texts"},
|
||||
]
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
@@ -1293,9 +1223,13 @@ def test_add_existing_user_to_another_service_with_manage_permissions(notify_api
|
||||
)
|
||||
save_model_user(user_to_add)
|
||||
|
||||
data = [{"permission": "manage_users"},
|
||||
data = {
|
||||
"permissions": [
|
||||
{"permission": "manage_users"},
|
||||
{"permission": "manage_settings"},
|
||||
{"permission": "manage_templates"}]
|
||||
{"permission": "manage_templates"},
|
||||
]
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
@@ -1336,7 +1270,7 @@ def test_add_existing_user_to_another_service_with_manage_api_keys(notify_api,
|
||||
)
|
||||
save_model_user(user_to_add)
|
||||
|
||||
data = [{"permission": "manage_api_keys"}]
|
||||
data = {"permissions": [{"permission": "manage_api_keys"}]}
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user