mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 14:31:57 -05:00
correct service_whitelist dao/rest functionality
additionally added dao tests
This commit is contained in:
@@ -19,6 +19,7 @@ from app.models import (
|
||||
ProviderStatistics,
|
||||
ProviderDetails,
|
||||
NotificationStatistics,
|
||||
ServiceWhitelist,
|
||||
KEY_TYPE_NORMAL, KEY_TYPE_TEST, KEY_TYPE_TEAM)
|
||||
from app.dao.users_dao import (save_model_user, create_user_code, create_secret_code)
|
||||
from app.dao.services_dao import (dao_create_service, dao_add_user_to_service)
|
||||
@@ -862,3 +863,18 @@ def already_registered_template(notify_db,
|
||||
template = Template(**data)
|
||||
db.session.add(template)
|
||||
return template
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def sample_service_whitelist(notify_db, notify_db_session, service=None, email_address=None, mobile_number=None):
|
||||
if service is None:
|
||||
service = sample_service(notify_db, notify_db_session)
|
||||
|
||||
if not email_address and not mobile_number:
|
||||
email_address = 'whitelisted_user@digital.gov.uk'
|
||||
|
||||
whitelisted_user = ServiceWhitelist.from_string(service.id, email_address or mobile_number)
|
||||
|
||||
notify_db.session.add(whitelisted_user)
|
||||
notify_db.session.commit()
|
||||
return whitelisted_user
|
||||
|
||||
25
tests/app/dao/test_service_whitelist_dao.py
Normal file
25
tests/app/dao/test_service_whitelist_dao.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import uuid
|
||||
|
||||
from app.models import ServiceWhitelist
|
||||
from app.dao.service_whitelist_dao import (#
|
||||
dao_fetch_service_whitelist,
|
||||
dao_add_and_commit_whitelisted_contacts,
|
||||
dao_remove_service_whitelist
|
||||
)
|
||||
|
||||
|
||||
def test_fetch_service_whitelist_gets_whitelists(sample_service_whitelist):
|
||||
whitelist = dao_fetch_service_whitelist(sample_service_whitelist.service_id)
|
||||
assert len(whitelist) == 1
|
||||
assert whitelist[0].id == sample_service_whitelist.id
|
||||
|
||||
def test_fetch_service_whitelist_ignores_other_service(sample_service_whitelist):
|
||||
assert len(dao_fetch_service_whitelist(uuid.uuid4())) == 0
|
||||
|
||||
def test_add_and_commit_whitelisted_contacts_saves_data(sample_service):
|
||||
whitelist = ServiceWhitelist.from_string(sample_service.id, 'foo@example.com')
|
||||
dao_add_and_commit_whitelisted_contacts([whitelist])
|
||||
|
||||
db_contents = ServiceWhitelist.query.all()
|
||||
assert len(db_contents) == 1
|
||||
assert db_contents[0].id == whitelist.id
|
||||
Reference in New Issue
Block a user