- is_default is required on the add_service_email_reply_to_request schema

- Added check that the service exists for the POST reply-to methods.
- Added tests
This commit is contained in:
Rebecca Law
2017-09-20 11:58:18 +01:00
parent 34aa541199
commit c6bf38e869
5 changed files with 45 additions and 12 deletions

View File

@@ -138,6 +138,15 @@ def test_add_reply_to_email_address_ensures_first_reply_to_is_default(sample_ser
email_address="first@address.com", is_default=False)
def test_add_reply_to_email_address_ensure_there_is_not_more_than_one_default(sample_service):
create_reply_to_email(service=sample_service, email_address='first@email.com', is_default=True)
create_reply_to_email(service=sample_service, email_address='second@email.com', is_default=True)
with pytest.raises(Exception):
add_reply_to_email_address_for_service(service_id=sample_service.id,
email_address='third_email@address.com',
is_default=False)
def test_update_reply_to_email_address(sample_service):
first_reply_to = create_reply_to_email(service=sample_service, email_address="first@address.com")
update_reply_to_email_address(service_id=sample_service.id, reply_to_id=first_reply_to.id,

View File

@@ -2180,8 +2180,6 @@ def test_get_email_reply_to_addresses_with_multiple_email_addresses(client, noti
reply_to_a = create_reply_to_email(service, 'test_a@mail.com')
reply_to_b = create_reply_to_email(service, 'test_b@mail.com', False)
service.reply_to_email_address = 'test_a@mail.com'
response = client.get('/service/{}/email-reply-to'.format(service.id),
headers=[create_authorization_header()])
json_response = json.loads(response.get_data(as_text=True))
@@ -2201,7 +2199,7 @@ def test_get_email_reply_to_addresses_with_multiple_email_addresses(client, noti
def test_add_service_reply_to_email_address(client, sample_service):
data = json.dumps({"email_address": "new@reply.com"})
data = json.dumps({"email_address": "new@reply.com", "is_default": True})
response = client.post('/service/{}/email-reply-to'.format(sample_service.id),
data=data,
headers=[('Content-Type', 'application/json'), create_authorization_header()])
@@ -2214,12 +2212,12 @@ def test_add_service_reply_to_email_address(client, sample_service):
def test_add_service_reply_to_email_address_can_add_multiple_addresses(client, sample_service):
data = json.dumps({"email_address": "first@reply.com"})
data = json.dumps({"email_address": "first@reply.com", "is_default": True})
client.post('/service/{}/email-reply-to'.format(sample_service.id),
data=data,
headers=[('Content-Type', 'application/json'), create_authorization_header()])
second = json.dumps({"email_address": "second@reply.com"})
second = json.dumps({"email_address": "second@reply.com", "is_default": True})
response = client.post('/service/{}/email-reply-to'.format(sample_service.id),
data=second,
headers=[('Content-Type', 'application/json'), create_authorization_header()])
@@ -2243,9 +2241,20 @@ def test_add_service_reply_to_email_address_raise_exception_if_no_default(client
assert json_resp['message'] == 'You must have at least one reply to email address as the default.'
def test_add_service_reply_to_email_address_404s_when_invalid_service_id(client, notify_db, notify_db_session):
response = client.post('/service/{}/email-reply-to'.format(uuid.uuid4()),
data={},
headers=[('Content-Type', 'application/json'), create_authorization_header()])
assert response.status_code == 404
result = json.loads(response.get_data(as_text=True))
assert result['result'] == 'error'
assert result['message'] == 'No result found'
def test_update_service_reply_to_email_address(client, sample_service):
original_reply_to = create_reply_to_email(service=sample_service, email_address="some@email.com")
data = json.dumps({"email_address": "changed@reply.com"})
data = json.dumps({"email_address": "changed@reply.com", "is_default": True})
response = client.post('/service/{}/email-reply-to/{}'.format(sample_service.id, original_reply_to.id),
data=data,
headers=[('Content-Type', 'application/json'), create_authorization_header()])
@@ -2267,3 +2276,14 @@ def test_update_service_reply_to_email_address_returns_400_when_no_default(clien
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 reply to email address as the default.'
def test_update_service_reply_to_email_address_404s_when_invalid_service_id(client, notify_db, notify_db_session):
response = client.post('/service/{}/email-reply-to/{}'.format(uuid.uuid4(), uuid.uuid4()),
data={},
headers=[('Content-Type', 'application/json'), create_authorization_header()])
assert response.status_code == 404
result = json.loads(response.get_data(as_text=True))
assert result['result'] == 'error'
assert result['message'] == 'No result found'