Template history endpoint added. All tests passing.

Code quality fix.
This commit is contained in:
Nicholas Staples
2016-05-06 15:42:43 +01:00
parent e10728ccae
commit 9b3d4a6087
6 changed files with 117 additions and 15 deletions

View File

@@ -218,3 +218,15 @@ def test_update_template_creates_a_history_record_with_current_data(sample_servi
assert Template.get_history_model().query.filter_by(name='Sample Template').one().version == 1
assert Template.get_history_model().query.filter_by(name='new name').one().version == 2
def test_get_template_history_version(sample_user, sample_service, sample_template):
old_content = sample_template.content
sample_template.content = "New content"
dao_update_template(sample_template)
old_template = dao_get_template_by_id_and_service_id(
sample_template.id,
sample_service.id,
'1'
)
assert old_template.content == old_content

View File

@@ -30,6 +30,7 @@ def test_should_create_a_new_sms_template_for_a_service(notify_api, sample_user,
assert json_resp['data']['content'] == 'template content'
assert json_resp['data']['service'] == str(sample_service.id)
assert json_resp['data']['id']
assert json_resp['data']['versions'] == [1]
assert not json_resp['data']['subject']
@@ -59,6 +60,7 @@ def test_should_create_a_new_email_template_for_a_service(notify_api, sample_use
assert json_resp['data']['content'] == 'template content'
assert json_resp['data']['service'] == str(sample_service.id)
assert json_resp['data']['subject'] == 'subject'
assert json_resp['data']['versions'] == [1]
assert json_resp['data']['id']
@@ -234,6 +236,7 @@ def test_should_be_able_to_update_a_template(notify_api, sample_user, sample_ser
assert update_response.status_code == 200
update_json_resp = json.loads(update_response.get_data(as_text=True))
assert update_json_resp['data']['content'] == 'my template has new content alert("foo")'
assert update_json_resp['data']['versions'] == [1, 2]
def test_should_be_able_to_archive_template(notify_api, sample_user, sample_service, sample_template):
@@ -307,7 +310,9 @@ def test_should_be_able_to_get_all_templates_for_a_service(notify_api, sample_us
assert response.status_code == 200
update_json_resp = json.loads(response.get_data(as_text=True))
assert update_json_resp['data'][0]['name'] == 'my template 1'
assert update_json_resp['data'][0]['versions'] == [1]
assert update_json_resp['data'][1]['name'] == 'my template 2'
assert update_json_resp['data'][1]['versions'] == [1]
def test_should_get_only_templates_for_that_service(notify_api, sample_user, service_factory):

View File

@@ -0,0 +1,64 @@
import json
from flask import url_for
from app.models import Template
from app.dao.templates_dao import dao_update_template
from tests import create_authorization_header
def test_template_history_version(notify_api, sample_template):
with notify_api.test_request_context():
with notify_api.test_client() as client:
auth_header = create_authorization_header()
endpoint = url_for(
'template.get_template_version',
service_id=sample_template.service.id,
template_id=sample_template.id,
version=1)
resp = client.get(
endpoint,
headers=[('Content-Type', 'application/json'), auth_header]
)
assert resp.status_code == 200
json_resp = json.loads(resp.get_data(as_text=True))
assert json_resp['data']['id'] == str(sample_template.id)
assert json_resp['data']['content'] == sample_template.content
assert json_resp['data']['version'] == 1
def test_previous_template_history_version(notify_api, sample_template):
old_content = sample_template.content
sample_template.content = "New content"
dao_update_template(sample_template)
with notify_api.test_request_context():
with notify_api.test_client() as client:
auth_header = create_authorization_header()
endpoint = url_for(
'template.get_template_version',
service_id=sample_template.service.id,
template_id=sample_template.id,
version=1)
resp = client.get(
endpoint,
headers=[('Content-Type', 'application/json'), auth_header]
)
assert resp.status_code == 200
json_resp = json.loads(resp.get_data(as_text=True))
assert json_resp['data']['id'] == str(sample_template.id)
assert json_resp['data']['version'] == 1
assert json_resp['data']['content'] == old_content
def test_404_missing_template_version(notify_api, sample_template):
with notify_api.test_request_context():
with notify_api.test_client() as client:
auth_header = create_authorization_header()
endpoint = url_for(
'template.get_template_version',
service_id=sample_template.service.id,
template_id=sample_template.id,
version=2)
resp = client.get(
endpoint,
headers=[('Content-Type', 'application/json'), auth_header]
)
assert resp.status_code == 404