mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-27 10:51:40 -05:00
Removed the tests for trial mode service for the scheduled tasks and the process job. Having the validation in the POST notification and create job endpoint is enough. Updated the test_service_whitelist test because the order of the array is not gaurenteed.
96 lines
3.5 KiB
Python
96 lines
3.5 KiB
Python
import uuid
|
|
import json
|
|
|
|
from tests import create_authorization_header
|
|
|
|
from app.models import (
|
|
ServiceWhitelist,
|
|
MOBILE_TYPE, EMAIL_TYPE)
|
|
|
|
from app.dao.service_whitelist_dao import dao_add_and_commit_whitelisted_contacts
|
|
|
|
|
|
def test_get_whitelist_returns_data(client, sample_service_whitelist):
|
|
service_id = sample_service_whitelist.service_id
|
|
|
|
response = client.get('service/{}/whitelist'.format(service_id), headers=[create_authorization_header()])
|
|
assert response.status_code == 200
|
|
assert json.loads(response.get_data(as_text=True)) == {
|
|
'email_addresses': [sample_service_whitelist.recipient],
|
|
'phone_numbers': []
|
|
}
|
|
|
|
|
|
def test_get_whitelist_separates_emails_and_phones(client, sample_service):
|
|
dao_add_and_commit_whitelisted_contacts([
|
|
ServiceWhitelist.from_string(sample_service.id, EMAIL_TYPE, 'service@example.com'),
|
|
ServiceWhitelist.from_string(sample_service.id, MOBILE_TYPE, '07123456789'),
|
|
ServiceWhitelist.from_string(sample_service.id, MOBILE_TYPE, '+1800-555-555'),
|
|
])
|
|
|
|
response = client.get('service/{}/whitelist'.format(sample_service.id), headers=[create_authorization_header()])
|
|
assert response.status_code == 200
|
|
json_resp = json.loads(response.get_data(as_text=True))
|
|
assert json_resp['email_addresses'] == ['service@example.com']
|
|
assert sorted(json_resp['phone_numbers']) == sorted(['+1800-555-555', '07123456789'])
|
|
|
|
|
|
def test_get_whitelist_404s_with_unknown_service_id(client):
|
|
path = 'service/{}/whitelist'.format(uuid.uuid4())
|
|
|
|
response = client.get(path, headers=[create_authorization_header()])
|
|
assert response.status_code == 404
|
|
json_resp = json.loads(response.get_data(as_text=True))
|
|
assert json_resp['result'] == 'error'
|
|
assert json_resp['message'] == 'No result found'
|
|
|
|
|
|
def test_get_whitelist_returns_no_data(client, sample_service):
|
|
path = 'service/{}/whitelist'.format(sample_service.id)
|
|
|
|
response = client.get(path, headers=[create_authorization_header()])
|
|
|
|
assert response.status_code == 200
|
|
assert json.loads(response.get_data(as_text=True)) == {'email_addresses': [], 'phone_numbers': []}
|
|
|
|
|
|
def test_update_whitelist_replaces_old_whitelist(client, sample_service_whitelist):
|
|
data = {
|
|
'email_addresses': ['foo@bar.com'],
|
|
'phone_numbers': ['07123456789']
|
|
}
|
|
|
|
response = client.put(
|
|
'service/{}/whitelist'.format(sample_service_whitelist.service_id),
|
|
data=json.dumps(data),
|
|
headers=[('Content-Type', 'application/json'), create_authorization_header()]
|
|
)
|
|
|
|
assert response.status_code == 204
|
|
whitelist = ServiceWhitelist.query.order_by(ServiceWhitelist.recipient).all()
|
|
assert len(whitelist) == 2
|
|
assert whitelist[0].recipient == '07123456789'
|
|
assert whitelist[1].recipient == 'foo@bar.com'
|
|
|
|
|
|
def test_update_whitelist_doesnt_remove_old_whitelist_if_error(client, sample_service_whitelist):
|
|
|
|
data = {
|
|
'email_addresses': [''],
|
|
'phone_numbers': ['07123456789']
|
|
}
|
|
|
|
response = client.put(
|
|
'service/{}/whitelist'.format(sample_service_whitelist.service_id),
|
|
data=json.dumps(data),
|
|
headers=[('Content-Type', 'application/json'), create_authorization_header()]
|
|
)
|
|
|
|
assert response.status_code == 400
|
|
assert json.loads(response.get_data(as_text=True)) == {
|
|
'result': 'error',
|
|
'message': 'Invalid whitelist: "" is not a valid email address or phone number'
|
|
}
|
|
whitelist = ServiceWhitelist.query.one()
|
|
assert whitelist.id == sample_service_whitelist.id
|