Creating multiple objects with foreign key

I need to create ten sample users (User) and each of them must have fifty documents (Doc). How to do this in tests.py using factoryboy? #factories.py from app_name.models import * import...

django factory boy factory with OneToOne relationship and related field

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...

Avoiding duplicates with factory_boy factories

I'm using factory_boy to create test fixtures. I've got two simple factories, backed by SQLAlchemy models (simplified below). I'd like to be able to call AddressFactory.create() multiple times,...

Django-Python Django Login test failed with factory_boy and Authtools

My unit testings are failing when i want to test Login functionality. When I test in my browser is's OK. I'm...

Using Factory Boy with GeoDjango PointFields

I'm working on writing tests for a new GeoDjango project I've started. Normally I used Factory Boy and Faker to create model instances for testing. However it's not clear to me how you can mock...

factory boy: define field that depends on other field

How to define a field that depends on other field using factory-boy? For instance, I'd like to define an email that depends on the first name and last name of an User. I tried using the...

Django: one-to-one field with factory_boy: UNIQUE constraint failed

I'm trying to make factories for these models with factory_boy: class Course(models.Model): group = models.OneToOneField(Group) title = models.CharField(max_length=1024) class...

How to use Faker from Factory_boy

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...

How to test signals when using factory_boy with muted signals

I am using factory_boy package and DjangoModelFactory to generate a factory model with muted signals @factory.django.mute_signals(signals.post_save) class...

Change default faker locale in factory_boy

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...

Django Model Factory get or create

I have a Django Model defined like below: class CustomModel(models.Model): column = models.CharField(max_length=50, unique=True) Define a Factory for the model from factory_boy...

OSX ld: library not found for -lssl

I am trying to install mysqlclient in virtrualenv on OSX high sierra, with python 3. And got the following error: Failed building wheel for mysqlclient Running setup.py clean for...

How to test auto_now_add in django

I have django 1.11 app and I want to write unit test for my solution. I want to test registration date feature. model.py: class User(models.Model): first_name =...

Installing MySQL-python causes command 'clang' failed with exit status 1 on Mac OS 10.13.15

I have installed tools via xcode-select --install but still show the following error while doing pip install MySQL-python Building wheels for collected packages: MySQL-python Running setup.py...

auto_add with FactoryBoy

This issue: https://github.com/FactoryBoy/factory_boy/issues/102 describes how you should go about testing a 'created' field in django. How should this be implemented for auto_add (rather than...

Django / Factoryboy - unable to delete instances in test

I am writings tests for a django application and I've run into a problem were deleted objects still exist in the test database after I've supposedly deleted them. I'm using the following...

How to generate a random number for a model field using Factory Boy

I need to create some fake data using factory boy. I have the following model: class Fabric(models.Model): title = models.CharField(max_length=200, blank=True) description =...

Django test IntegrityError in fixture teardown

I started using the factory_boy package so I've set up some factories and wanted to test that the objects created don't raise any validation errors. Here's the mixin I'm using that basically takes...

Python: Factory Boy to generate List of length specified on object creation

I'm trying to use Factoryboy to create a list in an object of the length specified when created. I can create the list, but every attempt to create a list with the length specified causes issues...

Choosing from a list of names using factory boy integrated with faker

I am trying to use factory.faker to randomly choose from a list of four companies and use them as a traffic source for a list of generated names. I am using the below code: from django.db...

How to use factory.LazyAttribute with Faker() functions

I am using factory_boy to build some fixtures in Django. I want to use factory.LazyAttribute to build one attribute based on the condition of another attribute. class...

How to test custom authentication backend in django

I wrote a custom authentication backend, I used it in my views to prove that it is working, however I would like to test it so in case it breaks in future for whatever reason, I would know. I...

Factory-Boy - KeyError: 'locale'

Got following exception from factory-boy during running my pytests: def generate(self, params): > locale = params.pop('locale') E KeyError: 'locale' How to solve that issue?...

sqlalchemy.exc.InvalidRequestError: Object '<Item at 0x111ff8640>' is already attached to session '5' (this is '4')

Introduction I am trying to seed data in the table for a test. For this, I am using factory boy package. I have set up a factory class that handles seeding. class...

Recommendation System by using Euclidean Distance (TypeError: unsupported operand type(s) for -: 'str' and 'str')

I have a problem about implementing recommendation system by using Euclidean Distance. What I want to do is to list some close games with respect to search criteria by game title and genre. Here...

Django Factory for model with Generic Foreign Key

I'm trying to write up a Factory for a model with a GFK for testing but I can't seem to get it working. I've referred to the common recipes in the docs, but my models don't match up exactly, and...

Django [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name 'MYSCHEMA.MyUnmanagedModel'

I'm running into this issue: django.db.utils.ProgrammingError: ('42S02', "[42S02] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name 'MYSCHEMA.MyUnmanagedModel'. It's an...

Django Tests - User Factory with create_batch

Ok I've faced interesting problem with my tests files. I'm using this simple code to check User's created by UserFactory UserFactory.create_batch(4) for u in User.objects.all(): ...

Building wheel for cffi (setup.py) ... error while installing the packages from requirements.txt in django

I am trying to install a new Django project from git, I created a new virtual envt using python3(version: 3.8.5). When I try to install the required libraries in the requirements.txt, I get the...

Running async code from a sync function with an event loop already running

I know, it's a mouthful. I am using pytest-asyncio, which gives you an async event loop for running async code in your tests. I want to use factory-boy with an async ORM. The only problem is that...