Initial
This commit is contained in:
84
example/cashbag_conform/factory.py
Normal file
84
example/cashbag_conform/factory.py
Normal file
@ -0,0 +1,84 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Type
|
||||
|
||||
import factory
|
||||
|
||||
from televend_core.databases.televend_repositories.author_info.factory import (
|
||||
AuthorInfoFactory,
|
||||
)
|
||||
from televend_core.databases.televend_repositories.cashbag.factory import (
|
||||
CashBagFactory,
|
||||
)
|
||||
from televend_core.databases.televend_repositories.cashbag_conform.model import (
|
||||
CashBagConform,
|
||||
)
|
||||
from televend_core.databases.televend_repositories.cashflow_collection.factory import (
|
||||
CashFlowCollectionFactory,
|
||||
)
|
||||
from televend_core.databases.televend_repositories.custom_user.factory import (
|
||||
CustomUserFactory,
|
||||
)
|
||||
from televend_core.databases.televend_repositories.machine.factory import MachineFactory
|
||||
from televend_core.test_extras.factory_boy_utils import (
|
||||
CustomSelfAttribute,
|
||||
TelevendBaseFactory,
|
||||
)
|
||||
|
||||
|
||||
class CashBagConformFactory(TelevendBaseFactory):
|
||||
alive = True
|
||||
id = None
|
||||
|
||||
count_coins = factory.Faker("pydecimal", left_digits=7, right_digits=4, positive=True)
|
||||
count_bills = factory.Faker("pydecimal", left_digits=7, right_digits=4, positive=True)
|
||||
tokens_number = factory.Faker("pydecimal", left_digits=7, right_digits=4, positive=True)
|
||||
tokens_total = factory.Faker("pydecimal", left_digits=7, right_digits=4, positive=True)
|
||||
count_timestamp = factory.Faker("date_time")
|
||||
count_receive_timestamp = factory.Faker("date_time")
|
||||
collect = factory.Faker("pydecimal", left_digits=7, right_digits=4, positive=True)
|
||||
collect_timestamp = factory.Faker("date_time")
|
||||
diff = factory.Faker("pydecimal", left_digits=7, right_digits=4, positive=True)
|
||||
|
||||
author_info = CustomSelfAttribute("..author_info", AuthorInfoFactory)
|
||||
author_info_id = factory.LazyAttribute(lambda a: a.author_info.id if a.author_info else None)
|
||||
|
||||
cashbag = CustomSelfAttribute("..cashbag", CashBagFactory)
|
||||
cashbag_id = factory.LazyAttribute(lambda a: a.cashbag.id if a.cashbag else None)
|
||||
|
||||
cashflow_collection = CustomSelfAttribute("..cashflow_collection", CashFlowCollectionFactory)
|
||||
cashflow_collection_id = factory.LazyAttribute(
|
||||
lambda a: a.cashflow_collection.id if a.cashflow_collection else None
|
||||
)
|
||||
|
||||
collect_user = CustomSelfAttribute("..collect_user", CustomUserFactory)
|
||||
collect_user_id = factory.LazyAttribute(
|
||||
lambda a: a.collect_user.user_ptr_id if a.collect_user else None
|
||||
)
|
||||
count_user = CustomSelfAttribute("..count_user", CustomUserFactory)
|
||||
count_user_id = factory.LazyAttribute(
|
||||
lambda a: a.count_user.user_ptr_id if a.count_user else None
|
||||
)
|
||||
|
||||
machine = CustomSelfAttribute("..machine", MachineFactory)
|
||||
machine_id = factory.LazyAttribute(lambda a: a.machine.id if a.machine else None)
|
||||
|
||||
external_route_id = factory.Faker("pyint")
|
||||
external_route_name = factory.Faker("pystr", max_chars=255)
|
||||
no_cashbag_reason = factory.Faker("pyint")
|
||||
|
||||
class Meta:
|
||||
model = CashBagConform
|
||||
|
||||
@classmethod
|
||||
def create_minimal(cls: Type[CashBagConformFactory], **kwargs) -> CashBagConform:
|
||||
minimal_params = {
|
||||
"author_info": kwargs.pop("author_info", None) or AuthorInfoFactory.create_minimal(),
|
||||
"cashbag": None,
|
||||
"cashflow_collection": None,
|
||||
"collect_user": None,
|
||||
"count_user": None,
|
||||
"machine": None,
|
||||
}
|
||||
minimal_params.update(kwargs)
|
||||
return cls.create(**minimal_params)
|
||||
Reference in New Issue
Block a user