From 4d98b9d729fa7f2525f346fbaf180030c3c3a5f8 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 11 Jul 2018 16:37:56 -0400 Subject: [PATCH] Refs #9804 -- Fixed test for sequence reset of M2M with inherited through model. --- tests/m2m_through_regress/models.py | 19 ------------------- tests/test_runner/models.py | 14 ++++++++++++++ tests/test_runner/tests.py | 23 ++++++++++++++--------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/m2m_through_regress/models.py b/tests/m2m_through_regress/models.py index 391ddc69c0..0fd7d9c911 100644 --- a/tests/m2m_through_regress/models.py +++ b/tests/m2m_through_regress/models.py @@ -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) 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):