Remove old style fixture

Use new `client` one instead
This commit is contained in:
Chris Hill-Scott
2016-11-07 15:37:39 +00:00
parent 6127ee422a
commit 28d5da638b

View File

@@ -15,299 +15,281 @@ from app.dao.templates_dao import dao_get_template_by_id
('letter', 'subject'), ('letter', 'subject'),
]) ])
def test_should_create_a_new_template_for_a_service( def test_should_create_a_new_template_for_a_service(
notify_api, sample_user, sample_service, template_type, subject client, sample_user, sample_service, template_type, subject
): ):
with notify_api.test_request_context(): data = {
with notify_api.test_client() as client: 'name': 'my template',
data = { 'template_type': template_type,
'name': 'my template', 'content': 'template <b>content</b>',
'template_type': template_type, 'service': str(sample_service.id),
'content': 'template <b>content</b>', 'created_by': str(sample_user.id)
'service': str(sample_service.id), }
'created_by': str(sample_user.id) if subject:
} data.update({'subject': subject})
if subject: data = json.dumps(data)
data.update({'subject': subject}) auth_header = create_authorization_header()
data = json.dumps(data)
auth_header = create_authorization_header()
response = client.post( response = client.post(
'/service/{}/template'.format(sample_service.id), '/service/{}/template'.format(sample_service.id),
headers=[('Content-Type', 'application/json'), auth_header], headers=[('Content-Type', 'application/json'), auth_header],
data=data data=data
) )
assert response.status_code == 201 assert response.status_code == 201
json_resp = json.loads(response.get_data(as_text=True)) json_resp = json.loads(response.get_data(as_text=True))
assert json_resp['data']['name'] == 'my template' assert json_resp['data']['name'] == 'my template'
assert json_resp['data']['template_type'] == template_type assert json_resp['data']['template_type'] == template_type
assert json_resp['data']['content'] == 'template content' assert json_resp['data']['content'] == 'template content'
assert json_resp['data']['service'] == str(sample_service.id) assert json_resp['data']['service'] == str(sample_service.id)
assert json_resp['data']['id'] assert json_resp['data']['id']
assert json_resp['data']['version'] == 1 assert json_resp['data']['version'] == 1
if subject: if subject:
assert json_resp['data']['subject'] == 'subject' assert json_resp['data']['subject'] == 'subject'
else: else:
assert not json_resp['data']['subject'] assert not json_resp['data']['subject']
def test_should_be_error_if_service_does_not_exist_on_create(notify_api, sample_user, fake_uuid): def test_should_be_error_if_service_does_not_exist_on_create(client, sample_user, fake_uuid):
with notify_api.test_request_context(): data = {
with notify_api.test_client() as client: 'name': 'my template',
data = { 'template_type': 'sms',
'name': 'my template', 'content': 'template content',
'template_type': 'sms', 'service': fake_uuid,
'content': 'template content', 'created_by': str(sample_user.id)
'service': fake_uuid, }
'created_by': str(sample_user.id) data = json.dumps(data)
} auth_header = create_authorization_header()
data = json.dumps(data)
auth_header = create_authorization_header()
response = client.post( response = client.post(
'/service/{}/template'.format(fake_uuid), '/service/{}/template'.format(fake_uuid),
headers=[('Content-Type', 'application/json'), auth_header], headers=[('Content-Type', 'application/json'), auth_header],
data=data data=data
) )
json_resp = json.loads(response.get_data(as_text=True)) json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 404 assert response.status_code == 404
assert json_resp['result'] == 'error' assert json_resp['result'] == 'error'
assert json_resp['message'] == 'No result found' assert json_resp['message'] == 'No result found'
def test_should_error_if_created_by_missing(notify_api, sample_user, sample_service): def test_should_error_if_created_by_missing(client, sample_user, sample_service):
with notify_api.test_request_context(): service_id = str(sample_service.id)
with notify_api.test_client() as client: data = {
service_id = str(sample_service.id) 'name': 'my template',
data = { 'template_type': 'sms',
'name': 'my template', 'content': 'template content',
'template_type': 'sms', 'service': service_id
'content': 'template content', }
'service': service_id data = json.dumps(data)
} auth_header = create_authorization_header()
data = json.dumps(data)
auth_header = create_authorization_header()
response = client.post( response = client.post(
'/service/{}/template'.format(service_id), '/service/{}/template'.format(service_id),
headers=[('Content-Type', 'application/json'), auth_header], headers=[('Content-Type', 'application/json'), auth_header],
data=data data=data
) )
json_resp = json.loads(response.get_data(as_text=True)) json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 400 assert response.status_code == 400
assert json_resp['result'] == 'error' assert json_resp['result'] == 'error'
def test_should_be_error_if_service_does_not_exist_on_update(notify_api, fake_uuid): def test_should_be_error_if_service_does_not_exist_on_update(client, fake_uuid):
with notify_api.test_request_context(): data = {
with notify_api.test_client() as client: 'name': 'my template'
data = { }
'name': 'my template' data = json.dumps(data)
} auth_header = create_authorization_header()
data = json.dumps(data)
auth_header = create_authorization_header()
response = client.post( response = client.post(
'/service/{}/template/{}'.format(fake_uuid, fake_uuid), '/service/{}/template/{}'.format(fake_uuid, fake_uuid),
headers=[('Content-Type', 'application/json'), auth_header], headers=[('Content-Type', 'application/json'), auth_header],
data=data data=data
) )
json_resp = json.loads(response.get_data(as_text=True)) json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 404 assert response.status_code == 404
assert json_resp['result'] == 'error' assert json_resp['result'] == 'error'
assert json_resp['message'] == 'No result found' assert json_resp['message'] == 'No result found'
@pytest.mark.parametrize('template_type', ['email', 'letter']) @pytest.mark.parametrize('template_type', ['email', 'letter'])
def test_must_have_a_subject_on_an_email_or_letter_template(notify_api, sample_user, sample_service, template_type): def test_must_have_a_subject_on_an_email_or_letter_template(client, sample_user, sample_service, template_type):
with notify_api.test_request_context(): data = {
with notify_api.test_client() as client: 'name': 'my template',
data = { 'template_type': template_type,
'name': 'my template', 'content': 'template content',
'template_type': template_type, 'service': str(sample_service.id),
'content': 'template content', 'created_by': str(sample_user.id)
'service': str(sample_service.id), }
'created_by': str(sample_user.id) data = json.dumps(data)
} auth_header = create_authorization_header()
data = json.dumps(data)
auth_header = create_authorization_header()
response = client.post( response = client.post(
'/service/{}/template'.format(sample_service.id), '/service/{}/template'.format(sample_service.id),
headers=[('Content-Type', 'application/json'), auth_header], headers=[('Content-Type', 'application/json'), auth_header],
data=data data=data
) )
json_resp = json.loads(response.get_data(as_text=True)) json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 400 assert response.status_code == 400
assert json_resp['result'] == 'error' assert json_resp['result'] == 'error'
assert json_resp['message'] == {'subject': ['Invalid template subject']} assert json_resp['message'] == {'subject': ['Invalid template subject']}
def test_update_should_update_a_template(notify_api, sample_user, sample_template): def test_update_should_update_a_template(client, sample_user, sample_template):
with notify_api.test_request_context(): data = {
with notify_api.test_client() as client: 'content': 'my template has new content <script type="text/javascript">alert("foo")</script>',
data = { 'created_by': str(sample_user.id)
'content': 'my template has new content <script type="text/javascript">alert("foo")</script>', }
'created_by': str(sample_user.id) data = json.dumps(data)
} auth_header = create_authorization_header()
data = json.dumps(data)
auth_header = create_authorization_header()
update_response = client.post( update_response = client.post(
'/service/{}/template/{}'.format(sample_template.service_id, sample_template.id), '/service/{}/template/{}'.format(sample_template.service_id, sample_template.id),
headers=[('Content-Type', 'application/json'), auth_header], headers=[('Content-Type', 'application/json'), auth_header],
data=data data=data
) )
assert update_response.status_code == 200 assert update_response.status_code == 200
update_json_resp = json.loads(update_response.get_data(as_text=True)) 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']['content'] == 'my template has new content alert("foo")'
assert update_json_resp['data']['name'] == sample_template.name assert update_json_resp['data']['name'] == sample_template.name
assert update_json_resp['data']['template_type'] == sample_template.template_type assert update_json_resp['data']['template_type'] == sample_template.template_type
assert update_json_resp['data']['version'] == 2 assert update_json_resp['data']['version'] == 2
def test_should_be_able_to_archive_template(notify_api, sample_template): def test_should_be_able_to_archive_template(client, sample_template):
with notify_api.test_request_context(): data = {
with notify_api.test_client() as client: 'name': sample_template.name,
data = { 'template_type': sample_template.template_type,
'name': sample_template.name, 'content': sample_template.content,
'template_type': sample_template.template_type, 'archived': True,
'content': sample_template.content, 'service': str(sample_template.service.id),
'archived': True, 'created_by': str(sample_template.created_by.id)
'service': str(sample_template.service.id), }
'created_by': str(sample_template.created_by.id)
}
json_data = json.dumps(data) json_data = json.dumps(data)
auth_header = create_authorization_header() auth_header = create_authorization_header()
resp = client.post( resp = client.post(
'/service/{}/template/{}'.format(sample_template.service.id, sample_template.id), '/service/{}/template/{}'.format(sample_template.service.id, sample_template.id),
headers=[('Content-Type', 'application/json'), auth_header], headers=[('Content-Type', 'application/json'), auth_header],
data=json_data data=json_data
) )
assert resp.status_code == 200 assert resp.status_code == 200
assert Template.query.first().archived assert Template.query.first().archived
def test_should_be_able_to_get_all_templates_for_a_service(notify_api, sample_user, sample_service): def test_should_be_able_to_get_all_templates_for_a_service(client, sample_user, sample_service):
with notify_api.test_request_context(): data = {
with notify_api.test_client() as client: 'name': 'my template 1',
data = { 'template_type': 'email',
'name': 'my template 1', 'subject': 'subject 1',
'template_type': 'email', 'content': 'template content',
'subject': 'subject 1', 'service': str(sample_service.id),
'content': 'template content', 'created_by': str(sample_user.id)
'service': str(sample_service.id), }
'created_by': str(sample_user.id) data_1 = json.dumps(data)
} data = {
data_1 = json.dumps(data) 'name': 'my template 2',
data = { 'template_type': 'email',
'name': 'my template 2', 'subject': 'subject 2',
'template_type': 'email', 'content': 'template content',
'subject': 'subject 2', 'service': str(sample_service.id),
'content': 'template content', 'created_by': str(sample_user.id)
'service': str(sample_service.id), }
'created_by': str(sample_user.id) data_2 = json.dumps(data)
} auth_header = create_authorization_header()
data_2 = json.dumps(data) client.post(
auth_header = create_authorization_header() '/service/{}/template'.format(sample_service.id),
client.post( headers=[('Content-Type', 'application/json'), auth_header],
'/service/{}/template'.format(sample_service.id), data=data_1
headers=[('Content-Type', 'application/json'), auth_header], )
data=data_1 auth_header = create_authorization_header()
)
auth_header = create_authorization_header()
client.post( client.post(
'/service/{}/template'.format(sample_service.id), '/service/{}/template'.format(sample_service.id),
headers=[('Content-Type', 'application/json'), auth_header], headers=[('Content-Type', 'application/json'), auth_header],
data=data_2 data=data_2
) )
auth_header = create_authorization_header() auth_header = create_authorization_header()
response = client.get( response = client.get(
'/service/{}/template'.format(sample_service.id), '/service/{}/template'.format(sample_service.id),
headers=[auth_header] headers=[auth_header]
) )
assert response.status_code == 200 assert response.status_code == 200
update_json_resp = json.loads(response.get_data(as_text=True)) update_json_resp = json.loads(response.get_data(as_text=True))
assert update_json_resp['data'][0]['name'] == 'my template 2' assert update_json_resp['data'][0]['name'] == 'my template 2'
assert update_json_resp['data'][0]['version'] == 1 assert update_json_resp['data'][0]['version'] == 1
assert update_json_resp['data'][0]['created_at'] assert update_json_resp['data'][0]['created_at']
assert update_json_resp['data'][1]['name'] == 'my template 1' assert update_json_resp['data'][1]['name'] == 'my template 1'
assert update_json_resp['data'][1]['version'] == 1 assert update_json_resp['data'][1]['version'] == 1
assert update_json_resp['data'][1]['created_at'] assert update_json_resp['data'][1]['created_at']
def test_should_get_only_templates_for_that_service(notify_api, sample_user, service_factory): def test_should_get_only_templates_for_that_service(client, sample_user, service_factory):
with notify_api.test_request_context():
with notify_api.test_client() as client:
service_1 = service_factory.get('service 1', email_from='service.1') service_1 = service_factory.get('service 1', email_from='service.1')
service_2 = service_factory.get('service 2', email_from='service.2') service_2 = service_factory.get('service 2', email_from='service.2')
auth_header_1 = create_authorization_header() auth_header_1 = create_authorization_header()
response_1 = client.get( response_1 = client.get(
'/service/{}/template'.format(service_1.id), '/service/{}/template'.format(service_1.id),
headers=[auth_header_1] headers=[auth_header_1]
) )
auth_header_2 = create_authorization_header() auth_header_2 = create_authorization_header()
response_2 = client.get( response_2 = client.get(
'/service/{}/template'.format(service_2.id), '/service/{}/template'.format(service_2.id),
headers=[auth_header_2] headers=[auth_header_2]
) )
assert response_1.status_code == 200 assert response_1.status_code == 200
assert response_2.status_code == 200 assert response_2.status_code == 200
json_resp_1 = json.loads(response_1.get_data(as_text=True)) json_resp_1 = json.loads(response_1.get_data(as_text=True))
json_resp_2 = json.loads(response_2.get_data(as_text=True)) json_resp_2 = json.loads(response_2.get_data(as_text=True))
assert len(json_resp_1['data']) == 1 assert len(json_resp_1['data']) == 1
assert len(json_resp_2['data']) == 1 assert len(json_resp_2['data']) == 1
data = { data = {
'name': 'my template 2', 'name': 'my template 2',
'template_type': 'email', 'template_type': 'email',
'subject': 'subject 2', 'subject': 'subject 2',
'content': 'template content', 'content': 'template content',
'service': str(service_1.id), 'service': str(service_1.id),
'created_by': str(sample_user.id) 'created_by': str(sample_user.id)
} }
data = json.dumps(data) data = json.dumps(data)
create_auth_header = create_authorization_header() create_auth_header = create_authorization_header()
resp = client.post( resp = client.post(
'/service/{}/template'.format(service_1.id), '/service/{}/template'.format(service_1.id),
headers=[('Content-Type', 'application/json'), create_auth_header], headers=[('Content-Type', 'application/json'), create_auth_header],
data=data data=data
) )
response_3 = client.get( response_3 = client.get(
'/service/{}/template'.format(service_1.id), '/service/{}/template'.format(service_1.id),
headers=[auth_header_1] headers=[auth_header_1]
) )
response_4 = client.get( response_4 = client.get(
'/service/{}/template'.format(service_2.id), '/service/{}/template'.format(service_2.id),
headers=[auth_header_2] headers=[auth_header_2]
) )
assert response_3.status_code == 200 assert response_3.status_code == 200
assert response_4.status_code == 200 assert response_4.status_code == 200
json_resp_3 = json.loads(response_3.get_data(as_text=True)) json_resp_3 = json.loads(response_3.get_data(as_text=True))
json_resp_4 = json.loads(response_4.get_data(as_text=True)) json_resp_4 = json.loads(response_4.get_data(as_text=True))
assert len(json_resp_3['data']) == 2 assert len(json_resp_3['data']) == 2
assert len(json_resp_4['data']) == 1 assert len(json_resp_4['data']) == 1
@pytest.mark.parametrize( @pytest.mark.parametrize(
@@ -331,29 +313,28 @@ def test_should_get_only_templates_for_that_service(notify_api, sample_user, ser
) )
def test_should_get_a_single_template( def test_should_get_a_single_template(
notify_db, notify_db,
notify_api, client,
sample_user, sample_user,
service_factory, service_factory,
subject, subject,
content, content,
template_type template_type
): ):
with notify_api.test_request_context(), notify_api.test_client() as client:
template = create_sample_template( template = create_sample_template(
notify_db, notify_db.session, subject_line=subject, content=content, template_type=template_type notify_db, notify_db.session, subject_line=subject, content=content, template_type=template_type
) )
response = client.get( response = client.get(
'/service/{}/template/{}'.format(template.service.id, template.id), '/service/{}/template/{}'.format(template.service.id, template.id),
headers=[create_authorization_header()] headers=[create_authorization_header()]
) )
data = json.loads(response.get_data(as_text=True))['data'] data = json.loads(response.get_data(as_text=True))['data']
assert response.status_code == 200 assert response.status_code == 200
assert data['content'] == content assert data['content'] == content
assert data['subject'] == subject assert data['subject'] == subject
@pytest.mark.parametrize( @pytest.mark.parametrize(
@@ -392,7 +373,7 @@ def test_should_get_a_single_template(
) )
def test_should_preview_a_single_template( def test_should_preview_a_single_template(
notify_db, notify_db,
notify_api, client,
sample_user, sample_user,
service_factory, service_factory,
subject, subject,
@@ -402,144 +383,136 @@ def test_should_preview_a_single_template(
expected_content, expected_content,
expected_error expected_error
): ):
with notify_api.test_request_context(), notify_api.test_client() as client:
template = create_sample_template( template = create_sample_template(
notify_db, notify_db.session, subject_line=subject, content=content, template_type='email' notify_db, notify_db.session, subject_line=subject, content=content, template_type='email'
) )
response = client.get( response = client.get(
path.format(template.service.id, template.id), path.format(template.service.id, template.id),
headers=[create_authorization_header()] headers=[create_authorization_header()]
) )
content = json.loads(response.get_data(as_text=True)) content = json.loads(response.get_data(as_text=True))
if expected_error: if expected_error:
assert response.status_code == 400 assert response.status_code == 400
assert content['message']['template'] == [expected_error] assert content['message']['template'] == [expected_error]
else: else:
assert response.status_code == 200 assert response.status_code == 200
assert content['content'] == expected_content assert content['content'] == expected_content
assert content['subject'] == expected_subject assert content['subject'] == expected_subject
def test_should_return_empty_array_if_no_templates_for_service(notify_api, sample_service): def test_should_return_empty_array_if_no_templates_for_service(client, sample_service):
with notify_api.test_request_context():
with notify_api.test_client() as client:
auth_header = create_authorization_header() auth_header = create_authorization_header()
response = client.get( response = client.get(
'/service/{}/template'.format(sample_service.id), '/service/{}/template'.format(sample_service.id),
headers=[auth_header] headers=[auth_header]
) )
assert response.status_code == 200 assert response.status_code == 200
json_resp = json.loads(response.get_data(as_text=True)) json_resp = json.loads(response.get_data(as_text=True))
assert len(json_resp['data']) == 0 assert len(json_resp['data']) == 0
def test_should_return_404_if_no_templates_for_service_with_id(notify_api, sample_service, fake_uuid): def test_should_return_404_if_no_templates_for_service_with_id(client, sample_service, fake_uuid):
with notify_api.test_request_context():
with notify_api.test_client() as client:
auth_header = create_authorization_header() auth_header = create_authorization_header()
response = client.get( response = client.get(
'/service/{}/template/{}'.format(sample_service.id, fake_uuid), '/service/{}/template/{}'.format(sample_service.id, fake_uuid),
headers=[auth_header] headers=[auth_header]
) )
assert response.status_code == 404 assert response.status_code == 404
json_resp = json.loads(response.get_data(as_text=True)) json_resp = json.loads(response.get_data(as_text=True))
assert json_resp['result'] == 'error' assert json_resp['result'] == 'error'
assert json_resp['message'] == 'No result found' assert json_resp['message'] == 'No result found'
def test_create_400_for_over_limit_content(notify_api, sample_user, sample_service, fake_uuid): def test_create_400_for_over_limit_content(client, notify_api, sample_user, sample_service, fake_uuid):
with notify_api.test_request_context():
with notify_api.test_client() as client:
limit = notify_api.config.get('SMS_CHAR_COUNT_LIMIT')
content = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(limit + 1))
data = {
'name': 'too big template',
'template_type': 'sms',
'content': content,
'service': str(sample_service.id),
'created_by': str(sample_user.id)
}
data = json.dumps(data)
auth_header = create_authorization_header()
response = client.post( limit = notify_api.config.get('SMS_CHAR_COUNT_LIMIT')
'/service/{}/template'.format(sample_service.id), content = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(limit + 1))
headers=[('Content-Type', 'application/json'), auth_header], data = {
data=data 'name': 'too big template',
) 'template_type': 'sms',
assert response.status_code == 400 'content': content,
json_resp = json.loads(response.get_data(as_text=True)) 'service': str(sample_service.id),
assert ( 'created_by': str(sample_user.id)
'Content has a character count greater than the limit of {}' }
).format(limit) in json_resp['message']['content'] data = json.dumps(data)
auth_header = create_authorization_header()
response = client.post(
'/service/{}/template'.format(sample_service.id),
headers=[('Content-Type', 'application/json'), auth_header],
data=data
)
assert response.status_code == 400
json_resp = json.loads(response.get_data(as_text=True))
assert (
'Content has a character count greater than the limit of {}'
).format(limit) in json_resp['message']['content']
def test_update_400_for_over_limit_content(notify_api, sample_user, sample_template): def test_update_400_for_over_limit_content(client, notify_api, sample_user, sample_template):
with notify_api.test_request_context():
with notify_api.test_client() as client: limit = notify_api.config.get('SMS_CHAR_COUNT_LIMIT')
limit = notify_api.config.get('SMS_CHAR_COUNT_LIMIT') json_data = json.dumps({
json_data = json.dumps({ 'content': ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(limit + 1)),
'content': ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(limit + 1)), 'created_by': str(sample_user.id)
'created_by': str(sample_user.id) })
}) auth_header = create_authorization_header()
auth_header = create_authorization_header() resp = client.post(
resp = client.post( '/service/{}/template/{}'.format(sample_template.service.id, sample_template.id),
'/service/{}/template/{}'.format(sample_template.service.id, sample_template.id), headers=[('Content-Type', 'application/json'), auth_header],
headers=[('Content-Type', 'application/json'), auth_header], data=json_data
data=json_data )
) assert resp.status_code == 400
assert resp.status_code == 400 json_resp = json.loads(resp.get_data(as_text=True))
json_resp = json.loads(resp.get_data(as_text=True)) assert (
assert ( 'Content has a character count greater than the limit of {}'
'Content has a character count greater than the limit of {}' ).format(limit) in json_resp['message']['content']
).format(limit) in json_resp['message']['content']
def test_should_return_all_template_versions_for_service_and_template_id(notify_api, sample_template): def test_should_return_all_template_versions_for_service_and_template_id(client, sample_template):
original_content = sample_template.content original_content = sample_template.content
from app.dao.templates_dao import dao_update_template from app.dao.templates_dao import dao_update_template
sample_template.content = original_content + '1' sample_template.content = original_content + '1'
dao_update_template(sample_template) dao_update_template(sample_template)
sample_template.content = original_content + '2' sample_template.content = original_content + '2'
dao_update_template(sample_template) dao_update_template(sample_template)
with notify_api.test_request_context():
with notify_api.test_client() as client: auth_header = create_authorization_header()
auth_header = create_authorization_header() resp = client.get('/service/{}/template/{}/versions'.format(sample_template.service_id, sample_template.id),
resp = client.get('/service/{}/template/{}/versions'.format(sample_template.service_id, sample_template.id), headers=[('Content-Type', 'application/json'), auth_header])
headers=[('Content-Type', 'application/json'), auth_header]) assert resp.status_code == 200
assert resp.status_code == 200 resp_json = json.loads(resp.get_data(as_text=True))['data']
resp_json = json.loads(resp.get_data(as_text=True))['data'] assert len(resp_json) == 3
assert len(resp_json) == 3 for x in resp_json:
for x in resp_json: if x['version'] == 1:
if x['version'] == 1: assert x['content'] == original_content
assert x['content'] == original_content elif x['version'] == 2:
elif x['version'] == 2: assert x['content'] == original_content + '1'
assert x['content'] == original_content + '1' else:
else: assert x['content'] == original_content + '2'
assert x['content'] == original_content + '2'
def test_update_does_not_create_new_version_when_there_is_no_change(notify_api, sample_template): def test_update_does_not_create_new_version_when_there_is_no_change(client, sample_template):
with notify_api.test_request_context():
with notify_api.test_client() as client: auth_header = create_authorization_header()
auth_header = create_authorization_header() data = {
data = { 'template_type': sample_template.template_type,
'template_type': sample_template.template_type, 'content': sample_template.content,
'content': sample_template.content, }
} resp = client.post('/service/{}/template/{}'.format(sample_template.service_id, sample_template.id),
resp = client.post('/service/{}/template/{}'.format(sample_template.service_id, sample_template.id), data=json.dumps(data),
data=json.dumps(data), headers=[('Content-Type', 'application/json'), auth_header])
headers=[('Content-Type', 'application/json'), auth_header]) assert resp.status_code == 200
assert resp.status_code == 200
template = dao_get_template_by_id(sample_template.id) template = dao_get_template_by_id(sample_template.id)
assert template.version == 1 assert template.version == 1