Skip to content

Commit

Permalink
Fix e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherSpelt committed Oct 28, 2024
1 parent f6f605b commit 6fd5625
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 105 deletions.
2 changes: 1 addition & 1 deletion amt/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Project(Base):

id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(255))
lifecycle: Mapped[Lifecycles | None] = mapped_column(ENUM(Lifecycles), nullable=True)
lifecycle: Mapped[Lifecycles | None] = mapped_column(ENUM(Lifecycles, name="lifecycle"), nullable=True)
system_card_json: Mapped[dict[str, Any]] = mapped_column(JSON, default=dict)
last_edited: Mapped[datetime] = mapped_column(server_default=func.now(), onupdate=func.now(), nullable=False)

Expand Down
10 changes: 10 additions & 0 deletions compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
amt-test:
build:
context: .
dockerfile: Dockerfile
target: test
image: ghcr.io/minbzk/amt-test:latest
env_file:
- path: prod.env
required: true
3 changes: 2 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions prod.env
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,3 @@ POSTGRES_PASSWORD=changethis
# Database viewer
PGADMIN_DEFAULT_PASSWORD=changethis
PGADMIN_DEFAULT_EMAIL=[email protected]

OIDC_CLIENT_ID=AMT
OIDC_CLIENT_SECRET=uIeFiKFazNEIbpJ3wzj0lZLLSJXefeld
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ liccheck = "^0.9.2"
authlib = "^1.3.2"
aiosqlite = "^0.20.0"
asyncpg = "^0.30.0"
nest-asyncio = "^1.6.0"


[tool.poetry.group.test.dependencies]
pytest = "^8.3.3"
pytest-asyncio = "^0.24.0"
nest-asyncio = "^1.6.0"
pytest-mock = "^3.14.0"
coverage = "^7.6.4"
playwright = "^1.47.0"
Expand Down Expand Up @@ -141,6 +141,7 @@ markers = [
"enable_auth: marks tests that require authentication"
]


[tool.liccheck]
level = "PARANOID"
dependencies = true
Expand Down
13 changes: 8 additions & 5 deletions tests/api/routes/test_health.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from fastapi.testclient import TestClient
import pytest
from httpx import AsyncClient


