factory-boy

How to add type hint to python factory_boy Factory classes?

How to add type hint to python factory_boy Factory classes? Question: So we are working with some existing code where there is an implementation of factories classes from the factory_boy project which create instances of other classes for example class TableFactory(Factory): class Meta: model = Table id = LazyAttribute(lambda x: uuid4()) color = SubFactory(ColorFactory) reference …

Total answers: 1

Factory boy to select from existing flask_sqlalchemy table with Iterator using parameter

Factory boy to select from existing flask_sqlalchemy table with Iterator using parameter Question: There are lots of great answers here, but I can’t quite find the one to solve my problem. Two SQLAlchemy models: Calendar and Transaction. Transactions link to the Calendar model: class Calendar(Model): calendar_id = db.Column(db.Integer, primary_key=True, autoincrement=True) cal_date = db.Column(db.Date, unique=True, nullable=False) …

Total answers: 1

Is there a way to use a temporary non-field variable in factoryboy?

Is there a way to use a temporary non-field variable in factoryboy? Question: I am defining some factories for testing my e-commerce store. I have created a Faker provider that can return, for instance, a dictionary containing all the data for a random product. I want to then use that dictionary to populate the fields …

Total answers: 2

How to use Faker from Factory_boy

How to use Faker from Factory_boy Question: Factory_boy uses fake-factory (Faker) to generate random values, I would like to generate some random values in my Django tests using Faker directly. Factory_boy docs suggests using factory.Faker and its provider as : class RandomUserFactory(factory.Factory): class Meta: model = models.User first_name = factory.Faker(‘first_name’) But this isn’t generating any …

Total answers: 5

Factory Boy random choice for a field with field option "choices"

Factory Boy random choice for a field with field option "choices" Question: When a field in a Django model has the option choices, see Django choices field option, it utilises an iterable containing iterables of 2 items to define which values are allowed. For example: Models class IceCreamProduct(models.Model): PRODUCT_TYPES = ( (0, ‘Soft Ice Cream’), …

Total answers: 6

django factory boy factory with OneToOne relationship and related field

django factory boy factory with OneToOne relationship and related field Question: I am using Factory Boy to create test factories for my django app. The model I am having an issue with is a very basic Account model which has a OneToOne relation to the django User auth model (using django < 1.5): # models.py …

Total answers: 3