Merge pull request #453 from chrisglass/fix-tests

Fix tests
This commit is contained in:
Chris Glass
2020-08-14 17:05:20 +02:00
committed by GitHub
6 changed files with 19 additions and 12 deletions
@@ -1450,6 +1450,13 @@ class Migration(migrations.Migration):
to="tests.ParentModelWithManager",
),
),
migrations.AddField(
model_name="childmodelwithmanager",
name="field1",
field=models.CharField(
max_length=10,
),
),
migrations.AddField(
model_name="childmodelwithmanager",
name="polymorphic_ctype",
+1
View File
@@ -222,6 +222,7 @@ class ParentModelWithManager(PolymorphicModel):
class ChildModelWithManager(PolymorphicModel):
# Also test whether foreign keys receive the manager:
field1 = models.CharField(max_length=10) # needed as MyManager uses it
fk = models.ForeignKey(
ParentModelWithManager, on_delete=models.CASCADE, related_name="childmodel_set"
)
+1 -1
View File
@@ -18,7 +18,7 @@ from polymorphic.tests.models import (
class MultipleDatabasesTests(TestCase):
multi_db = True
databases = ["default", "secondary"]
def test_save_to_non_default_database(self):
Model2A.objects.db_manager("secondary").create(field1="A1")
+4 -7
View File
@@ -481,21 +481,22 @@ class PolymorphicTests(TransactionTestCase):
def test_foreignkey_field(self):
self.create_model2abcd()
object2a = Model2A.base_objects.get(field1="C1")
object2a = Model2A.objects.get(field1="C1")
self.assertEqual(object2a.model2b.__class__, Model2B)
object2b = Model2B.base_objects.get(field1="C1")
object2b = Model2B.objects.get(field1="C1")
self.assertEqual(object2b.model2c.__class__, Model2C)
def test_onetoone_field(self):
self.create_model2abcd()
# FIXME: We should not use base_objects here.
a = Model2A.base_objects.get(field1="C1")
b = One2OneRelatingModelDerived.objects.create(
one2one=a, field1="f1", field2="f2"
)
# this result is basically wrong, probably due to Django cacheing (we used base_objects), but should not be a problem
# FIXME: this result is basically wrong, probably due to Django cacheing (we used base_objects), but should not be a problem
self.assertEqual(b.one2one.__class__, Model2A)
self.assertEqual(b.one2one_id, b.one2one.id)
@@ -808,7 +809,6 @@ class PolymorphicTests(TransactionTestCase):
self.assertIs(type(ModelWithMyManager.objects), MyManager)
self.assertIs(type(ModelWithMyManager._default_manager), MyManager)
self.assertIs(type(ModelWithMyManager.base_objects), models.Manager)
def test_user_defined_manager_as_secondary(self):
self.create_model2abcd()
@@ -831,7 +831,6 @@ class PolymorphicTests(TransactionTestCase):
self.assertIs(
type(ModelWithMyManagerNoDefault._default_manager), PolymorphicManager
)
self.assertIs(type(ModelWithMyManagerNoDefault.base_objects), models.Manager)
def test_user_objects_manager_as_secondary(self):
self.create_model2abcd()
@@ -841,7 +840,6 @@ class PolymorphicTests(TransactionTestCase):
self.assertIs(type(ModelWithMyManagerDefault.my_objects), MyManager)
self.assertIs(type(ModelWithMyManagerDefault.objects), PolymorphicManager)
self.assertIs(type(ModelWithMyManagerDefault._default_manager), MyManager)
self.assertIs(type(ModelWithMyManagerDefault.base_objects), models.Manager)
def test_user_defined_queryset_as_manager(self):
self.create_model2abcd()
@@ -864,7 +862,6 @@ class PolymorphicTests(TransactionTestCase):
type(ModelWithMyManager2._default_manager).__name__,
"PolymorphicManagerFromMyManagerQuerySet",
)
self.assertIs(type(ModelWithMyManager2.base_objects), models.Manager)
def test_manager_inheritance(self):
# by choice of MRO, should be MyManager from MROBase1.