Update invite user endpoint to set the reply_to_text on the notification.

Update v1 post notifications to set the reply_to_text on the notification.
This commit is contained in:
Rebecca Law
2017-11-27 12:30:50 +00:00
parent 12024e9619
commit 530f2e7f6a
5 changed files with 69 additions and 13 deletions

View File

@@ -29,7 +29,8 @@ from app.models import (
ServiceWhitelist,
KEY_TYPE_NORMAL, KEY_TYPE_TEST, KEY_TYPE_TEAM,
MOBILE_TYPE, EMAIL_TYPE, INBOUND_SMS_TYPE, SMS_TYPE, LETTER_TYPE, NOTIFICATION_STATUS_TYPES_COMPLETED,
SERVICE_PERMISSION_TYPES)
SERVICE_PERMISSION_TYPES, ServiceEmailReplyTo
)
from app.dao.users_dao import (create_user_code, create_secret_code)
from app.dao.services_dao import (dao_create_service, dao_add_user_to_service)
from app.dao.templates_dao import dao_create_template
@@ -985,17 +986,26 @@ def notify_service(notify_db, notify_db_session):
user = create_user()
service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID'])
if not service:
service = Service(
name='Notify Service',
message_limit=1000,
restricted=False,
email_from='notify.service',
created_by=user,
prefix_sms=False,
)
dao_create_service(service=service, service_id=current_app.config['NOTIFY_SERVICE_ID'], user=user)
data = {
'id': current_app.config['NOTIFY_SERVICE_ID'],
'name': 'Notify Service',
'message_limit': 1000,
'active': True,
'restricted': False,
'email_from': 'notify.service',
'created_by': user,
'service': service,
'email_address': "notify@gov.uk",
'is_default': True,
}
service = Service(**data)
db.session.add(service)
reply_to = ServiceEmailReplyTo(**data)
db.session.add(reply_to)
db.session.commit()
return service, user

View File

@@ -33,6 +33,7 @@ def test_create_invited_user(admin_request, sample_service, mocker, invitation_e
assert json_resp['data']['id']
notification = Notification.query.first()
assert notification.reply_to_text == "notify@gov.uk"
mocked.assert_called_once_with([(str(notification.id))], queue="notify-internal-tasks")

View File

@@ -31,6 +31,7 @@ from tests.app.conftest import (
from app.models import Template
from app.errors import InvalidRequest
from tests.app.db import create_service, create_reply_to_email
@pytest.mark.parametrize('template_type',
@@ -1219,3 +1220,34 @@ def test_should_throw_exception_if_notification_type_is_invalid(client, sample_s
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 400
assert json.loads(response.get_data(as_text=True))["message"] == err_msg
@pytest.mark.parametrize("notification_type, recipient",
[("sms", '07700 900 855'),
("email", "test@gov.uk")
]
)
def test_post_notification_should_set_reply_to_text(client, notify_db, notify_db_session, mocker, notification_type,
recipient):
mocker.patch('app.celery.provider_tasks.deliver_{}.apply_async'.format(notification_type))
service = create_service()
template = create_sample_template(notify_db=notify_db, notify_db_session=notify_db_session,
service=service, template_type=notification_type)
expected_reply_to = current_app.config['FROM_NUMBER']
if notification_type == EMAIL_TYPE:
expected_reply_to = 'reply_to@gov.uk'
create_reply_to_email(service=service, email_address=expected_reply_to, is_default=True)
data = {
'to': recipient,
'template': str(template.id)
}
response = client.post("/notifications/{}".format(notification_type),
data=json.dumps(data),
headers=[('Content-Type', 'application/json'),
create_authorization_header(service_id=service.id)]
)
assert response.status_code == 201
notifications = Notification.query.all()
assert len(notifications) == 1
assert notifications[0].reply_to_text == expected_reply_to