2016-04-19 10:54:26 +01:00
|
|
|
|
from flask import url_for, session
|
2016-05-20 12:05:05 +01:00
|
|
|
|
from unittest.mock import ANY
|
2016-03-31 15:17:05 +01:00
|
|
|
|
import app
|
|
|
|
|
|
|
2015-12-14 17:12:28 +00:00
|
|
|
|
|
2016-01-19 09:49:01 +00:00
|
|
|
|
def test_get_should_render_add_service_template(app_,
|
2016-01-27 12:22:32 +00:00
|
|
|
|
api_user_active,
|
2016-03-31 10:26:03 +01:00
|
|
|
|
mocker):
|
2016-01-15 15:15:35 +00:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
2016-03-31 10:26:03 +01:00
|
|
|
|
client.login(api_user_active, mocker)
|
2016-01-15 17:46:09 +00:00
|
|
|
|
response = client.get(url_for('main.add_service'))
|
2016-01-07 12:43:10 +00:00
|
|
|
|
assert response.status_code == 200
|
2016-02-26 10:21:51 +00:00
|
|
|
|
assert 'Which service do you want to set up notifications for?' in response.get_data(as_text=True)
|
2015-12-14 17:12:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-04-28 16:44:12 +01:00
|
|
|
|
def test_should_add_service_and_redirect_to_tour_when_no_services(app_,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_create_service,
|
2016-05-20 12:05:05 +01:00
|
|
|
|
mock_create_service_template,
|
2016-04-28 16:44:12 +01:00
|
|
|
|
mock_get_services_with_no_services,
|
|
|
|
|
|
api_user_active):
|
2016-01-15 15:15:35 +00:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
2016-03-31 10:26:03 +01:00
|
|
|
|
client.login(api_user_active, mocker)
|
2016-01-15 16:10:24 +00:00
|
|
|
|
response = client.post(
|
|
|
|
|
|
url_for('main.add_service'),
|
2016-01-18 17:35:28 +00:00
|
|
|
|
data={'name': 'testing the post'})
|
2016-04-28 16:44:12 +01:00
|
|
|
|
assert mock_get_services_with_no_services.called
|
2016-04-19 10:54:26 +01:00
|
|
|
|
mock_create_service.assert_called_once_with(
|
|
|
|
|
|
service_name='testing the post',
|
|
|
|
|
|
active=False,
|
|
|
|
|
|
message_limit=app_.config['DEFAULT_SERVICE_LIMIT'],
|
|
|
|
|
|
restricted=True,
|
|
|
|
|
|
user_id=api_user_active.id,
|
|
|
|
|
|
email_from='testing.the.post'
|
|
|
|
|
|
)
|
2016-07-01 10:40:34 +01:00
|
|
|
|
assert len(mock_create_service_template.call_args_list) == 1
|
2016-04-19 10:54:26 +01:00
|
|
|
|
assert session['service_id'] == 101
|
2016-01-07 12:43:10 +00:00
|
|
|
|
assert response.status_code == 302
|
2016-05-20 12:05:05 +01:00
|
|
|
|
assert response.location == url_for(
|
|
|
|
|
|
'main.send_test',
|
|
|
|
|
|
service_id=101,
|
|
|
|
|
|
template_id="Example text message template",
|
|
|
|
|
|
help=1,
|
|
|
|
|
|
_external=True
|
|
|
|
|
|
)
|
2015-12-15 10:17:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-04-28 16:44:12 +01:00
|
|
|
|
def test_should_add_service_and_redirect_to_dashboard_when_existing_service(app_,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_create_service,
|
2016-05-20 12:05:05 +01:00
|
|
|
|
mock_create_service_template,
|
2016-04-28 16:44:12 +01:00
|
|
|
|
mock_get_services,
|
|
|
|
|
|
api_user_active):
|
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
|
client.login(api_user_active, mocker)
|
|
|
|
|
|
response = client.post(
|
|
|
|
|
|
url_for('main.add_service'),
|
|
|
|
|
|
data={'name': 'testing the post'})
|
|
|
|
|
|
assert mock_get_services.called
|
|
|
|
|
|
mock_create_service.assert_called_once_with(
|
|
|
|
|
|
service_name='testing the post',
|
|
|
|
|
|
active=False,
|
|
|
|
|
|
message_limit=app_.config['DEFAULT_SERVICE_LIMIT'],
|
|
|
|
|
|
restricted=True,
|
|
|
|
|
|
user_id=api_user_active.id,
|
|
|
|
|
|
email_from='testing.the.post'
|
|
|
|
|
|
)
|
2016-05-20 12:05:05 +01:00
|
|
|
|
assert len(mock_create_service_template.call_args_list) == 0
|
2016-04-28 16:44:12 +01:00
|
|
|
|
assert session['service_id'] == 101
|
|
|
|
|
|
assert response.status_code == 302
|
|
|
|
|
|
assert response.location == url_for('main.service_dashboard', service_id=101, _external=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-01-15 15:15:35 +00:00
|
|
|
|
def test_should_return_form_errors_when_service_name_is_empty(app_,
|
2016-03-31 10:26:03 +01:00
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active):
|
2016-01-15 15:15:35 +00:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
2016-03-31 10:26:03 +01:00
|
|
|
|
client.login(api_user_active, mocker)
|
2016-01-15 17:46:09 +00:00
|
|
|
|
response = client.post(url_for('main.add_service'), data={})
|
2016-01-07 12:43:10 +00:00
|
|
|
|
assert response.status_code == 200
|
2016-04-04 10:42:04 +01:00
|
|
|
|
assert 'Can’t be empty' in response.get_data(as_text=True)
|
2016-01-15 16:10:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-03-31 10:26:03 +01:00
|
|
|
|
def test_should_return_form_errors_with_duplicate_service_name_regardless_of_case(app_,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_create_service):
|
2016-01-15 16:10:24 +00:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
2016-03-31 10:26:03 +01:00
|
|
|
|
client.login(api_user_active, mocker, service_one)
|
2016-03-31 15:17:05 +01:00
|
|
|
|
mocker.patch('app.service_api_client.find_all_service_email_from',
|
|
|
|
|
|
return_value=['service_one', 'service.two'])
|
|
|
|
|
|
response = client.post(url_for('main.add_service'), data={'name': 'SERVICE TWO'})
|
2016-03-31 10:26:03 +01:00
|
|
|
|
|
2016-01-15 16:10:24 +00:00
|
|
|
|
assert response.status_code == 200
|
2016-02-26 10:46:49 +00:00
|
|
|
|
assert 'This service name is already in use' in response.get_data(as_text=True)
|
2016-03-31 15:17:05 +01:00
|
|
|
|
app.service_api_client.find_all_service_email_from.assert_called_once_with()
|
2016-03-31 10:26:03 +01:00
|
|
|
|
assert not mock_create_service.called
|