Category overhaul (#20)
Tests / test (push) Successful in 16s
Tests / lint (push) Successful in 16s

Reviewed-on: #20
Co-authored-by: Mathias <mathias2784@web.de>
This commit was merged in pull request #20.
This commit is contained in:
2026-10-27 18:08:10 +00:00
committed by mathias2784
parent 4efef98c9c
commit 6babc560c7
36 changed files with 3021 additions and 176 deletions
+31 -1
View File
@@ -1,4 +1,5 @@
from decimal import Decimal
from pathlib import Path
from typing import Any
from faker import Faker
@@ -6,10 +7,39 @@ from polyfactory.factories.pydantic_factory import ModelFactory
from polyfactory.fields import Use
from src.models.b4w import B4wExport
from src.models.category import Category
from src.models.comdirect import ComdirectCreditCard, ComdirectDepot, ComdirectGiro
from src.models.transactions import Transaction
DEFAULT_CATEGORY = "root_category:parent_category:leaf_category"
CATEGORY_PATHS = tuple(
line.strip()
for line in (
Path(__file__).resolve().parents[1]
/ "scripts/initial_load/categories/categories.txt"
)
.read_text(encoding="utf-8")
.splitlines()
if line.strip()
)
def _category_from_path(path: str) -> Category:
category = Category.from_str(path)
if category is None:
raise ValueError("Category list contains an empty path")
return category
class CategoryFactory:
__faker__ = Faker("de_DE")
@classmethod
def build(cls) -> Category:
return _category_from_path(cls.__faker__.random_element(CATEGORY_PATHS))
@staticmethod
def build_all() -> list[Category]:
return [_category_from_path(path) for path in CATEGORY_PATHS]
def _faker_or_none(faker: Faker, non_default: Any, default: Any = None, p_value=0.5):