mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Let services have no default letter contact blocks
If they delete the default we’ll treat ‘Blank’ as the default on the frontend.
This commit is contained in:
@@ -9,8 +9,6 @@ from app.dao.service_letter_contact_dao import (
|
||||
dao_get_letter_contact_by_id,
|
||||
update_letter_contact
|
||||
)
|
||||
from app.errors import InvalidRequest
|
||||
from app.exceptions import ArchiveValidationError
|
||||
from app.models import ServiceLetterContact
|
||||
from tests.app.db import create_letter_contact, create_service, create_template
|
||||
|
||||
@@ -99,14 +97,14 @@ def test_add_letter_contact_does_not_override_default(notify_db_session):
|
||||
assert not results[1].is_default
|
||||
|
||||
|
||||
def test_add_letter_contact_with_no_default_raises_exception(notify_db_session):
|
||||
def test_add_letter_contact_with_no_default_is_fine(notify_db_session):
|
||||
service = create_service()
|
||||
with pytest.raises(expected_exception=InvalidRequest):
|
||||
add_letter_contact_for_service(
|
||||
service_id=service.id,
|
||||
contact_block='Swansea, SN1 3CC',
|
||||
is_default=False
|
||||
)
|
||||
letter_contact = add_letter_contact_for_service(
|
||||
service_id=service.id,
|
||||
contact_block='Swansea, SN1 3CC',
|
||||
is_default=False
|
||||
)
|
||||
assert service.letter_contacts == [letter_contact]
|
||||
|
||||
|
||||
def test_add_letter_contact_when_multiple_defaults_exist_raises_exception(notify_db_session):
|
||||
@@ -159,17 +157,16 @@ def test_update_letter_contact_as_default_overides_existing_default(notify_db_se
|
||||
assert not results[1].is_default
|
||||
|
||||
|
||||
def test_update_letter_contact_unset_default_for_only_letter_contact_raises_exception(notify_db_session):
|
||||
def test_update_letter_contact_unset_default_for_only_letter_contact_is_fine(notify_db_session):
|
||||
service = create_service()
|
||||
only_letter_contact = create_letter_contact(service=service, contact_block='Aberdeen, AB12 23X')
|
||||
|
||||
with pytest.raises(expected_exception=InvalidRequest):
|
||||
update_letter_contact(
|
||||
service_id=service.id,
|
||||
letter_contact_id=only_letter_contact.id,
|
||||
contact_block='Warwick, W14 TSR',
|
||||
is_default=False
|
||||
)
|
||||
update_letter_contact(
|
||||
service_id=service.id,
|
||||
letter_contact_id=only_letter_contact.id,
|
||||
contact_block='Warwick, W14 TSR',
|
||||
is_default=False
|
||||
)
|
||||
assert only_letter_contact.is_default is False
|
||||
|
||||
|
||||
def test_archive_letter_contact(notify_db_session):
|
||||
@@ -199,14 +196,11 @@ def test_archive_letter_contact_does_not_archive_a_letter_contact_for_a_differen
|
||||
assert not letter_contact.archived
|
||||
|
||||
|
||||
def test_archive_letter_contact_does_not_archive_a_service_default_letter_contact(notify_db_session):
|
||||
def test_archive_letter_contact_can_archive_a_service_default_letter_contact(notify_db_session):
|
||||
service = create_service()
|
||||
letter_contact = create_letter_contact(service=service, contact_block='Edinburgh, ED1 1AA')
|
||||
|
||||
with pytest.raises(ArchiveValidationError) as e:
|
||||
archive_letter_contact(service.id, letter_contact.id)
|
||||
|
||||
assert 'You cannot delete a default letter contact block' in str(e.value)
|
||||
archive_letter_contact(service.id, letter_contact.id)
|
||||
assert letter_contact.archived is True
|
||||
|
||||
|
||||
def test_archive_letter_contact_does_dissociates_template_defaults_before_archiving(notify_db_session):
|
||||
|
||||
@@ -2829,14 +2829,12 @@ def test_add_service_letter_contact_can_add_multiple_addresses(client, sample_se
|
||||
assert first_letter_contact_not_default[0].contact_block == 'London, E1 8QS'
|
||||
|
||||
|
||||
def test_add_service_letter_contact_block_raise_exception_if_no_default(client, sample_service):
|
||||
def test_add_service_letter_contact_block_fine_if_no_default(client, sample_service):
|
||||
data = json.dumps({"contact_block": "London, E1 8QS", "is_default": False})
|
||||
response = client.post('/service/{}/letter-contact'.format(sample_service.id),
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
assert response.status_code == 400
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert json_resp['message'] == 'You must have at least one letter contact as the default.'
|
||||
assert response.status_code == 201
|
||||
|
||||
|
||||
def test_add_service_letter_contact_block_404s_when_invalid_service_id(client, notify_db, notify_db_session):
|
||||
@@ -2864,16 +2862,13 @@ def test_update_service_letter_contact(client, sample_service):
|
||||
assert json_resp['data'] == results[0].serialize()
|
||||
|
||||
|
||||
def test_update_service_letter_contact_returns_400_when_no_default(client, sample_service):
|
||||
def test_update_service_letter_contact_returns_200_when_no_default(client, sample_service):
|
||||
original_reply_to = create_letter_contact(service=sample_service, contact_block="Aberdeen, AB23 1XH")
|
||||
data = json.dumps({"contact_block": "London, E1 8QS", "is_default": False})
|
||||
response = client.post('/service/{}/letter-contact/{}'.format(sample_service.id, original_reply_to.id),
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
|
||||
assert response.status_code == 400
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert json_resp['message'] == 'You must have at least one letter contact as the default.'
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_update_service_letter_contact_returns_404_when_invalid_service_id(client, notify_db, notify_db_session):
|
||||
|
||||
Reference in New Issue
Block a user