summaryrefslogtreecommitdiff
path: root/tests/test_runner
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2018-07-11 16:37:56 -0400
committerTim Graham <timograham@gmail.com>2018-07-11 16:45:29 -0400
commit4d98b9d729fa7f2525f346fbaf180030c3c3a5f8 (patch)
tree7b080d4a54670991766e44fdc2368354ad64138c /tests/test_runner
parent8a03445885346b789be246fbb4e62933582cfcc0 (diff)
Refs #9804 -- Fixed test for sequence reset of M2M with inherited through model.
Diffstat (limited to 'tests/test_runner')
-rw-r--r--tests/test_runner/models.py14
-rw-r--r--tests/test_runner/tests.py23
2 files changed, 28 insertions, 9 deletions
diff --git a/tests/test_runner/models.py b/tests/test_runner/models.py
index 20cb384b03..ea6d2cc499 100644
--- a/tests/test_runner/models.py
+++ b/tests/test_runner/models.py
@@ -4,3 +4,17 @@ from django.db import models
class Person(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
+
+
+# A set of models that use a non-abstract inherited 'through' model.
+class ThroughBase(models.Model):
+ person = models.ForeignKey(Person, models.CASCADE)
+ b = models.ForeignKey('B', models.CASCADE)
+
+
+class Through(ThroughBase):
+ extra = models.CharField(max_length=20)
+
+
+class B(models.Model):
+ people = models.ManyToManyField(Person, through=Through)
diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py
index 708a7c2da7..bf54e5f840 100644
--- a/tests/test_runner/tests.py
+++ b/tests/test_runner/tests.py
@@ -17,7 +17,7 @@ from django.test.runner import DiscoverRunner
from django.test.testcases import connections_support_transactions
from django.test.utils import dependency_ordered
-from .models import Person
+from .models import B, Person, Through
class DependencyOrderingTests(unittest.TestCase):
@@ -327,26 +327,31 @@ class SetupDatabasesTests(unittest.TestCase):
)
+@skipUnlessDBFeature('supports_sequence_reset')
class AutoIncrementResetTest(TransactionTestCase):
"""
- Here we test creating the same model two times in different test methods,
- and check that both times they get "1" as their PK value. That is, we test
- that AutoField values start from 1 for each transactional test case.
+ Creating the same models in different test methods receive the same PK
+ values since the sequences are reset before each test method.
"""
available_apps = ['test_runner']
reset_sequences = True
- @skipUnlessDBFeature('supports_sequence_reset')
- def test_autoincrement_reset1(self):
+ def _test(self):
+ # Regular model
p = Person.objects.create(first_name='Jack', last_name='Smith')
self.assertEqual(p.pk, 1)
+ # Many-to-many through model
+ b = B.objects.create()
+ t = Through.objects.create(person=p, b=b)
+ self.assertEqual(t.pk, 1)
+
+ def test_autoincrement_reset1(self):
+ self._test()
- @skipUnlessDBFeature('supports_sequence_reset')
def test_autoincrement_reset2(self):
- p = Person.objects.create(first_name='Jack', last_name='Smith')
- self.assertEqual(p.pk, 1)
+ self._test()
class EmptyDefaultDatabaseTest(unittest.TestCase):