mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Refs #9804 -- Fixed test for sequence reset of M2M with inherited through model.
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user