factory-boy

Django FactoryBoy: fill modelfield with choices throws error

自古美人都是妖i 提交于 2019-12-12 16:31:53
问题 I am working on a factory for a model and I am trying fill a field that has a list of choices. When I attempt to create an object with the Factory where I attempt to fill in a random choice from the choice list, an exception is thrown: TypeError: 'choice' is an invalid keyword argument for this function Traceback (most recent call last): File "<console>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/factory/base.py", line 551, in build return cls._generate(enums.BUILD

Getting id of associated child records in factory_boy

这一生的挚爱 提交于 2019-12-12 02:39:32
问题 I have a function with a number of parameters , then a specialized instantiation of that function, with some settings for each of the function's parameters. So I have a structure like the following: class Function(models.Model): name = models.CharField() class FunctionParameter(models.Model): function = models.ForeignKey(Function) class FunctionInstantiation(models.Model): function = models.ForeignKey(Function) class ParameterSetting(models.Model): function_instantiation = models.ForeignKey

Trouble installing factory_boy with pip

£可爱£侵袭症+ 提交于 2019-12-11 08:36:24
问题 I'm working on a Django project. I'm setting up my environment on another machine and when I run pip install factory_boy , I get the following traceback: https://gist.github.com/JSweetman/35f59536d6b87a0ce8c0 Does anyone know what's happening? I installed factory_boy in a different environment on the same machine and it worked so I'm not sure what's going on. 回答1: You need to update setuptools . Like so: pip install setuptools --upgrade and then pip install factory_boy should work. sudo may

Change default faker locale in factory_boy

邮差的信 提交于 2019-12-10 14:59:05
问题 How can I set the default locale in Python's factory_boy for all of my Factories? In docs says that one should set it with factory.Faker.override_default_locale but that does nothing to my fakers... import factory from app.models import Example from custom_fakers import CustomFakers # I use custom fakers, this indeed are added factory.Faker.add_provider(CustomFakers) # But not default locales factory.Faker.override_default_locale('es_ES') class ExampleFactory(factory.django.DjangoModelFactory

Lack of ROLLBACK within TestCase causes unique contraint violation in multi-db django app

不羁岁月 提交于 2019-12-10 14:42:39
问题 I'm just getting started with the factory_boy django library for test factories, and having an issue with a duplicate key constraint violation. test_member_programme.py from datetime import date, timedelta from django.test import TestCase from app.test.factories import MemberFactory, ProgrammeFactory from app.models.member_programme import MemberProgramme class MemberProgrammeTestCase(TestCase): def member_programme(self): yesterday = date.today() - timedelta(days=1) return MemberProgramme

Why isn't SQLAlchemy translating this object generated by a FactoryBoy SubFactory into a foreign key?

╄→гoц情女王★ 提交于 2019-12-07 08:41:09
问题 I'm using Flask and SQLAlchemy (via the Flask-SQLAlchemy extension) together with Factory_Boy. My GearItem model has a foreign key to GearCategory . Factory_Boy handles this through the SubFactory function that creates the object to be used as the foreign key in the original factory. Here are my model definitions: class GearCategory(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Text, unique=True, nullable=False) gear_items = db.relationship('GearItem', backref=

Why isn't SQLAlchemy translating this object generated by a FactoryBoy SubFactory into a foreign key?

送分小仙女□ 提交于 2019-12-05 12:27:47
I'm using Flask and SQLAlchemy (via the Flask-SQLAlchemy extension) together with Factory_Boy . My GearItem model has a foreign key to GearCategory . Factory_Boy handles this through the SubFactory function that creates the object to be used as the foreign key in the original factory. Here are my model definitions: class GearCategory(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Text, unique=True, nullable=False) gear_items = db.relationship('GearItem', backref='category', lazy='dynamic', order_by='GearItem.name') class GearItem(db.Model): id = db.Column(db

Is it possible to parametrize a test with fixtures?

大兔子大兔子 提交于 2019-12-02 01:35:43
I would like to pass @pytest.mark.parametrize not particular values but fixtures. Like so. Given a conftest with: @pytest.fixture def name1(): return 'foo' @pytest.fixture def name2(): return 'bar' within my test.py this works of course: @pytest.mark.parametrize('name', ['foo', 'bar', 'baz']) def test_name(name): print(name) This does not: @pytest.mark.parametrize('name', [name1, name2]) def test_name(name): print(name) I am aware that in this trivial case I could just create one name fixture and parametrize the fixture instead, but there are cases were this is not deireable. One way around