Fixed hanging indentation in various code.
This commit is contained in:
parent
aeb8c38178
commit
362813d628
|
@ -45,8 +45,7 @@ class FallbackStorage(BaseStorage):
|
||||||
"""
|
"""
|
||||||
for storage in self.storages:
|
for storage in self.storages:
|
||||||
if messages:
|
if messages:
|
||||||
messages = storage._store(messages, response,
|
messages = storage._store(messages, response, remove_oldest=False)
|
||||||
remove_oldest=False)
|
|
||||||
# Even if there are no more messages, continue iterating to ensure
|
# Even if there are no more messages, continue iterating to ensure
|
||||||
# storages which contained messages are flushed.
|
# storages which contained messages are flushed.
|
||||||
elif storage in self._used_storages:
|
elif storage in self._used_storages:
|
||||||
|
|
|
@ -397,8 +397,7 @@ class EmailMessage:
|
||||||
filename.encode('ascii')
|
filename.encode('ascii')
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
filename = ('utf-8', '', filename)
|
filename = ('utf-8', '', filename)
|
||||||
attachment.add_header('Content-Disposition', 'attachment',
|
attachment.add_header('Content-Disposition', 'attachment', filename=filename)
|
||||||
filename=filename)
|
|
||||||
return attachment
|
return attachment
|
||||||
|
|
||||||
def _set_list_header_if_not_empty(self, msg, header, values):
|
def _set_list_header_if_not_empty(self, msg, header, values):
|
||||||
|
|
|
@ -263,7 +263,8 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
nodb_connection = self.__class__(
|
nodb_connection = self.__class__(
|
||||||
self.settings_dict.copy(),
|
self.settings_dict.copy(),
|
||||||
alias=self.alias,
|
alias=self.alias,
|
||||||
allow_thread_sharing=False)
|
allow_thread_sharing=False,
|
||||||
|
)
|
||||||
return nodb_connection
|
return nodb_connection
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
|
|
|
@ -281,7 +281,8 @@ class BaseForm:
|
||||||
error_row='<tr><td colspan="2">%s</td></tr>',
|
error_row='<tr><td colspan="2">%s</td></tr>',
|
||||||
row_ender='</td></tr>',
|
row_ender='</td></tr>',
|
||||||
help_text_html='<br><span class="helptext">%s</span>',
|
help_text_html='<br><span class="helptext">%s</span>',
|
||||||
errors_on_separate_row=False)
|
errors_on_separate_row=False,
|
||||||
|
)
|
||||||
|
|
||||||
def as_ul(self):
|
def as_ul(self):
|
||||||
"Return this form rendered as HTML <li>s -- excluding the <ul></ul>."
|
"Return this form rendered as HTML <li>s -- excluding the <ul></ul>."
|
||||||
|
@ -290,7 +291,8 @@ class BaseForm:
|
||||||
error_row='<li>%s</li>',
|
error_row='<li>%s</li>',
|
||||||
row_ender='</li>',
|
row_ender='</li>',
|
||||||
help_text_html=' <span class="helptext">%s</span>',
|
help_text_html=' <span class="helptext">%s</span>',
|
||||||
errors_on_separate_row=False)
|
errors_on_separate_row=False,
|
||||||
|
)
|
||||||
|
|
||||||
def as_p(self):
|
def as_p(self):
|
||||||
"Return this form rendered as HTML <p>s."
|
"Return this form rendered as HTML <p>s."
|
||||||
|
@ -299,7 +301,8 @@ class BaseForm:
|
||||||
error_row='%s',
|
error_row='%s',
|
||||||
row_ender='</p>',
|
row_ender='</p>',
|
||||||
help_text_html=' <span class="helptext">%s</span>',
|
help_text_html=' <span class="helptext">%s</span>',
|
||||||
errors_on_separate_row=True)
|
errors_on_separate_row=True,
|
||||||
|
)
|
||||||
|
|
||||||
def non_field_errors(self):
|
def non_field_errors(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -130,7 +130,8 @@ class BrokenLinkEmailsMiddleware(MiddlewareMixin):
|
||||||
),
|
),
|
||||||
"Referrer: %s\nRequested URL: %s\nUser agent: %s\n"
|
"Referrer: %s\nRequested URL: %s\nUser agent: %s\n"
|
||||||
"IP address: %s\n" % (referer, path, ua, ip),
|
"IP address: %s\n" % (referer, path, ua, ip),
|
||||||
fail_silently=True)
|
fail_silently=True,
|
||||||
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def is_internal_request(self, domain, referer):
|
def is_internal_request(self, domain, referer):
|
||||||
|
|
|
@ -356,7 +356,8 @@ class ParallelTestSuite(unittest.TestSuite):
|
||||||
pool = multiprocessing.Pool(
|
pool = multiprocessing.Pool(
|
||||||
processes=self.processes,
|
processes=self.processes,
|
||||||
initializer=self.init_worker.__func__,
|
initializer=self.init_worker.__func__,
|
||||||
initargs=[counter])
|
initargs=[counter],
|
||||||
|
)
|
||||||
args = [
|
args = [
|
||||||
(self.runner_class, index, subsuite, self.failfast)
|
(self.runner_class, index, subsuite, self.failfast)
|
||||||
for index, subsuite in enumerate(self.subsuites)
|
for index, subsuite in enumerate(self.subsuites)
|
||||||
|
|
|
@ -146,7 +146,8 @@ class DjangoTranslation(gettext_module.GNUTranslations):
|
||||||
localedir=localedir,
|
localedir=localedir,
|
||||||
languages=[self.__locale],
|
languages=[self.__locale],
|
||||||
codeset='utf-8',
|
codeset='utf-8',
|
||||||
fallback=use_null_fallback)
|
fallback=use_null_fallback,
|
||||||
|
)
|
||||||
|
|
||||||
def _init_translation_catalog(self):
|
def _init_translation_catalog(self):
|
||||||
"""Create a base catalog using global django translations."""
|
"""Create a base catalog using global django translations."""
|
||||||
|
|
|
@ -282,8 +282,7 @@ download.short_description = 'Download subscription'
|
||||||
|
|
||||||
|
|
||||||
def no_perm(modeladmin, request, selected):
|
def no_perm(modeladmin, request, selected):
|
||||||
return HttpResponse(content='No permission to perform this action',
|
return HttpResponse(content='No permission to perform this action', status=403)
|
||||||
status=403)
|
|
||||||
|
|
||||||
|
|
||||||
no_perm.short_description = 'No permission to run'
|
no_perm.short_description = 'No permission to run'
|
||||||
|
@ -685,11 +684,7 @@ class ReportAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
def get_urls(self):
|
def get_urls(self):
|
||||||
# Corner case: Don't call parent implementation
|
# Corner case: Don't call parent implementation
|
||||||
return [
|
return [url(r'^extra/$', self.extra, name='cable_extra')]
|
||||||
url(r'^extra/$',
|
|
||||||
self.extra,
|
|
||||||
name='cable_extra'),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class CustomTemplateBooleanFieldListFilter(BooleanFieldListFilter):
|
class CustomTemplateBooleanFieldListFilter(BooleanFieldListFilter):
|
||||||
|
|
|
@ -283,9 +283,10 @@ class NonAggregateAnnotationTestCase(TestCase):
|
||||||
|
|
||||||
def test_annotation_reverse_m2m(self):
|
def test_annotation_reverse_m2m(self):
|
||||||
books = Book.objects.annotate(
|
books = Book.objects.annotate(
|
||||||
store_name=F('store__name')).filter(
|
store_name=F('store__name'),
|
||||||
name='Practical Django Projects').order_by(
|
).filter(
|
||||||
'store_name')
|
name='Practical Django Projects',
|
||||||
|
).order_by('store_name')
|
||||||
|
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
books, [
|
books, [
|
||||||
|
@ -497,7 +498,8 @@ class NonAggregateAnnotationTestCase(TestCase):
|
||||||
F('ticker_name'),
|
F('ticker_name'),
|
||||||
F('description'),
|
F('description'),
|
||||||
Value('No Tag'),
|
Value('No Tag'),
|
||||||
function='COALESCE')
|
function='COALESCE',
|
||||||
|
)
|
||||||
).annotate(
|
).annotate(
|
||||||
tagline_lower=Lower(F('tagline'), output_field=CharField())
|
tagline_lower=Lower(F('tagline'), output_field=CharField())
|
||||||
).order_by('name')
|
).order_by('name')
|
||||||
|
|
|
@ -559,8 +559,8 @@ class ChangedBackendSettingsTest(TestCase):
|
||||||
# Get a session for the test user
|
# Get a session for the test user
|
||||||
self.assertTrue(self.client.login(
|
self.assertTrue(self.client.login(
|
||||||
username=self.TEST_USERNAME,
|
username=self.TEST_USERNAME,
|
||||||
password=self.TEST_PASSWORD)
|
password=self.TEST_PASSWORD,
|
||||||
)
|
))
|
||||||
# Prepare a request object
|
# Prepare a request object
|
||||||
request = HttpRequest()
|
request = HttpRequest()
|
||||||
request.session = self.client.session
|
request.session = self.client.session
|
||||||
|
|
|
@ -13,7 +13,8 @@ class CheckSessionCookieSecureTest(SimpleTestCase):
|
||||||
@override_settings(
|
@override_settings(
|
||||||
SESSION_COOKIE_SECURE=False,
|
SESSION_COOKIE_SECURE=False,
|
||||||
INSTALLED_APPS=["django.contrib.sessions"],
|
INSTALLED_APPS=["django.contrib.sessions"],
|
||||||
MIDDLEWARE=[])
|
MIDDLEWARE=[],
|
||||||
|
)
|
||||||
def test_session_cookie_secure_with_installed_app(self):
|
def test_session_cookie_secure_with_installed_app(self):
|
||||||
"""
|
"""
|
||||||
Warn if SESSION_COOKIE_SECURE is off and "django.contrib.sessions" is
|
Warn if SESSION_COOKIE_SECURE is off and "django.contrib.sessions" is
|
||||||
|
@ -24,7 +25,8 @@ class CheckSessionCookieSecureTest(SimpleTestCase):
|
||||||
@override_settings(
|
@override_settings(
|
||||||
SESSION_COOKIE_SECURE=False,
|
SESSION_COOKIE_SECURE=False,
|
||||||
INSTALLED_APPS=[],
|
INSTALLED_APPS=[],
|
||||||
MIDDLEWARE=["django.contrib.sessions.middleware.SessionMiddleware"])
|
MIDDLEWARE=['django.contrib.sessions.middleware.SessionMiddleware'],
|
||||||
|
)
|
||||||
def test_session_cookie_secure_with_middleware(self):
|
def test_session_cookie_secure_with_middleware(self):
|
||||||
"""
|
"""
|
||||||
Warn if SESSION_COOKIE_SECURE is off and
|
Warn if SESSION_COOKIE_SECURE is off and
|
||||||
|
@ -36,7 +38,8 @@ class CheckSessionCookieSecureTest(SimpleTestCase):
|
||||||
@override_settings(
|
@override_settings(
|
||||||
SESSION_COOKIE_SECURE=False,
|
SESSION_COOKIE_SECURE=False,
|
||||||
INSTALLED_APPS=["django.contrib.sessions"],
|
INSTALLED_APPS=["django.contrib.sessions"],
|
||||||
MIDDLEWARE=["django.contrib.sessions.middleware.SessionMiddleware"])
|
MIDDLEWARE=['django.contrib.sessions.middleware.SessionMiddleware'],
|
||||||
|
)
|
||||||
def test_session_cookie_secure_both(self):
|
def test_session_cookie_secure_both(self):
|
||||||
"""
|
"""
|
||||||
If SESSION_COOKIE_SECURE is off and we find both the session app and
|
If SESSION_COOKIE_SECURE is off and we find both the session app and
|
||||||
|
@ -47,7 +50,8 @@ class CheckSessionCookieSecureTest(SimpleTestCase):
|
||||||
@override_settings(
|
@override_settings(
|
||||||
SESSION_COOKIE_SECURE=True,
|
SESSION_COOKIE_SECURE=True,
|
||||||
INSTALLED_APPS=["django.contrib.sessions"],
|
INSTALLED_APPS=["django.contrib.sessions"],
|
||||||
MIDDLEWARE=["django.contrib.sessions.middleware.SessionMiddleware"])
|
MIDDLEWARE=['django.contrib.sessions.middleware.SessionMiddleware'],
|
||||||
|
)
|
||||||
def test_session_cookie_secure_true(self):
|
def test_session_cookie_secure_true(self):
|
||||||
"""
|
"""
|
||||||
If SESSION_COOKIE_SECURE is on, there's no warning about it.
|
If SESSION_COOKIE_SECURE is on, there's no warning about it.
|
||||||
|
@ -64,7 +68,8 @@ class CheckSessionCookieHttpOnlyTest(SimpleTestCase):
|
||||||
@override_settings(
|
@override_settings(
|
||||||
SESSION_COOKIE_HTTPONLY=False,
|
SESSION_COOKIE_HTTPONLY=False,
|
||||||
INSTALLED_APPS=["django.contrib.sessions"],
|
INSTALLED_APPS=["django.contrib.sessions"],
|
||||||
MIDDLEWARE=[])
|
MIDDLEWARE=[],
|
||||||
|
)
|
||||||
def test_session_cookie_httponly_with_installed_app(self):
|
def test_session_cookie_httponly_with_installed_app(self):
|
||||||
"""
|
"""
|
||||||
Warn if SESSION_COOKIE_HTTPONLY is off and "django.contrib.sessions"
|
Warn if SESSION_COOKIE_HTTPONLY is off and "django.contrib.sessions"
|
||||||
|
@ -75,7 +80,8 @@ class CheckSessionCookieHttpOnlyTest(SimpleTestCase):
|
||||||
@override_settings(
|
@override_settings(
|
||||||
SESSION_COOKIE_HTTPONLY=False,
|
SESSION_COOKIE_HTTPONLY=False,
|
||||||
INSTALLED_APPS=[],
|
INSTALLED_APPS=[],
|
||||||
MIDDLEWARE=["django.contrib.sessions.middleware.SessionMiddleware"])
|
MIDDLEWARE=['django.contrib.sessions.middleware.SessionMiddleware'],
|
||||||
|
)
|
||||||
def test_session_cookie_httponly_with_middleware(self):
|
def test_session_cookie_httponly_with_middleware(self):
|
||||||
"""
|
"""
|
||||||
Warn if SESSION_COOKIE_HTTPONLY is off and
|
Warn if SESSION_COOKIE_HTTPONLY is off and
|
||||||
|
@ -87,7 +93,8 @@ class CheckSessionCookieHttpOnlyTest(SimpleTestCase):
|
||||||
@override_settings(
|
@override_settings(
|
||||||
SESSION_COOKIE_HTTPONLY=False,
|
SESSION_COOKIE_HTTPONLY=False,
|
||||||
INSTALLED_APPS=["django.contrib.sessions"],
|
INSTALLED_APPS=["django.contrib.sessions"],
|
||||||
MIDDLEWARE=["django.contrib.sessions.middleware.SessionMiddleware"])
|
MIDDLEWARE=['django.contrib.sessions.middleware.SessionMiddleware'],
|
||||||
|
)
|
||||||
def test_session_cookie_httponly_both(self):
|
def test_session_cookie_httponly_both(self):
|
||||||
"""
|
"""
|
||||||
If SESSION_COOKIE_HTTPONLY is off and we find both the session app and
|
If SESSION_COOKIE_HTTPONLY is off and we find both the session app and
|
||||||
|
@ -98,7 +105,8 @@ class CheckSessionCookieHttpOnlyTest(SimpleTestCase):
|
||||||
@override_settings(
|
@override_settings(
|
||||||
SESSION_COOKIE_HTTPONLY=True,
|
SESSION_COOKIE_HTTPONLY=True,
|
||||||
INSTALLED_APPS=["django.contrib.sessions"],
|
INSTALLED_APPS=["django.contrib.sessions"],
|
||||||
MIDDLEWARE=["django.contrib.sessions.middleware.SessionMiddleware"])
|
MIDDLEWARE=['django.contrib.sessions.middleware.SessionMiddleware'],
|
||||||
|
)
|
||||||
def test_session_cookie_httponly_true(self):
|
def test_session_cookie_httponly_true(self):
|
||||||
"""
|
"""
|
||||||
If SESSION_COOKIE_HTTPONLY is on, there's no warning about it.
|
If SESSION_COOKIE_HTTPONLY is on, there's no warning about it.
|
||||||
|
@ -119,8 +127,7 @@ class CheckCSRFMiddlewareTest(SimpleTestCase):
|
||||||
"""
|
"""
|
||||||
self.assertEqual(self.func(None), [csrf.W003])
|
self.assertEqual(self.func(None), [csrf.W003])
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(MIDDLEWARE=['django.middleware.csrf.CsrfViewMiddleware'])
|
||||||
MIDDLEWARE=["django.middleware.csrf.CsrfViewMiddleware"])
|
|
||||||
def test_with_csrf_middleware(self):
|
def test_with_csrf_middleware(self):
|
||||||
self.assertEqual(self.func(None), [])
|
self.assertEqual(self.func(None), [])
|
||||||
|
|
||||||
|
@ -133,7 +140,8 @@ class CheckCSRFCookieSecureTest(SimpleTestCase):
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=["django.middleware.csrf.CsrfViewMiddleware"],
|
MIDDLEWARE=["django.middleware.csrf.CsrfViewMiddleware"],
|
||||||
CSRF_COOKIE_SECURE=False)
|
CSRF_COOKIE_SECURE=False,
|
||||||
|
)
|
||||||
def test_with_csrf_cookie_secure_false(self):
|
def test_with_csrf_cookie_secure_false(self):
|
||||||
"""
|
"""
|
||||||
Warn if CsrfViewMiddleware is in MIDDLEWARE but
|
Warn if CsrfViewMiddleware is in MIDDLEWARE but
|
||||||
|
@ -144,7 +152,8 @@ class CheckCSRFCookieSecureTest(SimpleTestCase):
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=["django.middleware.csrf.CsrfViewMiddleware"],
|
MIDDLEWARE=["django.middleware.csrf.CsrfViewMiddleware"],
|
||||||
CSRF_USE_SESSIONS=True,
|
CSRF_USE_SESSIONS=True,
|
||||||
CSRF_COOKIE_SECURE=False)
|
CSRF_COOKIE_SECURE=False,
|
||||||
|
)
|
||||||
def test_use_sessions_with_csrf_cookie_secure_false(self):
|
def test_use_sessions_with_csrf_cookie_secure_false(self):
|
||||||
"""
|
"""
|
||||||
No warning if CSRF_COOKIE_SECURE isn't True while CSRF_USE_SESSIONS
|
No warning if CSRF_COOKIE_SECURE isn't True while CSRF_USE_SESSIONS
|
||||||
|
@ -162,7 +171,8 @@ class CheckCSRFCookieSecureTest(SimpleTestCase):
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=["django.middleware.csrf.CsrfViewMiddleware"],
|
MIDDLEWARE=["django.middleware.csrf.CsrfViewMiddleware"],
|
||||||
CSRF_COOKIE_SECURE=True)
|
CSRF_COOKIE_SECURE=True,
|
||||||
|
)
|
||||||
def test_with_csrf_cookie_secure_true(self):
|
def test_with_csrf_cookie_secure_true(self):
|
||||||
self.assertEqual(self.func(None), [])
|
self.assertEqual(self.func(None), [])
|
||||||
|
|
||||||
|
@ -180,8 +190,7 @@ class CheckSecurityMiddlewareTest(SimpleTestCase):
|
||||||
"""
|
"""
|
||||||
self.assertEqual(self.func(None), [base.W001])
|
self.assertEqual(self.func(None), [base.W001])
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(MIDDLEWARE=['django.middleware.security.SecurityMiddleware'])
|
||||||
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"])
|
|
||||||
def test_with_security_middleware(self):
|
def test_with_security_middleware(self):
|
||||||
self.assertEqual(self.func(None), [])
|
self.assertEqual(self.func(None), [])
|
||||||
|
|
||||||
|
@ -194,16 +203,15 @@ class CheckStrictTransportSecurityTest(SimpleTestCase):
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
||||||
SECURE_HSTS_SECONDS=0)
|
SECURE_HSTS_SECONDS=0,
|
||||||
|
)
|
||||||
def test_no_sts(self):
|
def test_no_sts(self):
|
||||||
"""
|
"""
|
||||||
Warn if SECURE_HSTS_SECONDS isn't > 0.
|
Warn if SECURE_HSTS_SECONDS isn't > 0.
|
||||||
"""
|
"""
|
||||||
self.assertEqual(self.func(None), [base.W004])
|
self.assertEqual(self.func(None), [base.W004])
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(MIDDLEWARE=[], SECURE_HSTS_SECONDS=0)
|
||||||
MIDDLEWARE=[],
|
|
||||||
SECURE_HSTS_SECONDS=0)
|
|
||||||
def test_no_sts_no_middleware(self):
|
def test_no_sts_no_middleware(self):
|
||||||
"""
|
"""
|
||||||
Don't warn if SECURE_HSTS_SECONDS isn't > 0 and SecurityMiddleware isn't
|
Don't warn if SECURE_HSTS_SECONDS isn't > 0 and SecurityMiddleware isn't
|
||||||
|
@ -213,7 +221,8 @@ class CheckStrictTransportSecurityTest(SimpleTestCase):
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
||||||
SECURE_HSTS_SECONDS=3600)
|
SECURE_HSTS_SECONDS=3600,
|
||||||
|
)
|
||||||
def test_with_sts(self):
|
def test_with_sts(self):
|
||||||
self.assertEqual(self.func(None), [])
|
self.assertEqual(self.func(None), [])
|
||||||
|
|
||||||
|
@ -227,7 +236,8 @@ class CheckStrictTransportSecuritySubdomainsTest(SimpleTestCase):
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
||||||
SECURE_HSTS_INCLUDE_SUBDOMAINS=False,
|
SECURE_HSTS_INCLUDE_SUBDOMAINS=False,
|
||||||
SECURE_HSTS_SECONDS=3600)
|
SECURE_HSTS_SECONDS=3600,
|
||||||
|
)
|
||||||
def test_no_sts_subdomains(self):
|
def test_no_sts_subdomains(self):
|
||||||
"""
|
"""
|
||||||
Warn if SECURE_HSTS_INCLUDE_SUBDOMAINS isn't True.
|
Warn if SECURE_HSTS_INCLUDE_SUBDOMAINS isn't True.
|
||||||
|
@ -237,7 +247,8 @@ class CheckStrictTransportSecuritySubdomainsTest(SimpleTestCase):
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=[],
|
MIDDLEWARE=[],
|
||||||
SECURE_HSTS_INCLUDE_SUBDOMAINS=False,
|
SECURE_HSTS_INCLUDE_SUBDOMAINS=False,
|
||||||
SECURE_HSTS_SECONDS=3600)
|
SECURE_HSTS_SECONDS=3600,
|
||||||
|
)
|
||||||
def test_no_sts_subdomains_no_middleware(self):
|
def test_no_sts_subdomains_no_middleware(self):
|
||||||
"""
|
"""
|
||||||
Don't warn if SecurityMiddleware isn't installed.
|
Don't warn if SecurityMiddleware isn't installed.
|
||||||
|
@ -247,7 +258,8 @@ class CheckStrictTransportSecuritySubdomainsTest(SimpleTestCase):
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
||||||
SECURE_SSL_REDIRECT=False,
|
SECURE_SSL_REDIRECT=False,
|
||||||
SECURE_HSTS_SECONDS=None)
|
SECURE_HSTS_SECONDS=None,
|
||||||
|
)
|
||||||
def test_no_sts_subdomains_no_seconds(self):
|
def test_no_sts_subdomains_no_seconds(self):
|
||||||
"""
|
"""
|
||||||
Don't warn if SECURE_HSTS_SECONDS isn't set.
|
Don't warn if SECURE_HSTS_SECONDS isn't set.
|
||||||
|
@ -257,7 +269,8 @@ class CheckStrictTransportSecuritySubdomainsTest(SimpleTestCase):
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
||||||
SECURE_HSTS_INCLUDE_SUBDOMAINS=True,
|
SECURE_HSTS_INCLUDE_SUBDOMAINS=True,
|
||||||
SECURE_HSTS_SECONDS=3600)
|
SECURE_HSTS_SECONDS=3600,
|
||||||
|
)
|
||||||
def test_with_sts_subdomains(self):
|
def test_with_sts_subdomains(self):
|
||||||
self.assertEqual(self.func(None), [])
|
self.assertEqual(self.func(None), [])
|
||||||
|
|
||||||
|
@ -365,16 +378,15 @@ class CheckContentTypeNosniffTest(SimpleTestCase):
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
||||||
SECURE_CONTENT_TYPE_NOSNIFF=False)
|
SECURE_CONTENT_TYPE_NOSNIFF=False,
|
||||||
|
)
|
||||||
def test_no_content_type_nosniff(self):
|
def test_no_content_type_nosniff(self):
|
||||||
"""
|
"""
|
||||||
Warn if SECURE_CONTENT_TYPE_NOSNIFF isn't True.
|
Warn if SECURE_CONTENT_TYPE_NOSNIFF isn't True.
|
||||||
"""
|
"""
|
||||||
self.assertEqual(self.func(None), [base.W006])
|
self.assertEqual(self.func(None), [base.W006])
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(MIDDLEWARE=[], SECURE_CONTENT_TYPE_NOSNIFF=False)
|
||||||
MIDDLEWARE=[],
|
|
||||||
SECURE_CONTENT_TYPE_NOSNIFF=False)
|
|
||||||
def test_no_content_type_nosniff_no_middleware(self):
|
def test_no_content_type_nosniff_no_middleware(self):
|
||||||
"""
|
"""
|
||||||
Don't warn if SECURE_CONTENT_TYPE_NOSNIFF isn't True and
|
Don't warn if SECURE_CONTENT_TYPE_NOSNIFF isn't True and
|
||||||
|
@ -384,7 +396,8 @@ class CheckContentTypeNosniffTest(SimpleTestCase):
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
||||||
SECURE_CONTENT_TYPE_NOSNIFF=True)
|
SECURE_CONTENT_TYPE_NOSNIFF=True,
|
||||||
|
)
|
||||||
def test_with_content_type_nosniff(self):
|
def test_with_content_type_nosniff(self):
|
||||||
self.assertEqual(self.func(None), [])
|
self.assertEqual(self.func(None), [])
|
||||||
|
|
||||||
|
@ -397,16 +410,15 @@ class CheckXssFilterTest(SimpleTestCase):
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
||||||
SECURE_BROWSER_XSS_FILTER=False)
|
SECURE_BROWSER_XSS_FILTER=False,
|
||||||
|
)
|
||||||
def test_no_xss_filter(self):
|
def test_no_xss_filter(self):
|
||||||
"""
|
"""
|
||||||
Warn if SECURE_BROWSER_XSS_FILTER isn't True.
|
Warn if SECURE_BROWSER_XSS_FILTER isn't True.
|
||||||
"""
|
"""
|
||||||
self.assertEqual(self.func(None), [base.W007])
|
self.assertEqual(self.func(None), [base.W007])
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(MIDDLEWARE=[], SECURE_BROWSER_XSS_FILTER=False)
|
||||||
MIDDLEWARE=[],
|
|
||||||
SECURE_BROWSER_XSS_FILTER=False)
|
|
||||||
def test_no_xss_filter_no_middleware(self):
|
def test_no_xss_filter_no_middleware(self):
|
||||||
"""
|
"""
|
||||||
Don't warn if SECURE_BROWSER_XSS_FILTER isn't True and
|
Don't warn if SECURE_BROWSER_XSS_FILTER isn't True and
|
||||||
|
@ -416,7 +428,8 @@ class CheckXssFilterTest(SimpleTestCase):
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
||||||
SECURE_BROWSER_XSS_FILTER=True)
|
SECURE_BROWSER_XSS_FILTER=True,
|
||||||
|
)
|
||||||
def test_with_xss_filter(self):
|
def test_with_xss_filter(self):
|
||||||
self.assertEqual(self.func(None), [])
|
self.assertEqual(self.func(None), [])
|
||||||
|
|
||||||
|
@ -429,16 +442,15 @@ class CheckSSLRedirectTest(SimpleTestCase):
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
||||||
SECURE_SSL_REDIRECT=False)
|
SECURE_SSL_REDIRECT=False,
|
||||||
|
)
|
||||||
def test_no_ssl_redirect(self):
|
def test_no_ssl_redirect(self):
|
||||||
"""
|
"""
|
||||||
Warn if SECURE_SSL_REDIRECT isn't True.
|
Warn if SECURE_SSL_REDIRECT isn't True.
|
||||||
"""
|
"""
|
||||||
self.assertEqual(self.func(None), [base.W008])
|
self.assertEqual(self.func(None), [base.W008])
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(MIDDLEWARE=[], SECURE_SSL_REDIRECT=False)
|
||||||
MIDDLEWARE=[],
|
|
||||||
SECURE_SSL_REDIRECT=False)
|
|
||||||
def test_no_ssl_redirect_no_middleware(self):
|
def test_no_ssl_redirect_no_middleware(self):
|
||||||
"""
|
"""
|
||||||
Don't warn if SECURE_SSL_REDIRECT is False and SecurityMiddleware isn't
|
Don't warn if SECURE_SSL_REDIRECT is False and SecurityMiddleware isn't
|
||||||
|
@ -448,7 +460,8 @@ class CheckSSLRedirectTest(SimpleTestCase):
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
|
||||||
SECURE_SSL_REDIRECT=True)
|
SECURE_SSL_REDIRECT=True,
|
||||||
|
)
|
||||||
def test_with_ssl_redirect(self):
|
def test_with_ssl_redirect(self):
|
||||||
self.assertEqual(self.func(None), [])
|
self.assertEqual(self.func(None), [])
|
||||||
|
|
||||||
|
|
|
@ -233,8 +233,7 @@ class TestDefer2(AssertionMixin, TestCase):
|
||||||
fetched parent model PK if it happens to be available.
|
fetched parent model PK if it happens to be available.
|
||||||
"""
|
"""
|
||||||
s1 = Secondary.objects.create(first="x1", second="y1")
|
s1 = Secondary.objects.create(first="x1", second="y1")
|
||||||
bc = BigChild.objects.create(name="b1", value="foo", related=s1,
|
bc = BigChild.objects.create(name='b1', value='foo', related=s1, other='bar')
|
||||||
other="bar")
|
|
||||||
bc_deferred = BigChild.objects.only('name').get(pk=bc.pk)
|
bc_deferred = BigChild.objects.only('name').get(pk=bc.pk)
|
||||||
with self.assertNumQueries(0):
|
with self.assertNumQueries(0):
|
||||||
bc_deferred.id
|
bc_deferred.id
|
||||||
|
|
|
@ -61,8 +61,7 @@ class DeleteCascadeTests(TestCase):
|
||||||
"""
|
"""
|
||||||
person = Person.objects.create(name='Nelson Mandela')
|
person = Person.objects.create(name='Nelson Mandela')
|
||||||
award = Award.objects.create(name='Nobel', content_object=person)
|
award = Award.objects.create(name='Nobel', content_object=person)
|
||||||
AwardNote.objects.create(note='a peace prize',
|
AwardNote.objects.create(note='a peace prize', award=award)
|
||||||
award=award)
|
|
||||||
self.assertEqual(AwardNote.objects.count(), 1)
|
self.assertEqual(AwardNote.objects.count(), 1)
|
||||||
person.delete()
|
person.delete()
|
||||||
self.assertEqual(Award.objects.count(), 0)
|
self.assertEqual(Award.objects.count(), 0)
|
||||||
|
@ -78,10 +77,8 @@ class DeleteCascadeTests(TestCase):
|
||||||
"""
|
"""
|
||||||
juan = Child.objects.create(name='Juan')
|
juan = Child.objects.create(name='Juan')
|
||||||
paints = Toy.objects.create(name='Paints')
|
paints = Toy.objects.create(name='Paints')
|
||||||
played = PlayedWith.objects.create(child=juan, toy=paints,
|
played = PlayedWith.objects.create(child=juan, toy=paints, date=datetime.date.today())
|
||||||
date=datetime.date.today())
|
PlayedWithNote.objects.create(played=played, note='the next Jackson Pollock')
|
||||||
PlayedWithNote.objects.create(played=played,
|
|
||||||
note='the next Jackson Pollock')
|
|
||||||
self.assertEqual(PlayedWithNote.objects.count(), 1)
|
self.assertEqual(PlayedWithNote.objects.count(), 1)
|
||||||
paints.delete()
|
paints.delete()
|
||||||
self.assertEqual(PlayedWith.objects.count(), 0)
|
self.assertEqual(PlayedWith.objects.count(), 0)
|
||||||
|
|
|
@ -22,12 +22,14 @@ class Company(models.Model):
|
||||||
ceo = models.ForeignKey(
|
ceo = models.ForeignKey(
|
||||||
Employee,
|
Employee,
|
||||||
models.CASCADE,
|
models.CASCADE,
|
||||||
related_name='company_ceo_set')
|
related_name='company_ceo_set',
|
||||||
|
)
|
||||||
point_of_contact = models.ForeignKey(
|
point_of_contact = models.ForeignKey(
|
||||||
Employee,
|
Employee,
|
||||||
models.SET_NULL,
|
models.SET_NULL,
|
||||||
related_name='company_point_of_contact_set',
|
related_name='company_point_of_contact_set',
|
||||||
null=True)
|
null=True,
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
|
@ -373,7 +373,8 @@ class BasicExpressionsTests(TestCase):
|
||||||
# other lookups could not reuse.
|
# other lookups could not reuse.
|
||||||
qs = Employee.objects.filter(
|
qs = Employee.objects.filter(
|
||||||
company_ceo_set__num_chairs=F('company_ceo_set__num_employees'),
|
company_ceo_set__num_chairs=F('company_ceo_set__num_employees'),
|
||||||
company_ceo_set__num_chairs__gte=1)
|
company_ceo_set__num_chairs__gte=1,
|
||||||
|
)
|
||||||
self.assertEqual(str(qs.query).count('JOIN'), 1)
|
self.assertEqual(str(qs.query).count('JOIN'), 1)
|
||||||
|
|
||||||
def test_ticket_18375_kwarg_ordering_2(self):
|
def test_ticket_18375_kwarg_ordering_2(self):
|
||||||
|
@ -793,17 +794,20 @@ class ExpressionsTests(TestCase):
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
Employee.objects.filter(firstname__contains=F('lastname')),
|
Employee.objects.filter(firstname__contains=F('lastname')),
|
||||||
["<Employee: %Joh\\nny %Joh\\n>", "<Employee: Jean-Claude Claude>", "<Employee: Johnny John>"],
|
["<Employee: %Joh\\nny %Joh\\n>", "<Employee: Jean-Claude Claude>", "<Employee: Johnny John>"],
|
||||||
ordered=False)
|
ordered=False,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
Employee.objects.filter(firstname__startswith=F('lastname')),
|
Employee.objects.filter(firstname__startswith=F('lastname')),
|
||||||
["<Employee: %Joh\\nny %Joh\\n>", "<Employee: Johnny John>"],
|
["<Employee: %Joh\\nny %Joh\\n>", "<Employee: Johnny John>"],
|
||||||
ordered=False)
|
ordered=False,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
Employee.objects.filter(firstname__endswith=F('lastname')),
|
Employee.objects.filter(firstname__endswith=F('lastname')),
|
||||||
["<Employee: Jean-Claude Claude>"],
|
["<Employee: Jean-Claude Claude>"],
|
||||||
ordered=False)
|
ordered=False,
|
||||||
|
)
|
||||||
|
|
||||||
def test_insensitive_patterns_escape(self):
|
def test_insensitive_patterns_escape(self):
|
||||||
r"""
|
r"""
|
||||||
|
@ -825,17 +829,20 @@ class ExpressionsTests(TestCase):
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
Employee.objects.filter(firstname__icontains=F('lastname')),
|
Employee.objects.filter(firstname__icontains=F('lastname')),
|
||||||
["<Employee: %Joh\\nny %joh\\n>", "<Employee: Jean-Claude claude>", "<Employee: Johnny john>"],
|
["<Employee: %Joh\\nny %joh\\n>", "<Employee: Jean-Claude claude>", "<Employee: Johnny john>"],
|
||||||
ordered=False)
|
ordered=False,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
Employee.objects.filter(firstname__istartswith=F('lastname')),
|
Employee.objects.filter(firstname__istartswith=F('lastname')),
|
||||||
["<Employee: %Joh\\nny %joh\\n>", "<Employee: Johnny john>"],
|
["<Employee: %Joh\\nny %joh\\n>", "<Employee: Johnny john>"],
|
||||||
ordered=False)
|
ordered=False,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
Employee.objects.filter(firstname__iendswith=F('lastname')),
|
Employee.objects.filter(firstname__iendswith=F('lastname')),
|
||||||
["<Employee: Jean-Claude claude>"],
|
["<Employee: Jean-Claude claude>"],
|
||||||
ordered=False)
|
ordered=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ExpressionsNumericTests(TestCase):
|
class ExpressionsNumericTests(TestCase):
|
||||||
|
|
|
@ -334,7 +334,8 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
|
||||||
self._dumpdata_assert(
|
self._dumpdata_assert(
|
||||||
['sites', 'fixtures'],
|
['sites', 'fixtures'],
|
||||||
'[{"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}]',
|
'[{"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}]',
|
||||||
exclude_list=['fixtures'])
|
exclude_list=['fixtures'],
|
||||||
|
)
|
||||||
|
|
||||||
# Excluding fixtures.Article/Book should leave fixtures.Category
|
# Excluding fixtures.Article/Book should leave fixtures.Category
|
||||||
self._dumpdata_assert(
|
self._dumpdata_assert(
|
||||||
|
|
|
@ -88,7 +88,8 @@ class Friendship(models.Model):
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
from_fields=['from_friend_country', 'from_friend_id'],
|
from_fields=['from_friend_country', 'from_friend_id'],
|
||||||
to_fields=['person_country_id', 'id'],
|
to_fields=['person_country_id', 'id'],
|
||||||
related_name='from_friend')
|
related_name='from_friend',
|
||||||
|
)
|
||||||
|
|
||||||
to_friend_country = models.ForeignObject(
|
to_friend_country = models.ForeignObject(
|
||||||
Country,
|
Country,
|
||||||
|
|
|
@ -50,8 +50,7 @@ class ChoiceModel(models.Model):
|
||||||
choice = models.CharField(max_length=2, blank=True, choices=CHOICES)
|
choice = models.CharField(max_length=2, blank=True, choices=CHOICES)
|
||||||
choice_string_w_none = models.CharField(
|
choice_string_w_none = models.CharField(
|
||||||
max_length=2, blank=True, null=True, choices=STRING_CHOICES_WITH_NONE)
|
max_length=2, blank=True, null=True, choices=STRING_CHOICES_WITH_NONE)
|
||||||
choice_integer = models.IntegerField(choices=INTEGER_CHOICES, blank=True,
|
choice_integer = models.IntegerField(choices=INTEGER_CHOICES, blank=True, null=True)
|
||||||
null=True)
|
|
||||||
|
|
||||||
|
|
||||||
class ChoiceOptionModel(models.Model):
|
class ChoiceOptionModel(models.Model):
|
||||||
|
|
|
@ -3240,9 +3240,11 @@ Good luck picking a username that doesn't already exist.</p>
|
||||||
bar = CharField()
|
bar = CharField()
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
raise ValidationError('<p>Non-field error.</p>',
|
raise ValidationError(
|
||||||
|
'<p>Non-field error.</p>',
|
||||||
code='secret',
|
code='secret',
|
||||||
params={'a': 1, 'b': 2})
|
params={'a': 1, 'b': 2},
|
||||||
|
)
|
||||||
|
|
||||||
control = {
|
control = {
|
||||||
'foo': [{'code': 'required', 'message': 'This field is required.'}],
|
'foo': [{'code': 'required', 'message': 'This field is required.'}],
|
||||||
|
|
|
@ -629,13 +629,11 @@ class KeepPotFileExtractorTests(ExtractorTests):
|
||||||
self.assertFalse(os.path.exists(self.POT_FILE))
|
self.assertFalse(os.path.exists(self.POT_FILE))
|
||||||
|
|
||||||
def test_keep_pot_explicitly_disabled(self):
|
def test_keep_pot_explicitly_disabled(self):
|
||||||
management.call_command('makemessages', locale=[LOCALE], verbosity=0,
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0, keep_pot=False)
|
||||||
keep_pot=False)
|
|
||||||
self.assertFalse(os.path.exists(self.POT_FILE))
|
self.assertFalse(os.path.exists(self.POT_FILE))
|
||||||
|
|
||||||
def test_keep_pot_enabled(self):
|
def test_keep_pot_enabled(self):
|
||||||
management.call_command('makemessages', locale=[LOCALE], verbosity=0,
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0, keep_pot=True)
|
||||||
keep_pot=True)
|
|
||||||
self.assertTrue(os.path.exists(self.POT_FILE))
|
self.assertTrue(os.path.exists(self.POT_FILE))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,8 @@ class CharFieldTests(TestCase):
|
||||||
('1', 'item1'),
|
('1', 'item1'),
|
||||||
('2', 'item2'),
|
('2', 'item2'),
|
||||||
],
|
],
|
||||||
db_index=True)
|
db_index=True,
|
||||||
|
)
|
||||||
|
|
||||||
field = Model._meta.get_field('field')
|
field = Model._meta.get_field('field')
|
||||||
self.assertEqual(field.check(), [])
|
self.assertEqual(field.check(), [])
|
||||||
|
|
|
@ -390,8 +390,10 @@ class SetupConfigureLogging(SimpleTestCase):
|
||||||
"""
|
"""
|
||||||
Calling django.setup() initializes the logging configuration.
|
Calling django.setup() initializes the logging configuration.
|
||||||
"""
|
"""
|
||||||
@override_settings(LOGGING_CONFIG='logging_tests.tests.dictConfig',
|
@override_settings(
|
||||||
LOGGING=OLD_LOGGING)
|
LOGGING_CONFIG='logging_tests.tests.dictConfig',
|
||||||
|
LOGGING=OLD_LOGGING,
|
||||||
|
)
|
||||||
def test_configure_initializes_logging(self):
|
def test_configure_initializes_logging(self):
|
||||||
from django import setup
|
from django import setup
|
||||||
setup()
|
setup()
|
||||||
|
|
|
@ -1300,7 +1300,8 @@ class SMTPBackendTests(BaseEmailBackendTests, SMTPBackendTestsBase):
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
EMAIL_HOST_USER="not empty username",
|
EMAIL_HOST_USER="not empty username",
|
||||||
EMAIL_HOST_PASSWORD="not empty password")
|
EMAIL_HOST_PASSWORD='not empty password',
|
||||||
|
)
|
||||||
def test_email_authentication_use_settings(self):
|
def test_email_authentication_use_settings(self):
|
||||||
backend = smtp.EmailBackend()
|
backend = smtp.EmailBackend()
|
||||||
self.assertEqual(backend.username, 'not empty username')
|
self.assertEqual(backend.username, 'not empty username')
|
||||||
|
@ -1308,7 +1309,8 @@ class SMTPBackendTests(BaseEmailBackendTests, SMTPBackendTestsBase):
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
EMAIL_HOST_USER="not empty username",
|
EMAIL_HOST_USER="not empty username",
|
||||||
EMAIL_HOST_PASSWORD="not empty password")
|
EMAIL_HOST_PASSWORD='not empty password',
|
||||||
|
)
|
||||||
def test_email_authentication_override_settings(self):
|
def test_email_authentication_override_settings(self):
|
||||||
backend = smtp.EmailBackend(username='username', password='password')
|
backend = smtp.EmailBackend(username='username', password='password')
|
||||||
self.assertEqual(backend.username, 'username')
|
self.assertEqual(backend.username, 'username')
|
||||||
|
@ -1316,7 +1318,8 @@ class SMTPBackendTests(BaseEmailBackendTests, SMTPBackendTestsBase):
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
EMAIL_HOST_USER="not empty username",
|
EMAIL_HOST_USER="not empty username",
|
||||||
EMAIL_HOST_PASSWORD="not empty password")
|
EMAIL_HOST_PASSWORD='not empty password',
|
||||||
|
)
|
||||||
def test_email_disabled_authentication(self):
|
def test_email_disabled_authentication(self):
|
||||||
backend = smtp.EmailBackend(username='', password='')
|
backend = smtp.EmailBackend(username='', password='')
|
||||||
self.assertEqual(backend.username, '')
|
self.assertEqual(backend.username, '')
|
||||||
|
|
|
@ -48,7 +48,8 @@ class SecurityMiddlewareTest(SimpleTestCase):
|
||||||
"""
|
"""
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.process_response(secure=True)["strict-transport-security"],
|
self.process_response(secure=True)["strict-transport-security"],
|
||||||
"max-age=3600")
|
'max-age=3600',
|
||||||
|
)
|
||||||
|
|
||||||
@override_settings(SECURE_HSTS_SECONDS=3600)
|
@override_settings(SECURE_HSTS_SECONDS=3600)
|
||||||
def test_sts_already_present(self):
|
def test_sts_already_present(self):
|
||||||
|
|
|
@ -783,8 +783,10 @@ class AutodetectorTests(TestCase):
|
||||||
self.assertOperationAttributes(changes, "testapp", 0, 0, name="name", preserve_default=True)
|
self.assertOperationAttributes(changes, "testapp", 0, 0, name="name", preserve_default=True)
|
||||||
self.assertOperationFieldAttributes(changes, "testapp", 0, 0, default='Ada Lovelace')
|
self.assertOperationFieldAttributes(changes, "testapp", 0, 0, default='Ada Lovelace')
|
||||||
|
|
||||||
@mock.patch('django.db.migrations.questioner.MigrationQuestioner.ask_not_null_alteration',
|
@mock.patch(
|
||||||
return_value=models.NOT_PROVIDED)
|
'django.db.migrations.questioner.MigrationQuestioner.ask_not_null_alteration',
|
||||||
|
return_value=models.NOT_PROVIDED,
|
||||||
|
)
|
||||||
def test_alter_field_to_not_null_without_default(self, mocked_ask_method):
|
def test_alter_field_to_not_null_without_default(self, mocked_ask_method):
|
||||||
"""
|
"""
|
||||||
#23609 - Tests autodetection of nullable to non-nullable alterations.
|
#23609 - Tests autodetection of nullable to non-nullable alterations.
|
||||||
|
@ -797,8 +799,10 @@ class AutodetectorTests(TestCase):
|
||||||
self.assertOperationAttributes(changes, "testapp", 0, 0, name="name", preserve_default=True)
|
self.assertOperationAttributes(changes, "testapp", 0, 0, name="name", preserve_default=True)
|
||||||
self.assertOperationFieldAttributes(changes, "testapp", 0, 0, default=models.NOT_PROVIDED)
|
self.assertOperationFieldAttributes(changes, "testapp", 0, 0, default=models.NOT_PROVIDED)
|
||||||
|
|
||||||
@mock.patch('django.db.migrations.questioner.MigrationQuestioner.ask_not_null_alteration',
|
@mock.patch(
|
||||||
return_value='Some Name')
|
'django.db.migrations.questioner.MigrationQuestioner.ask_not_null_alteration',
|
||||||
|
return_value='Some Name',
|
||||||
|
)
|
||||||
def test_alter_field_to_not_null_oneoff_default(self, mocked_ask_method):
|
def test_alter_field_to_not_null_oneoff_default(self, mocked_ask_method):
|
||||||
"""
|
"""
|
||||||
#23609 - Tests autodetection of nullable to non-nullable alterations.
|
#23609 - Tests autodetection of nullable to non-nullable alterations.
|
||||||
|
|
|
@ -64,8 +64,7 @@ class ImageFieldTestMixin(SerializeMixin):
|
||||||
self.file2.close()
|
self.file2.close()
|
||||||
shutil.rmtree(temp_storage_dir)
|
shutil.rmtree(temp_storage_dir)
|
||||||
|
|
||||||
def check_dimensions(self, instance, width, height,
|
def check_dimensions(self, instance, width, height, field_name='mugshot'):
|
||||||
field_name='mugshot'):
|
|
||||||
"""
|
"""
|
||||||
Asserts that the given width and height values match both the
|
Asserts that the given width and height values match both the
|
||||||
field's height and width attributes and the height and width fields
|
field's height and width attributes and the height and width fields
|
||||||
|
@ -363,8 +362,7 @@ class TwoImageFieldTests(ImageFieldTestMixin, TestCase):
|
||||||
self.check_dimensions(p, 8, 4, 'headshot')
|
self.check_dimensions(p, 8, 4, 'headshot')
|
||||||
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
p = self.PersonModel.objects.create(mugshot=self.file1,
|
p = self.PersonModel.objects.create(mugshot=self.file1, headshot=self.file2)
|
||||||
headshot=self.file2)
|
|
||||||
self.check_dimensions(p, 4, 8)
|
self.check_dimensions(p, 4, 8)
|
||||||
self.check_dimensions(p, 8, 4, 'headshot')
|
self.check_dimensions(p, 8, 4, 'headshot')
|
||||||
|
|
||||||
|
|
|
@ -173,8 +173,7 @@ class CustomErrorMessageForm(forms.ModelForm):
|
||||||
|
|
||||||
class ModelFormBaseTest(TestCase):
|
class ModelFormBaseTest(TestCase):
|
||||||
def test_base_form(self):
|
def test_base_form(self):
|
||||||
self.assertEqual(list(BaseCategoryForm.base_fields),
|
self.assertEqual(list(BaseCategoryForm.base_fields), ['name', 'slug', 'url'])
|
||||||
['name', 'slug', 'url'])
|
|
||||||
|
|
||||||
def test_no_model_class(self):
|
def test_no_model_class(self):
|
||||||
class NoModelModelForm(forms.ModelForm):
|
class NoModelModelForm(forms.ModelForm):
|
||||||
|
@ -224,8 +223,7 @@ class ModelFormBaseTest(TestCase):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields['character'].required = False
|
self.fields['character'].required = False
|
||||||
|
|
||||||
char = Character.objects.create(username='user',
|
char = Character.objects.create(username='user', last_action=datetime.datetime.today())
|
||||||
last_action=datetime.datetime.today())
|
|
||||||
data = {'study': 'Engineering'}
|
data = {'study': 'Engineering'}
|
||||||
data2 = {'study': 'Engineering', 'character': char.pk}
|
data2 = {'study': 'Engineering', 'character': char.pk}
|
||||||
|
|
||||||
|
@ -514,8 +512,7 @@ class ModelFormBaseTest(TestCase):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.assertEqual(list(SubCategoryForm.base_fields),
|
self.assertEqual(list(SubCategoryForm.base_fields), ['name', 'slug', 'url'])
|
||||||
['name', 'slug', 'url'])
|
|
||||||
|
|
||||||
def test_subclassmeta_form(self):
|
def test_subclassmeta_form(self):
|
||||||
class SomeCategoryForm(forms.ModelForm):
|
class SomeCategoryForm(forms.ModelForm):
|
||||||
|
@ -565,8 +562,7 @@ class ModelFormBaseTest(TestCase):
|
||||||
fields = ['slug', 'url', 'name']
|
fields = ['slug', 'url', 'name']
|
||||||
exclude = ['url']
|
exclude = ['url']
|
||||||
|
|
||||||
self.assertEqual(list(OrderFields2.base_fields),
|
self.assertEqual(list(OrderFields2.base_fields), ['slug', 'name'])
|
||||||
['slug', 'name'])
|
|
||||||
|
|
||||||
def test_default_populated_on_optional_field(self):
|
def test_default_populated_on_optional_field(self):
|
||||||
class PubForm(forms.ModelForm):
|
class PubForm(forms.ModelForm):
|
||||||
|
@ -934,8 +930,10 @@ class UniqueTest(TestCase):
|
||||||
})
|
})
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
self.assertEqual(len(form.errors), 1)
|
self.assertEqual(len(form.errors), 1)
|
||||||
self.assertEqual(form.errors['__all__'],
|
self.assertEqual(
|
||||||
['Derived book with this Suffix1 and Suffix2 already exists.'])
|
form.errors['__all__'],
|
||||||
|
['Derived book with this Suffix1 and Suffix2 already exists.'],
|
||||||
|
)
|
||||||
|
|
||||||
def test_explicitpk_unspecified(self):
|
def test_explicitpk_unspecified(self):
|
||||||
"""Test for primary_key being in the form and failing validation."""
|
"""Test for primary_key being in the form and failing validation."""
|
||||||
|
@ -1107,12 +1105,9 @@ class UniqueTest(TestCase):
|
||||||
|
|
||||||
class ModelFormBasicTests(TestCase):
|
class ModelFormBasicTests(TestCase):
|
||||||
def create_basic_data(self):
|
def create_basic_data(self):
|
||||||
self.c1 = Category.objects.create(
|
self.c1 = Category.objects.create(name='Entertainment', slug='entertainment', url='entertainment')
|
||||||
name="Entertainment", slug="entertainment", url="entertainment")
|
self.c2 = Category.objects.create(name="It's a test", slug='its-test', url='test')
|
||||||
self.c2 = Category.objects.create(
|
self.c3 = Category.objects.create(name='Third test', slug='third-test', url='third')
|
||||||
name="It's a test", slug="its-test", url="test")
|
|
||||||
self.c3 = Category.objects.create(
|
|
||||||
name="Third test", slug="third-test", url="third")
|
|
||||||
self.w_royko = Writer.objects.create(name='Mike Royko')
|
self.w_royko = Writer.objects.create(name='Mike Royko')
|
||||||
self.w_woodward = Writer.objects.create(name='Bob Woodward')
|
self.w_woodward = Writer.objects.create(name='Bob Woodward')
|
||||||
|
|
||||||
|
@ -1249,8 +1244,11 @@ class ModelFormBasicTests(TestCase):
|
||||||
return db_field.formfield(**kwargs)
|
return db_field.formfield(**kwargs)
|
||||||
|
|
||||||
# Create a ModelForm, instantiate it, and check that the output is as expected
|
# Create a ModelForm, instantiate it, and check that the output is as expected
|
||||||
ModelForm = modelform_factory(Article, fields=['headline', 'categories'],
|
ModelForm = modelform_factory(
|
||||||
formfield_callback=formfield_for_dbfield)
|
Article,
|
||||||
|
fields=['headline', 'categories'],
|
||||||
|
formfield_callback=formfield_for_dbfield,
|
||||||
|
)
|
||||||
form = ModelForm()
|
form = ModelForm()
|
||||||
self.assertHTMLEqual(
|
self.assertHTMLEqual(
|
||||||
form.as_ul(),
|
form.as_ul(),
|
||||||
|
@ -1558,12 +1556,9 @@ class ModelFormBasicTests(TestCase):
|
||||||
|
|
||||||
class ModelMultipleChoiceFieldTests(TestCase):
|
class ModelMultipleChoiceFieldTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.c1 = Category.objects.create(
|
self.c1 = Category.objects.create(name='Entertainment', slug='entertainment', url='entertainment')
|
||||||
name="Entertainment", slug="entertainment", url="entertainment")
|
self.c2 = Category.objects.create(name="It's a test", slug='its-test', url='test')
|
||||||
self.c2 = Category.objects.create(
|
self.c3 = Category.objects.create(name='Third', slug='third-test', url='third')
|
||||||
name="It's a test", slug="its-test", url="test")
|
|
||||||
self.c3 = Category.objects.create(
|
|
||||||
name="Third", slug="third-test", url="third")
|
|
||||||
|
|
||||||
def test_model_multiple_choice_field(self):
|
def test_model_multiple_choice_field(self):
|
||||||
f = forms.ModelMultipleChoiceField(Category.objects.all())
|
f = forms.ModelMultipleChoiceField(Category.objects.all())
|
||||||
|
@ -1669,9 +1664,7 @@ class ModelMultipleChoiceFieldTests(TestCase):
|
||||||
def my_validator(value):
|
def my_validator(value):
|
||||||
self._validator_run = True
|
self._validator_run = True
|
||||||
|
|
||||||
f = forms.ModelMultipleChoiceField(queryset=Writer.objects.all(),
|
f = forms.ModelMultipleChoiceField(queryset=Writer.objects.all(), validators=[my_validator])
|
||||||
validators=[my_validator])
|
|
||||||
|
|
||||||
f.clean([p.pk for p in Writer.objects.all()[8:9]])
|
f.clean([p.pk for p in Writer.objects.all()[8:9]])
|
||||||
self.assertTrue(self._validator_run)
|
self.assertTrue(self._validator_run)
|
||||||
|
|
||||||
|
@ -1680,8 +1673,7 @@ class ModelMultipleChoiceFieldTests(TestCase):
|
||||||
Test support of show_hidden_initial by ModelMultipleChoiceField.
|
Test support of show_hidden_initial by ModelMultipleChoiceField.
|
||||||
"""
|
"""
|
||||||
class WriterForm(forms.Form):
|
class WriterForm(forms.Form):
|
||||||
persons = forms.ModelMultipleChoiceField(show_hidden_initial=True,
|
persons = forms.ModelMultipleChoiceField(show_hidden_initial=True, queryset=Writer.objects.all())
|
||||||
queryset=Writer.objects.all())
|
|
||||||
|
|
||||||
person1 = Writer.objects.create(name="Person 1")
|
person1 = Writer.objects.create(name="Person 1")
|
||||||
person2 = Writer.objects.create(name="Person 2")
|
person2 = Writer.objects.create(name="Person 2")
|
||||||
|
@ -1777,8 +1769,7 @@ class ModelOneToOneFieldTests(TestCase):
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
bw = BetterWriter.objects.create(name='Joe Better', score=10)
|
bw = BetterWriter.objects.create(name='Joe Better', score=10)
|
||||||
self.assertEqual(sorted(model_to_dict(bw)),
|
self.assertEqual(sorted(model_to_dict(bw)), ['id', 'name', 'score', 'writer_ptr'])
|
||||||
['id', 'name', 'score', 'writer_ptr'])
|
|
||||||
|
|
||||||
form = BetterWriterForm({'name': 'Some Name', 'score': 12})
|
form = BetterWriterForm({'name': 'Some Name', 'score': 12})
|
||||||
self.assertTrue(form.is_valid())
|
self.assertTrue(form.is_valid())
|
||||||
|
@ -1918,9 +1909,11 @@ class FileAndImageFieldTests(TestCase):
|
||||||
form = DocumentForm(files={'myfile': SimpleUploadedFile('something.txt', b'content')})
|
form = DocumentForm(files={'myfile': SimpleUploadedFile('something.txt', b'content')})
|
||||||
self.assertTrue(form.is_valid())
|
self.assertTrue(form.is_valid())
|
||||||
doc = form.save(commit=False)
|
doc = form.save(commit=False)
|
||||||
form = DocumentForm(instance=doc,
|
form = DocumentForm(
|
||||||
|
instance=doc,
|
||||||
files={'myfile': SimpleUploadedFile('something.txt', b'content')},
|
files={'myfile': SimpleUploadedFile('something.txt', b'content')},
|
||||||
data={'myfile-clear': 'true'})
|
data={'myfile-clear': 'true'},
|
||||||
|
)
|
||||||
self.assertTrue(not form.is_valid())
|
self.assertTrue(not form.is_valid())
|
||||||
self.assertEqual(form.errors['myfile'],
|
self.assertEqual(form.errors['myfile'],
|
||||||
['Please either submit a file or check the clear checkbox, not both.'])
|
['Please either submit a file or check the clear checkbox, not both.'])
|
||||||
|
@ -1951,7 +1944,8 @@ class FileAndImageFieldTests(TestCase):
|
||||||
# Upload a file and ensure it all works as expected.
|
# Upload a file and ensure it all works as expected.
|
||||||
f = TextFileForm(
|
f = TextFileForm(
|
||||||
data={'description': 'Assistance'},
|
data={'description': 'Assistance'},
|
||||||
files={'file': SimpleUploadedFile('test1.txt', b'hello world')})
|
files={'file': SimpleUploadedFile('test1.txt', b'hello world')},
|
||||||
|
)
|
||||||
self.assertTrue(f.is_valid())
|
self.assertTrue(f.is_valid())
|
||||||
self.assertEqual(type(f.cleaned_data['file']), SimpleUploadedFile)
|
self.assertEqual(type(f.cleaned_data['file']), SimpleUploadedFile)
|
||||||
instance = f.save()
|
instance = f.save()
|
||||||
|
@ -1961,7 +1955,8 @@ class FileAndImageFieldTests(TestCase):
|
||||||
# If the previous file has been deleted, the file name can be reused
|
# If the previous file has been deleted, the file name can be reused
|
||||||
f = TextFileForm(
|
f = TextFileForm(
|
||||||
data={'description': 'Assistance'},
|
data={'description': 'Assistance'},
|
||||||
files={'file': SimpleUploadedFile('test1.txt', b'hello world')})
|
files={'file': SimpleUploadedFile('test1.txt', b'hello world')},
|
||||||
|
)
|
||||||
self.assertTrue(f.is_valid())
|
self.assertTrue(f.is_valid())
|
||||||
self.assertEqual(type(f.cleaned_data['file']), SimpleUploadedFile)
|
self.assertEqual(type(f.cleaned_data['file']), SimpleUploadedFile)
|
||||||
instance = f.save()
|
instance = f.save()
|
||||||
|
@ -1970,14 +1965,13 @@ class FileAndImageFieldTests(TestCase):
|
||||||
# Check if the max_length attribute has been inherited from the model.
|
# Check if the max_length attribute has been inherited from the model.
|
||||||
f = TextFileForm(
|
f = TextFileForm(
|
||||||
data={'description': 'Assistance'},
|
data={'description': 'Assistance'},
|
||||||
files={'file': SimpleUploadedFile('test-maxlength.txt', b'hello world')})
|
files={'file': SimpleUploadedFile('test-maxlength.txt', b'hello world')},
|
||||||
|
)
|
||||||
self.assertFalse(f.is_valid())
|
self.assertFalse(f.is_valid())
|
||||||
|
|
||||||
# Edit an instance that already has the file defined in the model. This will not
|
# Edit an instance that already has the file defined in the model. This will not
|
||||||
# save the file again, but leave it exactly as it is.
|
# save the file again, but leave it exactly as it is.
|
||||||
f = TextFileForm(
|
f = TextFileForm({'description': 'Assistance'}, instance=instance)
|
||||||
data={'description': 'Assistance'},
|
|
||||||
instance=instance)
|
|
||||||
self.assertTrue(f.is_valid())
|
self.assertTrue(f.is_valid())
|
||||||
self.assertEqual(f.cleaned_data['file'].name, 'tests/test1.txt')
|
self.assertEqual(f.cleaned_data['file'].name, 'tests/test1.txt')
|
||||||
instance = f.save()
|
instance = f.save()
|
||||||
|
@ -1989,7 +1983,9 @@ class FileAndImageFieldTests(TestCase):
|
||||||
# Override the file by uploading a new one.
|
# Override the file by uploading a new one.
|
||||||
f = TextFileForm(
|
f = TextFileForm(
|
||||||
data={'description': 'Assistance'},
|
data={'description': 'Assistance'},
|
||||||
files={'file': SimpleUploadedFile('test2.txt', b'hello world')}, instance=instance)
|
files={'file': SimpleUploadedFile('test2.txt', b'hello world')},
|
||||||
|
instance=instance,
|
||||||
|
)
|
||||||
self.assertTrue(f.is_valid())
|
self.assertTrue(f.is_valid())
|
||||||
instance = f.save()
|
instance = f.save()
|
||||||
self.assertEqual(instance.file.name, 'tests/test2.txt')
|
self.assertEqual(instance.file.name, 'tests/test2.txt')
|
||||||
|
@ -2008,15 +2004,15 @@ class FileAndImageFieldTests(TestCase):
|
||||||
|
|
||||||
f = TextFileForm(
|
f = TextFileForm(
|
||||||
data={'description': 'Assistance'},
|
data={'description': 'Assistance'},
|
||||||
files={'file': SimpleUploadedFile('test3.txt', b'hello world')}, instance=instance)
|
files={'file': SimpleUploadedFile('test3.txt', b'hello world')},
|
||||||
|
instance=instance,
|
||||||
|
)
|
||||||
self.assertTrue(f.is_valid())
|
self.assertTrue(f.is_valid())
|
||||||
instance = f.save()
|
instance = f.save()
|
||||||
self.assertEqual(instance.file.name, 'tests/test3.txt')
|
self.assertEqual(instance.file.name, 'tests/test3.txt')
|
||||||
|
|
||||||
# Instance can be edited w/out re-uploading the file and existing file should be preserved.
|
# Instance can be edited w/out re-uploading the file and existing file should be preserved.
|
||||||
f = TextFileForm(
|
f = TextFileForm({'description': 'New Description'}, instance=instance)
|
||||||
data={'description': 'New Description'},
|
|
||||||
instance=instance)
|
|
||||||
f.fields['file'].required = False
|
f.fields['file'].required = False
|
||||||
self.assertTrue(f.is_valid())
|
self.assertTrue(f.is_valid())
|
||||||
instance = f.save()
|
instance = f.save()
|
||||||
|
@ -2094,7 +2090,8 @@ class FileAndImageFieldTests(TestCase):
|
||||||
|
|
||||||
f = ImageFileForm(
|
f = ImageFileForm(
|
||||||
data={'description': 'An image'},
|
data={'description': 'An image'},
|
||||||
files={'image': SimpleUploadedFile('test.png', image_data)})
|
files={'image': SimpleUploadedFile('test.png', image_data)},
|
||||||
|
)
|
||||||
self.assertTrue(f.is_valid())
|
self.assertTrue(f.is_valid())
|
||||||
self.assertEqual(type(f.cleaned_data['image']), SimpleUploadedFile)
|
self.assertEqual(type(f.cleaned_data['image']), SimpleUploadedFile)
|
||||||
instance = f.save()
|
instance = f.save()
|
||||||
|
@ -2107,7 +2104,8 @@ class FileAndImageFieldTests(TestCase):
|
||||||
instance.image.delete(save=False)
|
instance.image.delete(save=False)
|
||||||
f = ImageFileForm(
|
f = ImageFileForm(
|
||||||
data={'description': 'An image'},
|
data={'description': 'An image'},
|
||||||
files={'image': SimpleUploadedFile('test.png', image_data)})
|
files={'image': SimpleUploadedFile('test.png', image_data)},
|
||||||
|
)
|
||||||
self.assertTrue(f.is_valid())
|
self.assertTrue(f.is_valid())
|
||||||
self.assertEqual(type(f.cleaned_data['image']), SimpleUploadedFile)
|
self.assertEqual(type(f.cleaned_data['image']), SimpleUploadedFile)
|
||||||
instance = f.save()
|
instance = f.save()
|
||||||
|
@ -2133,7 +2131,9 @@ class FileAndImageFieldTests(TestCase):
|
||||||
|
|
||||||
f = ImageFileForm(
|
f = ImageFileForm(
|
||||||
data={'description': 'Changed it'},
|
data={'description': 'Changed it'},
|
||||||
files={'image': SimpleUploadedFile('test2.png', image_data2)}, instance=instance)
|
files={'image': SimpleUploadedFile('test2.png', image_data2)},
|
||||||
|
instance=instance,
|
||||||
|
)
|
||||||
self.assertTrue(f.is_valid())
|
self.assertTrue(f.is_valid())
|
||||||
instance = f.save()
|
instance = f.save()
|
||||||
self.assertEqual(instance.image.name, 'tests/test2.png')
|
self.assertEqual(instance.image.name, 'tests/test2.png')
|
||||||
|
@ -2147,7 +2147,8 @@ class FileAndImageFieldTests(TestCase):
|
||||||
|
|
||||||
f = ImageFileForm(
|
f = ImageFileForm(
|
||||||
data={'description': 'Changed it'},
|
data={'description': 'Changed it'},
|
||||||
files={'image': SimpleUploadedFile('test2.png', image_data2)})
|
files={'image': SimpleUploadedFile('test2.png', image_data2)},
|
||||||
|
)
|
||||||
self.assertTrue(f.is_valid())
|
self.assertTrue(f.is_valid())
|
||||||
instance = f.save()
|
instance = f.save()
|
||||||
self.assertEqual(instance.image.name, 'tests/test2.png')
|
self.assertEqual(instance.image.name, 'tests/test2.png')
|
||||||
|
@ -2176,7 +2177,9 @@ class FileAndImageFieldTests(TestCase):
|
||||||
|
|
||||||
f = OptionalImageFileForm(
|
f = OptionalImageFileForm(
|
||||||
data={'description': 'And a final one'},
|
data={'description': 'And a final one'},
|
||||||
files={'image': SimpleUploadedFile('test3.png', image_data)}, instance=instance)
|
files={'image': SimpleUploadedFile('test3.png', image_data)},
|
||||||
|
instance=instance,
|
||||||
|
)
|
||||||
self.assertTrue(f.is_valid())
|
self.assertTrue(f.is_valid())
|
||||||
instance = f.save()
|
instance = f.save()
|
||||||
self.assertEqual(instance.image.name, 'tests/test3.png')
|
self.assertEqual(instance.image.name, 'tests/test3.png')
|
||||||
|
@ -2185,9 +2188,7 @@ class FileAndImageFieldTests(TestCase):
|
||||||
|
|
||||||
# Editing the instance without re-uploading the image should not affect
|
# Editing the instance without re-uploading the image should not affect
|
||||||
# the image or its width/height properties.
|
# the image or its width/height properties.
|
||||||
f = OptionalImageFileForm(
|
f = OptionalImageFileForm({'description': 'New Description'}, instance=instance)
|
||||||
data={'description': 'New Description'},
|
|
||||||
instance=instance)
|
|
||||||
self.assertTrue(f.is_valid())
|
self.assertTrue(f.is_valid())
|
||||||
instance = f.save()
|
instance = f.save()
|
||||||
self.assertEqual(instance.description, 'New Description')
|
self.assertEqual(instance.description, 'New Description')
|
||||||
|
@ -2212,7 +2213,8 @@ class FileAndImageFieldTests(TestCase):
|
||||||
# Test callable upload_to behavior that's dependent on the value of another field in the model
|
# Test callable upload_to behavior that's dependent on the value of another field in the model
|
||||||
f = ImageFileForm(
|
f = ImageFileForm(
|
||||||
data={'description': 'And a final one', 'path': 'foo'},
|
data={'description': 'And a final one', 'path': 'foo'},
|
||||||
files={'image': SimpleUploadedFile('test4.png', image_data)})
|
files={'image': SimpleUploadedFile('test4.png', image_data)},
|
||||||
|
)
|
||||||
self.assertTrue(f.is_valid())
|
self.assertTrue(f.is_valid())
|
||||||
instance = f.save()
|
instance = f.save()
|
||||||
self.assertEqual(instance.image.name, 'foo/test4.png')
|
self.assertEqual(instance.image.name, 'foo/test4.png')
|
||||||
|
@ -2378,8 +2380,7 @@ class OtherModelFormTests(TestCase):
|
||||||
model = Category
|
model = Category
|
||||||
fields = ['description', 'url']
|
fields = ['description', 'url']
|
||||||
|
|
||||||
self.assertEqual(list(CategoryForm.base_fields),
|
self.assertEqual(list(CategoryForm.base_fields), ['description', 'url'])
|
||||||
['description', 'url'])
|
|
||||||
|
|
||||||
self.assertHTMLEqual(
|
self.assertHTMLEqual(
|
||||||
str(CategoryForm()),
|
str(CategoryForm()),
|
||||||
|
@ -2400,8 +2401,7 @@ class OtherModelFormTests(TestCase):
|
||||||
self.assertQuerysetEqual(form.cleaned_data['items'], ['Core', 'Pear'])
|
self.assertQuerysetEqual(form.cleaned_data['items'], ['Core', 'Pear'])
|
||||||
|
|
||||||
def test_model_field_that_returns_none_to_exclude_itself_with_explicit_fields(self):
|
def test_model_field_that_returns_none_to_exclude_itself_with_explicit_fields(self):
|
||||||
self.assertEqual(list(CustomFieldForExclusionForm.base_fields),
|
self.assertEqual(list(CustomFieldForExclusionForm.base_fields), ['name'])
|
||||||
['name'])
|
|
||||||
self.assertHTMLEqual(
|
self.assertHTMLEqual(
|
||||||
str(CustomFieldForExclusionForm()),
|
str(CustomFieldForExclusionForm()),
|
||||||
'''<tr><th><label for="id_name">Name:</label></th>
|
'''<tr><th><label for="id_name">Name:</label></th>
|
||||||
|
|
|
@ -362,8 +362,7 @@ class FormfieldCallbackTests(TestCase):
|
||||||
|
|
||||||
def test_modelformset_custom_callback(self):
|
def test_modelformset_custom_callback(self):
|
||||||
callback = Callback()
|
callback = Callback()
|
||||||
modelformset_factory(UserSite, form=UserSiteForm,
|
modelformset_factory(UserSite, form=UserSiteForm, formfield_callback=callback)
|
||||||
formfield_callback=callback)
|
|
||||||
self.assertCallbackCalled(callback)
|
self.assertCallbackCalled(callback)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,18 +27,15 @@ class ModelInheritanceTest(TestCase):
|
||||||
# 'narrow()' API would require a similar approach.
|
# 'narrow()' API would require a similar approach.
|
||||||
|
|
||||||
# Create a child-parent-grandparent chain
|
# Create a child-parent-grandparent chain
|
||||||
place1 = Place(
|
place1 = Place(name="Guido's House of Pasta", address='944 W. Fullerton')
|
||||||
name="Guido's House of Pasta",
|
|
||||||
address='944 W. Fullerton')
|
|
||||||
place1.save_base(raw=True)
|
place1.save_base(raw=True)
|
||||||
restaurant = Restaurant(
|
restaurant = Restaurant(
|
||||||
place_ptr=place1,
|
place_ptr=place1,
|
||||||
serves_hot_dogs=True,
|
serves_hot_dogs=True,
|
||||||
serves_pizza=False)
|
serves_pizza=False,
|
||||||
|
)
|
||||||
restaurant.save_base(raw=True)
|
restaurant.save_base(raw=True)
|
||||||
italian_restaurant = ItalianRestaurant(
|
italian_restaurant = ItalianRestaurant(restaurant_ptr=restaurant, serves_gnocchi=True)
|
||||||
restaurant_ptr=restaurant,
|
|
||||||
serves_gnocchi=True)
|
|
||||||
italian_restaurant.save_base(raw=True)
|
italian_restaurant.save_base(raw=True)
|
||||||
|
|
||||||
# Create a child-parent chain with an explicit parent link
|
# Create a child-parent chain with an explicit parent link
|
||||||
|
@ -142,18 +139,15 @@ class ModelInheritanceTest(TestCase):
|
||||||
# Regression test for #7276: calling delete() on a model with
|
# Regression test for #7276: calling delete() on a model with
|
||||||
# multi-table inheritance should delete the associated rows from any
|
# multi-table inheritance should delete the associated rows from any
|
||||||
# ancestor tables, as well as any descendent objects.
|
# ancestor tables, as well as any descendent objects.
|
||||||
place1 = Place(
|
place1 = Place(name="Guido's House of Pasta", address='944 W. Fullerton')
|
||||||
name="Guido's House of Pasta",
|
|
||||||
address='944 W. Fullerton')
|
|
||||||
place1.save_base(raw=True)
|
place1.save_base(raw=True)
|
||||||
restaurant = Restaurant(
|
restaurant = Restaurant(
|
||||||
place_ptr=place1,
|
place_ptr=place1,
|
||||||
serves_hot_dogs=True,
|
serves_hot_dogs=True,
|
||||||
serves_pizza=False)
|
serves_pizza=False,
|
||||||
|
)
|
||||||
restaurant.save_base(raw=True)
|
restaurant.save_base(raw=True)
|
||||||
italian_restaurant = ItalianRestaurant(
|
italian_restaurant = ItalianRestaurant(restaurant_ptr=restaurant, serves_gnocchi=True)
|
||||||
restaurant_ptr=restaurant,
|
|
||||||
serves_gnocchi=True)
|
|
||||||
italian_restaurant.save_base(raw=True)
|
italian_restaurant.save_base(raw=True)
|
||||||
|
|
||||||
ident = ItalianRestaurant.objects.all()[0].id
|
ident = ItalianRestaurant.objects.all()[0].id
|
||||||
|
@ -162,7 +156,8 @@ class ModelInheritanceTest(TestCase):
|
||||||
name='a',
|
name='a',
|
||||||
address='xx',
|
address='xx',
|
||||||
serves_hot_dogs=True,
|
serves_hot_dogs=True,
|
||||||
serves_pizza=False)
|
serves_pizza=False,
|
||||||
|
)
|
||||||
|
|
||||||
# This should delete both Restaurants, plus the related places, plus
|
# This should delete both Restaurants, plus the related places, plus
|
||||||
# the ItalianRestaurant.
|
# the ItalianRestaurant.
|
||||||
|
@ -270,18 +265,18 @@ class ModelInheritanceTest(TestCase):
|
||||||
article = ArticleWithAuthor.objects.create(
|
article = ArticleWithAuthor.objects.create(
|
||||||
author="fred",
|
author="fred",
|
||||||
headline="Hey there!",
|
headline="Hey there!",
|
||||||
pub_date=datetime.datetime(2009, 3, 1, 8, 0, 0))
|
pub_date=datetime.datetime(2009, 3, 1, 8, 0, 0),
|
||||||
update = ArticleWithAuthor.objects.filter(
|
)
|
||||||
author="fred").update(headline="Oh, no!")
|
update = ArticleWithAuthor.objects.filter(author='fred').update(headline='Oh, no!')
|
||||||
self.assertEqual(update, 1)
|
self.assertEqual(update, 1)
|
||||||
update = ArticleWithAuthor.objects.filter(
|
update = ArticleWithAuthor.objects.filter(pk=article.pk).update(headline='Oh, no!')
|
||||||
pk=article.pk).update(headline="Oh, no!")
|
|
||||||
self.assertEqual(update, 1)
|
self.assertEqual(update, 1)
|
||||||
|
|
||||||
derivedm1 = DerivedM.objects.create(
|
derivedm1 = DerivedM.objects.create(
|
||||||
customPK=44,
|
customPK=44,
|
||||||
base_name="b1",
|
base_name="b1",
|
||||||
derived_name="d1")
|
derived_name='d1',
|
||||||
|
)
|
||||||
self.assertEqual(derivedm1.customPK, 44)
|
self.assertEqual(derivedm1.customPK, 44)
|
||||||
self.assertEqual(derivedm1.base_name, 'b1')
|
self.assertEqual(derivedm1.base_name, 'b1')
|
||||||
self.assertEqual(derivedm1.derived_name, 'd1')
|
self.assertEqual(derivedm1.derived_name, 'd1')
|
||||||
|
@ -320,7 +315,8 @@ class ModelInheritanceTest(TestCase):
|
||||||
headline="Problems in Django",
|
headline="Problems in Django",
|
||||||
pub_date=datetime.datetime.now(),
|
pub_date=datetime.datetime.now(),
|
||||||
quality=10,
|
quality=10,
|
||||||
assignee="adrian")
|
assignee='adrian',
|
||||||
|
)
|
||||||
|
|
||||||
def test_abstract_base_class_m2m_relation_inheritance(self):
|
def test_abstract_base_class_m2m_relation_inheritance(self):
|
||||||
# many-to-many relations defined on an abstract base class are
|
# many-to-many relations defined on an abstract base class are
|
||||||
|
@ -330,8 +326,7 @@ class ModelInheritanceTest(TestCase):
|
||||||
p3 = Person.objects.create(name='Carol')
|
p3 = Person.objects.create(name='Carol')
|
||||||
p4 = Person.objects.create(name='Dave')
|
p4 = Person.objects.create(name='Dave')
|
||||||
|
|
||||||
birthday = BirthdayParty.objects.create(
|
birthday = BirthdayParty.objects.create(name='Birthday party for Alice')
|
||||||
name='Birthday party for Alice')
|
|
||||||
birthday.attendees.set([p1, p3])
|
birthday.attendees.set([p1, p3])
|
||||||
|
|
||||||
bachelor = BachelorParty.objects.create(name='Bachelor party for Bob')
|
bachelor = BachelorParty.objects.create(name='Bachelor party for Bob')
|
||||||
|
@ -351,8 +346,7 @@ class ModelInheritanceTest(TestCase):
|
||||||
self.assertFalse(hasattr(p2, 'messybachelorparty_set'))
|
self.assertFalse(hasattr(p2, 'messybachelorparty_set'))
|
||||||
|
|
||||||
# ... but it does inherit the m2m from its parent
|
# ... but it does inherit the m2m from its parent
|
||||||
messy = MessyBachelorParty.objects.create(
|
messy = MessyBachelorParty.objects.create(name='Bachelor party for Dave')
|
||||||
name='Bachelor party for Dave')
|
|
||||||
messy.attendees.set([p4])
|
messy.attendees.set([p4])
|
||||||
messy_parent = messy.bachelorparty_ptr
|
messy_parent = messy.bachelorparty_ptr
|
||||||
|
|
||||||
|
|
|
@ -1068,9 +1068,11 @@ class RouterTestCase(TestCase):
|
||||||
|
|
||||||
def test_database_routing(self):
|
def test_database_routing(self):
|
||||||
marty = Person.objects.using('default').create(name="Marty Alchin")
|
marty = Person.objects.using('default').create(name="Marty Alchin")
|
||||||
pro = Book.objects.using('default').create(title="Pro Django",
|
pro = Book.objects.using('default').create(
|
||||||
|
title='Pro Django',
|
||||||
published=datetime.date(2008, 12, 16),
|
published=datetime.date(2008, 12, 16),
|
||||||
editor=marty)
|
editor=marty,
|
||||||
|
)
|
||||||
pro.authors.set([marty])
|
pro.authors.set([marty])
|
||||||
|
|
||||||
# Create a book and author on the other database
|
# Create a book and author on the other database
|
||||||
|
@ -1462,10 +1464,12 @@ class RouterTestCase(TestCase):
|
||||||
def test_foreign_key_managers(self):
|
def test_foreign_key_managers(self):
|
||||||
"FK reverse relations are represented by managers, and can be controlled like managers"
|
"FK reverse relations are represented by managers, and can be controlled like managers"
|
||||||
marty = Person.objects.using('other').create(pk=1, name="Marty Alchin")
|
marty = Person.objects.using('other').create(pk=1, name="Marty Alchin")
|
||||||
Book.objects.using('other').create(pk=1, title="Pro Django",
|
Book.objects.using('other').create(
|
||||||
|
pk=1,
|
||||||
|
title='Pro Django',
|
||||||
published=datetime.date(2008, 12, 16),
|
published=datetime.date(2008, 12, 16),
|
||||||
editor=marty)
|
editor=marty,
|
||||||
|
)
|
||||||
self.assertEqual(marty.edited.db, 'other')
|
self.assertEqual(marty.edited.db, 'other')
|
||||||
self.assertEqual(marty.edited.db_manager('default').db, 'default')
|
self.assertEqual(marty.edited.db_manager('default').db, 'default')
|
||||||
self.assertEqual(marty.edited.db_manager('default').all().db, 'default')
|
self.assertEqual(marty.edited.db_manager('default').all().db, 'default')
|
||||||
|
@ -1475,8 +1479,7 @@ class RouterTestCase(TestCase):
|
||||||
pro = Book.objects.using('other').create(title="Pro Django",
|
pro = Book.objects.using('other').create(title="Pro Django",
|
||||||
published=datetime.date(2008, 12, 16))
|
published=datetime.date(2008, 12, 16))
|
||||||
|
|
||||||
Review.objects.using('other').create(source="Python Monthly",
|
Review.objects.using('other').create(source='Python Monthly', content_object=pro)
|
||||||
content_object=pro)
|
|
||||||
|
|
||||||
self.assertEqual(pro.reviews.db, 'other')
|
self.assertEqual(pro.reviews.db, 'other')
|
||||||
self.assertEqual(pro.reviews.db_manager('default').db, 'default')
|
self.assertEqual(pro.reviews.db_manager('default').db, 'default')
|
||||||
|
@ -1487,9 +1490,11 @@ class RouterTestCase(TestCase):
|
||||||
# Create a book and author on the other database
|
# Create a book and author on the other database
|
||||||
|
|
||||||
mark = Person.objects.using('other').create(name="Mark Pilgrim")
|
mark = Person.objects.using('other').create(name="Mark Pilgrim")
|
||||||
Book.objects.using('other').create(title="Dive into Python",
|
Book.objects.using('other').create(
|
||||||
|
title='Dive into Python',
|
||||||
published=datetime.date(2009, 5, 4),
|
published=datetime.date(2009, 5, 4),
|
||||||
editor=mark)
|
editor=mark,
|
||||||
|
)
|
||||||
|
|
||||||
sub = Person.objects.filter(name='Mark Pilgrim')
|
sub = Person.objects.filter(name='Mark Pilgrim')
|
||||||
qs = Book.objects.filter(editor__in=sub)
|
qs = Book.objects.filter(editor__in=sub)
|
||||||
|
@ -1505,9 +1510,11 @@ class RouterTestCase(TestCase):
|
||||||
def test_deferred_models(self):
|
def test_deferred_models(self):
|
||||||
mark_def = Person.objects.using('default').create(name="Mark Pilgrim")
|
mark_def = Person.objects.using('default').create(name="Mark Pilgrim")
|
||||||
mark_other = Person.objects.using('other').create(name="Mark Pilgrim")
|
mark_other = Person.objects.using('other').create(name="Mark Pilgrim")
|
||||||
orig_b = Book.objects.using('other').create(title="Dive into Python",
|
orig_b = Book.objects.using('other').create(
|
||||||
|
title='Dive into Python',
|
||||||
published=datetime.date(2009, 5, 4),
|
published=datetime.date(2009, 5, 4),
|
||||||
editor=mark_other)
|
editor=mark_other,
|
||||||
|
)
|
||||||
b = Book.objects.using('other').only('title').get(pk=orig_b.pk)
|
b = Book.objects.using('other').only('title').get(pk=orig_b.pk)
|
||||||
self.assertEqual(b.published, datetime.date(2009, 5, 4))
|
self.assertEqual(b.published, datetime.date(2009, 5, 4))
|
||||||
b = Book.objects.using('other').only('title').get(pk=orig_b.pk)
|
b = Book.objects.using('other').only('title').get(pk=orig_b.pk)
|
||||||
|
@ -1706,8 +1713,7 @@ class SignalTests(TestCase):
|
||||||
|
|
||||||
# Create a copy of the models on the 'other' database to prevent
|
# Create a copy of the models on the 'other' database to prevent
|
||||||
# integrity errors on backends that don't defer constraints checks
|
# integrity errors on backends that don't defer constraints checks
|
||||||
Book.objects.using('other').create(pk=b.pk, title=b.title,
|
Book.objects.using('other').create(pk=b.pk, title=b.title, published=b.published)
|
||||||
published=b.published)
|
|
||||||
Person.objects.using('other').create(pk=p.pk, name=p.name)
|
Person.objects.using('other').create(pk=p.pk, name=p.name)
|
||||||
|
|
||||||
# Test addition
|
# Test addition
|
||||||
|
|
|
@ -2235,7 +2235,8 @@ class ValuesQuerysetTests(TestCase):
|
||||||
# testing for ticket 14930 issues
|
# testing for ticket 14930 issues
|
||||||
qs = Number.objects.extra(
|
qs = Number.objects.extra(
|
||||||
select={'value_plus_one': 'num+1', 'value_minus_one': 'num-1'},
|
select={'value_plus_one': 'num+1', 'value_minus_one': 'num-1'},
|
||||||
order_by=['value_minus_one'])
|
order_by=['value_minus_one'],
|
||||||
|
)
|
||||||
qs = qs.values('num')
|
qs = qs.values('num')
|
||||||
|
|
||||||
def test_extra_select_params_values_order_in_extra(self):
|
def test_extra_select_params_values_order_in_extra(self):
|
||||||
|
@ -2243,7 +2244,8 @@ class ValuesQuerysetTests(TestCase):
|
||||||
qs = Number.objects.extra(
|
qs = Number.objects.extra(
|
||||||
select={'value_plus_x': 'num+%s'},
|
select={'value_plus_x': 'num+%s'},
|
||||||
select_params=[1],
|
select_params=[1],
|
||||||
order_by=['value_plus_x'])
|
order_by=['value_plus_x'],
|
||||||
|
)
|
||||||
qs = qs.filter(num=72)
|
qs = qs.filter(num=72)
|
||||||
qs = qs.values('num')
|
qs = qs.values('num')
|
||||||
self.assertSequenceEqual(qs, [{'num': 72}])
|
self.assertSequenceEqual(qs, [{'num': 72}])
|
||||||
|
|
|
@ -38,8 +38,7 @@ class ReverseLookupTests(TestCase):
|
||||||
p1 = Poll.objects.get(poll_choice__name__exact="This is the answer.")
|
p1 = Poll.objects.get(poll_choice__name__exact="This is the answer.")
|
||||||
self.assertEqual(p1.question, "What's the first question?")
|
self.assertEqual(p1.question, "What's the first question?")
|
||||||
|
|
||||||
p2 = Poll.objects.get(
|
p2 = Poll.objects.get(related_choice__name__exact='This is the answer.')
|
||||||
related_choice__name__exact="This is the answer.")
|
|
||||||
self.assertEqual(p2.question, "What's the second question?")
|
self.assertEqual(p2.question, "What's the second question?")
|
||||||
|
|
||||||
def test_reverse_field_name_disallowed(self):
|
def test_reverse_field_name_disallowed(self):
|
||||||
|
|
|
@ -14,14 +14,12 @@ class ReverseSelectRelatedTestCase(TestCase):
|
||||||
user = User.objects.create(username="test")
|
user = User.objects.create(username="test")
|
||||||
UserProfile.objects.create(user=user, state="KS", city="Lawrence")
|
UserProfile.objects.create(user=user, state="KS", city="Lawrence")
|
||||||
results = UserStatResult.objects.create(results='first results')
|
results = UserStatResult.objects.create(results='first results')
|
||||||
userstat = UserStat.objects.create(user=user, posts=150,
|
userstat = UserStat.objects.create(user=user, posts=150, results=results)
|
||||||
results=results)
|
|
||||||
StatDetails.objects.create(base_stats=userstat, comments=259)
|
StatDetails.objects.create(base_stats=userstat, comments=259)
|
||||||
|
|
||||||
user2 = User.objects.create(username="bob")
|
user2 = User.objects.create(username="bob")
|
||||||
results2 = UserStatResult.objects.create(results='moar results')
|
results2 = UserStatResult.objects.create(results='moar results')
|
||||||
advstat = AdvancedUserStat.objects.create(user=user2, posts=200, karma=5,
|
advstat = AdvancedUserStat.objects.create(user=user2, posts=200, karma=5, results=results2)
|
||||||
results=results2)
|
|
||||||
StatDetails.objects.create(base_stats=advstat, comments=250)
|
StatDetails.objects.create(base_stats=advstat, comments=250)
|
||||||
p1 = Parent1(name1="Only Parent1")
|
p1 = Parent1(name1="Only Parent1")
|
||||||
p1.save()
|
p1.save()
|
||||||
|
|
|
@ -523,7 +523,8 @@ class FileSessionTests(SessionTestsMixin, unittest.TestCase):
|
||||||
shutil.rmtree(self.temp_session_store)
|
shutil.rmtree(self.temp_session_store)
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
SESSION_FILE_PATH="/if/this/directory/exists/you/have/a/weird/computer")
|
SESSION_FILE_PATH='/if/this/directory/exists/you/have/a/weird/computer',
|
||||||
|
)
|
||||||
def test_configuration_check(self):
|
def test_configuration_check(self):
|
||||||
del self.backend._storage_path
|
del self.backend._storage_path
|
||||||
# Make sure the file backend checks for a good storage dir
|
# Make sure the file backend checks for a good storage dir
|
||||||
|
|
|
@ -319,7 +319,8 @@ class TestCollectionFilesOverride(CollectionTestCase):
|
||||||
os.utime(self.testfile_path, (self.orig_atime - 1, self.orig_mtime - 1))
|
os.utime(self.testfile_path, (self.orig_atime - 1, self.orig_mtime - 1))
|
||||||
|
|
||||||
self.settings_with_test_app = self.modify_settings(
|
self.settings_with_test_app = self.modify_settings(
|
||||||
INSTALLED_APPS={'prepend': 'staticfiles_test_app'})
|
INSTALLED_APPS={'prepend': 'staticfiles_test_app'},
|
||||||
|
)
|
||||||
with extend_sys_path(self.temp_dir):
|
with extend_sys_path(self.temp_dir):
|
||||||
self.settings_with_test_app.enable()
|
self.settings_with_test_app.enable()
|
||||||
|
|
||||||
|
|
|
@ -348,7 +348,8 @@ class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase):
|
||||||
f.write('to be deleted in one test')
|
f.write('to be deleted in one test')
|
||||||
|
|
||||||
self.patched_settings = self.settings(
|
self.patched_settings = self.settings(
|
||||||
STATICFILES_DIRS=settings.STATICFILES_DIRS + [temp_dir])
|
STATICFILES_DIRS=settings.STATICFILES_DIRS + [temp_dir],
|
||||||
|
)
|
||||||
self.patched_settings.enable()
|
self.patched_settings.enable()
|
||||||
self.addCleanup(shutil.rmtree, temp_dir)
|
self.addCleanup(shutil.rmtree, temp_dir)
|
||||||
self._manifest_strict = storage.staticfiles_storage.manifest_strict
|
self._manifest_strict = storage.staticfiles_storage.manifest_strict
|
||||||
|
|
|
@ -249,8 +249,7 @@ class TemplateResponseTest(SimpleTestCase):
|
||||||
self.assertEqual(response.content, b'no')
|
self.assertEqual(response.content, b'no')
|
||||||
|
|
||||||
def test_kwargs(self):
|
def test_kwargs(self):
|
||||||
response = self._response(content_type='application/json',
|
response = self._response(content_type='application/json', status=504)
|
||||||
status=504)
|
|
||||||
self.assertEqual(response['content-type'], 'application/json')
|
self.assertEqual(response['content-type'], 'application/json')
|
||||||
self.assertEqual(response.status_code, 504)
|
self.assertEqual(response.status_code, 504)
|
||||||
|
|
||||||
|
|
|
@ -178,8 +178,7 @@ class ClientTest(TestCase):
|
||||||
test_doc = """<?xml version="1.0" encoding="utf-8"?>
|
test_doc = """<?xml version="1.0" encoding="utf-8"?>
|
||||||
<library><book><title>Blink</title><author>Malcolm Gladwell</author></book></library>
|
<library><book><title>Blink</title><author>Malcolm Gladwell</author></book></library>
|
||||||
"""
|
"""
|
||||||
response = self.client.post("/raw_post_view/", test_doc,
|
response = self.client.post('/raw_post_view/', test_doc, content_type='text/xml')
|
||||||
content_type="text/xml")
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.templates[0].name, "Book template")
|
self.assertEqual(response.templates[0].name, "Book template")
|
||||||
self.assertEqual(response.content, b"Blink - Malcolm Gladwell")
|
self.assertEqual(response.content, b"Blink - Malcolm Gladwell")
|
||||||
|
|
|
@ -160,15 +160,18 @@ class LegacyDatabaseTests(TestCase):
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
Session.objects.annotate(dt=Min('events__dt')).order_by('dt'),
|
Session.objects.annotate(dt=Min('events__dt')).order_by('dt'),
|
||||||
[morning_min_dt, afternoon_min_dt],
|
[morning_min_dt, afternoon_min_dt],
|
||||||
transform=lambda d: d.dt)
|
transform=lambda d: d.dt,
|
||||||
|
)
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
Session.objects.annotate(dt=Min('events__dt')).filter(dt__lt=afternoon_min_dt),
|
Session.objects.annotate(dt=Min('events__dt')).filter(dt__lt=afternoon_min_dt),
|
||||||
[morning_min_dt],
|
[morning_min_dt],
|
||||||
transform=lambda d: d.dt)
|
transform=lambda d: d.dt,
|
||||||
|
)
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
Session.objects.annotate(dt=Min('events__dt')).filter(dt__gte=afternoon_min_dt),
|
Session.objects.annotate(dt=Min('events__dt')).filter(dt__gte=afternoon_min_dt),
|
||||||
[afternoon_min_dt],
|
[afternoon_min_dt],
|
||||||
transform=lambda d: d.dt)
|
transform=lambda d: d.dt,
|
||||||
|
)
|
||||||
|
|
||||||
def test_query_datetimes(self):
|
def test_query_datetimes(self):
|
||||||
Event.objects.create(dt=datetime.datetime(2011, 1, 1, 1, 30, 0))
|
Event.objects.create(dt=datetime.datetime(2011, 1, 1, 1, 30, 0))
|
||||||
|
@ -389,15 +392,18 @@ class NewDatabaseTests(TestCase):
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
Session.objects.annotate(dt=Min('events__dt')).order_by('dt'),
|
Session.objects.annotate(dt=Min('events__dt')).order_by('dt'),
|
||||||
[morning_min_dt, afternoon_min_dt],
|
[morning_min_dt, afternoon_min_dt],
|
||||||
transform=lambda d: d.dt)
|
transform=lambda d: d.dt,
|
||||||
|
)
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
Session.objects.annotate(dt=Min('events__dt')).filter(dt__lt=afternoon_min_dt),
|
Session.objects.annotate(dt=Min('events__dt')).filter(dt__lt=afternoon_min_dt),
|
||||||
[morning_min_dt],
|
[morning_min_dt],
|
||||||
transform=lambda d: d.dt)
|
transform=lambda d: d.dt,
|
||||||
|
)
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
Session.objects.annotate(dt=Min('events__dt')).filter(dt__gte=afternoon_min_dt),
|
Session.objects.annotate(dt=Min('events__dt')).filter(dt__gte=afternoon_min_dt),
|
||||||
[afternoon_min_dt],
|
[afternoon_min_dt],
|
||||||
transform=lambda d: d.dt)
|
transform=lambda d: d.dt,
|
||||||
|
)
|
||||||
|
|
||||||
@skipUnlessDBFeature('has_zoneinfo_database')
|
@skipUnlessDBFeature('has_zoneinfo_database')
|
||||||
def test_query_datetimes(self):
|
def test_query_datetimes(self):
|
||||||
|
|
|
@ -83,8 +83,7 @@ class AdvancedTests(TestCase):
|
||||||
"""
|
"""
|
||||||
We can update multiple objects at once.
|
We can update multiple objects at once.
|
||||||
"""
|
"""
|
||||||
resp = DataPoint.objects.filter(value="banana").update(
|
resp = DataPoint.objects.filter(value='banana').update(value='pineapple')
|
||||||
value="pineapple")
|
|
||||||
self.assertEqual(resp, 2)
|
self.assertEqual(resp, 2)
|
||||||
self.assertEqual(DataPoint.objects.get(name="d2").value, 'pineapple')
|
self.assertEqual(DataPoint.objects.get(name="d2").value, 'pineapple')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue