mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 01:11:38 -05:00
fix non-functional/overengineered existing tests
This commit is contained in:
@@ -11,8 +11,8 @@ from app.dao.services_dao import dao_remove_user_from_service
|
||||
from app.models import User, Organisation
|
||||
from tests import create_authorization_header
|
||||
from tests.app.conftest import (
|
||||
sample_service as create_sample_service,
|
||||
sample_service_permission as create_sample_service_permission,
|
||||
sample_service as create_service,
|
||||
sample_service_permission as create_service_permission,
|
||||
sample_user as create_sample_user,
|
||||
sample_notification as create_sample_notification,
|
||||
sample_notification_with_job)
|
||||
@@ -38,50 +38,41 @@ def test_get_service_list(notify_api, service_factory):
|
||||
assert json_resp['data'][2]['name'] == 'three'
|
||||
|
||||
|
||||
def test_get_service_list_by_user(notify_api, sample_user, service_factory):
|
||||
def test_get_service_list_by_user(notify_db, notify_db_session, client, sample_user, service_factory):
|
||||
other_user = create_sample_user(notify_db, notify_db_session, email='foo@bar.gov.uk')
|
||||
service_factory.get('one', sample_user, email_from='one')
|
||||
service_factory.get('two', sample_user, email_from='two')
|
||||
service_factory.get('three', other_user, email_from='three')
|
||||
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
service_factory.get('one', sample_user, email_from='one')
|
||||
service_factory.get('two', sample_user, email_from='two')
|
||||
service_factory.get('three', sample_user, email_from='three')
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
'/service?user_id='.format(sample_user.id),
|
||||
headers=[auth_header]
|
||||
)
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert response.status_code == 200
|
||||
assert len(json_resp['data']) == 3
|
||||
assert json_resp['data'][0]['name'] == 'one'
|
||||
assert json_resp['data'][1]['name'] == 'two'
|
||||
assert json_resp['data'][2]['name'] == 'three'
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
'/service?user_id={}'.format(sample_user.id),
|
||||
headers=[auth_header]
|
||||
)
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert response.status_code == 200
|
||||
assert len(json_resp['data']) == 2
|
||||
assert json_resp['data'][0]['name'] == 'one'
|
||||
assert json_resp['data'][1]['name'] == 'two'
|
||||
|
||||
|
||||
def test_get_service_list_by_user_should_return_empty_list_if_no_services(notify_api, service_factory, sample_user):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
new_user = User(
|
||||
name='Test User',
|
||||
email_address='new_user@digital.cabinet-office.gov.uk',
|
||||
password='password',
|
||||
mobile_number='+447700900986'
|
||||
)
|
||||
save_model_user(new_user)
|
||||
def test_get_service_list_by_user_should_return_empty_list_if_no_services(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
client,
|
||||
sample_service
|
||||
):
|
||||
# service is already created by sample user
|
||||
new_user = create_sample_user(notify_db, notify_db_session, email='foo@bar.gov.uk')
|
||||
|
||||
service_factory.get('one', sample_user, email_from='one')
|
||||
service_factory.get('two', sample_user, email_from='two')
|
||||
service_factory.get('three', sample_user, email_from='three')
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
'/service?user_id={}'.format(new_user.id),
|
||||
headers=[auth_header]
|
||||
)
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert response.status_code == 200
|
||||
assert len(json_resp['data']) == 0
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get(
|
||||
'/service?user_id={}'.format(new_user.id),
|
||||
headers=[auth_header]
|
||||
)
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert response.status_code == 200
|
||||
assert len(json_resp['data']) == 0
|
||||
|
||||
|
||||
def test_get_service_list_should_return_empty_list_if_no_services(notify_api, notify_db, notify_db_session):
|
||||
@@ -445,7 +436,7 @@ def test_should_not_update_service_with_duplicate_name(notify_api,
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
service_name = "another name"
|
||||
service = create_sample_service(
|
||||
service = create_service(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
service_name=service_name,
|
||||
@@ -478,7 +469,7 @@ def test_should_not_update_service_with_duplicate_email_from(notify_api,
|
||||
with notify_api.test_client() as client:
|
||||
email_from = "duplicate.name"
|
||||
service_name = "duplicate name"
|
||||
service = create_sample_service(
|
||||
service = create_service(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
service_name=service_name,
|
||||
@@ -914,7 +905,7 @@ def test_remove_user_from_service(notify_api, notify_db, notify_db_session, samp
|
||||
notify_db_session,
|
||||
email="new@digital.cabinet-office.gov.uk")
|
||||
# Simulates successfully adding a user to the service
|
||||
second_permission = create_sample_service_permission(
|
||||
second_permission = create_service_permission(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
user=second_user)
|
||||
@@ -1018,8 +1009,8 @@ def test_set_reply_to_email_for_service(notify_api, sample_service):
|
||||
|
||||
def test_get_all_notifications_for_service_in_order(notify_api, notify_db, notify_db_session):
|
||||
with notify_api.test_request_context(), notify_api.test_client() as client:
|
||||
service_1 = create_sample_service(notify_db, notify_db_session, service_name="1", email_from='1')
|
||||
service_2 = create_sample_service(notify_db, notify_db_session, service_name="2", email_from='2')
|
||||
service_1 = create_service(notify_db, notify_db_session, service_name="1", email_from='1')
|
||||
service_2 = create_service(notify_db, notify_db_session, service_name="2", email_from='2')
|
||||
|
||||
create_sample_notification(notify_db, notify_db_session, service=service_2)
|
||||
|
||||
@@ -1239,8 +1230,8 @@ def test_get_services_with_detailed_flag(notify_api, notify_db, notify_db_sessio
|
||||
def test_get_detailed_services_groups_by_service(notify_db, notify_db_session):
|
||||
from app.service.rest import get_detailed_services
|
||||
|
||||
service_1 = create_sample_service(notify_db, notify_db_session, service_name="1", email_from='1')
|
||||
service_2 = create_sample_service(notify_db, notify_db_session, service_name="2", email_from='2')
|
||||
service_1 = create_service(notify_db, notify_db_session, service_name="1", email_from='1')
|
||||
service_2 = create_service(notify_db, notify_db_session, service_name="2", email_from='2')
|
||||
|
||||
create_sample_notification(notify_db, notify_db_session, service=service_1, status='created')
|
||||
create_sample_notification(notify_db, notify_db_session, service=service_2, status='created')
|
||||
@@ -1266,8 +1257,8 @@ def test_get_detailed_services_groups_by_service(notify_db, notify_db_session):
|
||||
def test_get_detailed_services_includes_services_with_no_notifications(notify_db, notify_db_session):
|
||||
from app.service.rest import get_detailed_services
|
||||
|
||||
service_1 = create_sample_service(notify_db, notify_db_session, service_name="1", email_from='1')
|
||||
service_2 = create_sample_service(notify_db, notify_db_session, service_name="2", email_from='2')
|
||||
service_1 = create_service(notify_db, notify_db_session, service_name="1", email_from='1')
|
||||
service_2 = create_service(notify_db, notify_db_session, service_name="2", email_from='2')
|
||||
|
||||
create_sample_notification(notify_db, notify_db_session, service=service_1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user