Skip to content

Commit

Permalink
add simple tests of query model field validation
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssadai committed Oct 24, 2024
1 parent e49fd0d commit 593bd6e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import httpx
import pytest
from fastapi import status
from fastapi.exceptions import HTTPException

from app.api.models import QueryModel


@pytest.fixture()
Expand Down Expand Up @@ -241,3 +244,21 @@ async def mock_httpx_get(self, **kwargs):
response = test_app.get("/query")

assert response.status_code == status.HTTP_200_OK


@pytest.mark.parametrize("valid_iscontrol", ["true", "True", "TRUE"])
def test_valid_iscontrol_values_unchanged(valid_iscontrol):
"""Test that valid values for the 'is_control' field are accepted without modification or errors."""
example_fquery = QueryModel(is_control=valid_iscontrol)
assert example_fquery.is_control == valid_iscontrol


@pytest.mark.parametrize("invalid_iscontrol", ["false", 52])
def test_invalid_iscontrol_value_raises_error(invalid_iscontrol):
"""Test that invalid values for the 'is_control' field fail model validation and raise an informative HTTPException."""
with pytest.raises(HTTPException) as exc:
QueryModel(is_control=invalid_iscontrol)

assert "'is_control' must be either set to 'true' or omitted" in str(
exc.value
)

0 comments on commit 593bd6e

Please sign in to comment.