diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_data.py b/tests/test_data.py similarity index 90% rename from test_data.py rename to tests/test_data.py index 7dd6789..33a50b3 100644 --- a/test_data.py +++ b/tests/test_data.py @@ -80,6 +80,26 @@ class Products: raw_data={}, ) + apple = products.Product( + id=0, + name="Apple", + product_id="0", + link="https://www.woolworths.com.au/shop/productdetails/0/apple", + img_small="https://cdn0.woolworths.media/content/wowproductimages/small/0.jpg", + img_large="https://cdn0.woolworths.media/content/wowproductimages/large/0.jpg", + raw_data={}, + ) + + banana = products.Product( + id=0, + name="Banana", + product_id="0", + link="https://www.woolworths.com.au/shop/productdetails/0/banana", + img_small="https://cdn0.woolworths.media/content/wowproductimages/small/0.jpg", + img_large="https://cdn0.woolworths.media/content/wowproductimages/large/0.jpg", + raw_data={}, + ) + _tags = { broccoli.product_id: ['broccoli', 'fresh broccoli'], garlic_bread.product_id: ['garlic bread', 'bread', 'garlic', 'frozen garlic bread'], @@ -92,6 +112,16 @@ class Products: import ingredients class Ingredients: + one_apple = ingredients.Ingredient( + id=0, + line='1 Apple', + name='Apple', + unit='Items', + quantity='1', + preparation='', + product=Products.apple, + ) + broccoli_chopped_1kg = ingredients.Ingredient( id=0, line='1kg Broccoli, Chopped', diff --git a/tests.py b/tests/test_main.py similarity index 96% rename from tests.py rename to tests/test_main.py index bdc87e0..4080887 100644 --- a/tests.py +++ b/tests/test_main.py @@ -1,14 +1,13 @@ import unittest import datetime -import test_data +import tests.test_data as test_data import importlib def reload_test_data(): global test_data test_data = importlib.reload(test_data) -import pathlib from db import connect, create import products.db as products_db @@ -24,14 +23,13 @@ def unique(lst: list, key: callable): class TestProducts(unittest.IsolatedAsyncioTestCase): async def asyncSetUp(self): - self.conn = await connect('./testdb.db') + self.conn = await connect(':memory:') await create(self.conn) reload_test_data() return await super().asyncSetUp() async def asyncTearDown(self) -> None: await self.conn.close() - pathlib.Path('./testdb.db').unlink(missing_ok=True) return await super().asyncTearDown() async def testCreateAndFind(self) -> None: @@ -52,8 +50,7 @@ import main class TestRecipe(unittest.IsolatedAsyncioTestCase): async def asyncSetUp(self): - pathlib.Path('./testdb.db').unlink(missing_ok=True) - self.conn = await connect('./testdb.db') + self.conn = await connect(':memory:') await create(self.conn) await test_data.create_persons(self.conn) reload_test_data() @@ -62,7 +59,6 @@ class TestRecipe(unittest.IsolatedAsyncioTestCase): async def asyncTearDown(self) -> None: await self.conn.close() - pathlib.Path('./testdb.db').unlink(missing_ok=True) return await super().asyncTearDown() async def testCreateAndFind(self) -> None: @@ -118,8 +114,7 @@ import meals class TestMeals(unittest.IsolatedAsyncioTestCase): async def asyncSetUp(self): - pathlib.Path('./testdb.db').unlink(missing_ok=True) - self.conn = await connect('./testdb.db') + self.conn = await connect(':memory:') await create(self.conn) await test_data.create_persons(self.conn) reload_test_data() @@ -127,7 +122,6 @@ class TestMeals(unittest.IsolatedAsyncioTestCase): async def asyncTearDown(self) -> None: await self.conn.close() - pathlib.Path('./testdb.db').unlink(missing_ok=True) return await super().asyncTearDown() async def testMultiplePariticpants(self) -> None: