mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
add remove_whitelist tests
This commit is contained in:
@@ -287,7 +287,6 @@ def get_whitelist(service_id):
|
|||||||
|
|
||||||
@service_blueprint.route('/<uuid:service_id>/whitelist', methods=['POST'])
|
@service_blueprint.route('/<uuid:service_id>/whitelist', methods=['POST'])
|
||||||
def update_whitelist(service_id):
|
def update_whitelist(service_id):
|
||||||
# todo: make this transactional
|
|
||||||
dao_remove_service_whitelist(service_id)
|
dao_remove_service_whitelist(service_id)
|
||||||
|
|
||||||
whitelist_objs = [ServiceWhitelist.from_string(service_id, contact) for contact in request.get_json()]
|
whitelist_objs = [ServiceWhitelist.from_string(service_id, contact) for contact in request.get_json()]
|
||||||
|
|||||||
@@ -130,9 +130,11 @@ def sample_service(notify_db,
|
|||||||
user=None,
|
user=None,
|
||||||
restricted=False,
|
restricted=False,
|
||||||
limit=1000,
|
limit=1000,
|
||||||
email_from="sample.service"):
|
email_from=None):
|
||||||
if user is None:
|
if user is None:
|
||||||
user = sample_user(notify_db, notify_db_session)
|
user = sample_user(notify_db, notify_db_session)
|
||||||
|
if email_from is None:
|
||||||
|
email_from = service_name.lower().replace(' ', '.')
|
||||||
data = {
|
data = {
|
||||||
'name': service_name,
|
'name': service_name,
|
||||||
'message_limit': limit,
|
'message_limit': limit,
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ import uuid
|
|||||||
|
|
||||||
from app.models import ServiceWhitelist
|
from app.models import ServiceWhitelist
|
||||||
from app.dao.service_whitelist_dao import (
|
from app.dao.service_whitelist_dao import (
|
||||||
|
|
||||||
dao_fetch_service_whitelist,
|
dao_fetch_service_whitelist,
|
||||||
dao_add_and_commit_whitelisted_contacts,
|
dao_add_and_commit_whitelisted_contacts,
|
||||||
dao_remove_service_whitelist
|
dao_remove_service_whitelist
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from tests.app.conftest import sample_service as create_service
|
||||||
|
|
||||||
|
|
||||||
def test_fetch_service_whitelist_gets_whitelists(sample_service_whitelist):
|
def test_fetch_service_whitelist_gets_whitelists(sample_service_whitelist):
|
||||||
whitelist = dao_fetch_service_whitelist(sample_service_whitelist.service_id)
|
whitelist = dao_fetch_service_whitelist(sample_service_whitelist.service_id)
|
||||||
@@ -21,8 +22,32 @@ def test_fetch_service_whitelist_ignores_other_service(sample_service_whitelist)
|
|||||||
|
|
||||||
def test_add_and_commit_whitelisted_contacts_saves_data(sample_service):
|
def test_add_and_commit_whitelisted_contacts_saves_data(sample_service):
|
||||||
whitelist = ServiceWhitelist.from_string(sample_service.id, 'foo@example.com')
|
whitelist = ServiceWhitelist.from_string(sample_service.id, 'foo@example.com')
|
||||||
|
|
||||||
dao_add_and_commit_whitelisted_contacts([whitelist])
|
dao_add_and_commit_whitelisted_contacts([whitelist])
|
||||||
|
|
||||||
db_contents = ServiceWhitelist.query.all()
|
db_contents = ServiceWhitelist.query.all()
|
||||||
assert len(db_contents) == 1
|
assert len(db_contents) == 1
|
||||||
assert db_contents[0].id == whitelist.id
|
assert db_contents[0].id == whitelist.id
|
||||||
|
|
||||||
|
|
||||||
|
def test_remove_service_whitelist_only_removes_for_my_service(notify_db, notify_db_session):
|
||||||
|
service_1 = create_service(notify_db, notify_db_session, service_name="service 1")
|
||||||
|
service_2 = create_service(notify_db, notify_db_session, service_name="service 2")
|
||||||
|
dao_add_and_commit_whitelisted_contacts([
|
||||||
|
ServiceWhitelist.from_string(service_1.id, 'service1@example.com'),
|
||||||
|
ServiceWhitelist.from_string(service_2.id, 'service2@example.com')
|
||||||
|
])
|
||||||
|
|
||||||
|
dao_remove_service_whitelist(service_1.id)
|
||||||
|
|
||||||
|
assert service_1.whitelist == []
|
||||||
|
assert len(service_2.whitelist) == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_remove_service_whitelist_does_not_commit(notify_db, sample_service_whitelist):
|
||||||
|
dao_remove_service_whitelist(sample_service_whitelist.service_id)
|
||||||
|
|
||||||
|
# since dao_remove_service_whitelist doesn't commit, we can still rollback its changes
|
||||||
|
notify_db.session.rollback()
|
||||||
|
|
||||||
|
assert ServiceWhitelist.query.count() == 1
|
||||||
|
|||||||
Reference in New Issue
Block a user