add a few first tests for /movies web route
This commit is contained in:
parent
bd3e35936a
commit
a468c8ad60
4 changed files with 71 additions and 2 deletions
20
poetry.lock
generated
20
poetry.lock
generated
|
|
@ -337,6 +337,20 @@ toml = "*"
|
||||||
[package.extras]
|
[package.extras]
|
||||||
testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"]
|
testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pytest-asyncio"
|
||||||
|
version = "0.16.0"
|
||||||
|
description = "Pytest support for asyncio."
|
||||||
|
category = "dev"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">= 3.6"
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
pytest = ">=5.4.0"
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
testing = ["coverage", "hypothesis (>=5.7.1)"]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "requests"
|
name = "requests"
|
||||||
version = "2.26.0"
|
version = "2.26.0"
|
||||||
|
|
@ -497,7 +511,7 @@ python-versions = "*"
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.10"
|
python-versions = "^3.10"
|
||||||
content-hash = "d5c421072660832e6e0786b7bf183d1a0919221a87f91a82e55d060aac1af69f"
|
content-hash = "dfd40d7d9a6e61c9845c3f80365b95dfe9638c44f9261af21907cd6b070c1170"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
aiosqlite = [
|
aiosqlite = [
|
||||||
|
|
@ -660,6 +674,10 @@ pytest = [
|
||||||
{file = "pytest-6.2.5-py3-none-any.whl", hash = "sha256:7310f8d27bc79ced999e760ca304d69f6ba6c6649c0b60fb0e04a4a77cacc134"},
|
{file = "pytest-6.2.5-py3-none-any.whl", hash = "sha256:7310f8d27bc79ced999e760ca304d69f6ba6c6649c0b60fb0e04a4a77cacc134"},
|
||||||
{file = "pytest-6.2.5.tar.gz", hash = "sha256:131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89"},
|
{file = "pytest-6.2.5.tar.gz", hash = "sha256:131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89"},
|
||||||
]
|
]
|
||||||
|
pytest-asyncio = [
|
||||||
|
{file = "pytest-asyncio-0.16.0.tar.gz", hash = "sha256:7496c5977ce88c34379df64a66459fe395cd05543f0a2f837016e7144391fcfb"},
|
||||||
|
{file = "pytest_asyncio-0.16.0-py3-none-any.whl", hash = "sha256:5f2a21273c47b331ae6aa5b36087047b4899e40f03f18397c0e65fa5cca54e9b"},
|
||||||
|
]
|
||||||
requests = [
|
requests = [
|
||||||
{file = "requests-2.26.0-py2.py3-none-any.whl", hash = "sha256:6c1246513ecd5ecd4528a0906f910e8f0f9c6b8ec72030dc9fd154dc1a6efd24"},
|
{file = "requests-2.26.0-py2.py3-none-any.whl", hash = "sha256:6c1246513ecd5ecd4528a0906f910e8f0f9c6b8ec72030dc9fd154dc1a6efd24"},
|
||||||
{file = "requests-2.26.0.tar.gz", hash = "sha256:b8aa58f8cf793ffd8782d3d8cb19e66ef36f7aba4353eec859e74678b01b07a7"},
|
{file = "requests-2.26.0.tar.gz", hash = "sha256:b8aa58f8cf793ffd8782d3d8cb19e66ef36f7aba4353eec859e74678b01b07a7"},
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ pytest = "^6.2.4"
|
||||||
pyright = "*"
|
pyright = "*"
|
||||||
black = "*"
|
black = "*"
|
||||||
isort = "*"
|
isort = "*"
|
||||||
|
pytest-asyncio = "^0.16.0"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core>=1.0.0"]
|
requires = ["poetry-core>=1.0.0"]
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
cd "$RUN_DIR"
|
cd "$RUN_DIR"
|
||||||
|
|
||||||
|
dbfile="$RUN_DIR/tests.sqlite.local"
|
||||||
|
|
||||||
|
trap 'rm "$dbfile"' EXIT TERM INT QUIT
|
||||||
|
|
||||||
[ -z "${DEBUG:-}" ] || set -x
|
[ -z "${DEBUG:-}" ] || set -x
|
||||||
|
|
||||||
exec python -m pytest "$@"
|
UNWIND_STORAGE="$dbfile" \
|
||||||
|
python -m pytest "$@"
|
||||||
|
|
|
||||||
45
tests/test_web.py
Normal file
45
tests/test_web.py
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
from starlette.testclient import TestClient
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from unwind import create_app
|
||||||
|
from unwind import db, models
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.asyncio
|
||||||
|
|
||||||
|
app = create_app()
|
||||||
|
|
||||||
|
|
||||||
|
async def test_app():
|
||||||
|
await db.open_connection_pool()
|
||||||
|
conn = db.shared_connection()
|
||||||
|
|
||||||
|
async with conn.transaction(force_rollback=True):
|
||||||
|
|
||||||
|
client = TestClient(app)
|
||||||
|
response = client.get("/api/v1/movies")
|
||||||
|
assert response.status_code == 403
|
||||||
|
|
||||||
|
client.auth = "user1", "secret1"
|
||||||
|
|
||||||
|
response = client.get("/api/v1/movies")
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json() == []
|
||||||
|
|
||||||
|
m = models.Movie(
|
||||||
|
title="test movie",
|
||||||
|
release_year=2013,
|
||||||
|
media_type="Movie",
|
||||||
|
imdb_id="tt12345678",
|
||||||
|
genres={"genre-1"},
|
||||||
|
)
|
||||||
|
await db.add(m)
|
||||||
|
|
||||||
|
response = client.get("/api/v1/movies", params={"include_unrated": 1})
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json() == [{**db.asplain(m), "user_scores": []}]
|
||||||
|
|
||||||
|
response = client.get("/api/v1/movies", params={"imdb_id": m.imdb_id})
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json() == [db.asplain(m)]
|
||||||
|
|
||||||
|
await db.close_connection_pool()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue