77 lines
1.8 KiB
Python
77 lines
1.8 KiB
Python
from collections.abc import Callable
|
|
from decimal import Decimal
|
|
from typing import Any
|
|
|
|
from faker import Faker
|
|
from polyfactory.factories.pydantic_factory import ModelFactory
|
|
from polyfactory.fields import Use
|
|
|
|
from src.models.b4w import B4wExport
|
|
from src.models.comdirect import ComdirectCreditCard, ComdirectDepot, ComdirectGiro
|
|
|
|
DEFAULT_CATEGORY = "root_category:parent_category:leaf_category"
|
|
|
|
|
|
def _faker_or_none(faker: Faker, non_default: Any, default: Any = None, p_value=0.5):
|
|
if faker.pyfloat(min_value=0.0, max_value=1.0) < p_value:
|
|
return default
|
|
return non_default
|
|
|
|
|
|
def _amount() -> Decimal:
|
|
return B4wExportFactory.__faker__.pydecimal(
|
|
left_digits=6,
|
|
right_digits=2,
|
|
positive=True,
|
|
min_value=Decimal("0.01"),
|
|
)
|
|
|
|
|
|
def _sentence() -> str:
|
|
return B4wExportFactory.__faker__.sentence(
|
|
nb_words=8,
|
|
variable_nb_words=False,
|
|
)
|
|
|
|
|
|
def _names() -> str:
|
|
return B4wExportFactory.__faker__.company()
|
|
|
|
|
|
def _iban() -> str:
|
|
return B4wExportFactory.__faker__.iban()
|
|
|
|
|
|
def _iban_or_none() -> str:
|
|
faker = B4wExportFactory.__faker__
|
|
return _faker_or_none(faker, faker.iban(), default="")
|
|
|
|
|
|
class B4wExportFactory(ModelFactory[B4wExport]):
|
|
__faker__ = Faker("de_DE")
|
|
__use_examples__ = True
|
|
|
|
Amt = Use(_amount)
|
|
RmtInf = Use(_sentence)
|
|
Notes = Use(_sentence)
|
|
RmtdNm = Use(_names)
|
|
OwnrAcctIBAN = Use(_iban)
|
|
RmtdAcctIBAN = Use(_iban_or_none)
|
|
|
|
|
|
class ComdirectGiroFactory(ModelFactory[ComdirectGiro]):
|
|
__faker__ = Faker("de_DE")
|
|
__use_example__ = True
|
|
|
|
Buchungstext = Use(_sentence)
|
|
|
|
|
|
class ComdirectCreditCardFactory(ModelFactory[ComdirectCreditCard]):
|
|
__faker__ = Faker("de_DE")
|
|
__use_example__ = True
|
|
|
|
|
|
class ComdirectDepotFactory(ModelFactory[ComdirectDepot]):
|
|
__faker__ = Faker("de_DE")
|
|
__use_example__ = True
|