2025-11-01 11:35:10 +00:00
|
|
|
from api.dtos import MemberRef
|
2024-04-25 04:57:39 +00:00
|
|
|
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2025-11-01 11:35:10 +00:00
|
|
|
class MemberRefs:
|
|
|
|
|
# Fixture MemberRef objects (id/display_name). Backcompat: .name property returns display_name.
|
|
|
|
|
jacob = MemberRef(id=1, display_name="Jacob")
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2025-11-01 11:35:10 +00:00
|
|
|
ryan = MemberRef(id=2, display_name="Ryan")
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2025-11-01 11:35:10 +00:00
|
|
|
ellie = MemberRef(id=3, display_name="Ellie")
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2025-11-01 11:35:10 +00:00
|
|
|
chris = MemberRef(id=4, display_name="Chris")
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2024-04-25 04:57:39 +00:00
|
|
|
|
2024-04-28 03:37:01 +00:00
|
|
|
import products
|
2024-04-25 04:57:39 +00:00
|
|
|
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2024-04-25 04:57:39 +00:00
|
|
|
class Products:
|
2024-04-28 03:37:01 +00:00
|
|
|
broccoli = products.Product(
|
2024-04-25 04:57:39 +00:00
|
|
|
id=0,
|
2025-10-18 03:26:42 +00:00
|
|
|
shop_code="woolworths",
|
2024-04-28 03:37:01 +00:00
|
|
|
name="Fresh Broccoli",
|
|
|
|
|
product_id="134681",
|
2024-05-19 12:35:37 +00:00
|
|
|
quantity=1,
|
|
|
|
|
unit="Items",
|
2024-04-28 03:37:01 +00:00
|
|
|
link="https://www.woolworths.com.au/shop/productdetails/134681/fresh-broccoli",
|
|
|
|
|
img_small="https://cdn0.woolworths.media/content/wowproductimages/small/134681.jpg",
|
|
|
|
|
img_large="https://cdn0.woolworths.media/content/wowproductimages/large/134681.jpg",
|
2024-04-25 04:57:39 +00:00
|
|
|
)
|
|
|
|
|
|
2024-04-28 03:37:01 +00:00
|
|
|
garlic_bread = products.Product(
|
2024-04-25 04:57:39 +00:00
|
|
|
id=0,
|
2025-10-18 03:26:42 +00:00
|
|
|
shop_code="woolworths",
|
2024-04-28 03:37:01 +00:00
|
|
|
name="La Famiglia Garlic Bread",
|
|
|
|
|
product_id="294517",
|
2024-05-19 12:35:37 +00:00
|
|
|
quantity=1,
|
|
|
|
|
unit="Loaf",
|
2024-04-28 03:37:01 +00:00
|
|
|
link="https://www.woolworths.com.au/shop/productdetails/294517/la-famiglia-garlic-bread",
|
|
|
|
|
img_small="https://cdn0.woolworths.media/content/wowproductimages/small/294517.jpg",
|
|
|
|
|
img_large="https://cdn0.woolworths.media/content/wowproductimages/large/294517.jpg",
|
2024-04-25 04:57:39 +00:00
|
|
|
)
|
|
|
|
|
|
2024-04-28 03:37:01 +00:00
|
|
|
beans_round = products.Product(
|
|
|
|
|
id=0,
|
2025-10-18 03:26:42 +00:00
|
|
|
shop_code="woolworths",
|
2024-04-28 03:37:01 +00:00
|
|
|
name="Beans Round",
|
|
|
|
|
product_id="134072",
|
2024-05-19 12:35:37 +00:00
|
|
|
quantity=1,
|
|
|
|
|
unit="kg",
|
2024-04-28 03:37:01 +00:00
|
|
|
link="https://www.woolworths.com.au/shop/productdetails/134072/beans-round",
|
|
|
|
|
img_small="https://cdn0.woolworths.media/content/wowproductimages/small/134072.jpg",
|
|
|
|
|
img_large="https://cdn0.woolworths.media/content/wowproductimages/large/134072.jpg",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
western_star_unsalted_butter_chefs_choice = products.Product(
|
|
|
|
|
id=0,
|
2025-10-18 03:26:42 +00:00
|
|
|
shop_code="woolworths",
|
2024-04-28 03:37:01 +00:00
|
|
|
name="Western Star Unsalted Butter Chef's Choice",
|
|
|
|
|
product_id="712251",
|
2024-05-19 12:35:37 +00:00
|
|
|
quantity=500,
|
|
|
|
|
unit="g",
|
2024-04-28 03:37:01 +00:00
|
|
|
link="https://www.woolworths.com.au/shop/productdetails/712251/western-star-unsalted-butter-chef-s-choice",
|
|
|
|
|
img_small="https://cdn0.woolworths.media/content/wowproductimages/small/712251.jpg",
|
|
|
|
|
img_large="https://cdn0.woolworths.media/content/wowproductimages/large/712251.jpg",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
saxa_iodised_table_salt_shaker = products.Product(
|
|
|
|
|
id=0,
|
2025-10-18 03:26:42 +00:00
|
|
|
shop_code="woolworths",
|
2024-04-28 03:37:01 +00:00
|
|
|
name="Saxa Iodised Table Salt Shaker",
|
2024-05-19 12:35:37 +00:00
|
|
|
quantity=750,
|
|
|
|
|
unit="g",
|
2024-04-28 03:37:01 +00:00
|
|
|
product_id="33245",
|
|
|
|
|
link="https://www.woolworths.com.au/shop/productdetails/33245/saxa-iodised-table-salt-shaker",
|
|
|
|
|
img_small="https://cdn0.woolworths.media/content/wowproductimages/small/033245.jpg",
|
|
|
|
|
img_large="https://cdn0.woolworths.media/content/wowproductimages/large/033245.jpg",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
mckenzies_pepper_black_ground = products.Product(
|
|
|
|
|
id=0,
|
2025-10-18 03:26:42 +00:00
|
|
|
shop_code="woolworths",
|
2024-04-28 03:37:01 +00:00
|
|
|
name="Mckenzie's Pepper Black Ground",
|
2024-05-19 12:35:37 +00:00
|
|
|
quantity=100,
|
|
|
|
|
unit="g",
|
2024-04-28 03:37:01 +00:00
|
|
|
product_id="75194",
|
|
|
|
|
link="https://www.woolworths.com.au/shop/productdetails/75194/mckenzie-s-pepper-black-ground",
|
|
|
|
|
img_small="https://cdn0.woolworths.media/content/wowproductimages/small/075194.jpg",
|
|
|
|
|
img_large="https://cdn0.woolworths.media/content/wowproductimages/large/075194.jpg",
|
|
|
|
|
)
|
|
|
|
|
|
2024-05-17 09:07:17 +00:00
|
|
|
apple = products.Product(
|
|
|
|
|
id=0,
|
2025-10-18 03:26:42 +00:00
|
|
|
shop_code="woolworths",
|
2024-05-17 09:07:17 +00:00
|
|
|
name="Apple",
|
2024-05-18 07:05:01 +00:00
|
|
|
product_id="3542",
|
2024-05-19 12:35:37 +00:00
|
|
|
quantity=1,
|
|
|
|
|
unit="Items",
|
2024-05-17 09:07:17 +00:00
|
|
|
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",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
banana = products.Product(
|
|
|
|
|
id=0,
|
2025-10-18 03:26:42 +00:00
|
|
|
shop_code="woolworths",
|
2024-05-17 09:07:17 +00:00
|
|
|
name="Banana",
|
2024-05-18 07:05:01 +00:00
|
|
|
product_id="214",
|
2024-05-19 12:35:37 +00:00
|
|
|
quantity=1,
|
|
|
|
|
unit="Items",
|
2024-05-17 09:07:17 +00:00
|
|
|
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",
|
|
|
|
|
)
|
|
|
|
|
|
2024-04-28 03:37:01 +00:00
|
|
|
_tags = {
|
2025-10-18 03:26:42 +00:00
|
|
|
apple.product_id: ["apple", "fruit", "fresh fruit"],
|
|
|
|
|
banana.product_id: ["banana", "fruit", "fresh fruit"],
|
|
|
|
|
broccoli.product_id: ["broccoli", "fresh broccoli"],
|
|
|
|
|
garlic_bread.product_id: ["garlic bread", "bread", "garlic", "frozen garlic bread"],
|
|
|
|
|
beans_round.product_id: ["beans", "green beans", "fresh green beans", "fresh beans"],
|
|
|
|
|
western_star_unsalted_butter_chefs_choice.product_id: [
|
|
|
|
|
"butter",
|
|
|
|
|
"unsalted butter",
|
|
|
|
|
"salted butter",
|
|
|
|
|
],
|
|
|
|
|
saxa_iodised_table_salt_shaker.product_id: ["salt", "iodised salt", "kosher salt"],
|
|
|
|
|
mckenzies_pepper_black_ground.product_id: [
|
|
|
|
|
"pepper",
|
|
|
|
|
"black pepper",
|
|
|
|
|
"ground pepper",
|
|
|
|
|
"fresh ground pepper",
|
|
|
|
|
],
|
2024-04-28 03:37:01 +00:00
|
|
|
}
|
|
|
|
|
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2024-04-28 03:37:01 +00:00
|
|
|
import ingredients
|
2024-04-25 04:57:39 +00:00
|
|
|
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2024-04-25 04:57:39 +00:00
|
|
|
class Ingredients:
|
2024-05-17 09:07:17 +00:00
|
|
|
one_apple = ingredients.Ingredient(
|
|
|
|
|
id=0,
|
2025-10-18 03:26:42 +00:00
|
|
|
line="1 Apple",
|
|
|
|
|
name="Apple",
|
|
|
|
|
unit="Items",
|
2025-11-01 10:37:35 +00:00
|
|
|
quantity=1.0,
|
2025-10-18 03:26:42 +00:00
|
|
|
preparation="",
|
2024-05-17 09:07:17 +00:00
|
|
|
product=Products.apple,
|
|
|
|
|
)
|
|
|
|
|
|
2024-04-28 03:37:01 +00:00
|
|
|
broccoli_chopped_1kg = ingredients.Ingredient(
|
2024-04-25 04:57:39 +00:00
|
|
|
id=0,
|
2025-10-18 03:26:42 +00:00
|
|
|
line="1kg Broccoli, Chopped",
|
|
|
|
|
name="Broccoli",
|
|
|
|
|
unit="kg",
|
2025-11-01 10:37:35 +00:00
|
|
|
quantity=1.0,
|
2025-10-18 03:26:42 +00:00
|
|
|
preparation="Chopped",
|
2024-04-25 04:57:39 +00:00
|
|
|
product=Products.broccoli,
|
|
|
|
|
)
|
|
|
|
|
|
2024-04-28 03:37:01 +00:00
|
|
|
garlic_bread_1_loaf = ingredients.Ingredient(
|
2024-04-25 04:57:39 +00:00
|
|
|
id=0,
|
2025-10-18 03:26:42 +00:00
|
|
|
line="1 Loaf Garlic Bread",
|
|
|
|
|
name="Garlic Bread",
|
|
|
|
|
unit="Loaf",
|
2025-11-01 10:37:35 +00:00
|
|
|
quantity=1.0,
|
2025-10-18 03:26:42 +00:00
|
|
|
preparation="",
|
2024-04-25 04:57:39 +00:00
|
|
|
product=Products.garlic_bread,
|
|
|
|
|
)
|
|
|
|
|
|
2024-04-28 03:37:01 +00:00
|
|
|
green_beans = ingredients.Ingredient(
|
|
|
|
|
id=0,
|
|
|
|
|
line="1 pound green beans (fresh)",
|
|
|
|
|
name="green beans",
|
|
|
|
|
unit="Pound",
|
|
|
|
|
quantity=1.0,
|
|
|
|
|
preparation="",
|
|
|
|
|
product=Products.beans_round,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
butter = ingredients.Ingredient(
|
|
|
|
|
id=0,
|
|
|
|
|
line="1 to 2 tablespoons butter",
|
|
|
|
|
name="butter",
|
|
|
|
|
unit="Tablespoon",
|
|
|
|
|
quantity=1.0,
|
|
|
|
|
preparation="",
|
|
|
|
|
product=Products.western_star_unsalted_butter_chefs_choice,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
salt = ingredients.Ingredient(
|
|
|
|
|
id=0,
|
|
|
|
|
line="Salt (to taste)",
|
|
|
|
|
name="Salt",
|
|
|
|
|
unit="Items",
|
|
|
|
|
quantity=1.0,
|
|
|
|
|
preparation="",
|
|
|
|
|
product=Products.saxa_iodised_table_salt_shaker,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
freshly_ground_black_pepper = ingredients.Ingredient(
|
|
|
|
|
id=0,
|
|
|
|
|
line="Freshly ground black pepper (to taste)",
|
|
|
|
|
name="Freshly ground black pepper",
|
|
|
|
|
unit="Items",
|
|
|
|
|
quantity=1.0,
|
|
|
|
|
preparation="",
|
|
|
|
|
product=Products.mckenzies_pepper_black_ground,
|
|
|
|
|
)
|
|
|
|
|
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2024-04-28 03:37:01 +00:00
|
|
|
import recipes
|
2024-04-25 04:57:39 +00:00
|
|
|
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2024-04-25 04:57:39 +00:00
|
|
|
class Recipes:
|
2024-04-28 03:37:01 +00:00
|
|
|
broccoli_soup = recipes.Recipe(
|
2024-04-25 04:57:39 +00:00
|
|
|
id=0,
|
2025-10-18 03:26:42 +00:00
|
|
|
name="Broccoli Soup",
|
|
|
|
|
link="https://www.bbcgoodfood.com/recipes/broccoli-soup",
|
2024-05-19 11:22:30 +00:00
|
|
|
serves=4,
|
2025-10-18 03:26:42 +00:00
|
|
|
image_urls=[
|
|
|
|
|
"https://www.bbcgoodfood.com/sites/default/files/styles/recipe/public/recipe/recipe-image/2018/10/broccoli-soup.jpg"
|
|
|
|
|
],
|
2024-04-25 04:57:39 +00:00
|
|
|
ingredients=[Ingredients.broccoli_chopped_1kg],
|
2025-11-01 11:35:10 +00:00
|
|
|
created_by_id=MemberRefs.jacob.id,
|
2024-04-25 04:57:39 +00:00
|
|
|
)
|
|
|
|
|
|
2024-04-28 03:37:01 +00:00
|
|
|
how_to_steam_green_beans = recipes.Recipe(
|
|
|
|
|
id=0,
|
|
|
|
|
name="How to Steam Green Beans",
|
|
|
|
|
link="https://www.thespruceeats.com/steamed-green-beans-3057051",
|
2024-05-19 11:22:30 +00:00
|
|
|
serves=4,
|
2025-10-18 03:26:42 +00:00
|
|
|
image_urls=[
|
|
|
|
|
"https://www.thespruceeats.com/thmb/CLROdq9dlYbjKjlOlA_kmFdunTY=/1500x0/filters:no_upscale():max_bytes(150000):strip_icc()/steamed-green-beans-3057051-hero-01-b1c4f894da5b4bc0a01cd43886df0100.jpg"
|
|
|
|
|
],
|
|
|
|
|
ingredients=[
|
|
|
|
|
Ingredients.green_beans,
|
|
|
|
|
Ingredients.butter,
|
|
|
|
|
Ingredients.salt,
|
|
|
|
|
Ingredients.freshly_ground_black_pepper,
|
|
|
|
|
],
|
2025-11-01 11:35:10 +00:00
|
|
|
created_by_id=MemberRefs.jacob.id,
|
2024-04-28 03:37:01 +00:00
|
|
|
)
|
|
|
|
|
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2025-10-19 09:24:23 +00:00
|
|
|
from meals import repository as meals_db
|
2024-04-25 04:57:39 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2024-04-25 04:57:39 +00:00
|
|
|
class Meals:
|
|
|
|
|
broccoli_soup_for_jacob = meals_db.Meal(
|
|
|
|
|
id=0,
|
2024-05-25 02:09:32 +00:00
|
|
|
suggested_date=datetime(2021, 12, 25),
|
2025-11-01 11:35:10 +00:00
|
|
|
chefs=[MemberRef(id=MemberRefs.jacob.id, display_name=MemberRefs.jacob.name)],
|
|
|
|
|
cleanup=[MemberRef(id=MemberRefs.ryan.id, display_name=MemberRefs.ryan.name)],
|
2025-11-01 10:37:35 +00:00
|
|
|
consumers=[
|
2025-11-01 11:35:10 +00:00
|
|
|
MemberRef(id=MemberRefs.ellie.id, display_name=MemberRefs.ellie.name),
|
|
|
|
|
MemberRef(id=MemberRefs.chris.id, display_name=MemberRefs.chris.name),
|
2025-11-01 10:37:35 +00:00
|
|
|
],
|
2025-10-18 03:26:42 +00:00
|
|
|
recipes=[
|
|
|
|
|
meals_db.MealRecipe(meal_id=-1, recipe_id=-1, servings=2, recipe=Recipes.broccoli_soup)
|
|
|
|
|
],
|
2024-04-25 04:57:39 +00:00
|
|
|
extra_ingredients=[Ingredients.garlic_bread_1_loaf],
|
2024-04-28 03:37:01 +00:00
|
|
|
)
|
|
|
|
|
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2024-04-28 03:37:01 +00:00
|
|
|
def class_fields(obj):
|
2025-10-18 03:26:42 +00:00
|
|
|
return {k: v for k, v in obj.__dict__.items() if not k.startswith("_")}
|
|
|
|
|
|
2024-04-28 03:37:01 +00:00
|
|
|
|
2024-04-28 03:42:21 +00:00
|
|
|
async def create_persons(conn):
|
2025-11-01 11:35:10 +00:00
|
|
|
# Seed explicit User rows for fixture MemberRefs (ids 1..4) without any legacy Person references
|
|
|
|
|
try:
|
|
|
|
|
from users.repository import insert_user_with_id
|
|
|
|
|
|
|
|
|
|
users = [
|
|
|
|
|
(MemberRefs.jacob.id, MemberRefs.jacob.display_name),
|
|
|
|
|
(MemberRefs.ryan.id, MemberRefs.ryan.display_name),
|
|
|
|
|
(MemberRefs.ellie.id, MemberRefs.ellie.display_name),
|
|
|
|
|
(MemberRefs.chris.id, MemberRefs.chris.display_name),
|
|
|
|
|
]
|
|
|
|
|
for uid, name in users:
|
|
|
|
|
await insert_user_with_id(conn, uid, f"{name.lower()}@example.com", name)
|
|
|
|
|
except Exception:
|
|
|
|
|
# If users repo/tables aren't available in some minimal contexts, ignore
|
|
|
|
|
pass
|
2024-04-28 03:42:21 +00:00
|
|
|
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2024-05-18 07:05:01 +00:00
|
|
|
async def create_test_data(conn):
|
|
|
|
|
await create_persons(conn)
|
2024-04-28 03:37:01 +00:00
|
|
|
|
2024-05-18 07:05:01 +00:00
|
|
|
for product in class_fields(Products).values():
|
|
|
|
|
await products.insert_product(conn, product, {})
|
|
|
|
|
await products.add_missing_tags(conn, product, Products._tags[product.product_id])
|
2024-04-28 03:37:01 +00:00
|
|
|
|
2024-05-18 07:05:01 +00:00
|
|
|
for recipe in class_fields(Recipes).values():
|
|
|
|
|
await recipes.insert_recipe(conn, recipe)
|
|
|
|
|
for ingredient in recipe.ingredients:
|
|
|
|
|
ingredient.recipe_id = recipe.id
|
|
|
|
|
ingredient.product_id = ingredient.product.id
|
|
|
|
|
await ingredients.insert_ingredient(conn, ingredient)
|
2024-04-28 03:37:01 +00:00
|
|
|
|
2024-05-18 07:05:01 +00:00
|
|
|
for meal in class_fields(Meals).values():
|
|
|
|
|
await meals_db.insert_meal(conn, meal)
|
2024-04-28 03:37:01 +00:00
|
|
|
|
2025-10-18 03:26:42 +00:00
|
|
|
|
2024-04-28 03:37:01 +00:00
|
|
|
"""
|
|
|
|
|
import re
|
|
|
|
|
def to_name(thing):
|
2025-11-01 10:37:35 +00:00
|
|
|
return re.sub(r"\\W", "", thing["name"].lower().replace(" ", "_"))
|
2024-04-28 03:37:01 +00:00
|
|
|
|
|
|
|
|
products_order= ['id', 'name', 'product_id', 'link', 'tags', 'img_small', 'img_large', 'raw_data']
|
|
|
|
|
ingredients_order = 'id line name unit quantity preparation product'.split(' ')
|
|
|
|
|
|
|
|
|
|
def stringify(k: str, v) -> str:
|
|
|
|
|
if k == 'id':
|
|
|
|
|
return '0'
|
|
|
|
|
if k == 'ingredients' and isinstance(v, dict):
|
|
|
|
|
return f'Ingredients.{to_name(v)}'
|
|
|
|
|
if k == 'product':
|
|
|
|
|
return f'Products.{to_name(v)}'
|
|
|
|
|
if k == 'created_by_id':
|
|
|
|
|
names = ['jacob', 'ryan', 'ellie', 'chris']
|
|
|
|
|
return f'Persons.{names[v - 1]}.id'
|
|
|
|
|
if v is None:
|
|
|
|
|
if k == 'raw_data':
|
|
|
|
|
return '{}'
|
|
|
|
|
if k == 'tags':
|
|
|
|
|
return '[]'
|
|
|
|
|
return 'None'
|
|
|
|
|
if isinstance(v, str):
|
|
|
|
|
return f'"{v}"'
|
|
|
|
|
if isinstance(v, list):
|
|
|
|
|
return f'[{",".join([stringify(k, x) for x in v])}]'
|
|
|
|
|
return str(v)
|
|
|
|
|
|
|
|
|
|
def to_param_list(item, order):
|
|
|
|
|
results = []
|
|
|
|
|
for k in order:
|
|
|
|
|
v = item[k] if k in item else None
|
|
|
|
|
results.append(f'{k}={stringify(k, v)}')
|
|
|
|
|
return results
|
|
|
|
|
|
|
|
|
|
def to_create_statements(items, type_name, order):
|
|
|
|
|
s = []
|
|
|
|
|
for item in items:
|
|
|
|
|
name = to_name(item)
|
|
|
|
|
params = to_param_list(item, order)
|
|
|
|
|
s.append(f'{name} = {type_name}(')
|
|
|
|
|
for p in params:
|
|
|
|
|
s.append(f'\t{p},')
|
|
|
|
|
s.append(')')
|
|
|
|
|
s.append('')
|
|
|
|
|
return '\n'.join(s)
|
2025-10-18 03:26:42 +00:00
|
|
|
"""
|