Files
notifications-admin/tests/app/main/views/test_add_service.py
Chris Hill-Scott c41944080c Make the tour interactive
_The code for this is quite hacky and light on tests. But I’d really like to get
it in the app for the research tomorrow to see how well the feature works._

This commit changes the tour from being a set of static screens to some help
which guides you through the process of sending your first test message.

The theory behind this is that what users are really struggling with is the
concept of a variable, rather than the relationship between the placeholders and
the column headers. And like learning to program, the best way to learn is by
taking an example and modifying it to your own needs.

This means that when someone adds their first service we set them up an
example email template and an example text message template. Then there is a
guided, three step process where _all_ the user can do is send a test message to
themselves.

Once the message is sent, the user still has the example templates which they
can edit, rather than having to remember what they’re supposed to be doing.
2016-05-25 13:14:09 +01:00

104 lines
5.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from flask import url_for, session
from unittest.mock import ANY
import app
def test_get_should_render_add_service_template(app_,
api_user_active,
mocker):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active, mocker)
response = client.get(url_for('main.add_service'))
assert response.status_code == 200
assert 'Which service do you want to set up notifications for?' in response.get_data(as_text=True)
def test_should_add_service_and_redirect_to_tour_when_no_services(app_,
mocker,
mock_create_service,
mock_create_service_template,
mock_get_services_with_no_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_with_no_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'
)
assert len(mock_create_service_template.call_args_list) == 2
assert session['service_id'] == 101
assert response.status_code == 302
assert response.location == url_for(
'main.send_test',
service_id=101,
template_id="Example text message template",
help=1,
_external=True
)
def test_should_add_service_and_redirect_to_dashboard_when_existing_service(app_,
mocker,
mock_create_service,
mock_create_service_template,
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'
)
assert len(mock_create_service_template.call_args_list) == 0
assert session['service_id'] == 101
assert response.status_code == 302
assert response.location == url_for('main.service_dashboard', service_id=101, _external=True)
def test_should_return_form_errors_when_service_name_is_empty(app_,
mocker,
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={})
assert response.status_code == 200
assert 'Cant be empty' in response.get_data(as_text=True)
def test_should_return_form_errors_with_duplicate_service_name_regardless_of_case(app_,
mocker,
service_one,
api_user_active,
mock_create_service):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active, mocker, service_one)
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'})
assert response.status_code == 200
assert 'This service name is already in use' in response.get_data(as_text=True)
app.service_api_client.find_all_service_email_from.assert_called_once_with()
assert not mock_create_service.called