mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-20 08:04:19 -04:00
Update python client to version 1.0.0.
This version of the client removed the request method, path and body from the encode and decode methods. The biggest changes here is to the unit tests.
This commit is contained in:
@@ -6,7 +6,7 @@ from app.dao.api_key_dao import (get_unsigned_secrets, save_model_api_key)
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
|
||||
|
||||
def create_authorization_header(path, method, request_body=None, service_id=None):
|
||||
def create_authorization_header(service_id=None):
|
||||
if service_id:
|
||||
client_id = str(service_id)
|
||||
secrets = get_unsigned_secrets(service_id)
|
||||
@@ -23,18 +23,5 @@ def create_authorization_header(path, method, request_body=None, service_id=None
|
||||
client_id = current_app.config.get('ADMIN_CLIENT_USER_NAME')
|
||||
secret = current_app.config.get('ADMIN_CLIENT_SECRET')
|
||||
|
||||
if request_body:
|
||||
token = create_jwt_token(
|
||||
request_method=method,
|
||||
request_path=path,
|
||||
secret=secret,
|
||||
client_id=client_id,
|
||||
request_body=request_body)
|
||||
|
||||
else:
|
||||
token = create_jwt_token(request_method=method,
|
||||
request_path=path,
|
||||
secret=secret,
|
||||
client_id=client_id)
|
||||
|
||||
token = create_jwt_token(secret=secret, client_id=client_id)
|
||||
return 'Authorization', 'Bearer {}'.format(token)
|
||||
|
||||
@@ -38,38 +38,10 @@ def test_should_not_allow_request_with_incorrect_token(notify_api, sample_user):
|
||||
assert data['message'] == 'Invalid token: signature'
|
||||
|
||||
|
||||
def test_should_ignore_path(notify_api, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
token = create_jwt_token(
|
||||
request_method="GET",
|
||||
request_path="/bad",
|
||||
secret=get_unsigned_secrets(sample_api_key.service_id)[0],
|
||||
client_id=str(sample_api_key.service_id)
|
||||
)
|
||||
response = client.get(
|
||||
'/service',
|
||||
headers={'Authorization': "Bearer {}".format(token)})
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_should_ignore_request(notify_api, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
token = __create_post_token(sample_api_key.service_id, {})
|
||||
response = client.get(
|
||||
'/service',
|
||||
headers={'Authorization': "Bearer {}".format(token)}
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_should_not_allow_invalid_secret(notify_api, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
token = create_jwt_token(
|
||||
request_method="POST",
|
||||
request_path="/service",
|
||||
secret="not-so-secret",
|
||||
client_id=str(sample_api_key.service_id))
|
||||
response = client.get(
|
||||
@@ -125,46 +97,6 @@ JSON_BODY = json.dumps({
|
||||
})
|
||||
|
||||
|
||||
def test_should_allow_valid_token_with_post_body(notify_api, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
service = Service.query.get(sample_api_key.service_id)
|
||||
data = {
|
||||
'email_from': 'new name',
|
||||
'name': 'new name',
|
||||
'users': [str(service.users[0].id)],
|
||||
'message_limit': 1000,
|
||||
'restricted': False,
|
||||
'active': False,
|
||||
'created_by': str(service.users[0].id)}
|
||||
|
||||
token = create_jwt_token(
|
||||
request_method="POST",
|
||||
request_path='/service/{}'.format(str(sample_api_key.service_id)),
|
||||
secret=get_unsigned_secret(sample_api_key.id),
|
||||
client_id=str(sample_api_key.service_id),
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
headers = [('Content-Type', 'application/json'), ('Authorization', 'Bearer {}'.format(token))]
|
||||
response = client.post(
|
||||
'/service/{}'.format(service.id),
|
||||
data=json.dumps(data),
|
||||
headers=headers)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_should_allow_valid_token_with_invalid_post_body_but_fail_at_endpoint(notify_api, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
token = __create_post_token(str(sample_api_key.service_id), JSON_BODY)
|
||||
with pytest.raises(AttributeError):
|
||||
response = client.post(
|
||||
'/service',
|
||||
data="spurious",
|
||||
headers={'Authorization': 'Bearer {}'.format(token)})
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_authentication_passes_admin_client_token(notify_api,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
@@ -172,8 +104,6 @@ def test_authentication_passes_admin_client_token(notify_api,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
token = create_jwt_token(
|
||||
request_method="GET",
|
||||
request_path='/service',
|
||||
secret=current_app.config.get('ADMIN_CLIENT_SECRET'),
|
||||
client_id=current_app.config.get('ADMIN_CLIENT_USER_NAME'))
|
||||
response = client.get(
|
||||
@@ -203,8 +133,6 @@ def test_authentication_passes_when_service_has_multiple_keys_some_expired(
|
||||
api_key = ApiKey(**another_key)
|
||||
save_model_api_key(api_key)
|
||||
token = create_jwt_token(
|
||||
request_method="GET",
|
||||
request_path='/service',
|
||||
secret=get_unsigned_secret(api_key.id),
|
||||
client_id=str(sample_api_key.service_id))
|
||||
response = client.get(
|
||||
@@ -232,8 +160,6 @@ def test_authentication_returns_token_expired_when_service_uses_expired_key_and_
|
||||
api_key = ApiKey(**another_key)
|
||||
save_model_api_key(api_key)
|
||||
token = create_jwt_token(
|
||||
request_method="GET",
|
||||
request_path='/service',
|
||||
secret=get_unsigned_secret(expired_api_key.id),
|
||||
client_id=str(sample_api_key.service_id))
|
||||
# expire the key
|
||||
@@ -258,8 +184,6 @@ def test_authentication_returns_error_when_api_client_has_no_secrets(notify_api,
|
||||
with notify_api.test_client() as client:
|
||||
api_secret = notify_api.config.get('ADMIN_CLIENT_SECRET')
|
||||
token = create_jwt_token(
|
||||
request_method="GET",
|
||||
request_path='/service',
|
||||
secret=api_secret,
|
||||
client_id=notify_api.config.get('ADMIN_CLIENT_USER_NAME')
|
||||
)
|
||||
@@ -281,8 +205,6 @@ def test_authentication_returns_error_when_service_has_no_secrets(notify_api,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
token = create_jwt_token(
|
||||
request_method="GET",
|
||||
request_path='/service',
|
||||
secret=fake_uuid,
|
||||
client_id=str(sample_service.id))
|
||||
|
||||
@@ -296,22 +218,15 @@ def test_authentication_returns_error_when_service_has_no_secrets(notify_api,
|
||||
|
||||
def __create_get_token(service_id):
|
||||
if service_id:
|
||||
return create_jwt_token(request_method="GET",
|
||||
request_path='/service/{}'.format(service_id),
|
||||
secret=get_unsigned_secrets(service_id)[0],
|
||||
return create_jwt_token(secret=get_unsigned_secrets(service_id)[0],
|
||||
client_id=str(service_id))
|
||||
else:
|
||||
return create_jwt_token(request_method="GET",
|
||||
request_path='/service',
|
||||
secret=get_unsigned_secrets(service_id)[0],
|
||||
return create_jwt_token(secret=get_unsigned_secrets(service_id)[0],
|
||||
client_id=service_id)
|
||||
|
||||
|
||||
def __create_post_token(service_id, request_body):
|
||||
return create_jwt_token(
|
||||
request_method="POST",
|
||||
request_path='/service',
|
||||
secret=get_unsigned_secrets(service_id)[0],
|
||||
client_id=str(service_id),
|
||||
request_body=request_body
|
||||
client_id=str(service_id)
|
||||
)
|
||||
|
||||
@@ -10,10 +10,7 @@ def test_create_event(notify_api):
|
||||
'data': {'something': 'random', 'in_fact': 'could be anything'}
|
||||
}
|
||||
path = '/events'
|
||||
auth_header = create_authorization_header(
|
||||
path=path,
|
||||
method='POST',
|
||||
request_body=json.dumps(data))
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
response = client.post(
|
||||
path,
|
||||
|
||||
@@ -25,11 +25,7 @@ def test_create_invited_user(notify_api, sample_service, mocker):
|
||||
|
||||
data = json.dumps(data)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/invite'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/invite'.format(sample_service.id),
|
||||
@@ -76,11 +72,7 @@ def test_create_invited_user_invalid_email(notify_api, sample_service, mocker):
|
||||
|
||||
data = json.dumps(data)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/invite'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/invite'.format(sample_service.id),
|
||||
@@ -112,10 +104,7 @@ def test_get_all_invited_users_by_service(notify_api, notify_db, notify_db_sessi
|
||||
|
||||
url = '/service/{}/invite'.format(sample_service.id)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path=url,
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
url,
|
||||
@@ -139,10 +128,7 @@ def test_get_invited_users_by_service_with_no_invites(notify_api, notify_db, not
|
||||
|
||||
url = '/service/{}/invite'.format(sample_service.id)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path=url,
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
url,
|
||||
@@ -159,10 +145,7 @@ def test_get_invited_user_by_service_and_id(notify_api, sample_service, sample_i
|
||||
|
||||
url = '/service/{}/invite/{}'.format(sample_service.id, sample_invited_user.id)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path=url,
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
url,
|
||||
@@ -186,10 +169,7 @@ def test_get_invited_user_by_service_but_unknown_invite_id_returns_404(notify_ap
|
||||
unknown_id = uuid.uuid4()
|
||||
url = '/service/{}/invite/{}'.format(sample_service.id, unknown_id)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path=url,
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
url,
|
||||
@@ -204,11 +184,7 @@ def test_update_invited_user_set_status_to_cancelled(notify_api, sample_invited_
|
||||
|
||||
data = {'status': 'cancelled'}
|
||||
url = '/service/{0}/invite/{1}'.format(sample_invited_user.service_id, sample_invited_user.id)
|
||||
auth_header = create_authorization_header(
|
||||
path=url,
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
response = client.post(url,
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -223,11 +199,7 @@ def test_update_invited_user_for_wrong_service_returns_404(notify_api, sample_in
|
||||
with notify_api.test_client() as client:
|
||||
data = {'status': 'cancelled'}
|
||||
url = '/service/{0}/invite/{1}'.format(fake_uuid, sample_invited_user.id)
|
||||
auth_header = create_authorization_header(
|
||||
path=url,
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
response = client.post(url, data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert response.status_code == 404
|
||||
@@ -240,11 +212,7 @@ def test_update_invited_user_for_invalid_data_returns_400(notify_api, sample_inv
|
||||
with notify_api.test_client() as client:
|
||||
data = {'status': 'garbage'}
|
||||
url = '/service/{0}/invite/{1}'.format(sample_invited_user.service_id, sample_invited_user.id)
|
||||
auth_header = create_authorization_header(
|
||||
path=url,
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
response = client.post(url, data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert response.status_code == 400
|
||||
|
||||
@@ -14,10 +14,7 @@ def test_get_jobs(notify_api, notify_db, notify_db_session, sample_template):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
path = '/service/{}/job'.format(service_id)
|
||||
auth_header = create_authorization_header(
|
||||
service_id=service_id,
|
||||
path=path,
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=service_id)
|
||||
response = client.get(path, headers=[auth_header])
|
||||
assert response.status_code == 200
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
@@ -28,10 +25,7 @@ def test_get_job_with_invalid_service_id_returns404(notify_api, sample_api_key,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
path = '/service/{}/job'.format(sample_service.id)
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_service.id,
|
||||
path=path,
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
response = client.get(path, headers=[auth_header])
|
||||
assert response.status_code == 200
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
@@ -43,10 +37,7 @@ def test_get_job_with_invalid_job_id_returns404(notify_api, sample_template):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
path = '/service/{}/job/{}'.format(service_id, "bad-id")
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_template.service.id,
|
||||
path=path,
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_template.service.id)
|
||||
response = client.get(path, headers=[auth_header])
|
||||
assert response.status_code == 404
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
@@ -59,10 +50,7 @@ def test_get_job_with_unknown_id_returns404(notify_api, sample_template, fake_uu
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
path = '/service/{}/job/{}'.format(service_id, fake_uuid)
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_template.service.id,
|
||||
path=path,
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_template.service.id)
|
||||
response = client.get(path, headers=[auth_header])
|
||||
assert response.status_code == 404
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
@@ -78,10 +66,7 @@ def test_get_job_by_id(notify_api, sample_job):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
path = '/service/{}/job/{}'.format(service_id, job_id)
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_job.service.id,
|
||||
path=path,
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_job.service.id)
|
||||
response = client.get(path, headers=[auth_header])
|
||||
assert response.status_code == 200
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
@@ -101,11 +86,7 @@ def test_create_job(notify_api, sample_template, mocker, fake_uuid):
|
||||
'created_by': str(sample_template.created_by.id)
|
||||
}
|
||||
path = '/service/{}/job'.format(sample_template.service.id)
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_template.service.id,
|
||||
path=path,
|
||||
method='POST',
|
||||
request_body=json.dumps(data))
|
||||
auth_header = create_authorization_header(service_id=sample_template.service.id)
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
response = client.post(
|
||||
path,
|
||||
@@ -133,11 +114,7 @@ def test_create_job_returns_400_if_missing_data(notify_api, sample_template, moc
|
||||
data = {
|
||||
}
|
||||
path = '/service/{}/job'.format(sample_template.service.id)
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_template.service.id,
|
||||
path=path,
|
||||
method='POST',
|
||||
request_body=json.dumps(data))
|
||||
auth_header = create_authorization_header(service_id=sample_template.service.id)
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
response = client.post(
|
||||
path,
|
||||
@@ -161,11 +138,7 @@ def test_create_job_returns_404_if_missing_service(notify_api, sample_template,
|
||||
random_id = str(uuid.uuid4())
|
||||
data = {}
|
||||
path = '/service/{}/job'.format(random_id)
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_template.service.id,
|
||||
path=path,
|
||||
method='POST',
|
||||
request_body=json.dumps(data))
|
||||
auth_header = create_authorization_header(service_id=sample_template.service.id)
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
response = client.post(
|
||||
path,
|
||||
|
||||
@@ -20,10 +20,7 @@ from freezegun import freeze_time
|
||||
def test_get_notification_by_id(notify_api, sample_notification):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_notification.service_id,
|
||||
path='/notifications/{}'.format(sample_notification.id),
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
|
||||
response = client.get(
|
||||
'/notifications/{}'.format(sample_notification.id),
|
||||
@@ -48,10 +45,7 @@ def test_get_notifications_empty_result(notify_api, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
missing_notification_id = uuid.uuid4()
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_api_key.service_id,
|
||||
path='/notifications/{}'.format(missing_notification_id),
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_api_key.service_id)
|
||||
|
||||
response = client.get(
|
||||
path='/notifications/{}'.format(missing_notification_id),
|
||||
@@ -66,10 +60,7 @@ def test_get_notifications_empty_result(notify_api, sample_api_key):
|
||||
def test_get_all_notifications(notify_api, sample_notification):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_notification.service_id,
|
||||
path='/notifications',
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
|
||||
response = client.get(
|
||||
'/notifications',
|
||||
@@ -97,10 +88,7 @@ def test_get_all_notifications_newest_first(notify_api, notify_db, notify_db_ses
|
||||
notification_2 = create_sample_notification(notify_db, notify_db_session, sample_email_template.service)
|
||||
notification_3 = create_sample_notification(notify_db, notify_db_session, sample_email_template.service)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_email_template.service_id,
|
||||
path='/notifications',
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
|
||||
response = client.get(
|
||||
'/notifications',
|
||||
@@ -126,9 +114,7 @@ def test_get_all_notifications_for_service_in_order(notify_api, notify_db, notif
|
||||
notification_2 = create_sample_notification(notify_db, notify_db_session, service=service_1)
|
||||
notification_3 = create_sample_notification(notify_db, notify_db_session, service=service_1)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/notifications'.format(service_1.id),
|
||||
method='GET')
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
path='/service/{}/notifications'.format(service_1.id),
|
||||
@@ -159,9 +145,7 @@ def test_get_all_notifications_for_job_in_order(notify_api, notify_db, notify_db
|
||||
)
|
||||
create_sample_notification(notify_db, notify_db_session, job=another_job)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/job/{}/notifications'.format(sample_service.id, main_job.id),
|
||||
method='GET')
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
path='/service/{}/job/{}/notifications'.format(sample_service.id, main_job.id),
|
||||
@@ -178,10 +162,7 @@ def test_get_all_notifications_for_job_in_order(notify_api, notify_db, notify_db
|
||||
def test_should_not_get_notifications_by_service_with_client_credentials(notify_api, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_api_key.service.id,
|
||||
path='/service/{}/notifications'.format(sample_api_key.service.id),
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_api_key.service.id)
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/notifications'.format(sample_api_key.service.id),
|
||||
@@ -196,10 +177,7 @@ def test_should_not_get_notifications_by_service_with_client_credentials(notify_
|
||||
def test_should_not_get_notifications_by_job_and_service_with_client_credentials(notify_api, sample_job):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_job.service.id,
|
||||
path='/service/{}/job/{}/notifications'.format(sample_job.service.id, sample_job.id),
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_job.service.id)
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/job/{}/notifications'.format(sample_job.service.id, sample_job.id),
|
||||
@@ -214,10 +192,7 @@ def test_should_not_get_notifications_by_job_and_service_with_client_credentials
|
||||
def test_should_reject_invalid_page_param(notify_api, sample_email_template):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_email_template.service_id,
|
||||
path='/notifications',
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
|
||||
response = client.get(
|
||||
'/notifications?page=invalid',
|
||||
@@ -234,10 +209,7 @@ def test_valid_page_size_param(notify_api, notify_db, notify_db_session, sample_
|
||||
n1 = create_sample_notification(notify_db, notify_db_session)
|
||||
n2 = create_sample_notification(notify_db, notify_db_session)
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_email_template.service_id,
|
||||
path='/notifications',
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
|
||||
response = client.get(
|
||||
'/notifications?page=1&page_size=1',
|
||||
@@ -255,10 +227,7 @@ def test_invalid_page_size_param(notify_api, notify_db, notify_db_session, sampl
|
||||
n1 = create_sample_notification(notify_db, notify_db_session)
|
||||
n2 = create_sample_notification(notify_db, notify_db_session)
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_email_template.service_id,
|
||||
path='/notifications',
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
|
||||
response = client.get(
|
||||
'/notifications?page=1&page_size=invalid',
|
||||
@@ -282,10 +251,7 @@ def test_should_return_pagination_links(notify_api, notify_db, notify_db_session
|
||||
notification_2 = create_sample_notification(notify_db, notify_db_session, sample_email_template.service)
|
||||
create_sample_notification(notify_db, notify_db_session, sample_email_template.service)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_email_template.service_id,
|
||||
path='/notifications',
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
|
||||
response = client.get(
|
||||
'/notifications?page=2',
|
||||
@@ -306,10 +272,7 @@ def test_should_return_pagination_links(notify_api, notify_db, notify_db_session
|
||||
def test_get_all_notifications_returns_empty_list(notify_api, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_api_key.service.id,
|
||||
path='/notifications',
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_api_key.service.id)
|
||||
|
||||
response = client.get(
|
||||
'/notifications',
|
||||
@@ -335,10 +298,7 @@ def test_filter_by_template_type(notify_api, notify_db, notify_db_session, sampl
|
||||
service=sample_email_template.service,
|
||||
template=sample_email_template)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_email_template.service_id,
|
||||
path='/notifications',
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
|
||||
response = client.get(
|
||||
'/notifications?template_type=sms',
|
||||
@@ -369,10 +329,7 @@ def test_filter_by_multiple_template_types(notify_api,
|
||||
service=sample_email_template.service,
|
||||
template=sample_email_template)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_email_template.service_id,
|
||||
path='/notifications',
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
|
||||
response = client.get(
|
||||
'/notifications?template_type=sms&template_type=email',
|
||||
@@ -402,10 +359,7 @@ def test_filter_by_status(notify_api, notify_db, notify_db_session, sample_email
|
||||
service=sample_email_template.service,
|
||||
template=sample_email_template)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_email_template.service_id,
|
||||
path='/notifications',
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
|
||||
response = client.get(
|
||||
'/notifications?status=delivered',
|
||||
@@ -437,10 +391,7 @@ def test_filter_by_multiple_statuss(notify_api,
|
||||
service=sample_email_template.service,
|
||||
template=sample_email_template)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_email_template.service_id,
|
||||
path='/notifications',
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
|
||||
response = client.get(
|
||||
'/notifications?status=delivered&status=sending',
|
||||
@@ -478,10 +429,7 @@ def test_filter_by_status_and_template_type(notify_api,
|
||||
template=sample_email_template,
|
||||
status="delivered")
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_email_template.service_id,
|
||||
path='/notifications',
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
|
||||
response = client.get(
|
||||
'/notifications?template_type=email&status=delivered',
|
||||
@@ -506,10 +454,7 @@ def test_get_notification_statistics(
|
||||
|
||||
path = '/service/{}/notifications-statistics'.format(sample_email_template.service)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_email_template.service_id,
|
||||
path=path,
|
||||
method='GET')
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
|
||||
response = client.get(path, headers=[auth_header])
|
||||
assert response.status_code == 404
|
||||
@@ -525,11 +470,7 @@ def test_create_sms_should_reject_if_missing_required_fields(notify_api, sample_
|
||||
mocker.patch('app.celery.tasks.send_sms.apply_async')
|
||||
|
||||
data = {}
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_api_key.service_id,
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/sms',
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=sample_api_key.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
@@ -553,11 +494,7 @@ def test_should_reject_bad_phone_numbers(notify_api, sample_template, mocker):
|
||||
'to': 'invalid',
|
||||
'template': sample_template.id
|
||||
}
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_template.service.id,
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/sms',
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=sample_template.service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
@@ -581,11 +518,7 @@ def test_send_notification_invalid_template_id(notify_api, sample_template, mock
|
||||
'to': '+447700900855',
|
||||
'template': fake_uuid
|
||||
}
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_template.service.id,
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/sms',
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=sample_template.service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
@@ -614,11 +547,7 @@ def test_send_notification_with_placeholders_replaced(notify_api, sample_templat
|
||||
'name': 'Jo'
|
||||
}
|
||||
}
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_template_with_placeholders.service.id,
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/sms',
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=sample_template_with_placeholders.service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
@@ -649,11 +578,7 @@ def test_send_notification_with_missing_personalisation(notify_api, sample_templ
|
||||
'foo': 'bar'
|
||||
}
|
||||
}
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_template_with_placeholders.service.id,
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/sms',
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=sample_template_with_placeholders.service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
@@ -681,11 +606,7 @@ def test_send_notification_with_too_much_personalisation_data(
|
||||
'name': 'Jo', 'foo': 'bar'
|
||||
}
|
||||
}
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_template_with_placeholders.service.id,
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/sms',
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=sample_template_with_placeholders.service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
@@ -715,11 +636,7 @@ def test_prevents_sending_to_any_mobile_on_restricted_service(notify_api, sample
|
||||
'template': sample_template.id
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_template.service.id,
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/sms',
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=sample_template.service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
@@ -747,11 +664,7 @@ def test_should_not_allow_template_from_another_service(notify_api, service_fact
|
||||
'template': service_2_templates[0].id
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
service_id=service_1.id,
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/sms',
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=service_1.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
@@ -780,11 +693,7 @@ def test_should_not_allow_template_content_too_large(notify_api, notify_db, noti
|
||||
}
|
||||
})
|
||||
endpoint = url_for('notifications.send_notification', notification_type='sms')
|
||||
auth_header = create_authorization_header(
|
||||
service_id=template.service.id,
|
||||
request_body=json_data,
|
||||
path=endpoint,
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=template.service.id)
|
||||
|
||||
resp = client.post(
|
||||
path=endpoint,
|
||||
@@ -809,12 +718,7 @@ def test_should_allow_valid_sms_notification(notify_api, sample_template, mocker
|
||||
'template': str(sample_template.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/sms',
|
||||
method='POST',
|
||||
service_id=sample_template.service_id
|
||||
)
|
||||
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
@@ -840,11 +744,7 @@ def test_create_email_should_reject_if_missing_required_fields(notify_api, sampl
|
||||
mocker.patch('app.celery.tasks.send_email.apply_async')
|
||||
|
||||
data = {}
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_api_key.service_id,
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/email',
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=sample_api_key.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/email',
|
||||
@@ -868,11 +768,7 @@ def test_should_reject_email_notification_with_bad_email(notify_api, sample_emai
|
||||
'to': to_address,
|
||||
'template': str(sample_email_template.service.id)
|
||||
}
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_email_template.service.id,
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/email',
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/email',
|
||||
@@ -895,11 +791,7 @@ def test_should_reject_email_notification_with_template_id_that_cant_be_found(
|
||||
'to': 'ok@ok.com',
|
||||
'template': fake_uuid
|
||||
}
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_email_template.service.id,
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/email',
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/email',
|
||||
@@ -931,11 +823,7 @@ def test_should_not_allow_email_template_from_another_service(notify_api, servic
|
||||
'template': str(service_2_templates[0].id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
service_id=service_1.id,
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/email',
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=service_1.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/email',
|
||||
@@ -963,11 +851,7 @@ def test_should_not_send_email_if_restricted_and_not_a_service_user(notify_api,
|
||||
'template': str(sample_email_template.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_email_template.service.id,
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/email',
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/email',
|
||||
@@ -999,11 +883,7 @@ def test_should_not_send_email_for_job_if_restricted_and_not_a_service_user(
|
||||
'job': (sample_job.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_job.service.id,
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/email',
|
||||
method='POST')
|
||||
auth_header = create_authorization_header(service_id=sample_job.service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/email',
|
||||
@@ -1029,12 +909,7 @@ def test_should_allow_valid_email_notification(notify_api, sample_email_template
|
||||
'template': str(sample_email_template.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/email',
|
||||
method='POST',
|
||||
service_id=sample_email_template.service_id
|
||||
)
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/email',
|
||||
@@ -1072,12 +947,7 @@ def test_should_block_api_call_if_over_day_limit(notify_db, notify_db_session, n
|
||||
'template': str(email_template.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/email',
|
||||
method='POST',
|
||||
service_id=service.id
|
||||
)
|
||||
auth_header = create_authorization_header(service_id=service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/email',
|
||||
@@ -1108,12 +978,7 @@ def test_no_limit_for_live_service(notify_api,
|
||||
'template': str(sample_email_template.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/email',
|
||||
method='POST',
|
||||
service_id=sample_service.id
|
||||
)
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/email',
|
||||
@@ -1142,12 +1007,7 @@ def test_should_block_api_call_if_over_day_limit_regardless_of_type(notify_db, n
|
||||
'template': str(sms_template.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/sms',
|
||||
method='POST',
|
||||
service_id=service.id
|
||||
)
|
||||
auth_header = create_authorization_header(service_id=service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
@@ -1175,12 +1035,7 @@ def test_should_allow_api_call_if_under_day_limit_regardless_of_type(notify_db,
|
||||
'template': str(sms_template.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
request_body=json.dumps(data),
|
||||
path='/notifications/sms',
|
||||
method='POST',
|
||||
service_id=service.id
|
||||
)
|
||||
auth_header = create_authorization_header(service_id=service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
|
||||
@@ -11,9 +11,7 @@ def test_get_permission_list(notify_api, notify_db, notify_db_session, sample_pe
|
||||
"""
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
header = create_authorization_header(
|
||||
path=url_for('permission.get_permissions'),
|
||||
method='GET')
|
||||
header = create_authorization_header()
|
||||
response = client.get(
|
||||
url_for('permission.get_permissions'),
|
||||
headers=[header])
|
||||
@@ -40,9 +38,7 @@ def test_get_permission_filter(notify_api,
|
||||
"""
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
header = create_authorization_header(
|
||||
path=url_for('permission.get_permissions'),
|
||||
method='GET')
|
||||
header = create_authorization_header()
|
||||
response = client.get(
|
||||
url_for('permission.get_permissions', service=str(sample_service.id)),
|
||||
headers=[header])
|
||||
@@ -65,9 +61,7 @@ def test_get_permission(notify_api, notify_db, notify_db_session, sample_permiss
|
||||
"""
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
header = create_authorization_header(
|
||||
path=url_for('permission.get_permission', permission_id=str(sample_permission.id)),
|
||||
method='GET')
|
||||
header = create_authorization_header()
|
||||
response = client.get(
|
||||
url_for('permission.get_permission', permission_id=str(sample_permission.id)),
|
||||
headers=[header])
|
||||
@@ -88,9 +82,7 @@ def test_get_permission_404(notify_api, notify_db, notify_db_session, sample_per
|
||||
"""
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
header = create_authorization_header(
|
||||
path=url_for('permission.get_permission', permission_id="123"),
|
||||
method='GET')
|
||||
header = create_authorization_header()
|
||||
response = client.get(
|
||||
url_for('permission.get_permission', permission_id="123"),
|
||||
headers=[header])
|
||||
|
||||
@@ -16,10 +16,7 @@ def test_api_key_should_create_new_api_key_for_service(notify_api, notify_db,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = {'name': 'some secret name', 'created_by': str(sample_service.created_by.id)}
|
||||
auth_header = create_authorization_header(path=url_for('service.renew_api_key',
|
||||
service_id=sample_service.id),
|
||||
method='POST',
|
||||
request_body=json.dumps(data))
|
||||
auth_header = create_authorization_header()
|
||||
response = client.post(url_for('service.renew_api_key', service_id=sample_service.id),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -36,9 +33,7 @@ def test_api_key_should_return_error_when_service_does_not_exist(notify_api, not
|
||||
with notify_api.test_client() as client:
|
||||
import uuid
|
||||
missing_service_id = uuid.uuid4()
|
||||
auth_header = create_authorization_header(path=url_for('service.renew_api_key',
|
||||
service_id=missing_service_id),
|
||||
method='POST')
|
||||
auth_header = create_authorization_header()
|
||||
response = client.post(url_for('service.renew_api_key', service_id=missing_service_id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert response.status_code == 404
|
||||
@@ -49,10 +44,7 @@ def test_revoke_should_expire_api_key_for_service(notify_api, notify_db, notify_
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
assert ApiKey.query.count() == 1
|
||||
auth_header = create_authorization_header(path=url_for('service.revoke_api_key',
|
||||
service_id=sample_api_key.service_id,
|
||||
api_key_id=sample_api_key.id),
|
||||
method='POST')
|
||||
auth_header = create_authorization_header()
|
||||
response = client.post(url_for('service.revoke_api_key',
|
||||
service_id=sample_api_key.service_id,
|
||||
api_key_id=sample_api_key.id),
|
||||
@@ -69,20 +61,14 @@ def test_api_key_should_create_multiple_new_api_key_for_service(notify_api, noti
|
||||
with notify_api.test_client() as client:
|
||||
assert ApiKey.query.count() == 0
|
||||
data = {'name': 'some secret name', 'created_by': str(sample_service.created_by.id)}
|
||||
auth_header = create_authorization_header(path=url_for('service.renew_api_key',
|
||||
service_id=sample_service.id),
|
||||
method='POST',
|
||||
request_body=json.dumps(data))
|
||||
auth_header = create_authorization_header()
|
||||
response = client.post(url_for('service.renew_api_key', service_id=sample_service.id),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert response.status_code == 201
|
||||
assert ApiKey.query.count() == 1
|
||||
data = {'name': 'another secret name', 'created_by': str(sample_service.created_by.id)}
|
||||
auth_header = create_authorization_header(path=url_for('service.renew_api_key',
|
||||
service_id=sample_service.id),
|
||||
method='POST',
|
||||
request_body=json.dumps(data))
|
||||
auth_header = create_authorization_header()
|
||||
response2 = client.post(url_for('service.renew_api_key', service_id=sample_service.id),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -115,9 +101,7 @@ def test_get_api_keys_should_return_all_keys_for_service(notify_api, notify_db,
|
||||
|
||||
assert ApiKey.query.count() == 4
|
||||
|
||||
auth_header = create_authorization_header(path=url_for('service.get_api_keys',
|
||||
service_id=sample_api_key.service_id),
|
||||
method='GET')
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(url_for('service.get_api_keys',
|
||||
service_id=sample_api_key.service_id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -131,10 +115,7 @@ def test_get_api_keys_should_return_one_key_for_service(notify_api, notify_db,
|
||||
sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(path=url_for('service.get_api_keys',
|
||||
service_id=sample_api_key.service_id,
|
||||
key_id=sample_api_key.id),
|
||||
method='GET')
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(url_for('service.get_api_keys',
|
||||
service_id=sample_api_key.service_id,
|
||||
key_id=sample_api_key.id),
|
||||
|
||||
@@ -17,10 +17,7 @@ def test_get_service_list(notify_api, service_factory):
|
||||
service_factory.get('one', email_from='one')
|
||||
service_factory.get('two', email_from='two')
|
||||
service_factory.get('three', email_from='three')
|
||||
auth_header = create_authorization_header(
|
||||
path='/service',
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
'/service',
|
||||
headers=[auth_header]
|
||||
@@ -41,10 +38,7 @@ def test_get_service_list_by_user(notify_api, sample_user, service_factory):
|
||||
service_factory.get('two', sample_user, email_from='two')
|
||||
service_factory.get('three', sample_user, email_from='three')
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service',
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
'/service?user_id='.format(sample_user.id),
|
||||
headers=[auth_header]
|
||||
@@ -72,10 +66,7 @@ def test_get_service_list_by_user_should_return_empty_list_if_no_services(notify
|
||||
service_factory.get('two', sample_user, email_from='two')
|
||||
service_factory.get('three', sample_user, email_from='three')
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service',
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
'/service?user_id={}'.format(new_user.id),
|
||||
headers=[auth_header]
|
||||
@@ -88,10 +79,7 @@ def test_get_service_list_by_user_should_return_empty_list_if_no_services(notify
|
||||
def test_get_service_list_should_return_empty_list_if_no_services(notify_api, notify_db, notify_db_session):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(
|
||||
path='/service',
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
'/service',
|
||||
headers=[auth_header]
|
||||
@@ -104,10 +92,7 @@ def test_get_service_list_should_return_empty_list_if_no_services(notify_api, no
|
||||
def test_get_service_by_id(notify_api, sample_service):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}'.format(sample_service.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.get(
|
||||
'/service/{}'.format(sample_service.id),
|
||||
headers=[auth_header]
|
||||
@@ -122,10 +107,7 @@ def test_get_service_by_id_should_404_if_no_service(notify_api, notify_db):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
service_id = str(uuid.uuid4())
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}'.format(service_id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.get(
|
||||
'/service/{}'.format(service_id),
|
||||
headers=[auth_header]
|
||||
@@ -140,10 +122,7 @@ def test_get_service_by_id_and_user(notify_api, service_factory, sample_user):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
service = service_factory.get('new service', sample_user, email_from='new.service')
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}'.format(service.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.get(
|
||||
'/service/{}?user_id={}'.format(service.id, sample_user.id),
|
||||
headers=[auth_header]
|
||||
@@ -158,10 +137,7 @@ def test_get_service_by_id_should_404_if_no_service_for_user(notify_api, sample_
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
service_id = str(uuid.uuid4())
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}'.format(service_id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.get(
|
||||
'/service/{}?user_id={}'.format(service_id, sample_user.id),
|
||||
headers=[auth_header]
|
||||
@@ -183,11 +159,7 @@ def test_create_service(notify_api, sample_user):
|
||||
'active': False,
|
||||
'email_from': 'created.service',
|
||||
'created_by': str(sample_user.id)}
|
||||
auth_header = create_authorization_header(
|
||||
path='/service',
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.post(
|
||||
'/service',
|
||||
@@ -199,10 +171,7 @@ def test_create_service(notify_api, sample_user):
|
||||
assert json_resp['data']['name'] == 'created service'
|
||||
assert json_resp['data']['email_from'] == 'created.service'
|
||||
|
||||
auth_header_fetch = create_authorization_header(
|
||||
path='/service/{}'.format(json_resp['data']['id']),
|
||||
method='GET'
|
||||
)
|
||||
auth_header_fetch = create_authorization_header()
|
||||
|
||||
resp = client.get(
|
||||
'/service/{}?user_id={}'.format(json_resp['data']['id'], sample_user.id),
|
||||
@@ -224,11 +193,7 @@ def test_should_not_create_service_with_missing_user_id_field(notify_api, fake_u
|
||||
'active': False,
|
||||
'created_by': str(fake_uuid)
|
||||
}
|
||||
auth_header = create_authorization_header(
|
||||
path='/service',
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.post(
|
||||
'/service',
|
||||
@@ -251,11 +216,7 @@ def test_should_error_if_created_by_missing(notify_api, sample_user):
|
||||
'active': False,
|
||||
'user_id': str(sample_user.id)
|
||||
}
|
||||
auth_header = create_authorization_header(
|
||||
path='/service',
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.post(
|
||||
'/service',
|
||||
@@ -282,11 +243,7 @@ def test_should_not_create_service_with_missing_if_user_id_is_not_in_database(no
|
||||
'active': False,
|
||||
'created_by': str(fake_uuid)
|
||||
}
|
||||
auth_header = create_authorization_header(
|
||||
path='/service',
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.post(
|
||||
'/service',
|
||||
@@ -304,11 +261,7 @@ def test_should_not_create_service_if_missing_data(notify_api, sample_user):
|
||||
data = {
|
||||
'user_id': str(sample_user.id)
|
||||
}
|
||||
auth_header = create_authorization_header(
|
||||
path='/service',
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.post(
|
||||
'/service',
|
||||
@@ -338,11 +291,7 @@ def test_should_not_create_service_with_duplicate_name(notify_api,
|
||||
'active': False,
|
||||
'email_from': 'sample.service2',
|
||||
'created_by': str(sample_user.id)}
|
||||
auth_header = create_authorization_header(
|
||||
path='/service',
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.post(
|
||||
'/service',
|
||||
@@ -370,11 +319,7 @@ def test_create_service_should_throw_duplicate_key_constraint_for_existing_email
|
||||
'active': False,
|
||||
'email_from': 'first.service',
|
||||
'created_by': str(sample_user.id)}
|
||||
auth_header = create_authorization_header(
|
||||
path='/service',
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.post(
|
||||
'/service',
|
||||
@@ -388,10 +333,7 @@ def test_create_service_should_throw_duplicate_key_constraint_for_existing_email
|
||||
def test_update_service(notify_api, sample_service):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}'.format(sample_service.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.get(
|
||||
'/service/{}'.format(sample_service.id),
|
||||
headers=[auth_header]
|
||||
@@ -406,11 +348,7 @@ def test_update_service(notify_api, sample_service):
|
||||
'created_by': str(sample_service.created_by.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}'.format(sample_service.id),
|
||||
@@ -442,11 +380,7 @@ def test_should_not_update_service_with_duplicate_name(notify_api,
|
||||
'created_by': str(service.created_by.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}'.format(sample_service.id),
|
||||
@@ -480,11 +414,7 @@ def test_should_not_update_service_with_duplicate_email_from(notify_api,
|
||||
'created_by': str(service.created_by.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}'.format(sample_service.id),
|
||||
@@ -509,11 +439,7 @@ def test_update_service_should_404_if_id_is_invalid(notify_api, notify_db, notif
|
||||
|
||||
missing_service_id = uuid.uuid4()
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}'.format(missing_service_id),
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}'.format(missing_service_id),
|
||||
@@ -527,10 +453,7 @@ def test_get_users_by_service(notify_api, notify_db, notify_db_session, sample_s
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
user_on_service = sample_service.users[0]
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/users'.format(sample_service.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.get(
|
||||
'/service/{}/users'.format(sample_service.id),
|
||||
@@ -552,10 +475,7 @@ def test_get_users_for_service_returns_empty_list_if_no_users_associated_with_se
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
dao_remove_user_from_service(sample_service, sample_service.users[0])
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/users'.format(sample_service.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/users'.format(sample_service.id),
|
||||
@@ -570,10 +490,7 @@ def test_get_users_for_service_returns_404_when_service_does_not_exist(notify_ap
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
service_id = uuid.uuid4()
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/users'.format(service_id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/users'.format(service_id),
|
||||
@@ -600,11 +517,7 @@ def test_default_permissions_are_added_for_user_service(notify_api,
|
||||
'active': False,
|
||||
'email_from': 'created.service',
|
||||
'created_by': str(sample_user.id)}
|
||||
auth_header = create_authorization_header(
|
||||
path='/service',
|
||||
method='POST',
|
||||
request_body=json.dumps(data)
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.post(
|
||||
'/service',
|
||||
@@ -616,19 +529,14 @@ def test_default_permissions_are_added_for_user_service(notify_api,
|
||||
assert json_resp['data']['name'] == 'created service'
|
||||
assert json_resp['data']['email_from'] == 'created.service'
|
||||
|
||||
auth_header_fetch = create_authorization_header(
|
||||
path='/service/{}'.format(json_resp['data']['id']),
|
||||
method='GET'
|
||||
)
|
||||
auth_header_fetch = create_authorization_header()
|
||||
|
||||
resp = client.get(
|
||||
'/service/{}?user_id={}'.format(json_resp['data']['id'], sample_user.id),
|
||||
headers=[auth_header_fetch]
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
header = create_authorization_header(
|
||||
path=url_for('user.get_user', user_id=sample_user.id),
|
||||
method='GET')
|
||||
header = create_authorization_header()
|
||||
response = client.get(
|
||||
url_for('user.get_user', user_id=sample_user.id),
|
||||
headers=[header])
|
||||
@@ -649,10 +557,7 @@ def test_add_existing_user_to_another_service_with_all_permissions(notify_api,
|
||||
|
||||
# check which users part of service
|
||||
user_already_in_service = sample_service.users[0]
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/users'.format(sample_service.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.get(
|
||||
'/service/{}/users'.format(sample_service.id),
|
||||
@@ -676,11 +581,7 @@ def test_add_existing_user_to_another_service_with_all_permissions(notify_api,
|
||||
|
||||
data = {'permissions': ['send_messages', 'manage_service', 'manage_api_keys']}
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/users/{}'.format(sample_service.id, user_to_add.id),
|
||||
request_body=json.dumps(data),
|
||||
method='POST'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}/users/{}'.format(sample_service.id, user_to_add.id),
|
||||
@@ -691,10 +592,7 @@ def test_add_existing_user_to_another_service_with_all_permissions(notify_api,
|
||||
assert resp.status_code == 201
|
||||
|
||||
# check new user added to service
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}'.format(sample_service.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.get(
|
||||
'/service/{}'.format(sample_service.id),
|
||||
@@ -705,10 +603,7 @@ def test_add_existing_user_to_another_service_with_all_permissions(notify_api,
|
||||
assert str(user_to_add.id) in json_resp['data']['users']
|
||||
|
||||
# check user has all permissions
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.get_user', user_id=user_to_add.id),
|
||||
method='GET'
|
||||
)
|
||||
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])
|
||||
|
||||
@@ -738,11 +633,7 @@ def test_add_existing_user_to_another_service_with_send_permissions(notify_api,
|
||||
save_model_user(user_to_add)
|
||||
|
||||
data = {'permissions': ['send_messages']}
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/users/{}'.format(sample_service.id, user_to_add.id),
|
||||
request_body=json.dumps(data),
|
||||
method='POST'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}/users/{}'.format(sample_service.id, user_to_add.id),
|
||||
@@ -753,10 +644,7 @@ def test_add_existing_user_to_another_service_with_send_permissions(notify_api,
|
||||
assert resp.status_code == 201
|
||||
|
||||
# check user has send permissions
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.get_user', user_id=user_to_add.id),
|
||||
method='GET'
|
||||
)
|
||||
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])
|
||||
|
||||
@@ -786,11 +674,7 @@ def test_add_existing_user_to_another_service_with_manage_permissions(notify_api
|
||||
save_model_user(user_to_add)
|
||||
|
||||
data = {'permissions': ['manage_service']}
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/users/{}'.format(sample_service.id, user_to_add.id),
|
||||
request_body=json.dumps(data),
|
||||
method='POST'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}/users/{}'.format(sample_service.id, user_to_add.id),
|
||||
@@ -801,10 +685,7 @@ def test_add_existing_user_to_another_service_with_manage_permissions(notify_api
|
||||
assert resp.status_code == 201
|
||||
|
||||
# check user has send permissions
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.get_user', user_id=user_to_add.id),
|
||||
method='GET'
|
||||
)
|
||||
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])
|
||||
|
||||
@@ -834,11 +715,7 @@ def test_add_existing_user_to_another_service_with_manage_api_keys(notify_api,
|
||||
save_model_user(user_to_add)
|
||||
|
||||
data = {'permissions': ['manage_api_keys']}
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/users/{}'.format(sample_service.id, user_to_add.id),
|
||||
request_body=json.dumps(data),
|
||||
method='POST'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}/users/{}'.format(sample_service.id, user_to_add.id),
|
||||
@@ -849,10 +726,7 @@ def test_add_existing_user_to_another_service_with_manage_api_keys(notify_api,
|
||||
assert resp.status_code == 201
|
||||
|
||||
# check user has send permissions
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.get_user', user_id=user_to_add.id),
|
||||
method='GET'
|
||||
)
|
||||
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])
|
||||
|
||||
@@ -882,11 +756,7 @@ def test_add_existing_user_to_non_existing_service_returns404(notify_api,
|
||||
incorrect_id = uuid.uuid4()
|
||||
|
||||
data = {'permissions': ['send_messages', 'manage_service', 'manage_api_keys']}
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/users/{}'.format(incorrect_id, user_to_add.id),
|
||||
request_body=json.dumps(data),
|
||||
method='POST'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}/users/{}'.format(incorrect_id, user_to_add.id),
|
||||
@@ -909,11 +779,7 @@ def test_add_existing_user_of_service_to_service_returns400(notify_api, notify_d
|
||||
existing_user_id = sample_service.users[0].id
|
||||
|
||||
data = {'permissions': ['send_messages', 'manage_service', 'manage_api_keys']}
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/users/{}'.format(sample_service.id, existing_user_id),
|
||||
request_body=json.dumps(data),
|
||||
method='POST'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}/users/{}'.format(sample_service.id, existing_user_id),
|
||||
@@ -936,11 +802,7 @@ def test_add_unknown_user_to_service_returns404(notify_api, notify_db, notify_db
|
||||
incorrect_id = 9876
|
||||
|
||||
data = {'permissions': ['send_messages', 'manage_service', 'manage_api_keys']}
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/users/{}'.format(sample_service.id, incorrect_id),
|
||||
request_body=json.dumps(data),
|
||||
method='POST'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}/users/{}'.format(sample_service.id, incorrect_id),
|
||||
@@ -972,10 +834,7 @@ def test_remove_user_from_service(notify_api, notify_db, notify_db_session, samp
|
||||
'service.remove_user_from_service',
|
||||
service_id=str(second_permission.service.id),
|
||||
user_id=str(second_permission.user.id))
|
||||
auth_header = create_authorization_header(
|
||||
path=endpoint,
|
||||
method='DELETE'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.delete(
|
||||
endpoint,
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -993,10 +852,7 @@ def test_remove_user_from_service(notify_api, notify_db, notify_db_session, samp
|
||||
'service.remove_user_from_service',
|
||||
service_id=str(sample_service_permission.service.id),
|
||||
user_id=str(second_user.id))
|
||||
auth_header = create_authorization_header(
|
||||
path=endpoint,
|
||||
method='DELETE'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.delete(
|
||||
endpoint,
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -1013,10 +869,7 @@ def test_cannot_remove_only_user_from_service(notify_api,
|
||||
'service.remove_user_from_service',
|
||||
service_id=str(sample_service_permission.service.id),
|
||||
user_id=str(sample_service_permission.user.id))
|
||||
auth_header = create_authorization_header(
|
||||
path=endpoint,
|
||||
method='DELETE'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.delete(
|
||||
endpoint,
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -1035,10 +888,7 @@ def test_get_service_and_api_key_history(notify_api, notify_db, notify_db_sessio
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/history'.format(sample_service.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
path='/service/{}/history'.format(sample_service.id),
|
||||
headers=[auth_header]
|
||||
|
||||
@@ -10,10 +10,7 @@ def test_fragment_count(notify_api, sample_provider_statistics):
|
||||
endpoint = url_for(
|
||||
'service.get_service_provider_aggregate_statistics',
|
||||
service_id=str(sample_provider_statistics.service.id))
|
||||
auth_header = create_authorization_header(
|
||||
path=endpoint,
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.get(
|
||||
endpoint,
|
||||
headers=[auth_header]
|
||||
@@ -32,10 +29,7 @@ def test_fragment_count_from_to(notify_api, sample_provider_statistics):
|
||||
service_id=str(sample_provider_statistics.service.id),
|
||||
date_from=today_str,
|
||||
date_to=today_str)
|
||||
auth_header = create_authorization_header(
|
||||
path=endpoint,
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.get(
|
||||
endpoint,
|
||||
headers=[auth_header]
|
||||
@@ -55,10 +49,7 @@ def test_fragment_count_from_greater_than_to(notify_api, sample_provider_statist
|
||||
service_id=str(sample_provider_statistics.service.id),
|
||||
date_from=today_str,
|
||||
date_to=yesterday_str)
|
||||
auth_header = create_authorization_header(
|
||||
path=endpoint,
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.get(
|
||||
endpoint,
|
||||
headers=[auth_header]
|
||||
@@ -76,10 +67,7 @@ def test_fragment_count_in_future(notify_api, sample_provider_statistics):
|
||||
'service.get_service_provider_aggregate_statistics',
|
||||
service_id=str(sample_provider_statistics.service.id),
|
||||
date_from=tomorrow_str)
|
||||
auth_header = create_authorization_header(
|
||||
path=endpoint,
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.get(
|
||||
endpoint,
|
||||
headers=[auth_header]
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import json
|
||||
import uuid
|
||||
import random
|
||||
import string
|
||||
from app.models import Template
|
||||
@@ -17,11 +16,7 @@ def test_should_create_a_new_sms_template_for_a_service(notify_api, sample_user,
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -50,11 +45,7 @@ def test_should_create_a_new_email_template_for_a_service(notify_api, sample_use
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -82,11 +73,7 @@ def test_should_be_error_if_service_does_not_exist_on_create(notify_api, sample_
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(fake_uuid),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(fake_uuid),
|
||||
@@ -110,11 +97,7 @@ def test_should_error_if_created_by_missing(notify_api, sample_user, sample_serv
|
||||
'service': service_id
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(service_id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(service_id),
|
||||
@@ -133,11 +116,7 @@ def test_should_be_error_if_service_does_not_exist_on_update(notify_api, fake_uu
|
||||
'name': 'my template'
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template/{}'.format(fake_uuid, fake_uuid),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template/{}'.format(fake_uuid, fake_uuid),
|
||||
@@ -161,11 +140,7 @@ def test_must_have_a_subject_on_an_email_template(notify_api, sample_user, sampl
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -190,11 +165,7 @@ def test_must_have_a_uniqe_subject_on_an_email_template(notify_api, sample_user,
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -212,11 +183,7 @@ def test_must_have_a_uniqe_subject_on_an_email_template(notify_api, sample_user,
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -241,11 +208,7 @@ def test_should_be_able_to_update_a_template(notify_api, sample_user, sample_ser
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
create_response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -260,11 +223,7 @@ def test_should_be_able_to_update_a_template(notify_api, sample_user, sample_ser
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template/{}'.format(sample_service.id, json_resp['data']['id']),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
update_response = client.post(
|
||||
'/service/{}/template/{}'.format(sample_service.id, json_resp['data']['id']),
|
||||
@@ -291,13 +250,7 @@ def test_should_be_able_to_archive_template(notify_api, sample_user, sample_serv
|
||||
|
||||
json_data = json.dumps(data)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template/{}'.format(
|
||||
str(sample_template.service.id),
|
||||
str(sample_template.id)),
|
||||
method='POST',
|
||||
request_body=json_data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}/template/{}'.format(sample_template.service.id, sample_template.id),
|
||||
@@ -330,21 +283,13 @@ def test_should_be_able_to_get_all_templates_for_a_service(notify_api, sample_us
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data_2 = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data_1
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
data=data_1
|
||||
)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data_2
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -352,10 +297,7 @@ def test_should_be_able_to_get_all_templates_for_a_service(notify_api, sample_us
|
||||
data=data_2
|
||||
)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -375,20 +317,14 @@ def test_should_get_only_templates_for_that_service(notify_api, sample_user, ser
|
||||
service_1 = service_factory.get('service 1', email_from='service.1')
|
||||
service_2 = service_factory.get('service 2', email_from='service.2')
|
||||
|
||||
auth_header_1 = create_authorization_header(
|
||||
path='/service/{}/template'.format(service_1.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header_1 = create_authorization_header()
|
||||
|
||||
response_1 = client.get(
|
||||
'/service/{}/template'.format(service_1.id),
|
||||
headers=[auth_header_1]
|
||||
)
|
||||
|
||||
auth_header_2 = create_authorization_header(
|
||||
path='/service/{}/template'.format(service_2.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header_2 = create_authorization_header()
|
||||
|
||||
response_2 = client.get(
|
||||
'/service/{}/template'.format(service_2.id),
|
||||
@@ -413,11 +349,7 @@ def test_should_get_only_templates_for_that_service(notify_api, sample_user, ser
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
create_auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(service_1.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
create_auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
'/service/{}/template'.format(service_1.id),
|
||||
headers=[('Content-Type', 'application/json'), create_auth_header],
|
||||
@@ -448,10 +380,7 @@ def test_should_return_empty_array_if_no_templates_for_service(notify_api, sampl
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -467,10 +396,7 @@ def test_should_return_404_if_no_templates_for_service_with_id(notify_api, sampl
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template/{}'.format(sample_service.id, fake_uuid),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template/{}'.format(sample_service.id, fake_uuid),
|
||||
@@ -496,11 +422,7 @@ def test_create_400_for_over_limit_content(notify_api, sample_user, sample_servi
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -522,11 +444,7 @@ def test_update_400_for_over_limit_content(notify_api, sample_user, sample_templ
|
||||
'content': ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(limit + 1)),
|
||||
'created_by': str(sample_user.id)
|
||||
})
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template/{}'.format(sample_template.service.id, sample_template.id),
|
||||
method='POST',
|
||||
request_body=json_data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
'/service/{}/template/{}'.format(sample_template.service.id, sample_template.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
|
||||
@@ -22,10 +22,7 @@ def test_get_template_statistics_for_service_for_last_week(notify_api, sample_te
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template-statistics'.format(sample_template.service_id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template-statistics'.format(sample_template.service_id),
|
||||
@@ -55,10 +52,7 @@ def test_get_template_statistics_for_service_for_last_week_with_no_data(notify_a
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template-statistics'.format(sample_template.service_id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
# Date is frozen at 2016-04-30 and no data written since
|
||||
response = client.get(
|
||||
@@ -96,10 +90,7 @@ def test_get_all_template_statistics_for_service(notify_api, sample_template):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template-statistics'.format(sample_template.service_id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template-statistics'.format(sample_template.service_id),
|
||||
@@ -127,10 +118,7 @@ def test_get_all_template_statistics_with_bad_limit_arg_returns_400(notify_api,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template-statistics'.format(sample_template.service_id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template-statistics'.format(sample_template.service_id),
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import json
|
||||
import uuid
|
||||
|
||||
from flask import url_for
|
||||
|
||||
import app
|
||||
from app.models import (User, Permission, MANAGE_SETTINGS, MANAGE_TEMPLATES)
|
||||
from app.dao.permissions_dao import default_service_permissions
|
||||
from app import db, encryption
|
||||
from tests import create_authorization_header
|
||||
|
||||
|
||||
@@ -16,8 +14,7 @@ def test_get_user_list(notify_api, notify_db, notify_db_session, sample_service)
|
||||
"""
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
header = create_authorization_header(path=url_for('user.get_user'),
|
||||
method='GET')
|
||||
header = create_authorization_header()
|
||||
response = client.get(url_for('user.get_user'),
|
||||
headers=[header])
|
||||
assert response.status_code == 200
|
||||
@@ -42,8 +39,7 @@ def test_get_user(notify_api, notify_db, notify_db_session, sample_service):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
sample_user = sample_service.users[0]
|
||||
header = create_authorization_header(path=url_for('user.get_user', user_id=sample_user.id),
|
||||
method='GET')
|
||||
header = create_authorization_header()
|
||||
resp = client.get(url_for('user.get_user',
|
||||
user_id=sample_user.id),
|
||||
headers=[header])
|
||||
@@ -79,9 +75,7 @@ def test_post_user(notify_api, notify_db, notify_db_session):
|
||||
"failed_login_count": 0,
|
||||
"permissions": {}
|
||||
}
|
||||
auth_header = create_authorization_header(path=url_for('user.create_user'),
|
||||
method='POST',
|
||||
request_body=json.dumps(data))
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.post(
|
||||
url_for('user.create_user'),
|
||||
@@ -111,9 +105,7 @@ def test_post_user_missing_attribute_email(notify_api, notify_db, notify_db_sess
|
||||
"failed_login_count": 0,
|
||||
"permissions": {}
|
||||
}
|
||||
auth_header = create_authorization_header(path=url_for('user.create_user'),
|
||||
method='POST',
|
||||
request_body=json.dumps(data))
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.post(
|
||||
url_for('user.create_user'),
|
||||
@@ -142,9 +134,7 @@ def test_post_user_missing_attribute_password(notify_api, notify_db, notify_db_s
|
||||
"failed_login_count": 0,
|
||||
"permissions": {}
|
||||
}
|
||||
auth_header = create_authorization_header(path=url_for('user.create_user'),
|
||||
method='POST',
|
||||
request_body=json.dumps(data))
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.post(
|
||||
url_for('user.create_user'),
|
||||
@@ -170,9 +160,7 @@ def test_put_user(notify_api, notify_db, notify_db_session, sample_service):
|
||||
'email_address': new_email,
|
||||
'mobile_number': sample_user.mobile_number
|
||||
}
|
||||
auth_header = create_authorization_header(path=url_for('user.update_user', user_id=sample_user.id),
|
||||
method='PUT',
|
||||
request_body=json.dumps(data))
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.put(
|
||||
url_for('user.update_user', user_id=sample_user.id),
|
||||
@@ -211,9 +199,7 @@ def test_put_user_update_password(notify_api,
|
||||
'mobile_number': sample_user.mobile_number,
|
||||
'password': new_password
|
||||
}
|
||||
auth_header = create_authorization_header(path=url_for('user.update_user', user_id=sample_user.id),
|
||||
method='PUT',
|
||||
request_body=json.dumps(data))
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.put(
|
||||
url_for('user.update_user', user_id=sample_user.id),
|
||||
@@ -224,9 +210,7 @@ def test_put_user_update_password(notify_api,
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
assert json_resp['data']['password_changed_at'] is not None
|
||||
data = {'password': new_password}
|
||||
auth_header = create_authorization_header(path=url_for('user.verify_user_password', user_id=sample_user.id),
|
||||
method='POST',
|
||||
request_body=json.dumps(data))
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_password', user_id=str(sample_user.id)),
|
||||
@@ -244,9 +228,7 @@ def test_put_user_not_exists(notify_api, notify_db, notify_db_session, sample_us
|
||||
assert User.query.count() == 1
|
||||
new_email = 'new@digital.cabinet-office.gov.uk'
|
||||
data = {'email_address': new_email}
|
||||
auth_header = create_authorization_header(path=url_for('user.update_user', user_id=fake_uuid),
|
||||
method='PUT',
|
||||
request_body=json.dumps(data))
|
||||
auth_header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), auth_header]
|
||||
resp = client.put(
|
||||
url_for('user.update_user', user_id=fake_uuid),
|
||||
@@ -268,7 +250,7 @@ def test_get_user_by_email(notify_api, notify_db, notify_db_session, sample_serv
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
sample_user = sample_service.users[0]
|
||||
header = create_authorization_header(path=url_for('user.get_by_email'), method='GET')
|
||||
header = create_authorization_header()
|
||||
url = url_for('user.get_by_email', email=sample_user.email_address)
|
||||
resp = client.get(url, headers=[header])
|
||||
assert resp.status_code == 200
|
||||
@@ -292,7 +274,7 @@ def test_get_user_by_email_not_found_returns_404(notify_api,
|
||||
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
header = create_authorization_header(path=url_for('user.get_by_email'), method='GET')
|
||||
header = create_authorization_header()
|
||||
url = url_for('user.get_by_email', email='no_user@digital.gov.uk')
|
||||
resp = client.get(url, headers=[header])
|
||||
assert resp.status_code == 404
|
||||
@@ -308,7 +290,7 @@ def test_get_user_by_email_bad_url_returns_404(notify_api,
|
||||
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
header = create_authorization_header(path=url_for('user.get_by_email'), method='GET')
|
||||
header = create_authorization_header()
|
||||
url = '/user/email'
|
||||
resp = client.get(url, headers=[header])
|
||||
assert resp.status_code == 400
|
||||
@@ -323,9 +305,7 @@ def test_get_user_with_permissions(notify_api,
|
||||
sample_service_permission):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
header = create_authorization_header(
|
||||
path=url_for('user.get_user', user_id=str(sample_service_permission.user.id)),
|
||||
method='GET')
|
||||
header = create_authorization_header()
|
||||
response = client.get(url_for('user.get_user', user_id=str(sample_service_permission.user.id)),
|
||||
headers=[header])
|
||||
assert response.status_code == 200
|
||||
@@ -341,13 +321,7 @@ def test_set_user_permissions(notify_api,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = json.dumps([{'permission': MANAGE_SETTINGS}])
|
||||
header = create_authorization_header(
|
||||
path=url_for(
|
||||
'user.set_permissions',
|
||||
user_id=str(sample_user.id),
|
||||
service_id=str(sample_service.id)),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), header]
|
||||
response = client.post(
|
||||
url_for(
|
||||
@@ -372,13 +346,7 @@ def test_set_user_permissions_multiple(notify_api,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = json.dumps([{'permission': MANAGE_SETTINGS}, {'permission': MANAGE_TEMPLATES}])
|
||||
header = create_authorization_header(
|
||||
path=url_for(
|
||||
'user.set_permissions',
|
||||
user_id=str(sample_user.id),
|
||||
service_id=str(sample_service.id)),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), header]
|
||||
response = client.post(
|
||||
url_for(
|
||||
@@ -407,13 +375,7 @@ def test_set_user_permissions_remove_old(notify_api,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = json.dumps([{'permission': MANAGE_SETTINGS}])
|
||||
header = create_authorization_header(
|
||||
path=url_for(
|
||||
'user.set_permissions',
|
||||
user_id=str(sample_user.id),
|
||||
service_id=str(sample_service.id)),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
header = create_authorization_header()
|
||||
headers = [('Content-Type', 'application/json'), header]
|
||||
response = client.post(
|
||||
url_for(
|
||||
@@ -437,10 +399,7 @@ def test_send_user_reset_password_should_send_reset_password_link(notify_api,
|
||||
with notify_api.test_client() as client:
|
||||
mocker.patch('app.celery.tasks.email_reset_password.apply_async')
|
||||
data = json.dumps({'email': sample_user.email_address})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.send_user_reset_password'),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.send_user_reset_password'),
|
||||
data=data,
|
||||
@@ -457,10 +416,7 @@ def test_send_user_reset_password_should_return_400_when_user_doesnot_exist(noti
|
||||
with notify_api.test_client() as client:
|
||||
bad_email_address = 'bad@email.gov.uk'
|
||||
data = json.dumps({'email': bad_email_address})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.send_user_reset_password'),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
url_for('user.send_user_reset_password'),
|
||||
@@ -476,10 +432,7 @@ def test_send_user_reset_password_should_return_400_when_data_is_not_email_addre
|
||||
with notify_api.test_client() as client:
|
||||
bad_email_address = 'bad.email.gov.uk'
|
||||
data = json.dumps({'email': bad_email_address})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.send_user_reset_password'),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
url_for('user.send_user_reset_password'),
|
||||
|
||||
@@ -32,10 +32,7 @@ def test_user_verify_code_sms(notify_api,
|
||||
data = json.dumps({
|
||||
'code_type': sample_sms_code.code_type,
|
||||
'code': sample_sms_code.txt_code})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.verify_user_code', user_id=sample_sms_code.user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_code', user_id=sample_sms_code.user.id),
|
||||
data=data,
|
||||
@@ -53,10 +50,7 @@ def test_user_verify_code_sms_missing_code(notify_api,
|
||||
with notify_api.test_client() as client:
|
||||
assert not VerifyCode.query.first().code_used
|
||||
data = json.dumps({'code_type': sample_sms_code.code_type})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.verify_user_code', user_id=sample_sms_code.user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_code', user_id=sample_sms_code.user.id),
|
||||
data=data,
|
||||
@@ -78,10 +72,7 @@ def test_user_verify_code_email(notify_api,
|
||||
data = json.dumps({
|
||||
'code_type': sample_email_code.code_type,
|
||||
'code': sample_email_code.txt_code})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.verify_user_code', user_id=sample_email_code.user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_code', user_id=sample_email_code.user.id),
|
||||
data=data,
|
||||
@@ -101,10 +92,7 @@ def test_user_verify_code_email_bad_code(notify_api,
|
||||
data = json.dumps({
|
||||
'code_type': sample_email_code.code_type,
|
||||
'code': "blah"})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.verify_user_code', user_id=sample_email_code.user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_code', user_id=sample_email_code.user.id),
|
||||
data=data,
|
||||
@@ -128,10 +116,7 @@ def test_user_verify_code_email_expired_code(notify_api,
|
||||
data = json.dumps({
|
||||
'code_type': sample_email_code.code_type,
|
||||
'code': sample_email_code.txt_code})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.verify_user_code', user_id=sample_email_code.user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_code', user_id=sample_email_code.user.id),
|
||||
data=data,
|
||||
@@ -151,10 +136,7 @@ def test_user_verify_password(notify_api,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = json.dumps({'password': 'password'})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.verify_user_password', user_id=sample_user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_password', user_id=sample_user.id),
|
||||
data=data,
|
||||
@@ -171,10 +153,7 @@ def test_user_verify_password_invalid_password(notify_api,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = json.dumps({'password': 'bad password'})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.verify_user_password', user_id=sample_user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
assert sample_user.failed_login_count == 0
|
||||
|
||||
@@ -193,10 +172,7 @@ def test_user_verify_password_valid_password_resets_failed_logins(notify_api,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = json.dumps({'password': 'bad password'})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.verify_user_password', user_id=sample_user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
assert sample_user.failed_login_count == 0
|
||||
|
||||
@@ -211,10 +187,7 @@ def test_user_verify_password_valid_password_resets_failed_logins(notify_api,
|
||||
assert sample_user.failed_login_count == 1
|
||||
|
||||
data = json.dumps({'password': 'password'})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.verify_user_password', user_id=sample_user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_password', user_id=sample_user.id),
|
||||
data=data,
|
||||
@@ -232,10 +205,7 @@ def test_user_verify_password_missing_password(notify_api,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = json.dumps({'bingo': 'bongo'})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.verify_user_password', user_id=sample_user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_password', user_id=sample_user.id),
|
||||
data=data,
|
||||
@@ -255,10 +225,7 @@ def test_send_user_sms_code(notify_api,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = json.dumps({})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.send_user_sms_code', user_id=sample_sms_code.user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.send_user_sms_code', user_id=sample_sms_code.user.id),
|
||||
data=data,
|
||||
@@ -278,10 +245,7 @@ def test_send_user_code_for_sms_with_optional_to_field(notify_api,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = json.dumps({'to': '+441119876757'})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.send_user_sms_code', user_id=sample_sms_code.user.id),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.send_user_sms_code', user_id=sample_sms_code.user.id),
|
||||
data=data,
|
||||
@@ -301,10 +265,7 @@ def test_send_sms_code_returns_404_for_bad_input_data(notify_api, notify_db, not
|
||||
data = json.dumps({})
|
||||
import uuid
|
||||
uuid_ = uuid.uuid4()
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.send_user_sms_code', user_id=uuid_),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.send_user_sms_code', user_id=uuid_),
|
||||
data=data,
|
||||
@@ -321,10 +282,7 @@ def test_send_user_email_verification(notify_api,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = json.dumps({})
|
||||
auth_header = create_authorization_header(
|
||||
path=url_for('user.send_user_email_verification', user_id=str(sample_email_code.user.id)),
|
||||
method='POST',
|
||||
request_body=data)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.send_user_email_verification', user_id=str(sample_email_code.user.id)),
|
||||
data=data,
|
||||
|
||||
Reference in New Issue
Block a user