b4w data factories and tests
This commit is contained in:
+11
-7
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user