Questions tagged [model-mommy]

Model-mommy offers a smart way to create fixtures for testing in Django. With a simple API you can create many objects with a single line of code. Instead of building an exhaustive test setup with every possible combination ,it allows you to use objects customized for the current test, while only declaring the test-specific fields.

Model-mommy offers a smart way to create fixtures for testing in Django. With a simple API you can create many objects with a single line of code. Instead of building an exhaustive test setup with every possible combination ,it allows you to use objects customized for the current test, while only declaring the test-specific fields.

18 questions
4
votes
0 answers

Delete model-mommy instance

I'm using model-mommy to generate test data like so class AuthorDetailViewTests(TestCase): def setUp(self): # set bio manually to avoid error being thrown by template tag markdown_format self.author = mommy.make('author.Author',…
chidimo
  • 2,684
  • 3
  • 32
  • 47
4
votes
1 answer

Model Mommy: Multiple recipes with foreign key relation to a single recipe

I have had this annoyance with ModelMommy for a while but I can't figure out how to do this properly. Let`s assume a simple relation: class Organization(models.Model): label = models.CharField(unique=True) class Asset(models.Model): …
3
votes
1 answer

model_mommy breaks django-mptt

I'm using model_mommy to create instances of an MPTTModel in my tests, but it seems like it breaks the tree managed by mptt: >>> parent = mommy.make(Category) >>> child = mommy.make(Category, parent=parent) >>> parent.get_descendants() [] The same…
Martin Maillard
  • 2,751
  • 19
  • 24
2
votes
1 answer

Model Mommy Recipe with Reverse FK

I'm using model_mommy with Django tests to create objects. I'm having trouble creating a model with a reverse FK. I can do it the opposite way round as a workaround, but whilst it works it doesn't look right so I wonder if I can do it the other way…
Ludo
  • 2,739
  • 2
  • 28
  • 42
1
vote
1 answer

Create a User with Model Bakery

I would like to create a Person instance with Model Bakery. My Person model looks like this: User = get_user_model() class Person(models.Model): user = models.OneToOneField(User, related_name="friend", on_delete=CASCADE) country =…
Andrew Einhorn
  • 741
  • 8
  • 23
1
vote
1 answer

django tests - model instance not created

I'm experiencing issues on creating fixtures for a particular model in a test class with Django and the DRF. I'm using model-mommy, but even creating a single instance just using the Django ORM for that model does not work: from…
Luke
  • 1,794
  • 10
  • 43
  • 70
1
vote
0 answers

Creating reverse relationship objects with Model Mommy

I use Model Mommy for creating test data and it's working fine so far. Now I have a Django model named Invoice and a related model named InvoiceItem. class Invoice(models.Model): created_by = models.ForeignKey(users.User) class…
damd
  • 6,116
  • 7
  • 48
  • 77
1
vote
1 answer

dealing with self-referential foreign keys; model mommy

I am getting the typical runtime error of self referencing FKs testing django with fake objects: ... last 4 frames repeated, from the frame below ... /home/cchilders/.virtualenvs/clientsite/lib/python3.4/site-packages/model_mommy/mommy.py in…
codyc4321
  • 9,014
  • 22
  • 92
  • 165
1
vote
2 answers

Testing Login with Model Mommy

I having a problem testing my login in my functional test. I am using model mommy to create a a user call Megan with a password, but my test still does not pass since when the information is sent it throws up and error on the html page of "Please…
user2770624
  • 293
  • 4
  • 18
1
vote
1 answer

Django: GEOSException on ModelMommy mommy.make function

getting a weird error from Model Mommy when I am trying to create a mommy model GEOSException: Error encountered checking Geometry returned from GEOS C function "GEOSWKBReader_readHEX_r". Weird thing is that the only goes stuff is in another…
lukeaus
  • 11,465
  • 7
  • 50
  • 60
0
votes
1 answer

mommy Recipe with OneToOne

I am using model_mommy with Django to create test objects. I want to implement Recipe functionality. I have a model Teacher and a model TeacherSchedule: Teacher(models.Model): some fields ... TeacherSchedule(models.Model): teacher =…
Anil Panda
  • 375
  • 1
  • 3
  • 14
0
votes
1 answer

Django model_mommy model instance isn't saved in Ajax test

I'm trying to test an django ajax view that saves a field. Here's the test: def test_ajax_save_draft(self): self.client.force_login(self.test_user) # view requires login sub = mommy.make(QuestSubmission, quest=self.quest2) draft_comment…
43Tesseracts
  • 4,617
  • 8
  • 48
  • 94
0
votes
1 answer

How to satisfy unique constraint in django unit test without hardcoding?

I have set a unique constraint on email field of my Member model. Now while writing unit tests, my tests fail due to expiring unique constraint. def setUp(self): self.car_provider = mommy.make(Member, username="car_provider") …
0
votes
1 answer

Wagtail Page create via model_mommy

I'm trying to create some tests for my first Django site. One thing that is burdensome is creating example pages for testing (at least you have to specify a lot of parameters and some (such as ContentType) are not always obvious. More generally,…
user1104605
  • 97
  • 1
  • 8
0
votes
1 answer

How can I mock the created field of a model that inherits from TimeStampedModel using model_mommy?

I am trying to test a date filter but have been unable to set the created date using mommy.make(). When I make the objects with model mommy the created field is set to the time the objects were created rather than what I passed in with…
1
2