mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
[WIP] added dao and rest endpoint for retrieving invited users
by service and by id.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import uuid
|
||||
|
||||
from tests import create_authorization_header
|
||||
|
||||
@@ -68,3 +69,107 @@ def test_create_invited_user_invalid_email(notify_api, sample_service):
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert json_resp['result'] == 'error'
|
||||
assert json_resp['message'] == {'email_address': ['Invalid email']}
|
||||
|
||||
|
||||
def test_get_all_invited_users_by_service(notify_api, notify_db, notify_db_session, sample_service):
|
||||
|
||||
from tests.app.conftest import sample_invited_user
|
||||
invites = []
|
||||
for i in range(0, 5):
|
||||
email = 'invited_user_{}@service.gov.uk'.format(i)
|
||||
|
||||
invited_user = sample_invited_user(notify_db,
|
||||
notify_db_session,
|
||||
sample_service,
|
||||
email)
|
||||
invites.append(invited_user)
|
||||
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
url = '/service/{}/invite'.format(sample_service.id)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path=url,
|
||||
method='GET'
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
url,
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
)
|
||||
assert response.status_code == 200
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
|
||||
invite_from = sample_service.users[0]
|
||||
|
||||
for invite in json_resp['data']:
|
||||
assert invite['service'] == str(sample_service.id)
|
||||
assert invite['from_user'] == invite_from.id
|
||||
assert invite['id']
|
||||
|
||||
|
||||
def test_get_invited_users_by_service_with_no_invites(notify_api, notify_db, notify_db_session, sample_service):
|
||||
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
url = '/service/{}/invite'.format(sample_service.id)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path=url,
|
||||
method='GET'
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
url,
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
)
|
||||
assert response.status_code == 200
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert len(json_resp['data']) == 0
|
||||
|
||||
|
||||
def test_get_invited_user_by_service_and_id(notify_api, sample_service, sample_invited_user):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
url = '/service/{}/invite/{}'.format(sample_service.id, sample_invited_user.id)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path=url,
|
||||
method='GET'
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
url,
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
)
|
||||
assert response.status_code == 200
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
|
||||
invite_email_address = sample_invited_user.email_address
|
||||
invite_from = sample_service.users[0]
|
||||
|
||||
assert json_resp['data']['service'] == str(sample_service.id)
|
||||
assert json_resp['data']['email_address'] == invite_email_address
|
||||
assert json_resp['data']['from_user'] == invite_from.id
|
||||
assert json_resp['data']['id']
|
||||
|
||||
|
||||
def test_get_invited_user_by_service_but_unknown_invite_id_returns_404(notify_api, sample_service):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
unknown_id = uuid.uuid4()
|
||||
url = '/service/{}/invite/{}'.format(sample_service.id, unknown_id)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path=url,
|
||||
method='GET'
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
url,
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
||||
Reference in New Issue
Block a user