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
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