Skip to content

Commit

Permalink
Merge pull request #596 from ProtixIT/status-test-model-naming
Browse files Browse the repository at this point in the history
Resolve name clash among test models
  • Loading branch information
foarsitter authored Mar 22, 2024
2 parents aaf93c9 + ed4f04f commit 6e722b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 6 additions & 2 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ class StatusCustomManager(Manager):
pass


class AbstractStatusCustomManager(StatusModel):
class AbstractCustomManagerStatusModel(StatusModel):
"""An abstract status model with a custom manager."""

STATUS = Choices(
("first_choice", _("First choice")),
("second_choice", _("Second choice")),
Expand All @@ -157,7 +159,9 @@ class Meta:
abstract = True


class StatusCustomManager(AbstractStatusCustomManager):
class CustomManagerStatusModel(AbstractCustomManagerStatusModel):
"""A concrete status model with a custom manager."""

title = models.CharField(max_length=50)


Expand Down
12 changes: 6 additions & 6 deletions tests/test_models/test_status_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time_machine
from django.test.testcases import TestCase

from tests.models import Status, StatusCustomManager, StatusPlainTuple
from tests.models import CustomManagerStatusModel, Status, StatusPlainTuple


class StatusModelTests(TestCase):
Expand Down Expand Up @@ -87,13 +87,13 @@ def test_default_manager_is_not_status_model_generated_ones(self):
# This situation only happens when we define a model inheriting from an "abstract"
# class which defines an "objects" manager.

StatusCustomManager.objects.create(status='first_choice')
StatusCustomManager.objects.create(status='second_choice')
StatusCustomManager.objects.create(status='second_choice')
CustomManagerStatusModel.objects.create(status='first_choice')
CustomManagerStatusModel.objects.create(status='second_choice')
CustomManagerStatusModel.objects.create(status='second_choice')

# ...which made this count() equal to 1 (only 1 element with status='first_choice')...
self.assertEqual(StatusCustomManager._default_manager.count(), 3)
self.assertEqual(CustomManagerStatusModel._default_manager.count(), 3)

# ...and this one equal to 0, because of 2 successive filters of 'first_choice'
# (default manager) and 'second_choice' (explicit filter below).
self.assertEqual(StatusCustomManager._default_manager.filter(status='second_choice').count(), 2)
self.assertEqual(CustomManagerStatusModel._default_manager.filter(status='second_choice').count(), 2)

0 comments on commit 6e722b5

Please sign in to comment.