56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
|
|
import unittest
|
||
|
|
from fastapi.testclient import TestClient
|
||
|
|
|
||
|
|
import main
|
||
|
|
from db import connect, create
|
||
|
|
|
||
|
|
|
||
|
|
class TestShoppingCurrentStructureV2(unittest.IsolatedAsyncioTestCase):
|
||
|
|
async def asyncSetUp(self):
|
||
|
|
self.conn = await connect(":memory:")
|
||
|
|
await create(self.conn)
|
||
|
|
|
||
|
|
async def override_get_db():
|
||
|
|
try:
|
||
|
|
yield self.conn
|
||
|
|
finally:
|
||
|
|
pass
|
||
|
|
|
||
|
|
main.app.dependency_overrides[main.get_db] = override_get_db
|
||
|
|
self.client = TestClient(main.app)
|
||
|
|
|
||
|
|
# Register user and create a household
|
||
|
|
r = self.client.post(
|
||
|
|
"/api/v1/auth/register",
|
||
|
|
json={"email": "s2@test.com", "password": "pw", "displayName": "S2"},
|
||
|
|
)
|
||
|
|
assert r.status_code == 200, r.text
|
||
|
|
token = r.json()["accessToken"]
|
||
|
|
self.headers = {"Authorization": f"Bearer {token}"}
|
||
|
|
|
||
|
|
r = self.client.post("/api/v1/households", headers=self.headers, json={"name": "H"})
|
||
|
|
assert r.status_code == 200, r.text
|
||
|
|
self.slug = r.json()["slug"]
|
||
|
|
|
||
|
|
async def asyncTearDown(self):
|
||
|
|
await self.conn.close()
|
||
|
|
main.app.dependency_overrides.clear()
|
||
|
|
|
||
|
|
def test_current_payload_keys(self):
|
||
|
|
r = self.client.get(
|
||
|
|
f"/api/v1/households/{self.slug}/shopping/current",
|
||
|
|
headers=self.headers,
|
||
|
|
)
|
||
|
|
assert r.status_code == 200, r.text
|
||
|
|
body = r.json()
|
||
|
|
for key in (
|
||
|
|
"outstandingItems",
|
||
|
|
"requestedMeals",
|
||
|
|
"purchasedItems",
|
||
|
|
"shoppingListLookup",
|
||
|
|
"ingredientsLookup",
|
||
|
|
"recipesLookup",
|
||
|
|
"mealsLookup",
|
||
|
|
):
|
||
|
|
assert key in body
|