45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
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()
|