mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Refactored tests and get template endpoint
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
import pytest
|
||||
import uuid
|
||||
|
||||
from flask import json
|
||||
|
||||
from app import DATETIME_FORMAT
|
||||
from app.models import EMAIL_TYPE, SMS_TYPE, LETTER_TYPE
|
||||
from tests import create_authorization_header
|
||||
from tests.app.conftest import sample_template as create_sample_template
|
||||
|
||||
EMAIL_TYPE = 'email'
|
||||
SMS_TYPE = 'sms'
|
||||
LETTER_TYPE = 'letter'
|
||||
from tests.app.db import create_template
|
||||
|
||||
template_types = [EMAIL_TYPE, SMS_TYPE, LETTER_TYPE]
|
||||
valid_version_params = [None, 1]
|
||||
@@ -16,8 +14,8 @@ valid_version_params = [None, 1]
|
||||
|
||||
@pytest.mark.parametrize("tmp_type", template_types)
|
||||
@pytest.mark.parametrize("version", valid_version_params)
|
||||
def test_get_email_template_by_id_returns_200(client, notify_db, notify_db_session, sample_service, tmp_type, version):
|
||||
template = create_sample_template(notify_db, notify_db_session, template_type=tmp_type)
|
||||
def test_get_email_template_by_id_returns_200(client, sample_service, tmp_type, version):
|
||||
template = create_template(sample_service, template_type=tmp_type)
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
|
||||
version_path = '/version/{}'.format(version) if version else ''
|
||||
@@ -44,12 +42,12 @@ def test_get_email_template_by_id_returns_200(client, notify_db, notify_db_sessi
|
||||
assert json_response == expected_response
|
||||
|
||||
|
||||
def test_get_template_with_invalid_template_id_returns_404(client, sample_service):
|
||||
def test_get_template_with_non_existent_template_id_returns_404(client, sample_service):
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
|
||||
invalid_template_id = 'some_other_id'
|
||||
random_template_id = str(uuid.uuid4())
|
||||
|
||||
response = client.get(path='/v2/template/{}'.format(invalid_template_id),
|
||||
response = client.get(path='/v2/template/{}'.format(random_template_id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
|
||||
assert response.status_code == 404
|
||||
@@ -58,20 +56,22 @@ def test_get_template_with_invalid_template_id_returns_404(client, sample_servic
|
||||
json_response = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert json_response == {
|
||||
"message": "The requested URL was not found on the server. "
|
||||
"If you entered the URL manually please check your spelling and try again.",
|
||||
"result": "error"
|
||||
"errors": [
|
||||
{
|
||||
"error": "NoResultFound",
|
||||
"message": "No result found"
|
||||
}
|
||||
],
|
||||
"status_code": 404
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tmp_type", template_types)
|
||||
def test_get_template_with_invalid_version_returns_404(client, notify_db, notify_db_session, sample_service, tmp_type):
|
||||
template = create_sample_template(
|
||||
notify_db, notify_db_session, template_type=tmp_type)
|
||||
def test_get_template_with_non_existent_version_returns_404(client, sample_service, tmp_type):
|
||||
template = create_template(sample_service, template_type=tmp_type)
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
|
||||
# test with version number beyond latest version
|
||||
invalid_version = template.version + 1
|
||||
|
||||
response = client.get(path='/v2/template/{}/version/{}'.format(template.id, invalid_version),
|
||||
|
||||
Reference in New Issue
Block a user