Loading django/contrib/auth/tests/models.py +17 −9 Original line number Diff line number Diff line import warnings from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.auth.models import (Group, User, SiteProfileNotAvailable, Loading @@ -17,18 +19,24 @@ class ProfileTestCase(TestCase): # calling get_profile without AUTH_PROFILE_MODULE set del settings.AUTH_PROFILE_MODULE with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) with six.assertRaisesRegex(self, SiteProfileNotAvailable, "You need to set AUTH_PROFILE_MODULE in your project"): user.get_profile() # Bad syntax in AUTH_PROFILE_MODULE: settings.AUTH_PROFILE_MODULE = 'foobar' with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) with six.assertRaisesRegex(self, SiteProfileNotAvailable, "app_label and model_name should be separated by a dot"): user.get_profile() # module that doesn't exist settings.AUTH_PROFILE_MODULE = 'foo.bar' with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) with six.assertRaisesRegex(self, SiteProfileNotAvailable, "Unable to load the profile model"): user.get_profile() Loading tests/modeltests/select_related/tests.py +22 −10 Original line number Diff line number Diff line from __future__ import absolute_import, unicode_literals import warnings from django.test import TestCase from .models import Domain, Kingdom, Phylum, Klass, Order, Family, Genus, Species Loading Loading @@ -53,6 +55,8 @@ class SelectRelatedTests(TestCase): extra queries """ with self.assertNumQueries(1): with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) person = Species.objects.select_related(depth=10).get(name="sapiens") domain = person.genus.family.order.klass.phylum.kingdom.domain self.assertEqual(domain.name, 'Eukaryota') Loading Loading @@ -94,6 +98,8 @@ class SelectRelatedTests(TestCase): """ # Notice: one fewer queries than above because of depth=1 with self.assertNumQueries(expected): with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) pea = Species.objects.select_related(depth=depth).get(name="sativum") self.assertEqual( pea.genus.family.order.klass.phylum.kingdom.domain.name, Loading @@ -113,12 +119,16 @@ class SelectRelatedTests(TestCase): particular level. This can be used on lists as well. """ with self.assertNumQueries(5): with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) world = Species.objects.all().select_related(depth=2) orders = [o.genus.family.order.name for o in world] self.assertEqual(sorted(orders), ['Agaricales', 'Diptera', 'Fabales', 'Primates']) def test_select_related_with_extra(self): with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) s = Species.objects.all().select_related(depth=1)\ .extra(select={'a': 'select_related_species.id + 10'})[0] self.assertEqual(s.id + 10, s.a) Loading Loading @@ -156,6 +166,8 @@ class SelectRelatedTests(TestCase): self.assertEqual(s, 'Diptera') def test_depth_fields_fails(self): with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) self.assertRaises(TypeError, Species.objects.select_related, 'genus__family__order', depth=4 Loading tests/regressiontests/multiple_database/tests.py +5 −2 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals import datetime import pickle from operator import attrgetter import warnings from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType Loading Loading @@ -1612,6 +1613,8 @@ class UserProfileTestCase(TestCase): bob_profile = UserProfile(user=bob, flavor='crunchy frog') bob_profile.save() with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) self.assertEqual(alice.get_profile().flavor, 'chocolate') self.assertEqual(bob.get_profile().flavor, 'crunchy frog') Loading Loading
django/contrib/auth/tests/models.py +17 −9 Original line number Diff line number Diff line import warnings from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.auth.models import (Group, User, SiteProfileNotAvailable, Loading @@ -17,18 +19,24 @@ class ProfileTestCase(TestCase): # calling get_profile without AUTH_PROFILE_MODULE set del settings.AUTH_PROFILE_MODULE with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) with six.assertRaisesRegex(self, SiteProfileNotAvailable, "You need to set AUTH_PROFILE_MODULE in your project"): user.get_profile() # Bad syntax in AUTH_PROFILE_MODULE: settings.AUTH_PROFILE_MODULE = 'foobar' with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) with six.assertRaisesRegex(self, SiteProfileNotAvailable, "app_label and model_name should be separated by a dot"): user.get_profile() # module that doesn't exist settings.AUTH_PROFILE_MODULE = 'foo.bar' with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) with six.assertRaisesRegex(self, SiteProfileNotAvailable, "Unable to load the profile model"): user.get_profile() Loading
tests/modeltests/select_related/tests.py +22 −10 Original line number Diff line number Diff line from __future__ import absolute_import, unicode_literals import warnings from django.test import TestCase from .models import Domain, Kingdom, Phylum, Klass, Order, Family, Genus, Species Loading Loading @@ -53,6 +55,8 @@ class SelectRelatedTests(TestCase): extra queries """ with self.assertNumQueries(1): with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) person = Species.objects.select_related(depth=10).get(name="sapiens") domain = person.genus.family.order.klass.phylum.kingdom.domain self.assertEqual(domain.name, 'Eukaryota') Loading Loading @@ -94,6 +98,8 @@ class SelectRelatedTests(TestCase): """ # Notice: one fewer queries than above because of depth=1 with self.assertNumQueries(expected): with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) pea = Species.objects.select_related(depth=depth).get(name="sativum") self.assertEqual( pea.genus.family.order.klass.phylum.kingdom.domain.name, Loading @@ -113,12 +119,16 @@ class SelectRelatedTests(TestCase): particular level. This can be used on lists as well. """ with self.assertNumQueries(5): with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) world = Species.objects.all().select_related(depth=2) orders = [o.genus.family.order.name for o in world] self.assertEqual(sorted(orders), ['Agaricales', 'Diptera', 'Fabales', 'Primates']) def test_select_related_with_extra(self): with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) s = Species.objects.all().select_related(depth=1)\ .extra(select={'a': 'select_related_species.id + 10'})[0] self.assertEqual(s.id + 10, s.a) Loading Loading @@ -156,6 +166,8 @@ class SelectRelatedTests(TestCase): self.assertEqual(s, 'Diptera') def test_depth_fields_fails(self): with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) self.assertRaises(TypeError, Species.objects.select_related, 'genus__family__order', depth=4 Loading
tests/regressiontests/multiple_database/tests.py +5 −2 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals import datetime import pickle from operator import attrgetter import warnings from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType Loading Loading @@ -1612,6 +1613,8 @@ class UserProfileTestCase(TestCase): bob_profile = UserProfile(user=bob, flavor='crunchy frog') bob_profile.save() with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) self.assertEqual(alice.get_profile().flavor, 'chocolate') self.assertEqual(bob.get_profile().flavor, 'crunchy frog') Loading