From c0874c5e90cfaef97f5b7a8014205966e27d668f Mon Sep 17 00:00:00 2001 From: Chris Glass Date: Fri, 14 Aug 2020 16:28:30 +0200 Subject: [PATCH 1/6] unrelated: add .venv to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index bab3b71..c18fed3 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ dist/ docs/_build/ htmlcov/ venv/ +.venv/ From 24dd1fff2cc33f06c1afc506385025173f0820da Mon Sep 17 00:00:00 2001 From: Chris Glass Date: Fri, 14 Aug 2020 16:29:49 +0200 Subject: [PATCH 2/6] Add ipdb to test deps This is not strictly necessary but it helps tremendously to have a REPL around to break into when a test fails. --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index e507416..0c7f938 100644 --- a/tox.ini +++ b/tox.ini @@ -12,6 +12,7 @@ setenv = postgres: DEFAULT_DATABASE = postgres:///default postgres: SECONDARY_DATABASE = postgres:///secondary deps = + ipdb coverage dj-database-url django21: Django ~= 2.1 From 76871e3863a3358d2ec81767e7a936538d5ebf19 Mon Sep 17 00:00:00 2001 From: Chris Glass Date: Fri, 14 Aug 2020 16:32:18 +0200 Subject: [PATCH 3/6] Fix warnings This is a little uncertain - while it does fix warnings I'm not sure the removed assertion were actually useful in checking the behavior, and I'm not certain how to recreate the assertion without using the depracated path. --- polymorphic/tests/test_orm.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/polymorphic/tests/test_orm.py b/polymorphic/tests/test_orm.py index a0fd1e8..84da2a5 100644 --- a/polymorphic/tests/test_orm.py +++ b/polymorphic/tests/test_orm.py @@ -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. From 0950478fcd556e89641c411eef3b562567d4981d Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Fri, 14 Aug 2020 16:42:51 +0200 Subject: [PATCH 4/6] Update usage of databases instead of multidb --- polymorphic/tests/test_multidb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polymorphic/tests/test_multidb.py b/polymorphic/tests/test_multidb.py index b70a8d5..dee08d4 100644 --- a/polymorphic/tests/test_multidb.py +++ b/polymorphic/tests/test_multidb.py @@ -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") From 76efd54df576d0869cd503ed750b938e09ac56a5 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Fri, 14 Aug 2020 16:48:12 +0200 Subject: [PATCH 5/6] Add missing field --- polymorphic/tests/migrations/0001_initial.py | 7 +++++++ polymorphic/tests/models.py | 1 + 2 files changed, 8 insertions(+) diff --git a/polymorphic/tests/migrations/0001_initial.py b/polymorphic/tests/migrations/0001_initial.py index 4707a36..38106a3 100644 --- a/polymorphic/tests/migrations/0001_initial.py +++ b/polymorphic/tests/migrations/0001_initial.py @@ -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", diff --git a/polymorphic/tests/models.py b/polymorphic/tests/models.py index 96e361f..494b98f 100644 --- a/polymorphic/tests/models.py +++ b/polymorphic/tests/models.py @@ -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" ) From 7f839aaa361ca87afcdac55d2c4d61122a78fa21 Mon Sep 17 00:00:00 2001 From: Chris Glass Date: Fri, 14 Aug 2020 17:02:40 +0200 Subject: [PATCH 6/6] Remove django master from env list When running locally, don't test against django master. The travis config will however still test those. --- tox.ini | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tox.ini b/tox.ini index 0c7f938..2e4d2c3 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,9 @@ [tox] envlist = - py35-django{21,22,master} - py36-django{21,22,30,31,master} - py37-django{21,22,30,31,master} - py38-django{21,22,30,31,master} + py35-django{21,22} + py36-django{21,22,30,31} + py37-django{21,22,30,31} + py38-django{21,22,30,31} docs [testenv]