2016-01-19 15:54:12 +00:00
|
|
|
import json
|
2016-02-02 14:24:08 +00:00
|
|
|
import uuid
|
2016-03-09 12:10:50 +00:00
|
|
|
from tests import validate_route_permission
|
2016-02-02 14:24:08 +00:00
|
|
|
|
2016-01-14 14:03:27 +00:00
|
|
|
from flask import url_for
|
2016-01-11 16:03:41 +00:00
|
|
|
|
|
|
|
|
|
2016-01-19 15:54:12 +00:00
|
|
|
def test_should_show_page_for_one_templates(app_,
|
2016-01-27 12:22:32 +00:00
|
|
|
api_user_active,
|
2016-01-20 15:13:15 +00:00
|
|
|
mock_get_service_template,
|
2016-01-27 16:30:33 +00:00
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
2016-02-29 17:03:56 +00:00
|
|
|
mock_login,
|
|
|
|
|
mock_has_permissions):
|
2016-01-15 15:15:35 +00:00
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
2016-01-27 12:22:32 +00:00
|
|
|
client.login(api_user_active)
|
2016-02-02 14:24:08 +00:00
|
|
|
service_id = str(uuid.uuid4())
|
2016-01-19 15:54:12 +00:00
|
|
|
template_id = 456
|
|
|
|
|
response = client.get(url_for(
|
|
|
|
|
'.edit_service_template',
|
|
|
|
|
service_id=service_id,
|
|
|
|
|
template_id=template_id))
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
2016-01-24 13:27:43 +00:00
|
|
|
assert "Two week reminder" in response.get_data(as_text=True)
|
|
|
|
|
assert "Your vehicle tax is about to expire" in response.get_data(as_text=True)
|
2016-01-19 15:54:12 +00:00
|
|
|
mock_get_service_template.assert_called_with(
|
|
|
|
|
service_id, template_id)
|
2015-12-20 00:00:01 +00:00
|
|
|
|
|
|
|
|
|
2016-01-19 15:54:12 +00:00
|
|
|
def test_should_redirect_when_saving_a_template(app_,
|
2016-01-27 12:22:32 +00:00
|
|
|
api_user_active,
|
2016-01-19 15:54:12 +00:00
|
|
|
mock_get_service_template,
|
2016-01-20 15:13:15 +00:00
|
|
|
mock_update_service_template,
|
2016-01-27 16:30:33 +00:00
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
2016-02-29 17:03:56 +00:00
|
|
|
mock_login,
|
|
|
|
|
mock_has_permissions):
|
2016-01-15 15:15:35 +00:00
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
2016-01-27 12:22:32 +00:00
|
|
|
client.login(api_user_active)
|
2016-02-02 14:24:08 +00:00
|
|
|
service_id = str(uuid.uuid4())
|
2016-01-19 15:54:12 +00:00
|
|
|
template_id = 456
|
|
|
|
|
name = "new name"
|
|
|
|
|
content = "template content"
|
|
|
|
|
data = {
|
|
|
|
|
'id': template_id,
|
|
|
|
|
'name': name,
|
2016-02-22 14:45:13 +00:00
|
|
|
'template_content': content,
|
|
|
|
|
'type': 'sms',
|
|
|
|
|
'service': service_id
|
2016-01-19 15:54:12 +00:00
|
|
|
}
|
|
|
|
|
response = client.post(url_for(
|
|
|
|
|
'.edit_service_template',
|
|
|
|
|
service_id=service_id,
|
|
|
|
|
template_id=template_id), data=data)
|
2015-12-20 00:00:01 +00:00
|
|
|
|
2016-01-14 14:03:27 +00:00
|
|
|
assert response.status_code == 302
|
2016-01-19 15:54:12 +00:00
|
|
|
assert response.location == url_for(
|
2016-02-22 14:45:13 +00:00
|
|
|
'.choose_template', service_id=service_id, template_type='sms', _external=True)
|
2016-01-19 15:54:12 +00:00
|
|
|
mock_update_service_template.assert_called_with(
|
2016-02-18 07:44:50 +00:00
|
|
|
template_id, name, 'sms', content, service_id)
|
2016-01-14 09:44:06 +00:00
|
|
|
|
|
|
|
|
|
2016-01-19 15:54:12 +00:00
|
|
|
def test_should_show_delete_template_page(app_,
|
2016-01-27 12:22:32 +00:00
|
|
|
api_user_active,
|
2016-01-20 15:13:15 +00:00
|
|
|
mock_get_service_template,
|
2016-01-27 16:30:33 +00:00
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
2016-02-29 17:03:56 +00:00
|
|
|
mock_login,
|
|
|
|
|
mock_has_permissions):
|
2016-01-19 09:49:01 +00:00
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
2016-01-27 12:22:32 +00:00
|
|
|
client.login(api_user_active)
|
2016-02-02 14:24:08 +00:00
|
|
|
service_id = str(uuid.uuid4())
|
2016-01-19 15:54:12 +00:00
|
|
|
template_id = 456
|
|
|
|
|
response = client.get(url_for(
|
|
|
|
|
'.delete_service_template',
|
|
|
|
|
service_id=service_id,
|
|
|
|
|
template_id=template_id))
|
2016-01-14 09:44:06 +00:00
|
|
|
|
2016-02-08 12:30:01 +00:00
|
|
|
content = response.get_data(as_text=True)
|
2016-01-14 09:44:06 +00:00
|
|
|
assert response.status_code == 200
|
2016-02-08 12:30:01 +00:00
|
|
|
assert 'Are you sure' in content
|
|
|
|
|
assert 'Two week reminder' in content
|
|
|
|
|
assert 'Your vehicle tax is about to expire' in content
|
2016-01-19 15:54:12 +00:00
|
|
|
mock_get_service_template.assert_called_with(
|
|
|
|
|
service_id, template_id)
|
2016-01-14 09:44:06 +00:00
|
|
|
|
|
|
|
|
|
2016-01-19 15:54:12 +00:00
|
|
|
def test_should_redirect_when_deleting_a_template(app_,
|
2016-01-27 12:22:32 +00:00
|
|
|
api_user_active,
|
2016-01-19 15:54:12 +00:00
|
|
|
mock_get_service_template,
|
2016-01-20 15:13:15 +00:00
|
|
|
mock_delete_service_template,
|
2016-01-27 16:30:33 +00:00
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
2016-02-29 17:03:56 +00:00
|
|
|
mock_login,
|
|
|
|
|
mock_has_permissions):
|
2016-01-19 09:49:01 +00:00
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
2016-01-27 12:22:32 +00:00
|
|
|
client.login(api_user_active)
|
2016-02-02 14:24:08 +00:00
|
|
|
service_id = str(uuid.uuid4())
|
2016-01-19 15:54:12 +00:00
|
|
|
template_id = 456
|
|
|
|
|
name = "new name"
|
|
|
|
|
type_ = "sms"
|
|
|
|
|
content = "template content"
|
|
|
|
|
data = {
|
|
|
|
|
'id': template_id,
|
|
|
|
|
'name': name,
|
|
|
|
|
'template_type': type_,
|
|
|
|
|
'content': content,
|
|
|
|
|
'service': service_id
|
|
|
|
|
}
|
|
|
|
|
response = client.post(url_for(
|
|
|
|
|
'.delete_service_template',
|
|
|
|
|
service_id=service_id,
|
2016-02-22 14:45:13 +00:00
|
|
|
template_id=template_id
|
|
|
|
|
), data=data)
|
2015-12-20 00:00:01 +00:00
|
|
|
|
2016-01-14 14:03:27 +00:00
|
|
|
assert response.status_code == 302
|
2016-01-19 15:54:12 +00:00
|
|
|
assert response.location == url_for(
|
2016-02-22 14:45:13 +00:00
|
|
|
'.choose_template',
|
|
|
|
|
service_id=service_id, template_type=type_, _external=True)
|
2016-01-19 15:54:12 +00:00
|
|
|
mock_get_service_template.assert_called_with(
|
|
|
|
|
service_id, template_id)
|
|
|
|
|
mock_delete_service_template.assert_called_with(
|
|
|
|
|
service_id, template_id)
|
2016-03-09 12:10:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_route_permissions(mocker,
|
|
|
|
|
app_,
|
|
|
|
|
api_user_active,
|
|
|
|
|
service_one,
|
|
|
|
|
mock_get_service_template):
|
|
|
|
|
routes = [
|
|
|
|
|
'main.add_service_template',
|
|
|
|
|
'main.edit_service_template',
|
|
|
|
|
'main.delete_service_template']
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
for route in routes:
|
|
|
|
|
validate_route_permission(
|
|
|
|
|
mocker,
|
|
|
|
|
app_,
|
|
|
|
|
"GET",
|
|
|
|
|
200,
|
|
|
|
|
url_for(
|
|
|
|
|
route,
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
template_type='sms',
|
|
|
|
|
template_id=123),
|
|
|
|
|
['manage_templates'],
|
|
|
|
|
api_user_active,
|
|
|
|
|
service_one)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_route_invalid_permissions(mocker,
|
|
|
|
|
app_,
|
|
|
|
|
api_user_active,
|
|
|
|
|
service_one,
|
|
|
|
|
mock_get_service_template):
|
|
|
|
|
routes = [
|
|
|
|
|
'main.add_service_template',
|
|
|
|
|
'main.edit_service_template',
|
|
|
|
|
'main.delete_service_template']
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
for route in routes:
|
|
|
|
|
validate_route_permission(
|
|
|
|
|
mocker,
|
|
|
|
|
app_,
|
|
|
|
|
"GET",
|
|
|
|
|
403,
|
|
|
|
|
url_for(
|
|
|
|
|
route,
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
template_type='sms',
|
|
|
|
|
template_id=123),
|
|
|
|
|
['blah'],
|
|
|
|
|
api_user_active,
|
|
|
|
|
service_one)
|