Add DAO function and endpoint for archiving email reply_to addresses

Added a new DAO function which archives email reply_to addresses by
setting archived to True. This raises a new type of error, an
ArchiveValidationError, if trying to archive a default reply_to address.

Added a new endpoint for archiving email reply_to addresses.
This commit is contained in:
Katie Smith
2018-04-25 16:34:36 +01:00
parent 663021e494
commit 5f43fe23a7
6 changed files with 111 additions and 1 deletions

View File

@@ -4,9 +4,13 @@ import pytest
from sqlalchemy.exc import SQLAlchemyError
from app.dao.service_email_reply_to_dao import (
add_reply_to_email_address_for_service,
archive_reply_to_email_address,
dao_get_reply_to_by_id,
dao_get_reply_to_by_service_id,
add_reply_to_email_address_for_service, update_reply_to_email_address, dao_get_reply_to_by_id)
update_reply_to_email_address)
from app.errors import InvalidRequest
from app.exceptions import ArchiveValidationError
from app.models import ServiceEmailReplyTo
from tests.app.db import create_reply_to_email, create_service
@@ -196,3 +200,40 @@ def test_dao_get_reply_to_by_id_raises_sqlalchemy_error_when_service_does_not_ex
reply_to = create_reply_to_email(service=sample_service, email_address='email@address.com')
with pytest.raises(SQLAlchemyError):
dao_get_reply_to_by_id(service_id=uuid.uuid4(), reply_to_id=reply_to.id)
def test_archive_reply_to_email_address(sample_service):
create_reply_to_email(service=sample_service, email_address="first@address.com")
second_reply_to = create_reply_to_email(
service=sample_service,
email_address="second@address.com",
is_default=False)
archive_reply_to_email_address(sample_service.id, second_reply_to.id)
assert second_reply_to.archived is True
assert second_reply_to.updated_at is not None
def test_archive_reply_to_email_address_does_not_archive_a_reply_to_for_a_different_service(sample_service):
service = create_service(service_name="First service")
reply_to = create_reply_to_email(service=sample_service, email_address="first@address.com", is_default=False)
with pytest.raises(SQLAlchemyError):
archive_reply_to_email_address(service.id, reply_to.id)
assert not reply_to.archived
def test_archive_reply_to_email_address_raises_an_error_if_attempting_to_archive_a_default(sample_service):
create_reply_to_email(
service=sample_service,
email_address="first@address.com",
is_default=False)
default_reply_to = create_reply_to_email(service=sample_service, email_address="first@address.com")
with pytest.raises(ArchiveValidationError) as e:
archive_reply_to_email_address(sample_service.id, default_reply_to.id)
assert 'You cannot delete a default email reply to address' in str(e.value)
assert not default_reply_to.archived

View File

@@ -2525,6 +2525,40 @@ def test_update_service_reply_to_email_address_404s_when_invalid_service_id(clie
assert result['message'] == 'No result found'
def test_delete_service_reply_to_email_address_archives_an_email_reply_to(
sample_service,
admin_request,
notify_db_session
):
create_reply_to_email(service=sample_service, email_address="some@email.com")
reply_to = create_reply_to_email(service=sample_service, email_address="some@email.com", is_default=False)
admin_request.post(
'service.delete_service_reply_to_email_address',
service_id=sample_service.id,
reply_to_email_id=reply_to.id,
)
assert reply_to.archived is True
def test_delete_service_reply_to_email_address_returns_400_if_archiving_default_reply_to(
admin_request,
notify_db_session,
sample_service
):
reply_to = create_reply_to_email(service=sample_service, email_address="some@email.com")
response = admin_request.post(
'service.delete_service_reply_to_email_address',
service_id=sample_service.id,
reply_to_email_id=reply_to.id,
_expected_status=400
)
assert response == {'message': 'You cannot delete a default email reply to address', 'result': 'error'}
assert reply_to.archived is False
def test_get_email_reply_to_address(client, notify_db, notify_db_session):
service = create_service()
reply_to = create_reply_to_email(service, 'test_a@mail.com')