kiwi/tests/db/test_store_recipes.py
pyr0ball c18bfec8f5
Some checks are pending
CI / Backend (Python) (push) Waiting to run
CI / Frontend (Vue) (push) Waiting to run
Mirror / mirror (push) Waiting to run
fix(lint): add ruff config, fix all lint errors for GitHub CI
- pyproject.toml: add [tool.ruff] config suppressing E402/W293 globally,
  F841/E741/E702 in tests, E741 in scripts
- inventory.py: split semicolon import (E702)
- recipes.py: fix logger -> log (F821 undefined name)
- shopping.py: rename l -> lnk in list comprehension (E741)
- format_conversion.py: noqa F841 on CUDA flag (used as future hook)
- backfill_keywords.py: rename done -> _done (F841)
- ingest_purplecarrot.py: drop == True comparison (E712)
- Auto-fix: I001 import sorting, F401 unused imports across all files
2026-07-06 02:49:02 -07:00

55 lines
2.2 KiB
Python

import pytest
@pytest.fixture
def store_with_recipes(store_with_profiles):
store_with_profiles.conn.executemany("""
INSERT INTO recipes (external_id, title, ingredients, ingredient_names,
directions, category, keywords, element_coverage)
VALUES (?,?,?,?,?,?,?,?)
""", [
("1", "Butter Pasta", '["butter","pasta","parmesan"]',
'["butter","pasta","parmesan"]', '["boil pasta","toss with butter"]',
"Italian", '["quick","pasta"]',
'{"Richness":0.5,"Depth":0.3,"Structure":0.2}'),
("2", "Lentil Soup", '["lentils","carrots","onion","broth"]',
'["lentils","carrots","onion","broth"]', '["simmer all"]',
"Soup", '["vegan","hearty"]',
'{"Depth":0.4,"Seasoning":0.3}'),
])
store_with_profiles.conn.commit()
return store_with_profiles
def test_search_recipes_by_ingredient_names(store_with_recipes):
results = store_with_recipes.search_recipes_by_ingredients(["butter", "parmesan"])
assert len(results) >= 1
assert any(r["title"] == "Butter Pasta" for r in results)
def test_search_recipes_respects_limit(store_with_recipes):
results = store_with_recipes.search_recipes_by_ingredients(["butter"], limit=1)
assert len(results) <= 1
def test_check_rate_limit_first_call(store_with_recipes):
allowed, count = store_with_recipes.check_and_increment_rate_limit("leftover_mode", daily_max=5)
assert allowed is True
assert count == 1
def test_check_rate_limit_exceeded(store_with_recipes):
for _ in range(5):
store_with_recipes.check_and_increment_rate_limit("leftover_mode", daily_max=5)
allowed, count = store_with_recipes.check_and_increment_rate_limit("leftover_mode", daily_max=5)
assert allowed is False
assert count == 5
def test_get_element_profiles_returns_known_items(store_with_profiles):
profiles = store_with_profiles.get_element_profiles(["butter", "parmesan", "unknown_item"])
assert profiles["butter"] == ["Richness"]
assert "Depth" in profiles["parmesan"]
assert "unknown_item" not in profiles
def test_get_element_profiles_empty_list(store_with_profiles):
profiles = store_with_profiles.get_element_profiles([])
assert profiles == {}