Refs #9804 -- Fixed test for sequence reset of M2M with inherited through model.
This commit is contained in:
parent
8a03445885
commit
4d98b9d729
|
@ -40,25 +40,6 @@ class Group(models.Model):
|
|||
return self.name
|
||||
|
||||
|
||||
# A set of models that use a non-abstract inherited model as the 'through' model.
|
||||
class A(models.Model):
|
||||
a_text = models.CharField(max_length=20)
|
||||
|
||||
|
||||
class ThroughBase(models.Model):
|
||||
a = models.ForeignKey(A, models.CASCADE)
|
||||
b = models.ForeignKey('B', models.CASCADE)
|
||||
|
||||
|
||||
class Through(ThroughBase):
|
||||
extra = models.CharField(max_length=20)
|
||||
|
||||
|
||||
class B(models.Model):
|
||||
b_text = models.CharField(max_length=20)
|
||||
a_list = models.ManyToManyField(A, through=Through)
|
||||
|
||||
|
||||
# Using to_field on the through model
|
||||
class Car(models.Model):
|
||||
make = models.CharField(max_length=20, unique=True, null=True)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue