mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Merge branch 'master' into select-inbound-number-to-assign
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from app.dao.service_email_reply_to_dao import (
|
||||
create_or_update_email_reply_to,
|
||||
dao_get_reply_to_by_service_id,
|
||||
add_reply_to_email_address_for_service, update_reply_to_email_address)
|
||||
add_reply_to_email_address_for_service, update_reply_to_email_address, dao_get_reply_to_by_id)
|
||||
from app.errors import InvalidRequest
|
||||
from app.models import ServiceEmailReplyTo
|
||||
from tests.app.db import create_reply_to_email, create_service
|
||||
@@ -58,13 +61,15 @@ def test_create_or_update_email_reply_to_raises_exception_if_multilple_email_add
|
||||
def test_dao_get_reply_to_by_service_id(notify_db_session):
|
||||
service = create_service()
|
||||
default_reply_to = create_reply_to_email(service=service, email_address='something@email.com')
|
||||
second_reply_to = create_reply_to_email(service=service, email_address='second@email.com', is_default=False)
|
||||
another_reply_to = create_reply_to_email(service=service, email_address='another@email.com', is_default=False)
|
||||
|
||||
results = dao_get_reply_to_by_service_id(service_id=service.id)
|
||||
|
||||
assert len(results) == 2
|
||||
assert default_reply_to in results
|
||||
assert another_reply_to in results
|
||||
assert len(results) == 3
|
||||
assert default_reply_to == results[0]
|
||||
assert another_reply_to == results[1]
|
||||
assert second_reply_to == results[2]
|
||||
|
||||
|
||||
def test_add_reply_to_email_address_for_service_creates_first_email_for_service(notify_db_session):
|
||||
@@ -191,3 +196,20 @@ def test_update_reply_to_email_address_raises_exception_if_single_reply_to_and_s
|
||||
reply_to_id=first_reply_to.id,
|
||||
email_address='should@fail.com',
|
||||
is_default=False)
|
||||
|
||||
|
||||
def test_dao_get_reply_to_by_id(sample_service):
|
||||
reply_to = create_reply_to_email(service=sample_service, email_address='email@address.com')
|
||||
result = dao_get_reply_to_by_id(service_id=sample_service.id, reply_to_id=reply_to.id)
|
||||
assert result == reply_to
|
||||
|
||||
|
||||
def test_dao_get_reply_to_by_id_raises_sqlalchemy_error_when_reply_to_does_not_exist(sample_service):
|
||||
with pytest.raises(SQLAlchemyError):
|
||||
dao_get_reply_to_by_id(service_id=sample_service.id, reply_to_id=uuid.uuid4())
|
||||
|
||||
|
||||
def test_dao_get_reply_to_by_id_raises_sqlalchemy_error_when_service_does_not_exist(sample_service):
|
||||
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)
|
||||
|
||||
@@ -26,7 +26,8 @@ from app.models import (
|
||||
INBOUND_SMS_TYPE,
|
||||
KEY_TYPE_NORMAL,
|
||||
ServiceInboundApi,
|
||||
ServiceEmailReplyTo
|
||||
ServiceEmailReplyTo,
|
||||
ServiceLetterContact
|
||||
)
|
||||
from app.dao.users_dao import save_model_user
|
||||
from app.dao.notifications_dao import dao_create_notification, dao_created_scheduled_notification
|
||||
@@ -347,3 +348,21 @@ def create_reply_to_email(
|
||||
db.session.commit()
|
||||
|
||||
return reply_to
|
||||
|
||||
|
||||
def create_letter_contact(
|
||||
service,
|
||||
contact_block,
|
||||
is_default=True
|
||||
):
|
||||
data = {
|
||||
'service': service,
|
||||
'contact_block': contact_block,
|
||||
'is_default': is_default,
|
||||
}
|
||||
letter_content = ServiceLetterContact(**data)
|
||||
|
||||
db.session.add(letter_content)
|
||||
db.session.commit()
|
||||
|
||||
return letter_content
|
||||
|
||||
@@ -2290,3 +2290,14 @@ def test_update_service_reply_to_email_address_404s_when_invalid_service_id(clie
|
||||
result = json.loads(response.get_data(as_text=True))
|
||||
assert result['result'] == 'error'
|
||||
assert result['message'] == 'No result found'
|
||||
|
||||
|
||||
def test_get_email_reply_to_address(client, notify_db, notify_db_session):
|
||||
service = create_service(notify_db=notify_db, notify_db_session=notify_db_session)
|
||||
reply_to = create_reply_to_email(service, 'test_a@mail.com')
|
||||
|
||||
response = client.get('/service/{}/email-reply-to/{}'.format(service.id, reply_to.id),
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
|
||||
assert response.status_code == 200
|
||||
assert json.loads(response.get_data(as_text=True)) == reply_to.serialize()
|
||||
|
||||
@@ -21,7 +21,13 @@ from tests.app.conftest import (
|
||||
sample_template as create_sample_template,
|
||||
sample_notification_with_job as create_sample_notification_with_job
|
||||
)
|
||||
from tests.app.db import create_notification, create_service, create_inbound_number, create_reply_to_email
|
||||
from tests.app.db import (
|
||||
create_notification,
|
||||
create_service,
|
||||
create_inbound_number,
|
||||
create_reply_to_email,
|
||||
create_letter_contact
|
||||
)
|
||||
from tests.conftest import set_config
|
||||
|
||||
|
||||
@@ -262,3 +268,14 @@ def test_service_get_default_reply_to_email_address(sample_service):
|
||||
create_reply_to_email(service=sample_service, email_address="default@email.com")
|
||||
|
||||
assert sample_service.get_default_reply_to_email_address() == 'default@email.com'
|
||||
|
||||
|
||||
def test_service_get_default_contact_letter(sample_service):
|
||||
create_letter_contact(service=sample_service, contact_block='London,\nNW1A 1AA')
|
||||
|
||||
assert sample_service.get_default_letter_contact() == 'London,\nNW1A 1AA'
|
||||
|
||||
|
||||
# this test will need to be removed after letter_contact_block is dropped
|
||||
def test_service_get_default_letter_contact_block_from_service(sample_service):
|
||||
assert sample_service.get_default_letter_contact() == sample_service.letter_contact_block
|
||||
|
||||
Reference in New Issue
Block a user