1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Refs #33476 -- Reformatted code with Black.

This commit is contained in:
django-bot
2022-02-03 20:24:19 +01:00
committed by Mariusz Felisiak
parent f68fa8b45d
commit 9c19aff7c7
1992 changed files with 139577 additions and 96284 deletions

View File

@@ -3,35 +3,39 @@ from django.test import SimpleTestCase
from django.test.utils import isolate_apps
@isolate_apps('absolute_url_overrides')
@isolate_apps("absolute_url_overrides")
class AbsoluteUrlOverrideTests(SimpleTestCase):
def test_get_absolute_url(self):
"""
get_absolute_url() functions as a normal method.
"""
def get_absolute_url(o):
return '/test-a/%s/' % o.pk
TestA = self._create_model_class('TestA', get_absolute_url)
self.assertTrue(hasattr(TestA, 'get_absolute_url'))
obj = TestA(pk=1, name='Foo')
self.assertEqual('/test-a/%s/' % obj.pk, obj.get_absolute_url())
def get_absolute_url(o):
return "/test-a/%s/" % o.pk
TestA = self._create_model_class("TestA", get_absolute_url)
self.assertTrue(hasattr(TestA, "get_absolute_url"))
obj = TestA(pk=1, name="Foo")
self.assertEqual("/test-a/%s/" % obj.pk, obj.get_absolute_url())
def test_override_get_absolute_url(self):
"""
ABSOLUTE_URL_OVERRIDES should override get_absolute_url().
"""
def get_absolute_url(o):
return '/test-b/%s/' % o.pk
return "/test-b/%s/" % o.pk
with self.settings(
ABSOLUTE_URL_OVERRIDES={
'absolute_url_overrides.testb': lambda o: '/overridden-test-b/%s/' % o.pk,
"absolute_url_overrides.testb": lambda o: "/overridden-test-b/%s/"
% o.pk,
},
):
TestB = self._create_model_class('TestB', get_absolute_url)
obj = TestB(pk=1, name='Foo')
self.assertEqual('/overridden-test-b/%s/' % obj.pk, obj.get_absolute_url())
TestB = self._create_model_class("TestB", get_absolute_url)
obj = TestB(pk=1, name="Foo")
self.assertEqual("/overridden-test-b/%s/" % obj.pk, obj.get_absolute_url())
def test_insert_get_absolute_url(self):
"""
@@ -40,19 +44,19 @@ class AbsoluteUrlOverrideTests(SimpleTestCase):
"""
with self.settings(
ABSOLUTE_URL_OVERRIDES={
'absolute_url_overrides.testc': lambda o: '/test-c/%s/' % o.pk,
"absolute_url_overrides.testc": lambda o: "/test-c/%s/" % o.pk,
},
):
TestC = self._create_model_class('TestC')
obj = TestC(pk=1, name='Foo')
self.assertEqual('/test-c/%s/' % obj.pk, obj.get_absolute_url())
TestC = self._create_model_class("TestC")
obj = TestC(pk=1, name="Foo")
self.assertEqual("/test-c/%s/" % obj.pk, obj.get_absolute_url())
def _create_model_class(self, class_name, get_absolute_url_method=None):
attrs = {
'name': models.CharField(max_length=50),
'__module__': 'absolute_url_overrides',
"name": models.CharField(max_length=50),
"__module__": "absolute_url_overrides",
}
if get_absolute_url_method:
attrs['get_absolute_url'] = get_absolute_url_method
attrs["get_absolute_url"] = get_absolute_url_method
return type(class_name, (models.Model,), attrs)