mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 05:29:38 -04:00
Mapped template actions to the api and mocked tests.
This commit is contained in:
@@ -1,49 +1,128 @@
|
||||
import json
|
||||
from flask import url_for
|
||||
|
||||
|
||||
def test_should_return_list_of_all_templates(app_, db_, db_session, active_user):
|
||||
def test_should_return_list_of_all_templates(app_,
|
||||
db_,
|
||||
db_session,
|
||||
active_user,
|
||||
mock_get_service_templates):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(active_user)
|
||||
response = client.get(url_for('.manage_templates', service_id=123))
|
||||
service_id = 123
|
||||
response = client.get(url_for(
|
||||
'.manage_service_templates', service_id=service_id))
|
||||
|
||||
assert response.status_code == 200
|
||||
mock_get_service_templates.assert_called_with(service_id)
|
||||
|
||||
|
||||
def test_should_show_page_for_one_templates(app_, db_, db_session, active_user):
|
||||
def test_should_show_page_for_one_templates(app_,
|
||||
db_,
|
||||
db_session,
|
||||
active_user,
|
||||
mock_get_service_template):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(active_user)
|
||||
response = client.get(url_for('.edit_template', service_id=123, template_id=1))
|
||||
service_id = 123
|
||||
template_id = 456
|
||||
response = client.get(url_for(
|
||||
'.edit_service_template',
|
||||
service_id=service_id,
|
||||
template_id=template_id))
|
||||
|
||||
assert response.status_code == 200
|
||||
mock_get_service_template.assert_called_with(
|
||||
service_id, template_id)
|
||||
|
||||
|
||||
def test_should_redirect_when_saving_a_template(app_, db_, db_session, active_user):
|
||||
def test_should_redirect_when_saving_a_template(app_,
|
||||
db_,
|
||||
db_session,
|
||||
active_user,
|
||||
mock_get_service_template,
|
||||
mock_update_service_template):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(active_user)
|
||||
response = client.post(url_for('.edit_template', service_id=123, template_id=1))
|
||||
service_id = 123
|
||||
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(
|
||||
'.edit_service_template',
|
||||
service_id=service_id,
|
||||
template_id=template_id), data=data)
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('.manage_templates', service_id=123, _external=True)
|
||||
assert response.location == url_for(
|
||||
'.manage_service_templates', service_id=service_id, _external=True)
|
||||
mock_update_service_template.assert_called_with(
|
||||
template_id, name, type_, content, service_id)
|
||||
|
||||
|
||||
def test_should_show_delete_template_page(app_, db_, db_session, active_user):
|
||||
def test_should_show_delete_template_page(app_,
|
||||
db_,
|
||||
db_session,
|
||||
active_user,
|
||||
mock_get_service_template):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(active_user)
|
||||
response = client.get(url_for('.delete_template', service_id=123, template_id=1))
|
||||
service_id = 123
|
||||
template_id = 456
|
||||
response = client.get(url_for(
|
||||
'.delete_service_template',
|
||||
service_id=service_id,
|
||||
template_id=template_id))
|
||||
|
||||
assert response.status_code == 200
|
||||
assert 'Are you sure' in response.get_data(as_text=True)
|
||||
mock_get_service_template.assert_called_with(
|
||||
service_id, template_id)
|
||||
|
||||
|
||||
def test_should_redirect_when_deleting_a_template(app_, db_, db_session, active_user):
|
||||
def test_should_redirect_when_deleting_a_template(app_,
|
||||
db_,
|
||||
db_session,
|
||||
active_user,
|
||||
mock_get_service_template,
|
||||
mock_delete_service_template):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(active_user)
|
||||
response = client.post(url_for('.delete_template', service_id=123, template_id=1))
|
||||
service_id = 123
|
||||
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,
|
||||
template_id=template_id), data=data)
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('.manage_templates', service_id=123, _external=True)
|
||||
assert response.location == url_for(
|
||||
'.manage_service_templates',
|
||||
service_id=service_id, _external=True)
|
||||
mock_get_service_template.assert_called_with(
|
||||
service_id, template_id)
|
||||
mock_delete_service_template.assert_called_with(
|
||||
service_id, template_id)
|
||||
|
||||
Reference in New Issue
Block a user