def test_health_ready(client: TestClient) -> None:
response = client.get(
@pytest.mark.asyncio
async def test_health_ready(client: AsyncClient) -> None:
response = await client.get(
"/health/ready",
)
assert response.status_code == 200
assert response.headers["content-type"] == "application/json"
assert response.json() == {"status": "ok"}


def test_health_live(client: TestClient) -> None:
response = client.get(
@pytest.mark.asyncio
async def test_health_live(client: AsyncClient) -> None:
response = await client.get(
"/health/live",
)
assert response.status_code == 200
Expand Down
8 changes: 5 additions & 3 deletions tests/api/routes/test_pages.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from fastapi.testclient import TestClient
import pytest
from httpx import AsyncClient

from tests.database_test_utils import DatabaseTestUtils


def test_get_main_page(client: TestClient, db: DatabaseTestUtils) -> None:
@pytest.mark.asyncio
async def test_get_main_page(client: AsyncClient, db: DatabaseTestUtils) -> None:
# when
response = client.get("/pages/")
response = await client.get("/pages/")

# then
assert response.status_code == 200
Expand Down
76 changes: 41 additions & 35 deletions tests/api/routes/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
import pytest
from amt.api.routes.project import set_path
from amt.models import Project
from fastapi.testclient import TestClient
from httpx import AsyncClient
from pytest_mock import MockFixture

from tests.constants import default_project, default_task
from tests.database_test_utils import DatabaseTestUtils


def test_get_unknown_project(client: TestClient) -> None:
@pytest.mark.asyncio
async def test_get_unknown_project(client: AsyncClient) -> None:
# when
response = client.get("/algorithm-system/1")
response = await client.get("/algorithm-system/1")

# then
assert response.status_code == 404
Expand All @@ -21,12 +22,12 @@ def test_get_unknown_project(client: TestClient) -> None:


@pytest.mark.asyncio
async def test_get_project_tasks(client: TestClient, db: DatabaseTestUtils) -> None:
async def test_get_project_tasks(client: AsyncClient, db: DatabaseTestUtils) -> None:
# given
await db.given([default_project("testproject1"), default_task(project_id=1, status_id=1)])

# when
response = client.get("/algorithm-system/1/details/tasks")
response = await client.get("/algorithm-system/1/details/tasks")

# then
assert response.status_code == 200
Expand All @@ -38,12 +39,12 @@ async def test_get_project_tasks(client: TestClient, db: DatabaseTestUtils) -> N
# is fixed for now. Tests need to be refactored and made proper once
# the actual stored system card in a project is being rendered.
@pytest.mark.asyncio
async def test_get_system_card(client: TestClient, db: DatabaseTestUtils) -> None:
async def test_get_system_card(client: AsyncClient, db: DatabaseTestUtils) -> None:
# given
await db.given([default_project("testproject1")])

# when
response = client.get("/algorithm-system/1/details/system_card")
response = await client.get("/algorithm-system/1/details/system_card")

# then
assert response.status_code == 200
Expand All @@ -54,9 +55,10 @@ async def test_get_system_card(client: TestClient, db: DatabaseTestUtils) -> Non
# TODO: Test are now have hard coded URL paths because the system card
# is fixed for now. Tests need to be refactored and made proper once
# the actual stored system card in a project is being rendered.
def test_get_system_card_unknown_project(client: TestClient) -> None:
@pytest.mark.asyncio
async def test_get_system_card_unknown_project(client: AsyncClient) -> None:
# when
response = client.get("/algorithm-system/1/details/system_card")
response = await client.get("/algorithm-system/1/details/system_card")

# then
assert response.status_code == 404
Expand All @@ -68,12 +70,12 @@ def test_get_system_card_unknown_project(client: TestClient) -> None:
# is fixed for now. Tests need to be refactored and made proper once
# the actual stored system card in a project is being rendered.
@pytest.mark.asyncio
async def test_get_assessment_card(client: TestClient, db: DatabaseTestUtils) -> None:
async def test_get_assessment_card(client: AsyncClient, db: DatabaseTestUtils) -> None:
# given
await db.given([default_project("testproject1")])

# when
response = client.get("/algorithm-system/1/details/system_card/assessments/iama")
response = await client.get("/algorithm-system/1/details/system_card/assessments/iama")

# then
assert response.status_code == 200
Expand All @@ -84,9 +86,10 @@ async def test_get_assessment_card(client: TestClient, db: DatabaseTestUtils) ->
# TODO: Test are now have hard coded URL paths because the system card
# is fixed for now. Tests need to be refactored and made proper once
# the actual stored system card in a project is being rendered.
def test_get_assessment_card_unknown_project(client: TestClient) -> None:
@pytest.mark.asyncio
async def test_get_assessment_card_unknown_project(client: AsyncClient) -> None:
# when
response = client.get("/algorithm-system/1/details/system_card/assessments/iama")
response = await client.get("/algorithm-system/1/details/system_card/assessments/iama")

# then
assert response.status_code == 404
Expand All @@ -98,12 +101,12 @@ def test_get_assessment_card_unknown_project(client: TestClient) -> None:
# is fixed for now. Tests need to be refactored and made proper once
# the actual stored system card in a project is being rendered.
@pytest.mark.asyncio
async def test_get_assessment_card_unknown_assessment(client: TestClient, db: DatabaseTestUtils) -> None:
async def test_get_assessment_card_unknown_assessment(client: AsyncClient, db: DatabaseTestUtils) -> None:
# given
await db.given([default_project("testproject1")])

# when
response = client.get("/algorithm-system/1/details/system_card/assessments/nonexistent")
response = await client.get("/algorithm-system/1/details/system_card/assessments/nonexistent")

# then
assert response.status_code == 404
Expand All @@ -115,12 +118,12 @@ async def test_get_assessment_card_unknown_assessment(client: TestClient, db: Da
# is fixed for now. Tests need to be refactored and made proper once
# the actual stored system card in a project is being rendered.
@pytest.mark.asyncio
async def test_get_model_card(client: TestClient, db: DatabaseTestUtils) -> None:
async def test_get_model_card(client: AsyncClient, db: DatabaseTestUtils) -> None:
# given
await db.given([default_project("testproject1")])

# when
response = client.get("/algorithm-system/1/details/system_card/models/logres_iris")
response = await client.get("/algorithm-system/1/details/system_card/models/logres_iris")

# then
assert response.status_code == 200
Expand All @@ -131,9 +134,10 @@ async def test_get_model_card(client: TestClient, db: DatabaseTestUtils) -> None
# TODO: Test are now have hard coded URL paths because the system card
# is fixed for now. Tests need to be refactored and made proper once
# the actual stored system card in a project is being rendered.
def test_get_model_card_unknown_project(client: TestClient) -> None:
@pytest.mark.asyncio
async def test_get_model_card_unknown_project(client: AsyncClient) -> None:
# when
response = client.get("/algorithm-system/1/details/system_card/models/logres_iris")
response = await client.get("/algorithm-system/1/details/system_card/models/logres_iris")

# then
assert response.status_code == 404
Expand All @@ -145,12 +149,12 @@ def test_get_model_card_unknown_project(client: TestClient) -> None:
# is fixed for now. Tests need to be refactored and made proper once
# the actual stored system card in a project is being rendered.
@pytest.mark.asyncio
async def test_get_assessment_card_unknown_model_card(client: TestClient, db: DatabaseTestUtils) -> None:
async def test_get_assessment_card_unknown_model_card(client: AsyncClient, db: DatabaseTestUtils) -> None:
# given
await db.given([default_project("testproject1")])

# when
response = client.get("/algorithm-system/1/details/system_card/models/nonexistent")
response = await client.get("/algorithm-system/1/details/system_card/models/nonexistent")

# then
assert response.status_code == 404
Expand All @@ -159,12 +163,12 @@ async def test_get_assessment_card_unknown_model_card(client: TestClient, db: Da


@pytest.mark.asyncio
async def test_get_project_details(client: TestClient, db: DatabaseTestUtils) -> None:
async def test_get_project_details(client: AsyncClient, db: DatabaseTestUtils) -> None:
# given
await db.given([default_project("testproject1"), default_task(project_id=1, status_id=1)])

# when
response = client.get("/algorithm-system/1/details")
response = await client.get("/algorithm-system/1/details")

# then
assert response.status_code == 200
Expand All @@ -173,12 +177,12 @@ async def test_get_project_details(client: TestClient, db: DatabaseTestUtils) ->


@pytest.mark.asyncio
async def test_get_system_card_requirements(client: TestClient, db: DatabaseTestUtils) -> None:
async def test_get_system_card_requirements(client: AsyncClient, db: DatabaseTestUtils) -> None:
# given
await db.given([default_project("testproject1"), default_task(project_id=1, status_id=1)])

# when
response = client.get("/algorithm-system/1/details/system_card/requirements")
response = await client.get("/algorithm-system/1/details/system_card/requirements")

# then
assert response.status_code == 200
Expand All @@ -187,12 +191,12 @@ async def test_get_system_card_requirements(client: TestClient, db: DatabaseTest


@pytest.mark.asyncio
async def test_get_system_card_data_page(client: TestClient, db: DatabaseTestUtils) -> None:
async def test_get_system_card_data_page(client: AsyncClient, db: DatabaseTestUtils) -> None:
# given
await db.given([default_project("testproject1"), default_task(project_id=1, status_id=1)])

# when
response = client.get("/algorithm-system/1/details/system_card/data")
response = await client.get("/algorithm-system/1/details/system_card/data")

# then
assert response.status_code == 200
Expand All @@ -201,12 +205,12 @@ async def test_get_system_card_data_page(client: TestClient, db: DatabaseTestUti


@pytest.mark.asyncio
async def test_get_system_card_instruments(client: TestClient, db: DatabaseTestUtils) -> None:
async def test_get_system_card_instruments(client: AsyncClient, db: DatabaseTestUtils) -> None:
# given
await db.given([default_project("testproject1"), default_task(project_id=1, status_id=1)])

# when
response = client.get("/algorithm-system/1/details/system_card/instruments")
response = await client.get("/algorithm-system/1/details/system_card/instruments")

# then
assert response.status_code == 200
Expand All @@ -215,12 +219,12 @@ async def test_get_system_card_instruments(client: TestClient, db: DatabaseTestU


@pytest.mark.asyncio
async def test_get_project_edit(client: TestClient, db: DatabaseTestUtils) -> None:
async def test_get_project_edit(client: AsyncClient, db: DatabaseTestUtils) -> None:
# given
await db.given([default_project("testproject1")])

# when
response = client.get("/algorithm-system/1/edit/system_card/lifecycle")
response = await client.get("/algorithm-system/1/edit/system_card/lifecycle")

# then
assert response.status_code == 200
Expand All @@ -230,12 +234,12 @@ async def test_get_project_edit(client: TestClient, db: DatabaseTestUtils) -> No


@pytest.mark.asyncio
async def test_get_project_cancel(client: TestClient, db: DatabaseTestUtils) -> None:
async def test_get_project_cancel(client: AsyncClient, db: DatabaseTestUtils) -> None:
# given
await db.given([default_project("testproject1")])

# when
response = client.get("/algorithm-system/1/cancel/system_card/lifecycle")
response = await client.get("/algorithm-system/1/cancel/system_card/lifecycle")

# then
assert response.status_code == 200
Expand All @@ -245,14 +249,16 @@ async def test_get_project_cancel(client: TestClient, db: DatabaseTestUtils) ->


@pytest.mark.asyncio
async def test_get_project_update(client: TestClient, mocker: MockFixture, db: DatabaseTestUtils) -> None:
async def test_get_project_update(client: AsyncClient, mocker: MockFixture, db: DatabaseTestUtils) -> None:
# given
await db.given([default_project("testproject1")])
client.cookies["fastapi-csrf-token"] = "1"
mocker.patch("fastapi_csrf_protect.CsrfProtect.validate_csrf", new_callable=mocker.AsyncMock)

# when
response = client.put("/algorithm-system/1/update/name", json={"value": "Test Name"}, headers={"X-CSRF-Token": "1"})
response = await client.put(
"/algorithm-system/1/update/name", json={"value": "Test Name"}, headers={"X-CSRF-Token": "1"}
)

# then
assert response.status_code == 200
Expand Down
Loading

0 comments on commit 6fd5625

Please sign in to comment.