More Enum goodness.

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2024-01-18 10:26:40 -05:00
parent 43f18eed6a
commit df866e40f7
26 changed files with 379 additions and 278 deletions

View File

@@ -3,7 +3,7 @@ from itertools import product
import pytest
from flask import json
from app.models import EMAIL_TYPE, TEMPLATE_TYPES
from app.models import TemplateType
from tests import create_service_authorization_header
from tests.app.db import create_template
@@ -13,10 +13,10 @@ def test_get_all_templates_returns_200(client, sample_service):
create_template(
sample_service,
template_type=tmp_type,
subject="subject_{}".format(name) if tmp_type == EMAIL_TYPE else "",
subject="subject_{}".format(name) if tmp_type == TemplateType.EMAIL else "",
template_name=name,
)
for name, tmp_type in product(("A", "B", "C"), TEMPLATE_TYPES)
for name, tmp_type in product(("A", "B", "C"), TemplateType)
]
auth_header = create_service_authorization_header(service_id=sample_service.id)
@@ -37,18 +37,18 @@ def test_get_all_templates_returns_200(client, sample_service):
assert template["id"] == str(templates[index].id)
assert template["body"] == templates[index].content
assert template["type"] == templates[index].template_type
if templates[index].template_type == EMAIL_TYPE:
if templates[index].template_type == TemplateType.EMAIL:
assert template["subject"] == templates[index].subject
@pytest.mark.parametrize("tmp_type", TEMPLATE_TYPES)
@pytest.mark.parametrize("tmp_type", list(TemplateType))
def test_get_all_templates_for_valid_type_returns_200(client, sample_service, tmp_type):
templates = [
create_template(
sample_service,
template_type=tmp_type,
template_name="Template {}".format(i),
subject="subject_{}".format(i) if tmp_type == EMAIL_TYPE else "",
subject="subject_{}".format(i) if tmp_type == TemplateType.EMAIL else "",
)
for i in range(3)
]
@@ -71,11 +71,11 @@ def test_get_all_templates_for_valid_type_returns_200(client, sample_service, tm
assert template["id"] == str(templates[index].id)
assert template["body"] == templates[index].content
assert template["type"] == tmp_type
if templates[index].template_type == EMAIL_TYPE:
if templates[index].template_type == TemplateType.EMAIL:
assert template["subject"] == templates[index].subject
@pytest.mark.parametrize("tmp_type", TEMPLATE_TYPES)
@pytest.mark.parametrize("tmp_type", list(TemplateType))
def test_get_correct_num_templates_for_valid_type_returns_200(
client, sample_service, tmp_type
):
@@ -85,7 +85,7 @@ def test_get_correct_num_templates_for_valid_type_returns_200(
for _ in range(num_templates):
templates.append(create_template(sample_service, template_type=tmp_type))
for other_type in TEMPLATE_TYPES:
for other_type in TemplateType:
if other_type != tmp_type:
templates.append(create_template(sample_service, template_type=other_type))

View File

@@ -4,7 +4,7 @@ import pytest
from flask import json
from jsonschema.exceptions import ValidationError
from app.models import EMAIL_TYPE, SMS_TYPE, TEMPLATE_TYPES
from app.models import TemplateType
from app.schema_validation import validate
from app.v2.templates.templates_schemas import (
get_all_template_request,
@@ -16,7 +16,7 @@ valid_json_get_all_response = [
"templates": [
{
"id": str(uuid.uuid4()),
"type": SMS_TYPE,
"type": TemplateType.SMS,
"created_at": "2017-01-10T18:25:43.511Z",
"updated_at": None,
"version": 1,
@@ -26,7 +26,7 @@ valid_json_get_all_response = [
},
{
"id": str(uuid.uuid4()),
"type": EMAIL_TYPE,
"type": TemplateType.EMAIL,
"created_at": "2017-02-10T18:25:43.511Z",
"updated_at": None,
"version": 2,
@@ -41,7 +41,7 @@ valid_json_get_all_response = [
"templates": [
{
"id": str(uuid.uuid4()),
"type": SMS_TYPE,
"type": TemplateType.SMS,
"created_at": "2017-02-10T18:25:43.511Z",
"updated_at": None,
"version": 2,
@@ -60,7 +60,7 @@ invalid_json_get_all_response = [
"templates": [
{
"id": "invalid_id",
"type": SMS_TYPE,
"type": TemplateType.SMS,
"created_at": "2017-02-10T18:25:43.511Z",
"updated_at": None,
"version": 1,
@@ -77,7 +77,7 @@ invalid_json_get_all_response = [
"templates": [
{
"id": str(uuid.uuid4()),
"type": SMS_TYPE,
"type": TemplateType.SMS,
"created_at": "2017-02-10T18:25:43.511Z",
"updated_at": None,
"version": "invalid_version",
@@ -94,7 +94,7 @@ invalid_json_get_all_response = [
"templates": [
{
"id": str(uuid.uuid4()),
"type": SMS_TYPE,
"type": TemplateType.SMS,
"created_at": "invalid_created_at",
"updated_at": None,
"version": 1,
@@ -111,7 +111,7 @@ invalid_json_get_all_response = [
{
"templates": [
{
"type": SMS_TYPE,
"type": TemplateType.SMS,
"created_at": "2017-02-10T18:25:43.511Z",
"updated_at": None,
"version": 1,
@@ -128,7 +128,7 @@ invalid_json_get_all_response = [
"templates": [
{
"id": str(uuid.uuid4()),
"type": SMS_TYPE,
"type": TemplateType.SMS,
"created_at": "2017-02-10T18:25:43.511Z",
"updated_at": None,
"version": 1,
@@ -160,7 +160,7 @@ invalid_json_get_all_response = [
"templates": [
{
"id": str(uuid.uuid4()),
"type": SMS_TYPE,
"type": TemplateType.SMS,
"updated_at": None,
"version": 1,
"created_by": "someone@test.com",
@@ -176,7 +176,7 @@ invalid_json_get_all_response = [
"templates": [
{
"id": str(uuid.uuid4()),
"type": SMS_TYPE,
"type": TemplateType.SMS,
"created_at": "2017-02-10T18:25:43.511Z",
"version": 1,
"created_by": "someone@test.com",
@@ -192,7 +192,7 @@ invalid_json_get_all_response = [
"templates": [
{
"id": str(uuid.uuid4()),
"type": SMS_TYPE,
"type": TemplateType.SMS,
"created_at": "2017-02-10T18:25:43.511Z",
"updated_at": None,
"created_by": "someone@test.com",
@@ -208,7 +208,7 @@ invalid_json_get_all_response = [
"templates": [
{
"id": str(uuid.uuid4()),
"type": SMS_TYPE,
"type": TemplateType.SMS,
"created_at": "2017-02-10T18:25:43.511Z",
"updated_at": None,
"version": 1,
@@ -224,7 +224,7 @@ invalid_json_get_all_response = [
"templates": [
{
"id": str(uuid.uuid4()),
"type": SMS_TYPE,
"type": TemplateType.SMS,
"created_at": "2017-02-10T18:25:43.511Z",
"updated_at": None,
"version": 1,
@@ -239,7 +239,7 @@ invalid_json_get_all_response = [
{
"templates": [
{
"type": SMS_TYPE,
"type": TemplateType.SMS,
"created_at": "2017-02-10T18:25:43.511Z",
"updated_at": None,
"created_by": "someone@test.com",
@@ -256,19 +256,19 @@ invalid_json_get_all_response = [
]
@pytest.mark.parametrize("template_type", TEMPLATE_TYPES)
@pytest.mark.parametrize("template_type", list(TemplateType))
def test_get_all_template_request_schema_against_no_args_is_valid(template_type):
data = {}
assert validate(data, get_all_template_request) == data
@pytest.mark.parametrize("template_type", TEMPLATE_TYPES)
@pytest.mark.parametrize("template_type", list(TemplateType))
def test_get_all_template_request_schema_against_valid_args_is_valid(template_type):
data = {"type": template_type}
assert validate(data, get_all_template_request) == data
@pytest.mark.parametrize("template_type", TEMPLATE_TYPES)
@pytest.mark.parametrize("template_type", list(TemplateType))
def test_get_all_template_request_schema_against_invalid_args_is_invalid(template_type):
data = {"type": "unknown"}