Files
notifications-admin/tests/app/main/views/test_add_service.py
T

60 lines
3.1 KiB
Python
Raw Normal View History

2016-01-15 16:10:24 +00:00
from flask import url_for
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_,
api_user_active,
mocker):
2016-01-15 15:15:35 +00:00
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
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
def test_should_add_service_and_redirect_to_next_page(app_,
mocker,
mock_create_service,
mock_get_services,
2016-03-13 09:37:17 +00:00
api_user_active):
2016-01-15 15:15:35 +00:00
with app_.test_request_context():
with app_.test_client() as client:
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'})
assert response.status_code == 302
assert response.location == url_for('main.service_dashboard', service_id=101, _external=True)
assert mock_get_services.called
2016-03-13 09:37:17 +00:00
mock_create_service.asset_called_once_with('testing the post', False,
app_.config['DEFAULT_SERVICE_LIMIT'],
True, api_user_active.id)
2016-01-15 15:15:35 +00:00
def test_should_return_form_errors_when_service_name_is_empty(app_,
mocker,
api_user_active):
2016-01-15 15:15:35 +00:00
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
2016-02-26 10:46:49 +00:00
assert 'Service name cant be empty' in response.get_data(as_text=True)
2016-01-15 16:10:24 +00:00
def test_should_return_form_errors_with_duplicate_service_name_regardless_of_case(app_,
mocker,
service_one,
mock_get_services,
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:
client.login(api_user_active, mocker, service_one)
response = client.post(url_for('main.add_service'), data={'name': 'SERVICE_TWO'})
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-01-15 16:10:24 +00:00
assert mock_get_services.called
assert not mock_create_service.called