-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updates validation routine when editing Collections and Batches * Validates GUID strings by looking them up in the database. * Adds those records to the DB session Starlette-admin uses for saving records. * Adds initial tests for CRUD on Batches, however skipping for now until we figure out how to auth users for tests. Also, * Removes rule enforcing single quotes to double quotes. --------- Co-authored-by: Harpo Harbert <ryan_harbert@wgbh.org>
- Loading branch information
Showing
6 changed files
with
142 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from fastapi import FastAPI | ||
from fastapi.testclient import TestClient | ||
from httpx import AsyncClient | ||
from pytest import fixture, mark | ||
from pytest_asyncio import fixture as async_fixture | ||
from sqlmodel import Session, select | ||
|
||
from chowda.db import engine | ||
from chowda.models import Batch | ||
|
||
|
||
@fixture | ||
def app(): | ||
from chowda.app import app | ||
|
||
return app | ||
|
||
|
||
@fixture | ||
def client(app: FastAPI): | ||
return TestClient(app) | ||
|
||
|
||
@async_fixture | ||
async def async_client(app: FastAPI): | ||
async with AsyncClient(app=app, base_url='http://testserver') as c: | ||
yield c | ||
|
||
|
||
@fixture | ||
def session(): | ||
return Session(engine) | ||
|
||
|
||
@fixture | ||
def unsaved_batch(): | ||
from tests.factories import BatchFactory | ||
|
||
return BatchFactory.build() | ||
|
||
|
||
@mark.anyio | ||
@mark.skip("Redirecting due to user being unauthenticated in tests") | ||
async def test_create_batch( | ||
async_client: AsyncClient, | ||
session: Session, | ||
unsaved_batch: Batch, | ||
): | ||
response = await async_client.post( | ||
'/admin/batch/create', | ||
data=unsaved_batch.dict(), | ||
follow_redirects=False, | ||
) | ||
assert response.status_code == 303 | ||
stmt = select(Batch).where(Batch.name == unsaved_batch.name) | ||
batch = session.execute(stmt).scalar_one() | ||
assert batch is not None |