Removed paging from get all templates

This commit is contained in:
Ken Tsang
2017-03-28 13:15:39 +01:00
parent e2ad8ba50d
commit d290a2e0ad
2 changed files with 24 additions and 75 deletions

View File

@@ -2,13 +2,12 @@ import pytest
from flask import json
from app import DATETIME_FORMAT
from app.models import EMAIL_TYPE, SMS_TYPE, LETTER_TYPE, TEMPLATE_TYPES
from app.models import TEMPLATE_TYPES
from tests import create_authorization_header
from tests.app.db import create_template
def test_get_all_templates(client, sample_service):
def test_get_all_templates_returns_200(client, sample_service):
num_templates = 3
templates = []
for i in range(num_templates):
@@ -17,9 +16,10 @@ def test_get_all_templates(client, sample_service):
auth_header = create_authorization_header(service_id=sample_service.id)
response = client.get(path='/v2/templates/?',
response = client.get(path='/v2/templates/',
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 200
assert response.headers['Content-type'] == 'application/json'
json_response = json.loads(response.get_data(as_text=True))
@@ -35,7 +35,7 @@ def test_get_all_templates(client, sample_service):
@pytest.mark.parametrize("tmp_type", TEMPLATE_TYPES)
def test_get_all_templates_for_type(client, sample_service, tmp_type):
def test_get_all_templates_for_valid_type_returns_200(client, sample_service, tmp_type):
num_templates = 3
templates = []
for i in range(num_templates):
@@ -46,6 +46,7 @@ def test_get_all_templates_for_type(client, sample_service, tmp_type):
response = client.get(path='/v2/templates/?type={}'.format(tmp_type),
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 200
assert response.headers['Content-type'] == 'application/json'
json_response = json.loads(response.get_data(as_text=True))
@@ -60,58 +61,25 @@ def test_get_all_templates_for_type(client, sample_service, tmp_type):
assert json_response['templates'][reverse_index]['type'] == templates[i].template_type
@pytest.mark.parametrize("tmp_type", [EMAIL_TYPE, SMS_TYPE])
def test_get_all_templates_older_than_parameter(client, sample_service, tmp_type):
num_templates = 5
templates = []
for i in range(num_templates):
template = create_template(sample_service, template_type=tmp_type)
templates.append(template)
num_templates_older = 3
# only get the first #num_templates_older templates
older_than_id = templates[num_templates_older].id
def test_get_all_templates_for_invalid_type_returns_400(client, sample_service):
auth_header = create_authorization_header(service_id=sample_service.id)
response = client.get(path='/v2/templates/?type={}&older_than={}'.format(tmp_type, older_than_id),
invalid_type = 'coconut'
response = client.get(path='/v2/templates/?type={}'.format(invalid_type),
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 200
assert response.status_code == 400
assert response.headers['Content-type'] == 'application/json'
json_response = json.loads(response.get_data(as_text=True))
assert len(json_response['templates']) == num_templates_older
# need to reverse index as get all templates returns list sorted by descending date
for i in range(num_templates_older):
reverse_index = num_templates_older - 1 - i
assert json_response['templates'][reverse_index]['id'] == str(templates[i].id)
assert json_response['templates'][reverse_index]['body'] == templates[i].content
assert json_response['templates'][reverse_index]['type'] == templates[i].template_type
assert str(older_than_id) in json_response['links']['current']
assert str(templates[0].id) in json_response['links']['next']
@pytest.mark.parametrize("tmp_type", [EMAIL_TYPE, SMS_TYPE])
def test_get_all_templates_none_existent_older_than_parameter(client, sample_service, tmp_type, fake_uuid):
num_templates = 2
templates = []
for i in range(num_templates):
template = create_template(sample_service, template_type=tmp_type)
templates.append(template)
auth_header = create_authorization_header(service_id=sample_service.id)
response = client.get(path='/v2/templates/?type={}&older_than={}'.format(tmp_type, fake_uuid),
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 200
assert response.headers['Content-type'] == 'application/json'
json_response = json.loads(response.get_data(as_text=True))
assert len(json_response['templates']) == 0
assert json_response == {
'status_code': 400,
'errors': [
{
'message': 'type coconut is not one of [sms, email, letter]',
'error': 'ValidationError'
}
]
}