mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-22 08:21:13 -05:00
Only return non-archived letter contact blocks
Changed DAO functions which return one letter contact block and all letter contact blocks for a service to only return non-archived ones.
This commit is contained in:
@@ -10,7 +10,8 @@ def dao_get_letter_contacts_by_service_id(service_id):
|
|||||||
letter_contacts = db.session.query(
|
letter_contacts = db.session.query(
|
||||||
ServiceLetterContact
|
ServiceLetterContact
|
||||||
).filter(
|
).filter(
|
||||||
ServiceLetterContact.service_id == service_id
|
ServiceLetterContact.service_id == service_id,
|
||||||
|
ServiceLetterContact.archived == False # noqa
|
||||||
).order_by(
|
).order_by(
|
||||||
desc(ServiceLetterContact.is_default),
|
desc(ServiceLetterContact.is_default),
|
||||||
desc(ServiceLetterContact.created_at)
|
desc(ServiceLetterContact.created_at)
|
||||||
@@ -24,7 +25,8 @@ def dao_get_letter_contact_by_id(service_id, letter_contact_id):
|
|||||||
ServiceLetterContact
|
ServiceLetterContact
|
||||||
).filter(
|
).filter(
|
||||||
ServiceLetterContact.service_id == service_id,
|
ServiceLetterContact.service_id == service_id,
|
||||||
ServiceLetterContact.id == letter_contact_id
|
ServiceLetterContact.id == letter_contact_id,
|
||||||
|
ServiceLetterContact.archived == False # noqa
|
||||||
).one()
|
).one()
|
||||||
return letter_contact
|
return letter_contact
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,23 @@ def test_dao_get_letter_contacts_by_service_id(notify_db_session):
|
|||||||
assert second_letter_contact == results[2]
|
assert second_letter_contact == results[2]
|
||||||
|
|
||||||
|
|
||||||
|
def test_dao_get_letter_contacts_by_service_id_does_not_return_archived_contacts(notify_db_session):
|
||||||
|
service = create_service()
|
||||||
|
create_letter_contact(service=service, contact_block='Edinburgh, ED1 1AA')
|
||||||
|
create_letter_contact(service=service, contact_block='Cardiff, CA1 2DB', is_default=False)
|
||||||
|
archived_contact = create_letter_contact(
|
||||||
|
service=service,
|
||||||
|
contact_block='London, E1 8QS',
|
||||||
|
is_default=False,
|
||||||
|
archived=True
|
||||||
|
)
|
||||||
|
|
||||||
|
results = dao_get_letter_contacts_by_service_id(service_id=service.id)
|
||||||
|
|
||||||
|
assert len(results) == 2
|
||||||
|
assert archived_contact not in results
|
||||||
|
|
||||||
|
|
||||||
def test_add_letter_contact_for_service_creates_additional_letter_contact_for_service(notify_db_session):
|
def test_add_letter_contact_for_service_creates_additional_letter_contact_for_service(notify_db_session):
|
||||||
service = create_service()
|
service = create_service()
|
||||||
|
|
||||||
@@ -164,6 +181,15 @@ def test_dao_get_letter_contact_by_id_raises_sqlalchemy_error_when_letter_contac
|
|||||||
dao_get_letter_contact_by_id(service_id=sample_service.id, letter_contact_id=uuid.uuid4())
|
dao_get_letter_contact_by_id(service_id=sample_service.id, letter_contact_id=uuid.uuid4())
|
||||||
|
|
||||||
|
|
||||||
|
def test_dao_get_letter_contact_by_id_raises_sqlalchemy_error_when_letter_contact_is_archived(sample_service):
|
||||||
|
archived_contact = create_letter_contact(
|
||||||
|
service=sample_service,
|
||||||
|
contact_block='Aberdeen, AB12 23X',
|
||||||
|
archived=True)
|
||||||
|
with pytest.raises(SQLAlchemyError):
|
||||||
|
dao_get_letter_contact_by_id(service_id=sample_service.id, letter_contact_id=archived_contact.id)
|
||||||
|
|
||||||
|
|
||||||
def test_dao_get_letter_contact_by_id_raises_sqlalchemy_error_when_service_does_not_exist(sample_service):
|
def test_dao_get_letter_contact_by_id_raises_sqlalchemy_error_when_service_does_not_exist(sample_service):
|
||||||
letter_contact = create_letter_contact(service=sample_service, contact_block='Some address')
|
letter_contact = create_letter_contact(service=sample_service, contact_block='Some address')
|
||||||
with pytest.raises(SQLAlchemyError):
|
with pytest.raises(SQLAlchemyError):
|
||||||
|
|||||||
@@ -440,12 +440,14 @@ def create_service_sms_sender(
|
|||||||
def create_letter_contact(
|
def create_letter_contact(
|
||||||
service,
|
service,
|
||||||
contact_block,
|
contact_block,
|
||||||
is_default=True
|
is_default=True,
|
||||||
|
archived=False
|
||||||
):
|
):
|
||||||
data = {
|
data = {
|
||||||
'service': service,
|
'service': service,
|
||||||
'contact_block': contact_block,
|
'contact_block': contact_block,
|
||||||
'is_default': is_default,
|
'is_default': is_default,
|
||||||
|
'archived': archived,
|
||||||
}
|
}
|
||||||
letter_content = ServiceLetterContact(**data)
|
letter_content = ServiceLetterContact(**data)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user