b4w data factories and tests

This commit is contained in:
2026-09-06 12:23:03 +02:00
parent e8a8844b10
commit d1c22470bb
4 changed files with 28 additions and 15 deletions
+2 -2
View File
@@ -3,9 +3,9 @@
import argparse
from pathlib import Path
from src.reader import reader_b4w, reader_raw
from src.helper_db import upsert_b4w
from src.db import get_session
from src.helper_db import upsert_b4w
from src.reader import reader_b4w
def ingest_b4w(path: Path):
+11 -7
View File
@@ -4,7 +4,7 @@ from datetime import date
from decimal import Decimal
from enum import Enum
from pydantic import BaseModel, Field, ValidationError, field_validator
from pydantic import BaseModel, Field, field_validator
IBAN_PATTERN = r"^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$"
@@ -57,12 +57,16 @@ class B4wExport(BaseModel):
@field_validator("category", mode="before")
@classmethod
def category_str_is_parsable(cls, category_str: str) -> Category | None:
category = Category.from_str(category_str)
assert category
category_str_2 = category.to_str()
if not category_str == category_str_2:
raise ValidationError(f"Category string cannot be parsed: {category_str}")
def category_str_is_parsable(
cls, category_in: str | Category | None
) -> Category | None:
if category_in is None or category_in == "":
return None
if isinstance(category_in, Category):
return category_in
category = Category.from_str(category_in)
if category is None or category.to_str() != category_in:
raise ValueError(f"Category string cannot be parsed: {category_in!r}")
return category