Category : factory-boy

What am I trying to do? I am trying to create a base factory boy class with the class meta set as follows: class DBFactoryBase(factory.alchemy.SQLAlchemyModelFactory): class Meta: sqlalchemy_session = common_session sqlalchemy_session_persistence = ‘flush’ I then want to inherit from this and use it in my factories instead of factory.alchemy.SQLAlchemyModelFactory: class SomeFactory(DBFactoryBase): class Meta: model = ..

Read more

I’m currently struggling to get the foreign key of a tables index from another factory working. My SQLAlchemy classes look as follows: class Rfq(Base): __tablename__ = "rfq_rfq" id = Column( Integer, primary_key=True, ) title = Column(Text) description = Column(Text) creator_id = Column( ForeignKey(User.id, deferrable=True, initially="DEFERRED"), index=True ) class User(Base): __tablename__ = "users_user" id = Column( ..

Read more

I have 2 models, django User model and Employee class Employee(TimeStampedModel): creator = models.ForeignKey(User, on_delete=models.CASCADE, related_name="employees") first_name = models.CharField(max_length=255, blank=True) last_name = models.CharField(max_length=255, blank=True) phone = models.CharField(validators=[phone_regex], max_length=17, blank=True) email = models.EmailField(validators=[email_regex], max_length=255, blank=True) user = models.OneToOneField(User, on_delete=models.SET_NULL, null=True, related_name="employee") 2 factories: class UserFactory(factory.django.DjangoModelFactory): class Meta: model = User employee = factory.RelatedFactory( "control_room.tests.factories.EmployeeFactory", factory_related_name=’user’ ) ..

Read more

Assume I have the following classes: @dataclass class Image: array: np.ndarray @dataclass class Label: array: np.ndarray @dataclass class Sample: image: Image label: Label with the following factory_boy factories: class ImageFactory(factory.Factory): class Meta: model = Image class Params: shape = (64, 64) array = factory.LazyAttribute(lambda o: np.random.random(o.shape)) class LabelFactory(factory.Factory): class Meta: model = Label class Params: ..

Read more

I try to add a role to a manager through @factory.post_generation. It seems to work when I access manager.roles, but it doesn’t create a real record in relationship table. # models.py assoc_managers_roles = sa.Table( "assoc_managers_roles", Base.metadata, sa.Column( "manager_id", sa.Integer, sa.ForeignKey("managers.id", ondelete="CASCADE"), primary_key=True, ), sa.Column( "role_id", sa.Integer, sa.ForeignKey("roles.id", ondelete="CASCADE"), primary_key=True, ), ) class Manager(Base, TimestampMixin): id ..

Read more

I’m trying to create some objects in setUp method of Django test case. I use FactoryBoy that helps me with creating the objects. But it seems that FactoryBoy can’t find any objects in the database. factories.py class ProductFactory(DjangoModelFactory): … market_category = factory.fuzzy.FuzzyChoice(list(MarketplaceCategory.objects.all())) class Meta: model = Product tests.py from django.test import TestCase from marketplaces.models import ..

Read more

I have a factoryboy factory for sqlalchemy model which uses faker from faker import Faker from db_init import session fake = Faker() class ClientAppFactory(factory.alchemy.SQLAlchemyModelFactory): class Meta: model = ClientApp sqlalchemy_session = session sqlalchemy_session_persistence = ‘commit’ name = fake.word() display_name = fake.word() This factory creates rows in database. Field name of my model must be unique. ..

Read more