mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Added user_id as a query param for get_services.
Need to add this query param for the services page on the admin app. Do not add the query param to path in the token.
This commit is contained in:
@@ -2,6 +2,7 @@ import pytest
|
||||
from app.dao.services_dao import (
|
||||
save_model_service, get_model_services, DAOException, delete_model_service)
|
||||
from tests.app.conftest import sample_service as create_sample_service
|
||||
from tests.app.conftest import sample_user as create_sample_user
|
||||
from app.models import Service
|
||||
|
||||
|
||||
@@ -47,6 +48,23 @@ def test_get_user_service(notify_api, notify_db, notify_db_session, sample_user)
|
||||
assert Service.query.count() == 1
|
||||
|
||||
|
||||
def test_get_services_for_user(notify_api, notify_db, notify_db_session, sample_service):
|
||||
assert Service.query.count() == 1
|
||||
service_name = "Random service"
|
||||
second_user = create_sample_user(notify_db, notify_db_session, 'an@other.gov.uk')
|
||||
create_sample_service(notify_db, notify_db_session, service_name='another service', user=second_user)
|
||||
|
||||
sample_service = create_sample_service(notify_db,
|
||||
notify_db_session,
|
||||
service_name=service_name,
|
||||
user=sample_service.users[0])
|
||||
assert Service.query.count() == 3
|
||||
services = get_model_services(user_id=sample_service.users[0].id)
|
||||
assert len(services) == 2
|
||||
assert service_name in [x.name for x in services]
|
||||
assert 'Sample service' in [x.name for x in services]
|
||||
|
||||
|
||||
def test_missing_user_attribute(notify_api, notify_db, notify_db_session):
|
||||
assert Service.query.count() == 0
|
||||
try:
|
||||
|
||||
@@ -6,6 +6,7 @@ from app.dao.services_dao import save_model_service
|
||||
from app.models import (Service, ApiKey, Template)
|
||||
from tests import create_authorization_header
|
||||
from tests.app.conftest import sample_user as create_sample_user
|
||||
from tests.app.conftest import sample_service as create_sample_service
|
||||
|
||||
|
||||
def test_get_service_list(notify_api, notify_db, notify_db_session, sample_service, sample_admin_service_id):
|
||||
@@ -45,6 +46,26 @@ def test_get_service(notify_api, notify_db, notify_db_session, sample_service, s
|
||||
assert json_resp['data']['id'] == sample_service.id
|
||||
|
||||
|
||||
def test_get_service_for_user(notify_api, notify_db, notify_db_session, sample_service):
|
||||
second_user = create_sample_user(notify_db, notify_db_session, 'an@other.gov.uk')
|
||||
create_sample_service(notify_db, notify_db_session, service_name='Second Service', user=second_user)
|
||||
create_sample_service(notify_db, notify_db_session, service_name='Another Service', user=sample_service.users[0])
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(
|
||||
path='/service',
|
||||
method='GET')
|
||||
resp = client.get('/service?user_id={}'.format(sample_service.users[0].id),
|
||||
headers=[auth_header])
|
||||
assert resp.status_code == 200
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
assert len(json_resp['data']) == 2
|
||||
print(x for x in json_resp['data'])
|
||||
assert 'Another Service' in [x.get('name') for x in json_resp['data']]
|
||||
assert 'Sample service' in [x.get('name') for x in json_resp['data']]
|
||||
assert 'Second Service' not in [x.get('name') for x in json_resp['data']]
|
||||
|
||||
|
||||
def test_post_service(notify_api, notify_db, notify_db_session, sample_user, sample_admin_service_id):
|
||||
"""
|
||||
Tests POST endpoint '/' to create a service.
|
||||
|
||||
Reference in New Issue
Block a user