From 5e824f3bb34ebcc1b50108db1de6fa697a6b61ad Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Mon, 22 May 2023 08:27:26 -0500 Subject: [PATCH] add custom attributes to factory --- learn_sql_model/factories/hero.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/learn_sql_model/factories/hero.py b/learn_sql_model/factories/hero.py index 6a98009..ea22968 100644 --- a/learn_sql_model/factories/hero.py +++ b/learn_sql_model/factories/hero.py @@ -1,7 +1,36 @@ +from faker import Faker from polyfactory.factories.pydantic_factory import ModelFactory +from learn_sql_model.factories.pet import PetFactory from learn_sql_model.models.hero import Hero +from learn_sql_model.models.pet import Pet class HeroFactory(ModelFactory[Hero]): __model__ = Hero + __faker__ = Faker(locale="en_US") + __set_as_default_factory_for_type__ = True + id = None + pet_id = None + + __random_seed__ = 10 + + @classmethod + def name(cls) -> str: + return cls.__faker__.first_name() + + @classmethod + def secret_name(cls) -> str: + return cls.__faker__.name() + + @classmethod + def age(cls) -> str: + return cls.__faker__.pyint(min_value=5, max_value=100) + + @classmethod + def shoe_size(cls) -> str: + return cls.__faker__.pyint(min_value=5, max_value=14) + + @classmethod + def pet(cls) -> Pet: + return PetFactory().build