From 070d1d97eb1486d280b2722403eae052f02bbd5a Mon Sep 17 00:00:00 2001 From: Nicholas Staples Date: Wed, 13 Jan 2016 13:01:04 +0000 Subject: [PATCH] Test added specifically for unicode content. --- tests/app/service/views/test_rest.py | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/app/service/views/test_rest.py b/tests/app/service/views/test_rest.py index f9dab77cb..6b971127a 100644 --- a/tests/app/service/views/test_rest.py +++ b/tests/app/service/views/test_rest.py @@ -292,6 +292,33 @@ def test_create_template(notify_api, notify_db, notify_db_session, sample_servic assert json_resp['data']['content'] == template_content +def test_create_template_service_not_exists(notify_api, notify_db, notify_db_session, sample_service): + """ + Tests POST endpoint '//template' a template can be created + from a service. + """ + with notify_api.test_request_context(): + with notify_api.test_client() as client: + assert Template.query.count() == 0 + template_name = "template name" + template_type = "sms" + template_content = "This is a template" + data = { + 'name': template_name, + 'template_type': template_type, + 'content': template_content, + 'service': sample_service.id + } + resp = client.post( + url_for('service.create_template', service_id="123"), + data=json.dumps(data), + headers=[('Content-Type', 'application/json')]) + assert resp.status_code == 404 + assert Template.query.count() == 0 + json_resp = json.loads(resp.get_data(as_text=True)) + assert "Service not found" in json_resp['message'] + + def test_update_template(notify_api, notify_db, notify_db_session, sample_template): """ Tests PUT endpoint '//template/' a template can be @@ -384,3 +411,33 @@ def test_update_template_template_not_exists(notify_api, notify_db, notify_db_se json_resp = json.loads(resp.get_data(as_text=True)) assert "Template not found" in json_resp['message'] assert template_name != sample_template.name + + +def test_create_template_unicode_content(notify_api, notify_db, notify_db_session, sample_service): + """ + Tests POST endpoint '//template/' a template is + created and the content encoding is respected after saving and loading + from the db. + """ + with notify_api.test_request_context(): + with notify_api.test_client() as client: + assert Template.query.count() == 0 + template_name = "template name" + template_type = "sms" + template_content = 'Россия' + data = { + 'name': template_name, + 'template_type': template_type, + 'content': template_content, + 'service': sample_service.id + } + resp = client.post( + url_for('service.create_template', service_id=sample_service.id), + data=json.dumps(data), + headers=[('Content-Type', 'application/json')]) + assert resp.status_code == 201 + assert Template.query.count() == 1 + json_resp = json.loads(resp.get_data(as_text=True)) + assert json_resp['data']['name'] == template_name + assert json_resp['data']['template_type'] == template_type + assert json_resp['data']['content'] == template_content