Skip to content

Commit

Permalink
Reuse existing test models, check the query count
Browse files Browse the repository at this point in the history
  • Loading branch information
amureki committed Aug 9, 2024
1 parent 38cf861 commit c9af3d4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

### Changed
- Handle bulk creation when using reverse related name

### Removed

Expand Down
8 changes: 0 additions & 8 deletions tests/generic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,3 @@ class ModelWithAutoNowFields(models.Model):
sent_date = models.DateTimeField()
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)


class House(models.Model):
pass


class HouseDetail(models.Model):
houses = models.ManyToManyField(House, blank=True)
16 changes: 11 additions & 5 deletions tests/test_baker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,11 +1069,17 @@ def test_create(self):
assert list(c1.students.all()) == list(c2.students.all()) == [person]

def test_make_should_create_objects_using_reverse_name(self):
detail = baker.make(models.HouseDetail)
houses = baker.make(
models.House, housedetail_set=[detail], _quantity=20, _bulk_create=True
)
assert houses[0].housedetail_set.count() == 1
classroom = baker.make(models.Classroom)

with self.assertNumQueries(21):
students = baker.make(
models.Person,
classroom_set=[classroom],
_quantity=10,
_bulk_create=True,
)

assert students[0].classroom_set.count() == 1


class TestBakerSeeded:
Expand Down

0 comments on commit c9af3d4

Please sign in to comment.