Skip to content

Commit

Permalink
Update tests to set session data the new way
Browse files Browse the repository at this point in the history
  • Loading branch information
afred committed Nov 16, 2023
1 parent 36ce4d2 commit c3588d6
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions tests/test_batch_actions.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import pytest
from fastapi.testclient import TestClient
from httpx import AsyncClient
from typing import Type, Callable
from chowda.config import AUTH0_API_AUDIENCE
from starlette.responses import Response


@pytest.mark.asyncio
@pytest.mark.skip(reason="TODO: Setting session data for test is buggy")
async def test_download_mmif_as_clammer(
async_client: AsyncClient, set_session_data: Type[Callable]
):
set_session_data(
{'user': {"name": "test user", f"{AUTH0_API_AUDIENCE}/roles": ["clammer"]}}
)

async def test_download_mmif_as_clammer(async_client: AsyncClient):
async with async_client as ac:
await ac.post(
"/test/session",
json={
"user": {
"name": "test user",
f"{AUTH0_API_AUDIENCE}/roles": ["clammer"],
}
},
)
response = await ac.get(
"/admin/api/batch/action",
params={"pks": [2, 3], "name": "download_mmif"},
Expand All @@ -22,15 +26,17 @@ async def test_download_mmif_as_clammer(


@pytest.mark.asyncio
@pytest.mark.skip(reason="TODO: Setting session data for test is buggy")
async def test_download_mmif_as_admin(
async_client: AsyncClient, set_session_data: Type[Callable]
):
set_session_data(
{'user': {"name": "test user", f"{AUTH0_API_AUDIENCE}/roles": ["admin"]}}
)

async def test_download_mmif_as_admin(async_client: AsyncClient):
async with async_client as ac:
await ac.post(
"/test/session",
json={
"user": {
"name": "test user",
f"{AUTH0_API_AUDIENCE}/roles": ["admin"],
}
},
)
response = await ac.get(
"/admin/api/batch/action",
params={"pks": [2, 3], "name": "download_mmif"},
Expand All @@ -39,11 +45,7 @@ async def test_download_mmif_as_admin(


@pytest.mark.asyncio
@pytest.mark.skip(reason="TODO: Setting session data for test is buggy")
async def test_download_mmif_unauthenticated(
async_client: AsyncClient, set_session_data: Type[Callable]
):
set_session_data(None)
async def test_download_mmif_unauthenticated(async_client: AsyncClient):
"""Assumes no user is in the session; responds with 401 Unauthorized."""
async with async_client as ac:
response = await ac.get(
Expand All @@ -54,15 +56,18 @@ async def test_download_mmif_unauthenticated(


@pytest.mark.asyncio
@pytest.mark.skip(reason="TODO: Setting session data for test is buggy")
async def test_download_mmif_insufficient_role(
async_client: AsyncClient, set_session_data: Type[Callable]
):
set_session_data(
{'user': {"name": "test user", f"{AUTH0_API_AUDIENCE}/roles": ["peon"]}}
)

async def test_download_mmif_insufficient_role(async_client: AsyncClient):
async with async_client as ac:
await ac.post(
"/test/session",
json={
"user": {
"name": "test user",
f"{AUTH0_API_AUDIENCE}/roles": ["peon"],
}
},
)

response = await ac.get(
"/admin/api/batch/action",
params={"pks": [2, 3], "name": "download_mmif"},
Expand Down

0 comments on commit c3588d6

Please sign in to comment.