')
@@ -3829,7 +3824,7 @@ class UserAdminTest(TestCase):
adminform = response.context['adminform']
self.assertTrue('password' not in adminform.form.errors)
self.assertEqual(adminform.form.errors['password2'],
- ["The two password fields didn't match."])
+ ["The two password fields didn't match."])
def test_user_fk_popup(self):
"""Quick user addition in a FK popup shouldn't invoke view for further user customization"""
diff --git a/tests/admin_views/views.py b/tests/admin_views/views.py
index bb5f24ebfe..cfae496aba 100644
--- a/tests/admin_views/views.py
+++ b/tests/admin_views/views.py
@@ -1,6 +1,7 @@
from django.contrib.admin.views.decorators import staff_member_required
from django.http import HttpResponse
+
@staff_member_required
def secure_view(request):
return HttpResponse('%s' % request.POST)
diff --git a/tests/admin_widgets/models.py b/tests/admin_widgets/models.py
index 6a6c6e096b..5d295f0c9b 100644
--- a/tests/admin_widgets/models.py
+++ b/tests/admin_widgets/models.py
@@ -8,6 +8,7 @@ from django.utils.encoding import python_2_unicode_compatible
class MyFileField(models.FileField):
pass
+
@python_2_unicode_compatible
class Member(models.Model):
name = models.CharField(max_length=100)
@@ -18,6 +19,7 @@ class Member(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Band(models.Model):
name = models.CharField(max_length=100)
@@ -27,6 +29,7 @@ class Band(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Album(models.Model):
band = models.ForeignKey(Band)
@@ -37,10 +40,12 @@ class Album(models.Model):
def __str__(self):
return self.name
+
class HiddenInventoryManager(models.Manager):
def get_queryset(self):
return super(HiddenInventoryManager, self).get_queryset().filter(hidden=False)
+
@python_2_unicode_compatible
class Inventory(models.Model):
barcode = models.PositiveIntegerField(unique=True)
@@ -55,6 +60,7 @@ class Inventory(models.Model):
def __str__(self):
return self.name
+
class Event(models.Model):
main_band = models.ForeignKey(Band, limit_choices_to=models.Q(pk__gt=0), related_name='events_main_band_at')
supporting_bands = models.ManyToManyField(Band, null=True, blank=True, related_name='events_supporting_band_at')
@@ -64,6 +70,7 @@ class Event(models.Model):
link = models.URLField(blank=True)
min_age = models.IntegerField(blank=True, null=True)
+
@python_2_unicode_compatible
class Car(models.Model):
owner = models.ForeignKey(User)
@@ -73,15 +80,18 @@ class Car(models.Model):
def __str__(self):
return "%s %s" % (self.make, self.model)
+
class CarTire(models.Model):
"""
A single car tire. This to test that a user can only select their own cars.
"""
car = models.ForeignKey(Car)
+
class Honeycomb(models.Model):
location = models.CharField(max_length=20)
+
class Bee(models.Model):
"""
A model with a FK to a model that won't be registered with the admin
@@ -90,6 +100,7 @@ class Bee(models.Model):
"""
honeycomb = models.ForeignKey(Honeycomb)
+
class Individual(models.Model):
"""
A model with a FK to itself. It won't be registered with the admin, so the
@@ -99,9 +110,11 @@ class Individual(models.Model):
name = models.CharField(max_length=20)
parent = models.ForeignKey('self', null=True)
+
class Company(models.Model):
name = models.CharField(max_length=20)
+
class Advisor(models.Model):
"""
A model with a m2m to a model that won't be registered with the admin
@@ -122,6 +135,7 @@ class Student(models.Model):
class Meta:
ordering = ('name',)
+
@python_2_unicode_compatible
class School(models.Model):
name = models.CharField(max_length=255)
diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py
index ac317b3434..04fe083eea 100644
--- a/tests/admin_widgets/tests.py
+++ b/tests/admin_widgets/tests.py
@@ -30,6 +30,7 @@ admin_static_prefix = lambda: {
'ADMIN_STATIC_PREFIX': "%sadmin/" % settings.STATIC_URL,
}
+
class AdminFormfieldForDBFieldTests(TestCase):
"""
Tests for correct behavior of ModelAdmin.formfield_for_dbfield
@@ -274,6 +275,7 @@ class FilteredSelectMultipleWidgetTest(DjangoTestCase):
'
\n \n' % admin_static_prefix()
)
+
class AdminDateWidgetTest(DjangoTestCase):
def test_attrs(self):
"""
@@ -292,6 +294,7 @@ class AdminDateWidgetTest(DjangoTestCase):
'
',
)
+
class AdminTimeWidgetTest(DjangoTestCase):
def test_attrs(self):
"""
@@ -310,6 +313,7 @@ class AdminTimeWidgetTest(DjangoTestCase):
'
',
)
+
class AdminSplitDateTimeWidgetTest(DjangoTestCase):
def test_render(self):
w = widgets.AdminSplitDateTime()
@@ -500,6 +504,7 @@ class ManyToManyRawIdWidgetTest(DjangoTestCase):
'
' % {'c1pk': c1.pk}
)
+
class RelatedFieldWidgetWrapperTests(DjangoTestCase):
def test_no_can_add_related(self):
rel = models.Individual._meta.get_field('parent').rel
@@ -636,6 +641,7 @@ class DateTimePickerSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
class DateTimePickerSeleniumChromeTests(DateTimePickerSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
+
class DateTimePickerSeleniumIETests(DateTimePickerSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
@@ -701,9 +707,11 @@ class DateTimePickerShortcutsSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase
self.assertGreater(member.birthdate, now - error_margin)
self.assertLess(member.birthdate, now + error_margin)
+
class DateTimePickerShortcutsSeleniumChromeTests(DateTimePickerShortcutsSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
+
class DateTimePickerShortcutsSeleniumIETests(DateTimePickerShortcutsSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
@@ -729,7 +737,7 @@ class HorizontalVerticalFilterSeleniumFirefoxTests(AdminSeleniumWebDriverTestCas
super(HorizontalVerticalFilterSeleniumFirefoxTests, self).setUp()
def assertActiveButtons(self, mode, field_name, choose, remove,
- choose_all=None, remove_all=None):
+ choose_all=None, remove_all=None):
choose_link = '#id_%s_add_link' % field_name
choose_all_link = '#id_%s_add_all_link' % field_name
remove_link = '#id_%s_remove_link' % field_name
@@ -943,9 +951,11 @@ class HorizontalVerticalFilterSeleniumFirefoxTests(AdminSeleniumWebDriverTestCas
self.assertEqual(list(self.school.alumni.all()),
[self.jason, self.peter])
+
class HorizontalVerticalFilterSeleniumChromeTests(HorizontalVerticalFilterSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
+
class HorizontalVerticalFilterSeleniumIETests(HorizontalVerticalFilterSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
@@ -1040,9 +1050,11 @@ class AdminRawIdWidgetSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
self.selenium.find_element_by_id('id_supporting_bands').get_attribute('value'),
'42,98')
+
class AdminRawIdWidgetSeleniumChromeTests(AdminRawIdWidgetSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
+
class AdminRawIdWidgetSeleniumIETests(AdminRawIdWidgetSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
@@ -1087,8 +1099,10 @@ class RelatedFieldWidgetSeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
self.assertEqual(len(profiles), 1)
self.assertEqual(profiles[0].user.username, username_value)
+
class RelatedFieldWidgetSeleniumChromeTests(RelatedFieldWidgetSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
+
class RelatedFieldWidgetSeleniumIETests(RelatedFieldWidgetSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
diff --git a/tests/aggregation/models.py b/tests/aggregation/models.py
index 9710afaf11..691737c17e 100644
--- a/tests/aggregation/models.py
+++ b/tests/aggregation/models.py
@@ -12,6 +12,7 @@ class Author(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Publisher(models.Model):
name = models.CharField(max_length=255)
@@ -20,6 +21,7 @@ class Publisher(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Book(models.Model):
isbn = models.CharField(max_length=9)
@@ -35,6 +37,7 @@ class Book(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Store(models.Model):
name = models.CharField(max_length=255)
diff --git a/tests/aggregation_regress/models.py b/tests/aggregation_regress/models.py
index a2dc060640..275e37c036 100644
--- a/tests/aggregation_regress/models.py
+++ b/tests/aggregation_regress/models.py
@@ -61,6 +61,7 @@ class Store(models.Model):
def __str__(self):
return self.name
+
class Entries(models.Model):
EntryID = models.AutoField(primary_key=True, db_column='Entry ID')
Entry = models.CharField(unique=True, max_length=50)
@@ -69,7 +70,7 @@ class Entries(models.Model):
class Clues(models.Model):
ID = models.AutoField(primary_key=True)
- EntryID = models.ForeignKey(Entries, verbose_name='Entry', db_column = 'Entry ID')
+ EntryID = models.ForeignKey(Entries, verbose_name='Entry', db_column='Entry ID')
Clue = models.CharField(max_length=150)
@@ -88,13 +89,16 @@ class HardbackBook(Book):
def __str__(self):
return "%s (hardback): %s" % (self.name, self.weight)
+
# Models for ticket #21150
class Alfa(models.Model):
name = models.CharField(max_length=10, null=True)
+
class Bravo(models.Model):
pass
+
class Charlie(models.Model):
alfa = models.ForeignKey(Alfa, null=True)
bravo = models.ForeignKey(Bravo, null=True)
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index 3c0cc67ea2..3a79b79411 100644
--- a/tests/backends/tests.py
+++ b/tests/backends/tests.py
@@ -432,6 +432,7 @@ class EscapingChecks(TestCase):
# response should be an non-zero integer
self.assertTrue(int(response))
+
@override_settings(DEBUG=True)
class EscapingChecksDebug(EscapingChecks):
pass
@@ -509,12 +510,12 @@ class BackendTestCase(TestCase):
def test_cursor_executemany(self):
#4896: Test cursor.executemany
- args = [(i, i**2) for i in range(-5, 6)]
+ args = [(i, i ** 2) for i in range(-5, 6)]
self.create_squares_with_executemany(args)
self.assertEqual(models.Square.objects.count(), 11)
for i in range(-5, 6):
square = models.Square.objects.get(root=i)
- self.assertEqual(square.square, i**2)
+ self.assertEqual(square.square, i ** 2)
def test_cursor_executemany_with_empty_params_list(self):
#4765: executemany with params=[] does nothing
@@ -524,11 +525,11 @@ class BackendTestCase(TestCase):
def test_cursor_executemany_with_iterator(self):
#10320: executemany accepts iterators
- args = iter((i, i**2) for i in range(-3, 2))
+ args = iter((i, i ** 2) for i in range(-3, 2))
self.create_squares_with_executemany(args)
self.assertEqual(models.Square.objects.count(), 5)
- args = iter((i, i**2) for i in range(3, 7))
+ args = iter((i, i ** 2) for i in range(3, 7))
with override_settings(DEBUG=True):
# same test for DebugCursorWrapper
self.create_squares_with_executemany(args)
@@ -544,20 +545,20 @@ class BackendTestCase(TestCase):
@skipUnlessDBFeature('supports_paramstyle_pyformat')
def test_cursor_executemany_with_pyformat(self):
#10070: Support pyformat style passing of paramters
- args = [{'root': i, 'square': i**2} for i in range(-5, 6)]
+ args = [{'root': i, 'square': i ** 2} for i in range(-5, 6)]
self.create_squares(args, 'pyformat', multiple=True)
self.assertEqual(models.Square.objects.count(), 11)
for i in range(-5, 6):
square = models.Square.objects.get(root=i)
- self.assertEqual(square.square, i**2)
+ self.assertEqual(square.square, i ** 2)
@skipUnlessDBFeature('supports_paramstyle_pyformat')
def test_cursor_executemany_with_pyformat_iterator(self):
- args = iter({'root': i, 'square': i**2} for i in range(-3, 2))
+ args = iter({'root': i, 'square': i ** 2} for i in range(-3, 2))
self.create_squares(args, 'pyformat', multiple=True)
self.assertEqual(models.Square.objects.count(), 5)
- args = iter({'root': i, 'square': i**2} for i in range(3, 7))
+ args = iter({'root': i, 'square': i ** 2} for i in range(3, 7))
with override_settings(DEBUG=True):
# same test for DebugCursorWrapper
self.create_squares(args, 'pyformat', multiple=True)
@@ -987,6 +988,7 @@ class BackendUtilTests(TestCase):
equal('0.1234567890', 12, 0,
'0')
+
@unittest.skipUnless(
connection.vendor == 'postgresql',
"This test applies only to PostgreSQL")
diff --git a/tests/basic/models.py b/tests/basic/models.py
index 38cb813d42..5e67b0dca9 100644
--- a/tests/basic/models.py
+++ b/tests/basic/models.py
@@ -19,11 +19,13 @@ class Article(models.Model):
def __str__(self):
return self.headline
+
class ArticleSelectOnSave(Article):
class Meta:
proxy = True
select_on_save = True
+
@python_2_unicode_compatible
class SelfRef(models.Model):
selfref = models.ForeignKey('self', null=True, blank=True,
diff --git a/tests/basic/tests.py b/tests/basic/tests.py
index e4559dc7d7..976fb1124d 100644
--- a/tests/basic/tests.py
+++ b/tests/basic/tests.py
@@ -87,7 +87,8 @@ class ModelTest(TestCase):
# Django raises an Article.DoesNotExist exception for get() if the
# parameters don't match any object.
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
ObjectDoesNotExist,
"Article matching query does not exist.",
Article.objects.get,
@@ -102,7 +103,8 @@ class ModelTest(TestCase):
pub_date__month=8,
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
ObjectDoesNotExist,
"Article matching query does not exist.",
Article.objects.get,
@@ -135,21 +137,24 @@ class ModelTest(TestCase):
# Django raises an Article.MultipleObjectsReturned exception if the
# lookup matches more than one object
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
MultipleObjectsReturned,
"get\(\) returned more than one Article -- it returned 2!",
Article.objects.get,
headline__startswith='Area',
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
MultipleObjectsReturned,
"get\(\) returned more than one Article -- it returned 2!",
Article.objects.get,
pub_date__year=2005,
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
MultipleObjectsReturned,
"get\(\) returned more than one Article -- it returned 2!",
Article.objects.get,
@@ -165,14 +170,16 @@ class ModelTest(TestCase):
Article(headline='Area %s' % i, pub_date=datetime(2005, 7, 28))
for i in range(MAX_GET_RESULTS)
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
MultipleObjectsReturned,
"get\(\) returned more than one Article -- it returned %d!" % MAX_GET_RESULTS,
Article.objects.get,
headline__startswith='Area',
)
Article.objects.create(headline='Area %s' % MAX_GET_RESULTS, pub_date=datetime(2005, 7, 28))
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
MultipleObjectsReturned,
"get\(\) returned more than one Article -- it returned more than %d!" % MAX_GET_RESULTS,
Article.objects.get,
@@ -219,7 +226,8 @@ class ModelTest(TestCase):
self.assertEqual(a4.headline, 'Fourth article')
# Don't use invalid keyword arguments.
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
TypeError,
"'foo' is an invalid keyword argument for this function",
Article,
@@ -315,7 +323,8 @@ class ModelTest(TestCase):
Article.objects.dates,
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
FieldDoesNotExist,
"Article has no field named 'invalid_field'",
Article.objects.dates,
@@ -323,7 +332,8 @@ class ModelTest(TestCase):
"year",
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
AssertionError,
"'kind' must be one of 'year', 'month' or 'day'.",
Article.objects.dates,
@@ -331,7 +341,8 @@ class ModelTest(TestCase):
"bad_kind",
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
AssertionError,
"'order' must be either 'ASC' or 'DESC'.",
Article.objects.dates,
@@ -419,14 +430,16 @@ class ModelTest(TestCase):
"
"])
# Also, once you have sliced you can't filter, re-order or combine
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
AssertionError,
"Cannot filter a query once a slice has been taken.",
Article.objects.all()[0:5].filter,
id=a.id,
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
AssertionError,
"Cannot reorder a query once a slice has been taken.",
Article.objects.all()[0:5].order_by,
@@ -461,7 +474,8 @@ class ModelTest(TestCase):
# An Article instance doesn't have access to the "objects" attribute.
# That's only available on the class.
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
AttributeError,
"Manager isn't accessible via Article instances",
getattr,
@@ -605,8 +619,8 @@ class ModelTest(TestCase):
)
dicts = Article.objects.filter(
- pub_date__year=2008).extra(select={'dashed-value': '1'}
- ).values('headline', 'dashed-value')
+ pub_date__year=2008).extra(
+ select={'dashed-value': '1'}).values('headline', 'dashed-value')
self.assertEqual([sorted(d.items()) for d in dicts],
[[('dashed-value', 1), ('headline', 'Article 11')], [('dashed-value', 1), ('headline', 'Article 12')]])
@@ -723,6 +737,7 @@ class ModelTest(TestCase):
# hash)
hash(Article())
+
class ConcurrentSaveTests(TransactionTestCase):
available_apps = ['basic']
@@ -808,6 +823,7 @@ class ManagerTest(TestCase):
sorted(self.QUERYSET_PROXY_METHODS),
)
+
class SelectOnSaveTests(TestCase):
def test_select_on_save(self):
a1 = Article.objects.create(pub_date=datetime.now())
diff --git a/tests/bug639/models.py b/tests/bug639/models.py
index fa8e7d2c07..3b6a007f6b 100644
--- a/tests/bug639/models.py
+++ b/tests/bug639/models.py
@@ -8,6 +8,7 @@ from django.forms import ModelForm
temp_storage_dir = tempfile.mkdtemp()
temp_storage = FileSystemStorage(temp_storage_dir)
+
class Photo(models.Model):
title = models.CharField(max_length=30)
image = models.FileField(storage=temp_storage, upload_to='tests')
@@ -22,6 +23,7 @@ class Photo(models.Model):
super(Photo, self).save(force_insert, force_update)
self._savecount += 1
+
class PhotoForm(ModelForm):
class Meta:
model = Photo
diff --git a/tests/bulk_create/models.py b/tests/bulk_create/models.py
index bc685bbbe4..fcc4b4177e 100644
--- a/tests/bulk_create/models.py
+++ b/tests/bulk_create/models.py
@@ -5,21 +5,26 @@ class Country(models.Model):
name = models.CharField(max_length=255)
iso_two_letter = models.CharField(max_length=2)
+
class Place(models.Model):
name = models.CharField(max_length=100)
class Meta:
abstract = True
+
class Restaurant(Place):
pass
+
class Pizzeria(Restaurant):
pass
+
class State(models.Model):
two_letter_code = models.CharField(max_length=2, primary_key=True)
+
class TwoFields(models.Model):
f1 = models.IntegerField(unique=True)
f2 = models.IntegerField(unique=True)
diff --git a/tests/cache/closeable_cache.py b/tests/cache/closeable_cache.py
index 83073850b7..1ac868dde9 100644
--- a/tests/cache/closeable_cache.py
+++ b/tests/cache/closeable_cache.py
@@ -7,5 +7,6 @@ class CloseHookMixin(object):
def close(self, **kwargs):
self.closed = True
+
class CacheClass(CloseHookMixin, LocMemCache):
pass
diff --git a/tests/cache/liberal_backend.py b/tests/cache/liberal_backend.py
index 3e3ce3beeb..339066b0ff 100644
--- a/tests/cache/liberal_backend.py
+++ b/tests/cache/liberal_backend.py
@@ -5,5 +5,6 @@ class LiberalKeyValidationMixin(object):
def validate_key(self, key):
pass
+
class CacheClass(LiberalKeyValidationMixin, LocMemCache):
pass
diff --git a/tests/cache/models.py b/tests/cache/models.py
index 2cd648b780..4fccbb664b 100644
--- a/tests/cache/models.py
+++ b/tests/cache/models.py
@@ -7,6 +7,7 @@ def expensive_calculation():
expensive_calculation.num_runs += 1
return timezone.now()
+
class Poll(models.Model):
question = models.CharField(max_length=200)
answer = models.CharField(max_length=200)
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index a79d4d9fac..a93ed4418a 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -40,10 +40,12 @@ from django.views.decorators.cache import cache_page
from .models import Poll, expensive_calculation
+
# functions/classes for complex data type tests
def f():
return 42
+
class C:
def m(n):
return 24
@@ -823,6 +825,7 @@ class BaseCacheTests(object):
self.assertEqual(get_cache_data.content, content.encode('utf-8'))
self.assertEqual(get_cache_data.cookies, response.cookies)
+
def custom_key_func(key, key_prefix, version):
"A customized cache key function"
return 'CUSTOM-' + '-'.join([key_prefix, str(version), key])
@@ -1004,6 +1007,7 @@ class LocMemCacheTests(unittest.TestCase, BaseCacheTests):
self.cache.decr(key)
self.assertEqual(expire, self.cache._expire_info[_key])
+
# memcached backend isn't guaranteed to be available.
# To check the memcached backend, the test settings file will
# need to contain at least one cache backend setting that points at
@@ -1581,6 +1585,7 @@ class CacheI18nTest(TestCase):
get_cache_data = FetchFromCacheMiddleware().process_request(request)
self.assertIsNone(get_cache_data)
+
@override_settings(
CACHES={
'default': {
@@ -1816,6 +1821,7 @@ class CacheMiddlewareTest(IgnoreDeprecationWarningsMixin, TestCase):
response = other_with_prefix_view(request, '16')
self.assertEqual(response.content, b'Hello World 16')
+
@override_settings(
CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
CACHE_MIDDLEWARE_SECONDS=1,
diff --git a/tests/check/models.py b/tests/check/models.py
index 212b01bdd2..ddeed23982 100644
--- a/tests/check/models.py
+++ b/tests/check/models.py
@@ -1,9 +1,11 @@
from django.db import models
+
class Book(models.Model):
title = models.CharField(max_length=250)
is_published = models.BooleanField(default=False)
+
class BlogPost(models.Model):
title = models.CharField(max_length=250)
is_published = models.BooleanField(default=False)
diff --git a/tests/check/tests.py b/tests/check/tests.py
index 19b3840a9a..577dcd610b 100644
--- a/tests/check/tests.py
+++ b/tests/check/tests.py
@@ -7,6 +7,7 @@ from django.test import TestCase
from .models import Book
+
class StubCheckModule(object):
# Has no ``run_checks`` attribute & will trigger a warning.
__name__ = 'StubCheckModule'
diff --git a/tests/choices/models.py b/tests/choices/models.py
index 2fa33a9680..4fcef6f48f 100644
--- a/tests/choices/models.py
+++ b/tests/choices/models.py
@@ -18,6 +18,7 @@ GENDER_CHOICES = (
('F', 'Female'),
)
+
@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=20)
diff --git a/tests/commands_sql/tests.py b/tests/commands_sql/tests.py
index 1a1a190ec5..3a0b5527f4 100644
--- a/tests/commands_sql/tests.py
+++ b/tests/commands_sql/tests.py
@@ -58,6 +58,7 @@ class TestRouter(object):
def allow_migrate(self, db, model):
return False
+
class SQLCommandsRouterTestCase(TestCase):
def setUp(self):
self._old_routers = router.routers
diff --git a/tests/conditional_processing/tests.py b/tests/conditional_processing/tests.py
index 77f1ff54ed..2c832e527c 100644
--- a/tests/conditional_processing/tests.py
+++ b/tests/conditional_processing/tests.py
@@ -15,6 +15,7 @@ EXPIRED_LAST_MODIFIED_STR = 'Sat, 20 Oct 2007 23:21:47 GMT'
ETAG = 'b4246ffc4f62314ca13147c9d4f76974'
EXPIRED_ETAG = '7fae4cd4b0f81e7d2914700043aa8ed6'
+
class ConditionalGet(TestCase):
urls = 'conditional_processing.urls'
diff --git a/tests/conditional_processing/views.py b/tests/conditional_processing/views.py
index 2960e0533d..496e79fd34 100644
--- a/tests/conditional_processing/views.py
+++ b/tests/conditional_processing/views.py
@@ -8,18 +8,22 @@ def index(request):
return HttpResponse(FULL_RESPONSE)
index = condition(lambda r: ETAG, lambda r: LAST_MODIFIED)(index)
+
def last_modified_view1(request):
return HttpResponse(FULL_RESPONSE)
last_modified_view1 = condition(last_modified_func=lambda r: LAST_MODIFIED)(last_modified_view1)
+
def last_modified_view2(request):
return HttpResponse(FULL_RESPONSE)
last_modified_view2 = last_modified(lambda r: LAST_MODIFIED)(last_modified_view2)
+
def etag_view1(request):
return HttpResponse(FULL_RESPONSE)
etag_view1 = condition(etag_func=lambda r: ETAG)(etag_view1)
+
def etag_view2(request):
return HttpResponse(FULL_RESPONSE)
etag_view2 = etag(lambda r: ETAG)(etag_view2)
diff --git a/tests/contenttypes_tests/models.py b/tests/contenttypes_tests/models.py
index 5d21ad5b96..b2669367eb 100644
--- a/tests/contenttypes_tests/models.py
+++ b/tests/contenttypes_tests/models.py
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
+
@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=100)
@@ -13,6 +14,7 @@ class Author(models.Model):
def get_absolute_url(self):
return '/views/authors/%s/' % self.id
+
@python_2_unicode_compatible
class Article(models.Model):
title = models.CharField(max_length=100)
diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py
index 63f02697df..29ae6c5336 100644
--- a/tests/contenttypes_tests/tests.py
+++ b/tests/contenttypes_tests/tests.py
@@ -5,6 +5,7 @@ from django.test import TestCase
from .models import Author, Article
+
class ContentTypesViewsTests(TestCase):
fixtures = ['testdata.json']
urls = 'contenttypes_tests.urls'
diff --git a/tests/csrf_tests/tests.py b/tests/csrf_tests/tests.py
index 57f8359cc7..ac48c17af6 100644
--- a/tests/csrf_tests/tests.py
+++ b/tests/csrf_tests/tests.py
@@ -19,10 +19,12 @@ def post_form_response():
""", mimetype="text/html")
return resp
+
def post_form_view(request):
"""A view that returns a POST form (without a token)"""
return post_form_response()
+
# Response/views used for template tag tests
def token_view(request):
@@ -31,6 +33,7 @@ def token_view(request):
template = Template("{% csrf_token %}")
return HttpResponse(template.render(context))
+
def non_token_view_using_request_processor(request):
"""
A view that doesn't use the token, but does use the csrf view processor.
@@ -39,6 +42,7 @@ def non_token_view_using_request_processor(request):
template = Template("")
return HttpResponse(template.render(context))
+
class TestingHttpRequest(HttpRequest):
"""
A version of HttpRequest that allows us to change some things
@@ -47,6 +51,7 @@ class TestingHttpRequest(HttpRequest):
def is_secure(self):
return getattr(self, '_is_secure_override', False)
+
class CsrfViewMiddlewareTest(TestCase):
# The csrf token is potentially from an untrusted source, so could have
# characters that need dealing with.
diff --git a/tests/custom_columns/models.py b/tests/custom_columns/models.py
index 2549dde749..df1e743be9 100644
--- a/tests/custom_columns/models.py
+++ b/tests/custom_columns/models.py
@@ -33,6 +33,7 @@ class Author(models.Model):
db_table = 'my_author_table'
ordering = ('last_name', 'first_name')
+
@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
diff --git a/tests/custom_columns_regress/models.py b/tests/custom_columns_regress/models.py
index e848b8ec23..1c026a44c0 100644
--- a/tests/custom_columns_regress/models.py
+++ b/tests/custom_columns_regress/models.py
@@ -24,6 +24,7 @@ class Article(models.Model):
class Meta:
ordering = ('headline',)
+
@python_2_unicode_compatible
class Author(models.Model):
Author_ID = models.AutoField(primary_key=True, db_column='Author ID')
diff --git a/tests/custom_columns_regress/tests.py b/tests/custom_columns_regress/tests.py
index 034de08d45..24297b9fa5 100644
--- a/tests/custom_columns_regress/tests.py
+++ b/tests/custom_columns_regress/tests.py
@@ -10,6 +10,7 @@ def pks(objects):
""" Return pks to be able to compare lists"""
return [o.pk for o in objects]
+
class CustomColumnRegression(TestCase):
def setUp(self):
diff --git a/tests/custom_managers/models.py b/tests/custom_managers/models.py
index 26d848b7c0..c6a99620e9 100644
--- a/tests/custom_managers/models.py
+++ b/tests/custom_managers/models.py
@@ -17,18 +17,21 @@ from django.utils.encoding import python_2_unicode_compatible
# An example of a custom manager called "objects".
+
class PersonManager(models.Manager):
def get_fun_people(self):
return self.filter(fun=True)
# An example of a custom manager that sets get_queryset().
+
class PublishedBookManager(models.Manager):
def get_queryset(self):
return super(PublishedBookManager, self).get_queryset().filter(is_published=True)
# An example of a custom queryset that copies its methods onto the manager.
+
class CustomQuerySet(models.QuerySet):
def filter(self, *args, **kwargs):
queryset = super(CustomQuerySet, self).filter(fun=True)
@@ -49,6 +52,7 @@ class CustomQuerySet(models.QuerySet):
return self.all()
_optin_private_method.queryset_only = False
+
class BaseCustomManager(models.Manager):
def __init__(self, arg):
super(BaseCustomManager, self).__init__()
@@ -64,14 +68,17 @@ class BaseCustomManager(models.Manager):
CustomManager = BaseCustomManager.from_queryset(CustomQuerySet)
+
class FunPeopleManager(models.Manager):
def get_queryset(self):
return super(FunPeopleManager, self).get_queryset().filter(fun=True)
+
class BoringPeopleManager(models.Manager):
def get_queryset(self):
return super(BoringPeopleManager, self).get_queryset().filter(fun=False)
+
@python_2_unicode_compatible
class Person(models.Model):
first_name = models.CharField(max_length=30)
@@ -93,6 +100,7 @@ class Person(models.Model):
def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
+
@python_2_unicode_compatible
class Book(models.Model):
title = models.CharField(max_length=50)
@@ -109,10 +117,12 @@ class Book(models.Model):
# An example of providing multiple custom managers.
+
class FastCarManager(models.Manager):
def get_queryset(self):
return super(FastCarManager, self).get_queryset().filter(top_speed__gt=150)
+
@python_2_unicode_compatible
class Car(models.Model):
name = models.CharField(max_length=10)
diff --git a/tests/custom_managers_regress/models.py b/tests/custom_managers_regress/models.py
index 95cf6e8ca1..eda711f8d7 100644
--- a/tests/custom_managers_regress/models.py
+++ b/tests/custom_managers_regress/models.py
@@ -13,6 +13,7 @@ class RestrictedManager(models.Manager):
def get_queryset(self):
return super(RestrictedManager, self).get_queryset().filter(is_public=True)
+
@python_2_unicode_compatible
class RelatedModel(models.Model):
name = models.CharField(max_length=50)
@@ -20,6 +21,7 @@ class RelatedModel(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class RestrictedModel(models.Model):
name = models.CharField(max_length=50)
@@ -32,6 +34,7 @@ class RestrictedModel(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class OneToOneRestrictedModel(models.Model):
name = models.CharField(max_length=50)
diff --git a/tests/custom_pk/fields.py b/tests/custom_pk/fields.py
index 92096a0ff7..2aa3bad963 100644
--- a/tests/custom_pk/fields.py
+++ b/tests/custom_pk/fields.py
@@ -22,6 +22,7 @@ class MyWrapper(object):
return self.value == other.value
return self.value == other
+
class MyAutoField(six.with_metaclass(models.SubfieldBase, models.CharField)):
def __init__(self, *args, **kwargs):
diff --git a/tests/custom_pk/models.py b/tests/custom_pk/models.py
index 5fffb84641..bfa6777b10 100644
--- a/tests/custom_pk/models.py
+++ b/tests/custom_pk/models.py
@@ -16,7 +16,7 @@ from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class Employee(models.Model):
- employee_code = models.IntegerField(primary_key=True, db_column = 'code')
+ employee_code = models.IntegerField(primary_key=True, db_column='code')
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
@@ -26,6 +26,7 @@ class Employee(models.Model):
def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
+
@python_2_unicode_compatible
class Business(models.Model):
name = models.CharField(max_length=20, primary_key=True)
@@ -37,6 +38,7 @@ class Business(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Bar(models.Model):
id = MyAutoField(primary_key=True, db_index=True)
diff --git a/tests/datatypes/models.py b/tests/datatypes/models.py
index 8e6027dd0f..cabe5297bd 100644
--- a/tests/datatypes/models.py
+++ b/tests/datatypes/models.py
@@ -23,6 +23,7 @@ class Donut(models.Model):
def __str__(self):
return self.name
+
class RumBaba(models.Model):
baked_date = models.DateField(auto_now_add=True)
baked_timestamp = models.DateTimeField(auto_now_add=True)
diff --git a/tests/dates/models.py b/tests/dates/models.py
index 23350755e7..d27c22ff67 100644
--- a/tests/dates/models.py
+++ b/tests/dates/models.py
@@ -14,6 +14,7 @@ class Article(models.Model):
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class Comment(models.Model):
article = models.ForeignKey(Article, related_name="comments")
@@ -24,5 +25,6 @@ class Comment(models.Model):
def __str__(self):
return 'Comment to %s (%s)' % (self.article.title, self.pub_date)
+
class Category(models.Model):
name = models.CharField(max_length=255)
diff --git a/tests/datetimes/models.py b/tests/datetimes/models.py
index f21376aa1c..cfdd521b53 100644
--- a/tests/datetimes/models.py
+++ b/tests/datetimes/models.py
@@ -14,6 +14,7 @@ class Article(models.Model):
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class Comment(models.Model):
article = models.ForeignKey(Article, related_name="comments")
@@ -24,5 +25,6 @@ class Comment(models.Model):
def __str__(self):
return 'Comment to %s (%s)' % (self.article.title, self.pub_date)
+
class Category(models.Model):
name = models.CharField(max_length=255)
diff --git a/tests/db_typecasts/tests.py b/tests/db_typecasts/tests.py
index 27b89c0c8c..e391743028 100644
--- a/tests/db_typecasts/tests.py
+++ b/tests/db_typecasts/tests.py
@@ -48,6 +48,7 @@ TEST_CASES = {
),
}
+
class DBTypeCasts(unittest.TestCase):
def test_typeCasts(self):
for k, v in six.iteritems(TEST_CASES):
diff --git a/tests/decorators/tests.py b/tests/decorators/tests.py
index 4016273ef5..db00f36051 100644
--- a/tests/decorators/tests.py
+++ b/tests/decorators/tests.py
@@ -44,7 +44,7 @@ full_decorator = compose(
vary_on_cookie,
# django.views.decorators.cache
- cache_page(60*15),
+ cache_page(60 * 15),
cache_control(private=True),
never_cache,
@@ -65,6 +65,7 @@ full_decorator = compose(
fully_decorated = full_decorator(fully_decorated)
+
class DecoratorsTest(TestCase):
def test_attributes(self):
diff --git a/tests/defer/models.py b/tests/defer/models.py
index cf3bae86bb..ffc8a0c2c7 100644
--- a/tests/defer/models.py
+++ b/tests/defer/models.py
@@ -10,6 +10,7 @@ class Secondary(models.Model):
first = models.CharField(max_length=50)
second = models.CharField(max_length=50)
+
@python_2_unicode_compatible
class Primary(models.Model):
name = models.CharField(max_length=50)
@@ -19,12 +20,15 @@ class Primary(models.Model):
def __str__(self):
return self.name
+
class Child(Primary):
pass
+
class BigChild(Primary):
other = models.CharField(max_length=50)
+
class ChildProxy(Child):
class Meta:
proxy = True
diff --git a/tests/defer_regress/models.py b/tests/defer_regress/models.py
index 0170221cb9..d858558e97 100644
--- a/tests/defer_regress/models.py
+++ b/tests/defer_regress/models.py
@@ -16,13 +16,16 @@ class Item(models.Model):
def __str__(self):
return self.name
+
class RelatedItem(models.Model):
item = models.ForeignKey(Item)
+
class Child(models.Model):
name = models.CharField(max_length=10)
value = models.IntegerField()
+
@python_2_unicode_compatible
class Leaf(models.Model):
name = models.CharField(max_length=10)
@@ -33,14 +36,17 @@ class Leaf(models.Model):
def __str__(self):
return self.name
+
class ResolveThis(models.Model):
num = models.FloatField()
name = models.CharField(max_length=16)
+
class Proxy(Item):
class Meta:
proxy = True
+
@python_2_unicode_compatible
class SimpleItem(models.Model):
name = models.CharField(max_length=15)
@@ -49,29 +55,37 @@ class SimpleItem(models.Model):
def __str__(self):
return self.name
+
class Feature(models.Model):
item = models.ForeignKey(SimpleItem)
+
class SpecialFeature(models.Model):
feature = models.ForeignKey(Feature)
+
class OneToOneItem(models.Model):
item = models.OneToOneField(Item, related_name="one_to_one_item")
name = models.CharField(max_length=15)
+
class ItemAndSimpleItem(models.Model):
item = models.ForeignKey(Item)
simple = models.ForeignKey(SimpleItem)
+
class Profile(models.Model):
profile1 = models.CharField(max_length=1000, default='profile1')
+
class Location(models.Model):
location1 = models.CharField(max_length=1000, default='location1')
+
class Item(models.Model):
pass
+
class Request(models.Model):
profile = models.ForeignKey(Profile, null=True, blank=True)
location = models.ForeignKey(Location)
diff --git a/tests/defer_regress/tests.py b/tests/defer_regress/tests.py
index ffb47a8133..c03388b50e 100644
--- a/tests/defer_regress/tests.py
+++ b/tests/defer_regress/tests.py
@@ -245,6 +245,7 @@ class DeferRegressionTest(TestCase):
new_class.__name__,
'Item_Deferred_this_is_some_very_long_attribute_nac34b1f495507dad6b02e2cb235c875e')
+
class DeferAnnotateSelectRelatedTest(TestCase):
def test_defer_annotate_select_related(self):
location = Location.objects.create()
diff --git a/tests/delete/models.py b/tests/delete/models.py
index 65d4e6f725..408b6b83f8 100644
--- a/tests/delete/models.py
+++ b/tests/delete/models.py
@@ -109,20 +109,26 @@ class HiddenUser(models.Model):
class HiddenUserProfile(models.Model):
user = models.ForeignKey(HiddenUser)
+
class M2MTo(models.Model):
pass
+
class M2MFrom(models.Model):
m2m = models.ManyToManyField(M2MTo)
+
class Parent(models.Model):
pass
+
class Child(Parent):
pass
+
class Base(models.Model):
pass
+
class RelToBase(models.Model):
base = models.ForeignKey(Base, on_delete=models.DO_NOTHING)
diff --git a/tests/delete/tests.py b/tests/delete/tests.py
index 7bef83a670..6ecdb01e65 100644
--- a/tests/delete/tests.py
+++ b/tests/delete/tests.py
@@ -167,7 +167,7 @@ class DeletionTests(TestCase):
def test_bulk(self):
from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE
s = S.objects.create(r=R.objects.create())
- for i in xrange(2*GET_ITERATOR_CHUNK_SIZE):
+ for i in xrange(2 * GET_ITERATOR_CHUNK_SIZE):
T.objects.create(s=s)
# 1 (select related `T` instances)
# + 1 (select related `U` instances)
@@ -311,6 +311,7 @@ class DeletionTests(TestCase):
r.delete()
self.assertEqual(HiddenUserProfile.objects.count(), 0)
+
class FastDeleteTests(TestCase):
def test_fast_delete_fk(self):
diff --git a/tests/delete_regress/models.py b/tests/delete_regress/models.py
index 3632a7dbc1..033689519a 100644
--- a/tests/delete_regress/models.py
+++ b/tests/delete_regress/models.py
@@ -2,51 +2,64 @@ from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models
+
class Award(models.Model):
name = models.CharField(max_length=25)
object_id = models.PositiveIntegerField()
content_type = models.ForeignKey(ContentType)
content_object = generic.GenericForeignKey()
+
class AwardNote(models.Model):
award = models.ForeignKey(Award)
note = models.CharField(max_length=100)
+
class Person(models.Model):
name = models.CharField(max_length=25)
awards = generic.GenericRelation(Award)
+
class Book(models.Model):
pagecount = models.IntegerField()
+
class Toy(models.Model):
name = models.CharField(max_length=50)
+
class Child(models.Model):
name = models.CharField(max_length=50)
toys = models.ManyToManyField(Toy, through='PlayedWith')
+
class PlayedWith(models.Model):
child = models.ForeignKey(Child)
toy = models.ForeignKey(Toy)
date = models.DateField(db_column='date_col')
+
class PlayedWithNote(models.Model):
played = models.ForeignKey(PlayedWith)
note = models.TextField()
+
class Contact(models.Model):
label = models.CharField(max_length=100)
+
class Email(Contact):
email_address = models.EmailField(max_length=100)
+
class Researcher(models.Model):
contacts = models.ManyToManyField(Contact, related_name="research_contacts")
+
class Food(models.Model):
name = models.CharField(max_length=20, unique=True)
+
class Eaten(models.Model):
food = models.ForeignKey(Food, to_field="name")
meal = models.CharField(max_length=20)
@@ -54,55 +67,70 @@ class Eaten(models.Model):
# Models for #15776
+
class Policy(models.Model):
policy_number = models.CharField(max_length=10)
+
class Version(models.Model):
policy = models.ForeignKey(Policy)
+
class Location(models.Model):
version = models.ForeignKey(Version, blank=True, null=True)
+
class Item(models.Model):
version = models.ForeignKey(Version)
location = models.ForeignKey(Location, blank=True, null=True)
# Models for #16128
+
class File(models.Model):
pass
+
class Image(File):
class Meta:
proxy = True
+
class Photo(Image):
class Meta:
proxy = True
+
class FooImage(models.Model):
my_image = models.ForeignKey(Image)
+
class FooFile(models.Model):
my_file = models.ForeignKey(File)
+
class FooPhoto(models.Model):
my_photo = models.ForeignKey(Photo)
+
class FooFileProxy(FooFile):
class Meta:
proxy = True
+
class OrgUnit(models.Model):
name = models.CharField(max_length=64, unique=True)
+
class Login(models.Model):
description = models.CharField(max_length=32)
orgunit = models.ForeignKey(OrgUnit)
+
class House(models.Model):
address = models.CharField(max_length=32)
+
class OrderedPerson(models.Model):
name = models.CharField(max_length=32)
lives_in = models.ForeignKey(House)
diff --git a/tests/delete_regress/tests.py b/tests/delete_regress/tests.py
index ecc754920c..e1cbe7070f 100644
--- a/tests/delete_regress/tests.py
+++ b/tests/delete_regress/tests.py
@@ -146,7 +146,7 @@ class LargeDeleteTests(TestCase):
def test_large_deletes(self):
"Regression for #13309 -- if the number of objects > chunk size, deletion still occurs"
for x in range(300):
- Book.objects.create(pagecount=x+100)
+ Book.objects.create(pagecount=x + 100)
# attach a signal to make sure we will not fast-delete
def noop(*args, **kwargs):
@@ -268,6 +268,7 @@ class ProxyDeleteTest(TestCase):
with self.assertRaises(TypeError):
Image.objects.values_list().delete()
+
class Ticket19102Tests(TestCase):
"""
Test different queries which alter the SELECT clause of the query. We
diff --git a/tests/dispatch/tests/test_dispatcher.py b/tests/dispatch/tests/test_dispatcher.py
index 9a8d7146cf..1ab4a69d33 100644
--- a/tests/dispatch/tests/test_dispatcher.py
+++ b/tests/dispatch/tests/test_dispatcher.py
@@ -23,9 +23,11 @@ else:
def garbage_collect():
gc.collect()
+
def receiver_1_arg(val, **kwargs):
return val
+
class Callable(object):
def __call__(self, val, **kwargs):
return val
@@ -116,10 +118,10 @@ class DispatcherTests(unittest.TestCase):
def uid_based_receiver_2(**kwargs):
pass
- a_signal.connect(uid_based_receiver_1, dispatch_uid = "uid")
- a_signal.connect(uid_based_receiver_2, dispatch_uid = "uid")
+ a_signal.connect(uid_based_receiver_1, dispatch_uid="uid")
+ a_signal.connect(uid_based_receiver_2, dispatch_uid="uid")
self.assertEqual(len(a_signal.receivers), 1)
- a_signal.disconnect(dispatch_uid = "uid")
+ a_signal.disconnect(dispatch_uid="uid")
self._testIsClean(a_signal)
def testRobust(self):
diff --git a/tests/dispatch/tests/test_saferef.py b/tests/dispatch/tests/test_saferef.py
index 531e8f43de..6da756362a 100644
--- a/tests/dispatch/tests/test_saferef.py
+++ b/tests/dispatch/tests/test_saferef.py
@@ -3,17 +3,21 @@ import unittest
from django.dispatch.saferef import safeRef
from django.utils.six.moves import xrange
+
class Test1(object):
def x(self):
pass
+
def test2(obj):
pass
+
class Test2(object):
def __call__(self, obj):
pass
+
class SaferefTests(unittest.TestCase):
def setUp(self):
ts = []
diff --git a/tests/distinct_on_fields/models.py b/tests/distinct_on_fields/models.py
index 7982f435d0..053fd9cc5f 100644
--- a/tests/distinct_on_fields/models.py
+++ b/tests/distinct_on_fields/models.py
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
+
@python_2_unicode_compatible
class Tag(models.Model):
name = models.CharField(max_length=10)
@@ -15,6 +16,7 @@ class Tag(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Celebrity(models.Model):
name = models.CharField("Name", max_length=20)
@@ -23,9 +25,11 @@ class Celebrity(models.Model):
def __str__(self):
return self.name
+
class Fan(models.Model):
fan_of = models.ForeignKey(Celebrity)
+
@python_2_unicode_compatible
class Staff(models.Model):
id = models.IntegerField(primary_key=True)
@@ -37,6 +41,7 @@ class Staff(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class StaffTag(models.Model):
staff = models.ForeignKey(Staff)
diff --git a/tests/distinct_on_fields/tests.py b/tests/distinct_on_fields/tests.py
index e14f06f2ed..9dedd98f81 100644
--- a/tests/distinct_on_fields/tests.py
+++ b/tests/distinct_on_fields/tests.py
@@ -6,6 +6,7 @@ from django.test.utils import str_prefix
from .models import Tag, Celebrity, Fan, Staff, StaffTag
+
@skipUnlessDBFeature('can_distinct_on_fields')
class DistinctOnTests(TestCase):
def setUp(self):
@@ -77,7 +78,7 @@ class DistinctOnTests(TestCase):
# Fetch the alphabetically first coworker for each worker
(
(Staff.objects.distinct('id').order_by('id', 'coworkers__name').
- values_list('id', 'coworkers__name')),
+ values_list('id', 'coworkers__name')),
[str_prefix("(1, %(_)s'p2')"), str_prefix("(2, %(_)s'p1')"),
str_prefix("(3, %(_)s'p1')"), "(4, None)"]
),
diff --git a/tests/expressions/models.py b/tests/expressions/models.py
index f592a0eb13..e66bb0a135 100644
--- a/tests/expressions/models.py
+++ b/tests/expressions/models.py
@@ -15,6 +15,7 @@ class Employee(models.Model):
def __str__(self):
return '%s %s' % (self.firstname, self.lastname)
+
@python_2_unicode_compatible
class Company(models.Model):
name = models.CharField(max_length=100)
diff --git a/tests/expressions_regress/models.py b/tests/expressions_regress/models.py
index bd3e52f54d..c70338933a 100644
--- a/tests/expressions_regress/models.py
+++ b/tests/expressions_regress/models.py
@@ -14,6 +14,7 @@ class Number(models.Model):
def __str__(self):
return '%i, %.3f' % (self.integer, self.float)
+
class Experiment(models.Model):
name = models.CharField(max_length=24)
assigned = models.DateField()
diff --git a/tests/expressions_regress/tests.py b/tests/expressions_regress/tests.py
index 0e168e924a..e603c410ac 100644
--- a/tests/expressions_regress/tests.py
+++ b/tests/expressions_regress/tests.py
@@ -79,12 +79,12 @@ class ExpressionsRegressTests(TestCase):
"""
n = Number.objects.create(integer=10, float=123.45)
self.assertEqual(Number.objects.filter(pk=n.pk)
- .update(float=F('integer') + F('float') * 2),
- 1)
+ .update(float=F('integer') + F('float') * 2), 1)
self.assertEqual(Number.objects.get(pk=n.pk).integer, 10)
self.assertEqual(Number.objects.get(pk=n.pk).float, Approximate(256.900, places=3))
+
class ExpressionOperatorTests(TestCase):
def setUp(self):
self.n = Number.objects.create(integer=42, float=15.5)
@@ -220,13 +220,13 @@ class FTimeDeltaTests(TestCase):
self.days_long = []
# e0: started same day as assigned, zero duration
- end = stime+delta0
+ end = stime + delta0
e0 = Experiment.objects.create(name='e0', assigned=sday, start=stime,
end=end, completed=end.date())
self.deltas.append(delta0)
self.delays.append(e0.start -
datetime.datetime.combine(e0.assigned, midnight))
- self.days_long.append(e0.completed-e0.assigned)
+ self.days_long.append(e0.completed - e0.assigned)
# e1: started one day after assigned, tiny duration, data
# set so that end time has no fractional seconds, which
@@ -237,86 +237,86 @@ class FTimeDeltaTests(TestCase):
delay = datetime.timedelta(1)
end = stime + delay + delta1
e1 = Experiment.objects.create(name='e1', assigned=sday,
- start=stime+delay, end=end, completed=end.date())
+ start=stime + delay, end=end, completed=end.date())
self.deltas.append(delta1)
self.delays.append(e1.start -
datetime.datetime.combine(e1.assigned, midnight))
- self.days_long.append(e1.completed-e1.assigned)
+ self.days_long.append(e1.completed - e1.assigned)
# e2: started three days after assigned, small duration
- end = stime+delta2
+ end = stime + delta2
e2 = Experiment.objects.create(name='e2',
- assigned=sday-datetime.timedelta(3), start=stime, end=end,
+ assigned=sday - datetime.timedelta(3), start=stime, end=end,
completed=end.date())
self.deltas.append(delta2)
self.delays.append(e2.start -
datetime.datetime.combine(e2.assigned, midnight))
- self.days_long.append(e2.completed-e2.assigned)
+ self.days_long.append(e2.completed - e2.assigned)
# e3: started four days after assigned, medium duration
delay = datetime.timedelta(4)
end = stime + delay + delta3
e3 = Experiment.objects.create(name='e3',
- assigned=sday, start=stime+delay, end=end, completed=end.date())
+ assigned=sday, start=stime + delay, end=end, completed=end.date())
self.deltas.append(delta3)
self.delays.append(e3.start -
datetime.datetime.combine(e3.assigned, midnight))
- self.days_long.append(e3.completed-e3.assigned)
+ self.days_long.append(e3.completed - e3.assigned)
# e4: started 10 days after assignment, long duration
end = stime + delta4
e4 = Experiment.objects.create(name='e4',
- assigned=sday-datetime.timedelta(10), start=stime, end=end,
+ assigned=sday - datetime.timedelta(10), start=stime, end=end,
completed=end.date())
self.deltas.append(delta4)
self.delays.append(e4.start -
datetime.datetime.combine(e4.assigned, midnight))
- self.days_long.append(e4.completed-e4.assigned)
+ self.days_long.append(e4.completed - e4.assigned)
self.expnames = [e.name for e in Experiment.objects.all()]
def test_delta_add(self):
for i in range(len(self.deltas)):
delta = self.deltas[i]
test_set = [e.name for e in
- Experiment.objects.filter(end__lt=F('start')+delta)]
+ Experiment.objects.filter(end__lt=F('start') + delta)]
self.assertEqual(test_set, self.expnames[:i])
test_set = [e.name for e in
- Experiment.objects.filter(end__lte=F('start')+delta)]
- self.assertEqual(test_set, self.expnames[:i+1])
+ Experiment.objects.filter(end__lte=F('start') + delta)]
+ self.assertEqual(test_set, self.expnames[:i + 1])
def test_delta_subtract(self):
for i in range(len(self.deltas)):
delta = self.deltas[i]
test_set = [e.name for e in
- Experiment.objects.filter(start__gt=F('end')-delta)]
+ Experiment.objects.filter(start__gt=F('end') - delta)]
self.assertEqual(test_set, self.expnames[:i])
test_set = [e.name for e in
- Experiment.objects.filter(start__gte=F('end')-delta)]
- self.assertEqual(test_set, self.expnames[:i+1])
+ Experiment.objects.filter(start__gte=F('end') - delta)]
+ self.assertEqual(test_set, self.expnames[:i + 1])
def test_exclude(self):
for i in range(len(self.deltas)):
delta = self.deltas[i]
test_set = [e.name for e in
- Experiment.objects.exclude(end__lt=F('start')+delta)]
+ Experiment.objects.exclude(end__lt=F('start') + delta)]
self.assertEqual(test_set, self.expnames[i:])
test_set = [e.name for e in
- Experiment.objects.exclude(end__lte=F('start')+delta)]
- self.assertEqual(test_set, self.expnames[i+1:])
+ Experiment.objects.exclude(end__lte=F('start') + delta)]
+ self.assertEqual(test_set, self.expnames[i + 1:])
def test_date_comparison(self):
for i in range(len(self.days_long)):
days = self.days_long[i]
test_set = [e.name for e in
- Experiment.objects.filter(completed__lt=F('assigned')+days)]
+ Experiment.objects.filter(completed__lt=F('assigned') + days)]
self.assertEqual(test_set, self.expnames[:i])
test_set = [e.name for e in
- Experiment.objects.filter(completed__lte=F('assigned')+days)]
- self.assertEqual(test_set, self.expnames[:i+1])
+ Experiment.objects.filter(completed__lte=F('assigned') + days)]
+ self.assertEqual(test_set, self.expnames[:i + 1])
@skipUnlessDBFeature("supports_mixed_date_datetime_comparisons")
def test_mixed_comparisons1(self):
@@ -325,35 +325,35 @@ class FTimeDeltaTests(TestCase):
if not connection.features.supports_microsecond_precision:
delay = datetime.timedelta(delay.days, delay.seconds)
test_set = [e.name for e in
- Experiment.objects.filter(assigned__gt=F('start')-delay)]
+ Experiment.objects.filter(assigned__gt=F('start') - delay)]
self.assertEqual(test_set, self.expnames[:i])
test_set = [e.name for e in
- Experiment.objects.filter(assigned__gte=F('start')-delay)]
- self.assertEqual(test_set, self.expnames[:i+1])
+ Experiment.objects.filter(assigned__gte=F('start') - delay)]
+ self.assertEqual(test_set, self.expnames[:i + 1])
def test_mixed_comparisons2(self):
delays = [datetime.timedelta(delay.days) for delay in self.delays]
for i in range(len(delays)):
delay = delays[i]
test_set = [e.name for e in
- Experiment.objects.filter(start__lt=F('assigned')+delay)]
+ Experiment.objects.filter(start__lt=F('assigned') + delay)]
self.assertEqual(test_set, self.expnames[:i])
test_set = [e.name for e in
Experiment.objects.filter(start__lte=F('assigned') + delay +
datetime.timedelta(1))]
- self.assertEqual(test_set, self.expnames[:i+1])
+ self.assertEqual(test_set, self.expnames[:i + 1])
def test_delta_update(self):
for i in range(len(self.deltas)):
delta = self.deltas[i]
exps = Experiment.objects.all()
expected_durations = [e.duration() for e in exps]
- expected_starts = [e.start+delta for e in exps]
- expected_ends = [e.end+delta for e in exps]
+ expected_starts = [e.start + delta for e in exps]
+ expected_ends = [e.end + delta for e in exps]
- Experiment.objects.update(start=F('start')+delta, end=F('end')+delta)
+ Experiment.objects.update(start=F('start') + delta, end=F('end') + delta)
exps = Experiment.objects.all()
new_starts = [e.start for e in exps]
new_ends = [e.end for e in exps]
@@ -365,7 +365,7 @@ class FTimeDeltaTests(TestCase):
def test_delta_invalid_op_mult(self):
raised = False
try:
- repr(Experiment.objects.filter(end__lt=F('start')*self.deltas[0]))
+ repr(Experiment.objects.filter(end__lt=F('start') * self.deltas[0]))
except TypeError:
raised = True
self.assertTrue(raised, "TypeError not raised on attempt to multiply datetime by timedelta.")
@@ -373,7 +373,7 @@ class FTimeDeltaTests(TestCase):
def test_delta_invalid_op_div(self):
raised = False
try:
- repr(Experiment.objects.filter(end__lt=F('start')/self.deltas[0]))
+ repr(Experiment.objects.filter(end__lt=F('start') / self.deltas[0]))
except TypeError:
raised = True
self.assertTrue(raised, "TypeError not raised on attempt to divide datetime by timedelta.")
diff --git a/tests/extra_regress/models.py b/tests/extra_regress/models.py
index 5523a06a8a..432aa02963 100644
--- a/tests/extra_regress/models.py
+++ b/tests/extra_regress/models.py
@@ -30,10 +30,12 @@ class RevisionableModel(models.Model):
new_revision.pk = None
return new_revision
+
class Order(models.Model):
created_by = models.ForeignKey(User)
text = models.TextField()
+
@python_2_unicode_compatible
class TestObject(models.Model):
first = models.CharField(max_length=20)
diff --git a/tests/field_subclassing/fields.py b/tests/field_subclassing/fields.py
index a3867e3671..e9c7a982e8 100644
--- a/tests/field_subclassing/fields.py
+++ b/tests/field_subclassing/fields.py
@@ -20,6 +20,7 @@ class Small(object):
def __str__(self):
return '%s%s' % (force_text(self.first), force_text(self.second))
+
class SmallField(six.with_metaclass(models.SubfieldBase, models.Field)):
"""
Turns the "Small" class into a Django field. Because of the similarities
@@ -51,6 +52,7 @@ class SmallField(six.with_metaclass(models.SubfieldBase, models.Field)):
return []
raise TypeError('Invalid lookup type: %r' % lookup_type)
+
class SmallerField(SmallField):
pass
diff --git a/tests/field_subclassing/models.py b/tests/field_subclassing/models.py
index 67a95b02f2..c2f7e4f66b 100644
--- a/tests/field_subclassing/models.py
+++ b/tests/field_subclassing/models.py
@@ -17,8 +17,10 @@ class MyModel(models.Model):
def __str__(self):
return force_text(self.name)
+
class OtherModel(models.Model):
data = SmallerField()
+
class DataModel(models.Model):
data = JSONField()
diff --git a/tests/file_storage/models.py b/tests/file_storage/models.py
index eea3ddaf09..738a3a1772 100644
--- a/tests/file_storage/models.py
+++ b/tests/file_storage/models.py
@@ -15,6 +15,7 @@ from django.core.files.storage import FileSystemStorage
temp_storage_location = tempfile.mkdtemp()
temp_storage = FileSystemStorage(location=temp_storage_location)
+
class Storage(models.Model):
def custom_upload_to(self, filename):
return 'foo'
diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py
index 1f676d04b1..20eaf4c89c 100644
--- a/tests/file_storage/tests.py
+++ b/tests/file_storage/tests.py
@@ -69,6 +69,7 @@ class GetStorageClassTests(SimpleTestCase):
get_storage_class(
'django.core.files.non_existing_storage.NonExistingStorage')
+
class FileStorageTests(unittest.TestCase):
storage_class = FileSystemStorage
@@ -379,6 +380,7 @@ class CustomStorage(FileSystemStorage):
return name
+
class CustomStorageTests(FileStorageTests):
storage_class = CustomStorage
@@ -531,6 +533,7 @@ class SlowFile(ContentFile):
time.sleep(1)
return super(ContentFile, self).chunks()
+
class FileSaveRaceConditionTest(unittest.TestCase):
def setUp(self):
self.storage_dir = tempfile.mkdtemp()
@@ -552,6 +555,7 @@ class FileSaveRaceConditionTest(unittest.TestCase):
self.storage.delete('conflict')
self.storage.delete('conflict_1')
+
@unittest.skipIf(sys.platform.startswith('win'), "Windows only partially supports umasks and chmod.")
class FileStoragePermissions(unittest.TestCase):
def setUp(self):
@@ -591,6 +595,7 @@ class FileStoragePermissions(unittest.TestCase):
dir_mode = os.stat(os.path.dirname(self.storage.path(name)))[0] & 0o777
self.assertEqual(dir_mode, 0o777 & ~self.umask)
+
class FileStoragePathParsing(unittest.TestCase):
def setUp(self):
self.storage_dir = tempfile.mkdtemp()
diff --git a/tests/file_uploads/tests.py b/tests/file_uploads/tests.py
index 72f9d7a77c..7aa6797630 100644
--- a/tests/file_uploads/tests.py
+++ b/tests/file_uploads/tests.py
@@ -397,6 +397,7 @@ class FileUploadTests(TestCase):
# shouldn't differ.
self.assertEqual(os.path.basename(obj.testfile.path), 'MiXeD_cAsE.txt')
+
@override_settings(MEDIA_ROOT=MEDIA_ROOT)
class DirectoryCreationTests(TestCase):
"""
@@ -436,7 +437,7 @@ class DirectoryCreationTests(TestCase):
# The test needs to be done on a specific string as IOError
# is raised even without the patch (just not early enough)
self.assertEqual(exc_info.exception.args[0],
- "%s exists and is not a directory." % UPLOAD_TO)
+ "%s exists and is not a directory." % UPLOAD_TO)
class MultiParserTests(unittest.TestCase):
diff --git a/tests/file_uploads/uploadhandler.py b/tests/file_uploads/uploadhandler.py
index 2d4e52e4d5..b69cc751cb 100644
--- a/tests/file_uploads/uploadhandler.py
+++ b/tests/file_uploads/uploadhandler.py
@@ -11,7 +11,7 @@ class QuotaUploadHandler(FileUploadHandler):
(5MB) is uploaded.
"""
- QUOTA = 5 * 2**20 # 5 MB
+ QUOTA = 5 * 2 ** 20 # 5 MB
def __init__(self, request=None):
super(QuotaUploadHandler, self).__init__(request)
@@ -26,9 +26,11 @@ class QuotaUploadHandler(FileUploadHandler):
def file_complete(self, file_size):
return None
+
class CustomUploadError(Exception):
pass
+
class ErroringUploadHandler(FileUploadHandler):
"""A handler that raises an exception."""
def receive_data_chunk(self, raw_data, start):
diff --git a/tests/file_uploads/views.py b/tests/file_uploads/views.py
index 1940987815..a29391af6e 100644
--- a/tests/file_uploads/views.py
+++ b/tests/file_uploads/views.py
@@ -30,6 +30,7 @@ def file_upload_view(request):
else:
return HttpResponseServerError()
+
def file_upload_view_verify(request):
"""
Use the sha digest hash to verify the uploaded contents.
@@ -57,6 +58,7 @@ def file_upload_view_verify(request):
return HttpResponse('')
+
def file_upload_unicode_name(request):
# Check to see if unicode name came through properly.
@@ -85,6 +87,7 @@ def file_upload_unicode_name(request):
else:
return HttpResponse('')
+
def file_upload_echo(request):
"""
Simple view to echo back info about uploaded files for tests.
@@ -92,6 +95,7 @@ def file_upload_echo(request):
r = dict((k, f.name) for k, f in request.FILES.items())
return HttpResponse(json.dumps(r))
+
def file_upload_echo_content(request):
"""
Simple view to echo back the content of uploaded files for tests.
@@ -99,6 +103,7 @@ def file_upload_echo_content(request):
r = dict((k, f.read().decode('utf-8')) for k, f in request.FILES.items())
return HttpResponse(json.dumps(r))
+
def file_upload_quota(request):
"""
Dynamically add in an upload handler.
@@ -106,6 +111,7 @@ def file_upload_quota(request):
request.upload_handlers.insert(0, QuotaUploadHandler())
return file_upload_echo(request)
+
def file_upload_quota_broken(request):
"""
You can't change handlers after reading FILES; this view shouldn't work.
@@ -114,6 +120,7 @@ def file_upload_quota_broken(request):
request.upload_handlers.insert(0, QuotaUploadHandler())
return response
+
def file_upload_getlist_count(request):
"""
Check the .getlist() function to ensure we receive the correct number of files.
@@ -124,10 +131,12 @@ def file_upload_getlist_count(request):
file_counts[key] = len(request.FILES.getlist(key))
return HttpResponse(json.dumps(file_counts))
+
def file_upload_errors(request):
request.upload_handlers.insert(0, ErroringUploadHandler())
return file_upload_echo(request)
+
def file_upload_filename_case_view(request):
"""
Check adding the file to the database will preserve the filename case.
@@ -137,6 +146,7 @@ def file_upload_filename_case_view(request):
obj.testfile.save(file.name, file)
return HttpResponse('%d' % obj.pk)
+
def file_upload_content_type_extra(request):
"""
Simple view to echo back extra content-type parameters.
diff --git a/tests/fixtures/models.py b/tests/fixtures/models.py
index 56bb601c27..08cb02ce72 100644
--- a/tests/fixtures/models.py
+++ b/tests/fixtures/models.py
@@ -26,6 +26,7 @@ class Category(models.Model):
class Meta:
ordering = ('title',)
+
@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline')
@@ -37,6 +38,7 @@ class Article(models.Model):
class Meta:
ordering = ('-pub_date', 'headline')
+
@python_2_unicode_compatible
class Blog(models.Model):
name = models.CharField(max_length=100)
@@ -60,10 +62,12 @@ class Tag(models.Model):
return '<%s: %s> tagged "%s"' % (self.tagged.__class__.__name__,
self.tagged, self.name)
+
class PersonManager(models.Manager):
def get_by_natural_key(self, name):
return self.get(name=name)
+
@python_2_unicode_compatible
class Person(models.Model):
objects = PersonManager()
@@ -78,14 +82,17 @@ class Person(models.Model):
def natural_key(self):
return (self.name,)
+
class SpyManager(PersonManager):
def get_queryset(self):
return super(SpyManager, self).get_queryset().filter(cover_blown=False)
+
class Spy(Person):
objects = SpyManager()
cover_blown = models.BooleanField(default=False)
+
@python_2_unicode_compatible
class Visa(models.Model):
person = models.ForeignKey(Person)
@@ -95,6 +102,7 @@ class Visa(models.Model):
return '%s %s' % (self.person.name,
', '.join(p.name for p in self.permissions.all()))
+
@python_2_unicode_compatible
class Book(models.Model):
name = models.CharField(max_length=100)
diff --git a/tests/fixtures_model_package/models/__init__.py b/tests/fixtures_model_package/models/__init__.py
index deeba48aa9..c48cfd451d 100644
--- a/tests/fixtures_model_package/models/__init__.py
+++ b/tests/fixtures_model_package/models/__init__.py
@@ -14,6 +14,7 @@ class Article(models.Model):
app_label = 'fixtures_model_package'
ordering = ('-pub_date', 'headline')
+
class Book(models.Model):
name = models.CharField(max_length=100)
diff --git a/tests/fixtures_regress/models.py b/tests/fixtures_regress/models.py
index 4b33cef09b..95f9488ab7 100644
--- a/tests/fixtures_regress/models.py
+++ b/tests/fixtures_regress/models.py
@@ -27,6 +27,7 @@ class Plant(models.Model):
# For testing when upper case letter in app name; regression for #4057
db_table = "Fixtures_regress_plant"
+
@python_2_unicode_compatible
class Stuff(models.Model):
name = models.CharField(max_length=20, null=True)
diff --git a/tests/force_insert_update/models.py b/tests/force_insert_update/models.py
index 56d6624e0d..7067613ccd 100644
--- a/tests/force_insert_update/models.py
+++ b/tests/force_insert_update/models.py
@@ -9,16 +9,20 @@ class Counter(models.Model):
name = models.CharField(max_length = 10)
value = models.IntegerField()
+
class InheritedCounter(Counter):
tag = models.CharField(max_length=10)
+
class ProxyCounter(Counter):
class Meta:
proxy = True
+
class SubCounter(Counter):
pass
+
class WithCustomPK(models.Model):
name = models.IntegerField(primary_key=True)
value = models.IntegerField()
diff --git a/tests/foreign_object/models.py b/tests/foreign_object/models.py
index d8c3bc10d4..7673d27af6 100644
--- a/tests/foreign_object/models.py
+++ b/tests/foreign_object/models.py
@@ -5,6 +5,7 @@ from django.db.models.fields.related import ReverseSingleRelatedObjectDescriptor
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import get_language
+
@python_2_unicode_compatible
class Country(models.Model):
# Table Column Fields
@@ -13,6 +14,7 @@ class Country(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Person(models.Model):
# Table Column Fields
@@ -30,6 +32,7 @@ class Person(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Group(models.Model):
# Table Column Fields
@@ -96,6 +99,7 @@ class Friendship(models.Model):
to_fields=['person_country_id', 'id'],
related_name='to_friend')
+
class ArticleTranslationDescriptor(ReverseSingleRelatedObjectDescriptor):
"""
The set of articletranslation should not set any local fields.
@@ -107,6 +111,7 @@ class ArticleTranslationDescriptor(ReverseSingleRelatedObjectDescriptor):
if value is not None and not self.field.rel.multiple:
setattr(value, self.field.related.get_cache_name(), instance)
+
class ColConstraint(object):
# Antyhing with as_sql() method works in get_extra_restriction().
def __init__(self, alias, col, value):
@@ -115,6 +120,7 @@ class ColConstraint(object):
def as_sql(self, qn, connection):
return '%s.%s = %%s' % (qn(self.alias), qn(self.col)), [self.value]
+
class ActiveTranslationField(models.ForeignObject):
"""
This field will allow querying and fetching the currently active translation
@@ -132,6 +138,7 @@ class ActiveTranslationField(models.ForeignObject):
super(ActiveTranslationField, self).contribute_to_class(cls, name)
setattr(cls, self.name, ArticleTranslationDescriptor(self))
+
@python_2_unicode_compatible
class Article(models.Model):
active_translation = ActiveTranslationField(
@@ -148,9 +155,11 @@ class Article(models.Model):
except ArticleTranslation.DoesNotExist:
return '[No translation found]'
+
class NewsArticle(Article):
pass
+
class ArticleTranslation(models.Model):
article = models.ForeignKey(Article)
lang = models.CharField(max_length='2')
@@ -162,10 +171,12 @@ class ArticleTranslation(models.Model):
unique_together = ('article', 'lang')
ordering = ('active_translation__title',)
+
class ArticleTag(models.Model):
article = models.ForeignKey(Article, related_name="tags", related_query_name="tag")
name = models.CharField(max_length=255)
+
class ArticleIdea(models.Model):
articles = models.ManyToManyField(Article, related_name="ideas",
related_query_name="idea_things")
diff --git a/tests/foreign_object/tests.py b/tests/foreign_object/tests.py
index 77582162a8..66f57b6f3c 100644
--- a/tests/foreign_object/tests.py
+++ b/tests/foreign_object/tests.py
@@ -12,6 +12,7 @@ from django import forms
# Note that these tests are testing internal implementation details.
# ForeignObject is not part of public API.
+
class MultiColumnFKTests(TestCase):
def setUp(self):
# Creating countries
@@ -379,6 +380,7 @@ class MultiColumnFKTests(TestCase):
'active_translation')[0].active_translation.title,
"foo")
+
class FormsTests(TestCase):
# ForeignObjects should not have any form fields, currently the user needs
# to manually deal with the foreignobject relation.
diff --git a/tests/forms_tests/models.py b/tests/forms_tests/models.py
index 33898ffbb8..8ade923a91 100644
--- a/tests/forms_tests/models.py
+++ b/tests/forms_tests/models.py
@@ -19,6 +19,8 @@ class BoundaryModel(models.Model):
callable_default_value = 0
+
+
def callable_default():
global callable_default_value
callable_default_value = callable_default_value + 1
@@ -27,7 +29,7 @@ def callable_default():
class Defaults(models.Model):
name = models.CharField(max_length=255, default='class default value')
- def_date = models.DateField(default = datetime.date(1980, 1, 1))
+ def_date = models.DateField(default=datetime.date(1980, 1, 1))
value = models.IntegerField(default=42)
callable_default = models.IntegerField(default=callable_default)
@@ -86,6 +88,7 @@ class ChoiceFieldModel(models.Model):
multi_choice_int = models.ManyToManyField(ChoiceOptionModel, blank=False, related_name='multi_choice_int',
default=lambda: [1])
+
class OptionalMultiChoiceModel(models.Model):
multi_choice = models.ManyToManyField(ChoiceOptionModel, blank=False, related_name='not_relevant',
default=lambda: ChoiceOptionModel.objects.filter(name='default'))
diff --git a/tests/forms_tests/tests/test_error_messages.py b/tests/forms_tests/tests/test_error_messages.py
index 2d532c7cf9..86f26df3bc 100644
--- a/tests/forms_tests/tests/test_error_messages.py
+++ b/tests/forms_tests/tests/test_error_messages.py
@@ -24,6 +24,7 @@ class AssertFormErrorsMixin(object):
except ValidationError as e:
self.assertEqual(e.messages, expected)
+
class FormsErrorMessagesTestCase(TestCase, AssertFormErrorsMixin):
def test_charfield(self):
e = {
diff --git a/tests/forms_tests/tests/test_extra.py b/tests/forms_tests/tests/test_extra.py
index 183b5dabdf..4585a4e6ef 100644
--- a/tests/forms_tests/tests/test_extra.py
+++ b/tests/forms_tests/tests/test_extra.py
@@ -25,12 +25,15 @@ from .test_error_messages import AssertFormErrorsMixin
class GetDate(Form):
mydate = DateField(widget=SelectDateWidget)
+
class GetNotRequiredDate(Form):
mydate = DateField(widget=SelectDateWidget, required=False)
+
class GetDateShowHiddenInitial(Form):
mydate = DateField(widget=SelectDateWidget, show_hidden_initial=True)
+
class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):
###############
# Extra stuff #
diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py
index cf721b5510..52dfdf4044 100644
--- a/tests/forms_tests/tests/test_formsets.py
+++ b/tests/forms_tests/tests/test_formsets.py
@@ -57,7 +57,7 @@ SplitDateTimeFormSet = formset_factory(SplitDateTimeForm)
class FormsFormsetTestCase(TestCase):
def make_choiceformset(self, formset_data=None, formset_class=ChoiceFormSet,
- total_forms=None, initial_forms=0, max_num_forms=0, min_num_forms=0, **kwargs):
+ total_forms=None, initial_forms=0, max_num_forms=0, min_num_forms=0, **kwargs):
"""
Make a ChoiceFormset from the given formset_data.
The data should be given as a list of (choice, votes) tuples.
@@ -1097,12 +1097,14 @@ data = {
'choices-0-votes': '100',
}
+
class Choice(Form):
choice = CharField()
votes = IntegerField()
ChoiceFormSet = formset_factory(Choice)
+
class FormsetAsFooTests(TestCase):
def test_as_table(self):
formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
@@ -1130,6 +1132,7 @@ class ArticleForm(Form):
ArticleFormSet = formset_factory(ArticleForm)
+
class TestIsBoundBehavior(TestCase):
def test_no_data_raises_validation_error(self):
with self.assertRaises(ValidationError):
@@ -1184,6 +1187,7 @@ class TestIsBoundBehavior(TestCase):
# The empty forms should be equal.
self.assertHTMLEqual(empty_forms[0].as_p(), empty_forms[1].as_p())
+
class TestEmptyFormSet(TestCase):
def test_empty_formset_is_valid(self):
"""Test that an empty formset still calls clean()"""
diff --git a/tests/forms_tests/tests/test_input_formats.py b/tests/forms_tests/tests/test_input_formats.py
index 25b491a499..b9c29c7609 100644
--- a/tests/forms_tests/tests/test_input_formats.py
+++ b/tests/forms_tests/tests/test_input_formats.py
@@ -490,6 +490,7 @@ class CustomDateInputFormatsTests(SimpleTestCase):
text = f.widget._format_value(result)
self.assertEqual(text, "21.12.2010")
+
class SimpleDateFormatTests(SimpleTestCase):
def test_dateField(self):
"DateFields can parse dates in the default format"
@@ -776,6 +777,7 @@ class CustomDateTimeInputFormatsTests(SimpleTestCase):
text = f.widget._format_value(result)
self.assertEqual(text, "01:30:00 PM 21/12/2010")
+
class SimpleDateTimeFormatTests(SimpleTestCase):
def test_dateTimeField(self):
"DateTimeFields can parse dates in the default format"
diff --git a/tests/forms_tests/tests/test_widgets.py b/tests/forms_tests/tests/test_widgets.py
index c601a3ad58..21134d1a24 100644
--- a/tests/forms_tests/tests/test_widgets.py
+++ b/tests/forms_tests/tests/test_widgets.py
@@ -286,7 +286,7 @@ class FormsWidgetTestCase(TestCase):
things = ({'id': 1, 'name': 'And Boom'}, {'id': 2, 'name': 'One More Thing!'})
class SomeForm(Form):
- somechoice = ChoiceField(choices=chain((('', '-'*9),), [(thing['id'], thing['name']) for thing in things]))
+ somechoice = ChoiceField(choices=chain((('', '-' * 9),), [(thing['id'], thing['name']) for thing in things]))
f = SomeForm()
self.assertHTMLEqual(f.as_table(), 'Somechoice: \n--------- \nAnd Boom \nOne More Thing! \n ')
self.assertHTMLEqual(f.as_table(), 'Somechoice: \n--------- \nAnd Boom \nOne More Thing! \n ')
@@ -1003,6 +1003,7 @@ class NullBooleanSelectLazyForm(Form):
"""Form to test for lazy evaluation. Refs #17190"""
bool = BooleanField(widget=NullBooleanSelect())
+
@override_settings(USE_L10N=True)
class FormsI18NWidgetsTestCase(TestCase):
def setUp(self):
@@ -1136,6 +1137,7 @@ class FakeFieldFile(object):
def __str__(self):
return self.url
+
class ClearableFileInputTests(TestCase):
def test_clear_input_renders(self):
"""
diff --git a/tests/forms_tests/tests/tests.py b/tests/forms_tests/tests/tests.py
index 8212d4ee5c..622b6386e9 100644
--- a/tests/forms_tests/tests/tests.py
+++ b/tests/forms_tests/tests/tests.py
@@ -217,6 +217,7 @@ class FormsModelTestCase(TestCase):
self.assertEqual(obj.value, 99)
self.assertEqual(obj.def_date, datetime.date(1999, 3, 2))
+
class RelatedModelFormTests(TestCase):
def test_invalid_loading_order(self):
"""
diff --git a/tests/generic_inline_admin/admin.py b/tests/generic_inline_admin/admin.py
index 1917024fa5..c701e4a9eb 100644
--- a/tests/generic_inline_admin/admin.py
+++ b/tests/generic_inline_admin/admin.py
@@ -7,6 +7,7 @@ from .models import (Media, PhoneNumber, Episode, EpisodeExtra, Contact,
site = admin.AdminSite(name="admin")
+
class MediaInline(generic.GenericTabularInline):
model = Media
diff --git a/tests/generic_inline_admin/models.py b/tests/generic_inline_admin/models.py
index cc7de62454..af3a474cdf 100644
--- a/tests/generic_inline_admin/models.py
+++ b/tests/generic_inline_admin/models.py
@@ -34,6 +34,7 @@ class Media(models.Model):
# Generic inline with extra = 0
#
+
class EpisodeExtra(Episode):
pass
@@ -67,6 +68,7 @@ class Contact(models.Model):
name = models.CharField(max_length=50)
phone_numbers = generic.GenericRelation(PhoneNumber)
+
#
# Generic inline with can_delete=False
#
diff --git a/tests/generic_inline_admin/tests.py b/tests/generic_inline_admin/tests.py
index 23f17f7b22..09a802a1bc 100644
--- a/tests/generic_inline_admin/tests.py
+++ b/tests/generic_inline_admin/tests.py
@@ -129,6 +129,7 @@ class GenericAdminViewTest(TestCase):
formset = inline_formset(instance=e)
self.assertTrue(formset.get_queryset().ordered)
+
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class GenericInlineAdminParametersTest(TestCase):
urls = "generic_inline_admin.urls"
@@ -210,6 +211,7 @@ class GenericInlineAdminWithUniqueTogetherTest(TestCase):
response = self.client.post('/generic_inline_admin/admin/generic_inline_admin/contact/add/', post_data)
self.assertEqual(response.status_code, 302) # redirect somewhere
+
class NoInlineDeletionTest(TestCase):
urls = "generic_inline_admin.urls"
@@ -224,6 +226,7 @@ class NoInlineDeletionTest(TestCase):
class MockRequest(object):
pass
+
class MockSuperUser(object):
def has_perm(self, perm):
return True
diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py
index 60821903d9..8cd319bf03 100644
--- a/tests/generic_relations/tests.py
+++ b/tests/generic_relations/tests.py
@@ -290,12 +290,14 @@ class GenericRelationsTests(TestCase):
class CustomWidget(forms.TextInput):
pass
+
class TaggedItemForm(forms.ModelForm):
class Meta:
model = TaggedItem
fields = '__all__'
widgets = {'tag': CustomWidget}
+
class GenericInlineFormsetTest(TestCase):
def test_generic_inlineformset_factory(self):
"""
diff --git a/tests/generic_relations_regress/models.py b/tests/generic_relations_regress/models.py
index d716f09058..300ed9d54a 100644
--- a/tests/generic_relations_regress/models.py
+++ b/tests/generic_relations_regress/models.py
@@ -8,6 +8,7 @@ __all__ = ('Link', 'Place', 'Restaurant', 'Person', 'Address',
'CharLink', 'TextLink', 'OddRelation1', 'OddRelation2',
'Contact', 'Organization', 'Note', 'Company')
+
@python_2_unicode_compatible
class Link(models.Model):
content_type = models.ForeignKey(ContentType)
@@ -17,6 +18,7 @@ class Link(models.Model):
def __str__(self):
return "Link to %s id=%s" % (self.content_type, self.object_id)
+
@python_2_unicode_compatible
class Place(models.Model):
name = models.CharField(max_length=100)
@@ -25,11 +27,13 @@ class Place(models.Model):
def __str__(self):
return "Place: %s" % self.name
+
@python_2_unicode_compatible
class Restaurant(Place):
def __str__(self):
return "Restaurant: %s" % self.name
+
@python_2_unicode_compatible
class Address(models.Model):
street = models.CharField(max_length=80)
@@ -43,6 +47,7 @@ class Address(models.Model):
def __str__(self):
return '%s %s, %s %s' % (self.street, self.city, self.state, self.zipcode)
+
@python_2_unicode_compatible
class Person(models.Model):
account = models.IntegerField(primary_key=True)
@@ -52,24 +57,29 @@ class Person(models.Model):
def __str__(self):
return self.name
+
class CharLink(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.CharField(max_length=100)
content_object = generic.GenericForeignKey()
+
class TextLink(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.TextField()
content_object = generic.GenericForeignKey()
+
class OddRelation1(models.Model):
name = models.CharField(max_length=100)
clinks = generic.GenericRelation(CharLink)
+
class OddRelation2(models.Model):
name = models.CharField(max_length=100)
tlinks = generic.GenericRelation(TextLink)
+
# models for test_q_object_or:
class Note(models.Model):
content_type = models.ForeignKey(ContentType)
@@ -77,13 +87,16 @@ class Note(models.Model):
content_object = generic.GenericForeignKey()
note = models.TextField()
+
class Contact(models.Model):
notes = generic.GenericRelation(Note)
+
class Organization(models.Model):
name = models.CharField(max_length=255)
contacts = models.ManyToManyField(Contact, related_name='organizations')
+
@python_2_unicode_compatible
class Company(models.Model):
name = models.CharField(max_length=100)
@@ -92,10 +105,12 @@ class Company(models.Model):
def __str__(self):
return "Company: %s" % self.name
+
# For testing #13085 fix, we also use Note model defined above
class Developer(models.Model):
name = models.CharField(max_length=15)
+
@python_2_unicode_compatible
class Team(models.Model):
name = models.CharField(max_length=15)
@@ -107,49 +122,59 @@ class Team(models.Model):
def __len__(self):
return self.members.count()
+
class Guild(models.Model):
name = models.CharField(max_length=15)
members = models.ManyToManyField(Developer)
def __nonzero__(self):
+
return self.members.count()
+
class Tag(models.Model):
content_type = models.ForeignKey(ContentType, related_name='g_r_r_tags')
object_id = models.CharField(max_length=15)
content_object = generic.GenericForeignKey()
label = models.CharField(max_length=15)
+
class Board(models.Model):
name = models.CharField(primary_key=True, max_length=15)
+
class HasLinks(models.Model):
links = generic.GenericRelation(Link)
class Meta:
abstract = True
+
class HasLinkThing(HasLinks):
pass
+
class A(models.Model):
flag = models.NullBooleanField()
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
+
class B(models.Model):
a = generic.GenericRelation(A)
class Meta:
ordering = ('id',)
+
class C(models.Model):
b = models.ForeignKey(B)
class Meta:
ordering = ('id',)
+
class D(models.Model):
b = models.ForeignKey(B, null=True)
diff --git a/tests/generic_views/models.py b/tests/generic_views/models.py
index 30c73d67ca..f5554d1a20 100644
--- a/tests/generic_views/models.py
+++ b/tests/generic_views/models.py
@@ -18,6 +18,7 @@ class Artist(models.Model):
def get_absolute_url(self):
return reverse('artist_detail', kwargs={'pk': self.id})
+
@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=100)
@@ -29,6 +30,7 @@ class Author(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Book(models.Model):
name = models.CharField(max_length=300)
@@ -43,9 +45,11 @@ class Book(models.Model):
def __str__(self):
return self.name
+
class Page(models.Model):
content = models.TextField()
template = models.CharField(max_length=300)
+
class BookSigning(models.Model):
event_date = models.DateTimeField()
diff --git a/tests/generic_views/test_base.py b/tests/generic_views/test_base.py
index eafa61a271..66ce224162 100644
--- a/tests/generic_views/test_base.py
+++ b/tests/generic_views/test_base.py
@@ -10,6 +10,7 @@ from django.views.generic import View, TemplateView, RedirectView
from . import views
+
class SimpleView(View):
"""
A simple view with a docstring.
diff --git a/tests/generic_views/test_dates.py b/tests/generic_views/test_dates.py
index 58ee0dfcbe..944a3dcfe3 100644
--- a/tests/generic_views/test_dates.py
+++ b/tests/generic_views/test_dates.py
@@ -15,9 +15,10 @@ def _make_books(n, base_date):
Book.objects.create(
name='Book %d' % i,
slug='book-%d' % i,
- pages=100+i,
+ pages=100 + i,
pubdate=base_date - datetime.timedelta(days=i))
+
class ArchiveIndexViewTests(TestCase):
fixtures = ['generic-views-test-data.json']
urls = 'generic_views.urls'
diff --git a/tests/generic_views/views.py b/tests/generic_views/views.py
index fd88debc0f..00e74d4708 100644
--- a/tests/generic_views/views.py
+++ b/tests/generic_views/views.py
@@ -65,6 +65,7 @@ class CustomPaginator(Paginator):
orphans=2,
allow_empty_first_page=allow_empty_first_page)
+
class AuthorListCustomPaginator(AuthorList):
paginate_by = 5
@@ -176,33 +177,42 @@ class BookConfig(object):
queryset = Book.objects.all()
date_field = 'pubdate'
+
class BookArchive(BookConfig, generic.ArchiveIndexView):
pass
+
class BookYearArchive(BookConfig, generic.YearArchiveView):
pass
+
class BookMonthArchive(BookConfig, generic.MonthArchiveView):
pass
+
class BookWeekArchive(BookConfig, generic.WeekArchiveView):
pass
+
class BookDayArchive(BookConfig, generic.DayArchiveView):
pass
+
class BookTodayArchive(BookConfig, generic.TodayArchiveView):
pass
+
class BookDetail(BookConfig, generic.DateDetailView):
pass
+
class AuthorGetQuerySetFormView(generic.edit.ModelFormMixin):
fields = '__all__'
def get_queryset(self):
return Author.objects.all()
+
class BookDetailGetObjectCustomQueryset(BookDetail):
def get_object(self, queryset=None):
return super(BookDetailGetObjectCustomQueryset, self).get_object(
@@ -234,10 +244,12 @@ class CustomContextView(generic.detail.SingleObjectMixin, generic.View):
def get_context_object_name(self, obj):
return "test_name"
+
class CustomSingleObjectView(generic.detail.SingleObjectMixin, generic.View):
model = Book
object = Book(name="dummy")
+
class BookSigningConfig(object):
model = BookSigning
date_field = 'event_date'
@@ -246,24 +258,31 @@ class BookSigningConfig(object):
def get_template_names(self):
return ['generic_views/book%s.html' % self.template_name_suffix]
+
class BookSigningArchive(BookSigningConfig, generic.ArchiveIndexView):
pass
+
class BookSigningYearArchive(BookSigningConfig, generic.YearArchiveView):
pass
+
class BookSigningMonthArchive(BookSigningConfig, generic.MonthArchiveView):
pass
+
class BookSigningWeekArchive(BookSigningConfig, generic.WeekArchiveView):
pass
+
class BookSigningDayArchive(BookSigningConfig, generic.DayArchiveView):
pass
+
class BookSigningTodayArchive(BookSigningConfig, generic.TodayArchiveView):
pass
+
class BookSigningDetail(BookSigningConfig, generic.DateDetailView):
context_object_name = 'book'
diff --git a/tests/get_object_or_404/models.py b/tests/get_object_or_404/models.py
index bb9aa60383..ea6e3e40d5 100644
--- a/tests/get_object_or_404/models.py
+++ b/tests/get_object_or_404/models.py
@@ -21,10 +21,12 @@ class Author(models.Model):
def __str__(self):
return self.name
+
class ArticleManager(models.Manager):
def get_queryset(self):
return super(ArticleManager, self).get_queryset().filter(authors__name__icontains='sir')
+
@python_2_unicode_compatible
class Article(models.Model):
authors = models.ManyToManyField(Author)
diff --git a/tests/get_or_create_regress/models.py b/tests/get_or_create_regress/models.py
index 637bbf62af..2ffc5c93ac 100644
--- a/tests/get_or_create_regress/models.py
+++ b/tests/get_or_create_regress/models.py
@@ -4,9 +4,11 @@ from django.db import models
class Publisher(models.Model):
name = models.CharField(max_length=100)
+
class Author(models.Model):
name = models.CharField(max_length=100)
+
class Book(models.Model):
name = models.CharField(max_length=100)
authors = models.ManyToManyField(Author, related_name='books')
diff --git a/tests/handlers/views.py b/tests/handlers/views.py
index 1b75b27043..84cac97e62 100644
--- a/tests/handlers/views.py
+++ b/tests/handlers/views.py
@@ -4,18 +4,23 @@ from django.core.exceptions import SuspiciousOperation
from django.db import connection, transaction
from django.http import HttpResponse, StreamingHttpResponse
+
def regular(request):
return HttpResponse(b"regular content")
+
def streaming(request):
return StreamingHttpResponse([b"streaming", b" ", b"content"])
+
def in_transaction(request):
return HttpResponse(str(connection.in_atomic_block))
+
@transaction.non_atomic_requests
def not_in_transaction(request):
return HttpResponse(str(connection.in_atomic_block))
+
def suspicious(request):
raise SuspiciousOperation('dubious')
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py
index 820aecf1f7..ccea20f9c5 100644
--- a/tests/httpwrappers/tests.py
+++ b/tests/httpwrappers/tests.py
@@ -239,6 +239,7 @@ class QueryDictTests(unittest.TestCase):
self.assertEqual(copy.copy(q).encoding, 'iso-8859-15')
self.assertEqual(copy.deepcopy(q).encoding, 'iso-8859-15')
+
class HttpResponseTests(unittest.TestCase):
def test_headers_type(self):
@@ -414,6 +415,7 @@ class HttpResponseTests(unittest.TestCase):
self.assertRaises(SuspiciousOperation,
HttpResponsePermanentRedirect, url)
+
class HttpResponseSubclassesTests(TestCase):
def test_redirect(self):
response = HttpResponseRedirect('/redirected/')
@@ -448,6 +450,7 @@ class HttpResponseSubclassesTests(TestCase):
content_type='text/html')
self.assertContains(response, 'Only the GET method is allowed', status_code=405)
+
class StreamingHttpResponseTests(TestCase):
def test_streaming_response(self):
r = StreamingHttpResponse(iter(['hello', 'world']))
@@ -501,6 +504,7 @@ class StreamingHttpResponseTests(TestCase):
with self.assertRaises(Exception):
r.tell()
+
class FileCloseTests(TestCase):
def setUp(self):
@@ -566,6 +570,7 @@ class FileCloseTests(TestCase):
self.assertTrue(file1.closed)
self.assertTrue(file2.closed)
+
class CookieTests(unittest.TestCase):
def test_encode(self):
"""
diff --git a/tests/i18n/forms.py b/tests/i18n/forms.py
index 07b015d590..e06ed4b18d 100644
--- a/tests/i18n/forms.py
+++ b/tests/i18n/forms.py
@@ -12,9 +12,11 @@ class I18nForm(forms.Form):
time_field = forms.TimeField(localize=True)
integer_field = forms.IntegerField(localize=True)
+
class SelectDateForm(forms.Form):
date_field = forms.DateField(widget=SelectDateWidget)
+
class CompanyForm(forms.ModelForm):
cents_paid = forms.DecimalField(max_digits=4, decimal_places=2, localize=True)
products_delivered = forms.IntegerField(localize=True)
diff --git a/tests/i18n/models.py b/tests/i18n/models.py
index 6e3591de24..3afc0841c6 100644
--- a/tests/i18n/models.py
+++ b/tests/i18n/models.py
@@ -7,6 +7,7 @@ from django.utils.translation import ugettext_lazy as _
class TestModel(models.Model):
text = models.CharField(max_length=10, default=_('Anything'))
+
class Company(models.Model):
name = models.CharField(max_length=50)
date_added = models.DateTimeField(default=datetime(1799, 1, 31, 23, 59, 59, 0))
diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py
index 18088e5e16..633184f7c5 100644
--- a/tests/i18n/test_extraction.py
+++ b/tests/i18n/test_extraction.py
@@ -21,6 +21,7 @@ from django.utils.translation import TranslatorCommentWarning
LOCALE = 'de'
has_xgettext = find_command('xgettext')
+
@skipUnless(has_xgettext, 'xgettext is mandatory for extraction tests')
class ExtractorTests(SimpleTestCase):
@@ -130,9 +131,10 @@ class BasicExtractorTests(ExtractorTests):
self.assertRaises(SyntaxError, management.call_command, 'makemessages', locale=LOCALE, extensions=['tpl'], verbosity=0)
with self.assertRaises(SyntaxError) as context_manager:
management.call_command('makemessages', locale=LOCALE, extensions=['tpl'], verbosity=0)
- six.assertRegex(self, str(context_manager.exception),
- r'Translation blocks must not include other block tags: blocktrans \(file templates[/\\]template_with_error\.tpl, line 3\)'
- )
+ six.assertRegex(
+ self, str(context_manager.exception),
+ r'Translation blocks must not include other block tags: blocktrans \(file templates[/\\]template_with_error\.tpl, line 3\)'
+ )
# Check that the temporary file was cleaned up
self.assertFalse(os.path.exists('./templates/template_with_error.tpl.py'))
@@ -210,13 +212,16 @@ class BasicExtractorTests(ExtractorTests):
self.assertEqual(len(ws), 3)
for w in ws:
self.assertTrue(issubclass(w.category, TranslatorCommentWarning))
- six.assertRegex(self, str(ws[0].message),
+ six.assertRegex(
+ self, str(ws[0].message),
r"The translator-targeted comment 'Translators: ignored i18n comment #1' \(file templates[/\\]comments.thtml, line 4\) was ignored, because it wasn't the last item on the line\."
)
- six.assertRegex(self, str(ws[1].message),
+ six.assertRegex(
+ self, str(ws[1].message),
r"The translator-targeted comment 'Translators: ignored i18n comment #3' \(file templates[/\\]comments.thtml, line 6\) was ignored, because it wasn't the last item on the line\."
)
- six.assertRegex(self, str(ws[2].message),
+ six.assertRegex(
+ self, str(ws[2].message),
r"The translator-targeted comment 'Translators: ignored i18n comment #4' \(file templates[/\\]comments.thtml, line 8\) was ignored, because it wasn't the last item on the line\."
)
# Now test .po file contents
@@ -281,6 +286,7 @@ class JavascriptExtractorTests(ExtractorTests):
self.assertMsgId("quz", po_contents)
self.assertMsgId("foobar", po_contents)
+
class IgnoredExtractorTests(ExtractorTests):
def test_ignore_option(self):
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
index b1f3de0ef9..ac9242241d 100644
--- a/tests/i18n/tests.py
+++ b/tests/i18n/tests.py
@@ -956,12 +956,14 @@ class ResolutionOrderI18NTests(TransRealMixin, TestCase):
self.assertTrue(msgstr in result, ("The string '%s' isn't in the "
"translation of '%s'; the actual result is '%s'." % (msgstr, msgid, result)))
+
@override_settings(INSTALLED_APPS=['i18n.resolution'] + list(settings.INSTALLED_APPS))
class AppResolutionOrderI18NTests(ResolutionOrderI18NTests):
def test_app_translation(self):
self.assertUgettext('Date/time', 'APP')
+
@override_settings(LOCALE_PATHS=extended_locale_paths)
class LocalePathsResolutionOrderI18NTests(ResolutionOrderI18NTests):
@@ -973,6 +975,7 @@ class LocalePathsResolutionOrderI18NTests(ResolutionOrderI18NTests):
with self.settings(INSTALLED_APPS=extended_apps):
self.assertUgettext('Time', 'LOCALE_PATHS')
+
class DjangoFallbackResolutionOrderI18NTests(ResolutionOrderI18NTests):
def test_django_fallback(self):
diff --git a/tests/inline_formsets/models.py b/tests/inline_formsets/models.py
index 40c85fe739..383122dbd7 100644
--- a/tests/inline_formsets/models.py
+++ b/tests/inline_formsets/models.py
@@ -6,15 +6,18 @@ from django.utils.encoding import python_2_unicode_compatible
class School(models.Model):
name = models.CharField(max_length=100)
+
class Parent(models.Model):
name = models.CharField(max_length=100)
+
class Child(models.Model):
mother = models.ForeignKey(Parent, related_name='mothers_children')
father = models.ForeignKey(Parent, related_name='fathers_children')
school = models.ForeignKey(School)
name = models.CharField(max_length=100)
+
@python_2_unicode_compatible
class Poet(models.Model):
name = models.CharField(max_length=100)
@@ -22,6 +25,7 @@ class Poet(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Poem(models.Model):
poet = models.ForeignKey(Poet)
diff --git a/tests/inspectdb/models.py b/tests/inspectdb/models.py
index 83cd906a07..f7c8af73c6 100644
--- a/tests/inspectdb/models.py
+++ b/tests/inspectdb/models.py
@@ -9,22 +9,27 @@ class People(models.Model):
name = models.CharField(max_length=255)
parent = models.ForeignKey('self')
+
class Message(models.Model):
from_field = models.ForeignKey(People, db_column='from_id')
+
class PeopleData(models.Model):
people_pk = models.ForeignKey(People, primary_key=True)
ssn = models.CharField(max_length=11)
+
class PeopleMoreData(models.Model):
people_unique = models.ForeignKey(People, unique=True)
license = models.CharField(max_length=255)
+
class DigitsInColumnName(models.Model):
all_digits = models.CharField(max_length=11, db_column='123')
leading_digit = models.CharField(max_length=11, db_column='4extra')
leading_digits = models.CharField(max_length=11, db_column='45extra')
+
class SpecialColumnName(models.Model):
field = models.IntegerField(db_column='field')
# Underscores
@@ -35,6 +40,7 @@ class SpecialColumnName(models.Model):
prc_x = models.IntegerField(db_column='prc(%) x')
non_ascii = models.IntegerField(db_column='tamaño')
+
class ColumnTypes(models.Model):
id = models.AutoField(primary_key=True)
big_int_field = models.BigIntegerField()
diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py
index 82802843d9..abd43f10e3 100644
--- a/tests/inspectdb/tests.py
+++ b/tests/inspectdb/tests.py
@@ -14,6 +14,7 @@ if connection.vendor == 'oracle':
else:
expectedFailureOnOracle = lambda f: f
+
class InspectDBTestCase(TestCase):
def test_stealth_table_name_filter_option(self):
@@ -166,7 +167,7 @@ class InspectDBTestCase(TestCase):
self.assertIn(" managed = False", output, msg='inspectdb should generate unmanaged models.')
@skipUnless(connection.vendor == 'sqlite',
- "Only patched sqlite's DatabaseIntrospection.data_types_reverse for this test")
+ "Only patched sqlite's DatabaseIntrospection.data_types_reverse for this test")
def test_custom_fields(self):
"""
Introspection of columns with a custom field (#21090)
diff --git a/tests/known_related_objects/models.py b/tests/known_related_objects/models.py
index cfee4650d9..2b5ab6cfe5 100644
--- a/tests/known_related_objects/models.py
+++ b/tests/known_related_objects/models.py
@@ -6,17 +6,21 @@ Test that queries are not redone when going back through known relations.
from django.db import models
+
class Tournament(models.Model):
name = models.CharField(max_length=30)
+
class Organiser(models.Model):
name = models.CharField(max_length=30)
+
class Pool(models.Model):
name = models.CharField(max_length=30)
tournament = models.ForeignKey(Tournament)
organiser = models.ForeignKey(Organiser)
+
class PoolStyle(models.Model):
name = models.CharField(max_length=30)
pool = models.OneToOneField(Pool)
diff --git a/tests/known_related_objects/tests.py b/tests/known_related_objects/tests.py
index 6fd507cbdc..03307f49ac 100644
--- a/tests/known_related_objects/tests.py
+++ b/tests/known_related_objects/tests.py
@@ -4,6 +4,7 @@ from django.test import TestCase
from .models import Tournament, Organiser, Pool, PoolStyle
+
class ExistingRelatedInstancesTests(TestCase):
fixtures = ['tournament.json']
diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py
index bd1983f74e..1b3a20cc24 100644
--- a/tests/logging_tests/tests.py
+++ b/tests/logging_tests/tests.py
@@ -62,6 +62,7 @@ class LoggingFiltersTest(TestCase):
with self.settings(DEBUG=False):
self.assertEqual(filter_.filter("record is not used"), False)
+
class DefaultLoggingTest(TestCase):
def setUp(self):
self.logger = logging.getLogger('django')
@@ -83,6 +84,7 @@ class DefaultLoggingTest(TestCase):
self.logger.error("Hey, this is an error.")
self.assertEqual(output.getvalue(), 'Hey, this is an error.\n')
+
class WarningLoggerTests(TestCase):
"""
Tests that warnings output for DeprecationWarnings is enabled
diff --git a/tests/lookup/models.py b/tests/lookup/models.py
index a130d35e8e..df8b26c4e9 100644
--- a/tests/lookup/models.py
+++ b/tests/lookup/models.py
@@ -17,6 +17,7 @@ class Author(models.Model):
class Meta:
ordering = ('name', )
+
@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
@@ -29,6 +30,7 @@ class Article(models.Model):
def __str__(self):
return self.headline
+
class Tag(models.Model):
articles = models.ManyToManyField(Article)
name = models.CharField(max_length=100)
@@ -36,6 +38,7 @@ class Tag(models.Model):
class Meta:
ordering = ('name', )
+
@python_2_unicode_compatible
class Season(models.Model):
year = models.PositiveSmallIntegerField()
@@ -44,6 +47,7 @@ class Season(models.Model):
def __str__(self):
return six.text_type(self.year)
+
@python_2_unicode_compatible
class Game(models.Model):
season = models.ForeignKey(Season, related_name='games')
@@ -53,6 +57,7 @@ class Game(models.Model):
def __str__(self):
return "%s at %s" % (self.away, self.home)
+
@python_2_unicode_compatible
class Player(models.Model):
name = models.CharField(max_length=100)
diff --git a/tests/m2m_and_m2o/models.py b/tests/m2m_and_m2o/models.py
index c303743f04..482ae9a1fa 100644
--- a/tests/m2m_and_m2o/models.py
+++ b/tests/m2m_and_m2o/models.py
@@ -13,6 +13,7 @@ from django.utils.encoding import python_2_unicode_compatible
class User(models.Model):
username = models.CharField(max_length=20)
+
@python_2_unicode_compatible
class Issue(models.Model):
num = models.IntegerField()
@@ -25,5 +26,6 @@ class Issue(models.Model):
class Meta:
ordering = ('num',)
+
class UnicodeReferenceModel(models.Model):
others = models.ManyToManyField("UnicodeReferenceModel")
diff --git a/tests/m2m_and_m2o/tests.py b/tests/m2m_and_m2o/tests.py
index 35443e32e4..e950a839d2 100644
--- a/tests/m2m_and_m2o/tests.py
+++ b/tests/m2m_and_m2o/tests.py
@@ -50,7 +50,7 @@ class RelatedObjectTests(TestCase):
# These queries combine results from the m2m and the m2o relationships.
# They're three ways of saying the same thing.
self.assertQuerysetEqual(
- Issue.objects.filter(Q(cc__id__exact = r.id) | Q(client=r.id)), [
+ Issue.objects.filter(Q(cc__id__exact=r.id) | Q(client=r.id)), [
1,
2,
3,
@@ -74,6 +74,7 @@ class RelatedObjectTests(TestCase):
lambda i: i.num
)
+
class RelatedObjectUnicodeTests(TestCase):
def test_m2m_with_unicode_reference(self):
"""
diff --git a/tests/m2m_intermediary/models.py b/tests/m2m_intermediary/models.py
index 770681f91c..9b194e321b 100644
--- a/tests/m2m_intermediary/models.py
+++ b/tests/m2m_intermediary/models.py
@@ -23,6 +23,7 @@ class Reporter(models.Model):
def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
+
@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
@@ -31,6 +32,7 @@ class Article(models.Model):
def __str__(self):
return self.headline
+
@python_2_unicode_compatible
class Writer(models.Model):
reporter = models.ForeignKey(Reporter)
diff --git a/tests/m2m_regress/models.py b/tests/m2m_regress/models.py
index abd012b3d0..48fdad9304 100644
--- a/tests/m2m_regress/models.py
+++ b/tests/m2m_regress/models.py
@@ -2,6 +2,7 @@ from django.contrib.auth import models as auth
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
+
# No related name is needed here, since symmetrical relations are not
# explicitly reversible.
@python_2_unicode_compatible
@@ -13,6 +14,7 @@ class SelfRefer(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Tag(models.Model):
name = models.CharField(max_length=10)
@@ -20,6 +22,7 @@ class Tag(models.Model):
def __str__(self):
return self.name
+
# Regression for #11956 -- a many to many to the base class
@python_2_unicode_compatible
class TagCollection(Tag):
@@ -28,6 +31,7 @@ class TagCollection(Tag):
def __str__(self):
return self.name
+
# A related_name is required on one of the ManyToManyField entries here because
# they are both addressable as reverse relations from Tag.
@python_2_unicode_compatible
@@ -39,21 +43,26 @@ class Entry(models.Model):
def __str__(self):
return self.name
+
# Two models both inheriting from a base model with a self-referential m2m field
class SelfReferChild(SelfRefer):
pass
+
class SelfReferChildSibling(SelfRefer):
pass
+
# Many-to-Many relation between models, where one of the PK's isn't an Autofield
class Line(models.Model):
name = models.CharField(max_length=100)
+
class Worksheet(models.Model):
id = models.CharField(primary_key=True, max_length=100)
lines = models.ManyToManyField(Line, blank=True, null=True)
+
# Regression for #11226 -- A model with the same name that another one to
# which it has a m2m relation. This shouldn't cause a name clash between
# the automatically created m2m intermediary table FK field names when
diff --git a/tests/m2m_signals/models.py b/tests/m2m_signals/models.py
index e997d87f21..e4110ccf34 100644
--- a/tests/m2m_signals/models.py
+++ b/tests/m2m_signals/models.py
@@ -12,6 +12,7 @@ class Part(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Car(models.Model):
name = models.CharField(max_length=20)
@@ -24,9 +25,11 @@ class Car(models.Model):
def __str__(self):
return self.name
+
class SportsCar(Car):
price = models.IntegerField()
+
@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=20)
diff --git a/tests/m2m_through/models.py b/tests/m2m_through/models.py
index a896f6d9ff..70d6baeca8 100644
--- a/tests/m2m_through/models.py
+++ b/tests/m2m_through/models.py
@@ -15,6 +15,7 @@ class Person(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Group(models.Model):
name = models.CharField(max_length=128)
@@ -28,6 +29,7 @@ class Group(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Membership(models.Model):
person = models.ForeignKey(Person)
@@ -41,6 +43,7 @@ class Membership(models.Model):
def __str__(self):
return "%s is a member of %s" % (self.person.name, self.group.name)
+
@python_2_unicode_compatible
class CustomMembership(models.Model):
person = models.ForeignKey(Person, db_column="custom_person_column", related_name="custom_person_related_name")
@@ -54,11 +57,13 @@ class CustomMembership(models.Model):
class Meta:
db_table = "test_table"
+
class TestNoDefaultsOrNulls(models.Model):
person = models.ForeignKey(Person)
group = models.ForeignKey(Group)
nodefaultnonull = models.CharField(max_length=5)
+
@python_2_unicode_compatible
class PersonSelfRefM2M(models.Model):
name = models.CharField(max_length=5)
@@ -67,6 +72,7 @@ class PersonSelfRefM2M(models.Model):
def __str__(self):
return self.name
+
class Friendship(models.Model):
first = models.ForeignKey(PersonSelfRefM2M, related_name="rel_from_set")
second = models.ForeignKey(PersonSelfRefM2M, related_name="rel_to_set")
diff --git a/tests/m2m_through_regress/models.py b/tests/m2m_through_regress/models.py
index 91e1aa8cc1..c49e5b02eb 100644
--- a/tests/m2m_through_regress/models.py
+++ b/tests/m2m_through_regress/models.py
@@ -15,6 +15,7 @@ class Membership(models.Model):
def __str__(self):
return "%s is a member of %s" % (self.person.name, self.group.name)
+
# using custom id column to test ticket #11107
@python_2_unicode_compatible
class UserMembership(models.Model):
@@ -26,6 +27,7 @@ class UserMembership(models.Model):
def __str__(self):
return "%s is a user and member of %s" % (self.user.username, self.group.name)
+
@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=128)
@@ -33,6 +35,7 @@ class Person(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Group(models.Model):
name = models.CharField(max_length=128)
@@ -43,17 +46,21 @@ class Group(models.Model):
def __str__(self):
return self.name
+
# A set of models that use an non-abstract inherited model as the 'through' model.
class A(models.Model):
a_text = models.CharField(max_length=20)
+
class ThroughBase(models.Model):
a = models.ForeignKey(A)
b = models.ForeignKey('B')
+
class Through(ThroughBase):
extra = models.CharField(max_length=20)
+
class B(models.Model):
b_text = models.CharField(max_length=20)
a_list = models.ManyToManyField(A, through=Through)
@@ -68,6 +75,7 @@ class Car(models.Model):
def __str__(self):
return "%s" % self.make
+
@python_2_unicode_compatible
class Driver(models.Model):
name = models.CharField(max_length=20, unique=True, null=True)
@@ -78,6 +86,7 @@ class Driver(models.Model):
class Meta:
ordering = ('name',)
+
@python_2_unicode_compatible
class CarDriver(models.Model):
car = models.ForeignKey('Car', to_field='make')
diff --git a/tests/m2o_recursive/models.py b/tests/m2o_recursive/models.py
index 2775d713dd..b41e0cb0a3 100644
--- a/tests/m2o_recursive/models.py
+++ b/tests/m2o_recursive/models.py
@@ -22,6 +22,7 @@ class Category(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Person(models.Model):
full_name = models.CharField(max_length=20)
diff --git a/tests/m2o_recursive/tests.py b/tests/m2o_recursive/tests.py
index f5e8938706..b21aef95d3 100644
--- a/tests/m2o_recursive/tests.py
+++ b/tests/m2o_recursive/tests.py
@@ -21,6 +21,7 @@ class ManyToOneRecursiveTests(TestCase):
self.assertQuerysetEqual(self.c.child_set.all(), [])
self.assertEqual(self.c.parent.id, self.r.id)
+
class MultipleManyToOneRecursiveTests(TestCase):
def setUp(self):
diff --git a/tests/many_to_many/models.py b/tests/many_to_many/models.py
index 31793b3974..eaf98ce565 100644
--- a/tests/many_to_many/models.py
+++ b/tests/many_to_many/models.py
@@ -22,6 +22,7 @@ class Publication(models.Model):
class Meta:
ordering = ('title',)
+
@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
diff --git a/tests/many_to_one/models.py b/tests/many_to_one/models.py
index 4e2ed67eea..8c50ffe53b 100644
--- a/tests/many_to_one/models.py
+++ b/tests/many_to_one/models.py
@@ -18,6 +18,7 @@ class Reporter(models.Model):
def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
+
@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
diff --git a/tests/many_to_one_null/models.py b/tests/many_to_one_null/models.py
index e00ca85928..16ee56cec6 100644
--- a/tests/many_to_one_null/models.py
+++ b/tests/many_to_one_null/models.py
@@ -16,6 +16,7 @@ class Reporter(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
diff --git a/tests/many_to_one_regress/models.py b/tests/many_to_one_regress/models.py
index 0ac0871793..c94bc5e05c 100644
--- a/tests/many_to_one_regress/models.py
+++ b/tests/many_to_one_regress/models.py
@@ -10,21 +10,26 @@ from django.utils.encoding import python_2_unicode_compatible
# created (the field names being lower-cased versions of their opposite
# classes is important here).
+
class First(models.Model):
second = models.IntegerField()
+
class Second(models.Model):
- first = models.ForeignKey(First, related_name = 'the_first')
+ first = models.ForeignKey(First, related_name='the_first')
+
# Protect against repetition of #1839, #2415 and #2536.
class Third(models.Model):
name = models.CharField(max_length=20)
third = models.ForeignKey('self', null=True, related_name='child_set')
+
class Parent(models.Model):
name = models.CharField(max_length=20)
bestchild = models.ForeignKey('Child', null=True, related_name='favored_by')
+
class Child(models.Model):
name = models.CharField(max_length=20)
parent = models.ForeignKey(Parent)
@@ -38,9 +43,11 @@ class Category(models.Model):
def __str__(self):
return self.name
+
class Record(models.Model):
category = models.ForeignKey(Category)
+
@python_2_unicode_compatible
class Relation(models.Model):
left = models.ForeignKey(Record, related_name='left_set')
@@ -49,8 +56,10 @@ class Relation(models.Model):
def __str__(self):
return "%s - %s" % (self.left.category.name, self.right.category.name)
+
class Car(models.Model):
make = models.CharField(max_length=100, null=True, unique=True)
+
class Driver(models.Model):
car = models.ForeignKey(Car, to_field='make', null=True, related_name='drivers')
diff --git a/tests/max_lengths/models.py b/tests/max_lengths/models.py
index d66e833e8c..ec4cc8e114 100644
--- a/tests/max_lengths/models.py
+++ b/tests/max_lengths/models.py
@@ -7,6 +7,7 @@ class PersonWithDefaultMaxLengths(models.Model):
homepage = models.URLField()
avatar = models.FilePathField()
+
class PersonWithCustomMaxLengths(models.Model):
email = models.EmailField(max_length=250)
vcard = models.FileField(upload_to='/tmp', max_length=250)
diff --git a/tests/max_lengths/tests.py b/tests/max_lengths/tests.py
index 5dd33fc80f..25101cd535 100644
--- a/tests/max_lengths/tests.py
+++ b/tests/max_lengths/tests.py
@@ -22,6 +22,7 @@ class MaxLengthArgumentsTests(unittest.TestCase):
self.verify_max_length(PersonWithCustomMaxLengths, 'homepage', 250)
self.verify_max_length(PersonWithCustomMaxLengths, 'avatar', 250)
+
class MaxLengthORMTests(unittest.TestCase):
def test_custom_max_lengths(self):
diff --git a/tests/middleware/tests.py b/tests/middleware/tests.py
index b474f6b0e3..0124e33c98 100644
--- a/tests/middleware/tests.py
+++ b/tests/middleware/tests.py
@@ -120,7 +120,7 @@ class CommonMiddlewareTest(TestCase):
r = CommonMiddleware().process_request(request)
self.assertEqual(r.status_code, 301)
self.assertEqual(r.url,
- 'http://www.testserver/middleware/slash/')
+ 'http://www.testserver/middleware/slash/')
@override_settings(APPEND_SLASH=True, PREPEND_WWW=True)
def test_prepend_www_append_slash_slashless(self):
@@ -128,7 +128,7 @@ class CommonMiddlewareTest(TestCase):
r = CommonMiddleware().process_request(request)
self.assertEqual(r.status_code, 301)
self.assertEqual(r.url,
- 'http://www.testserver/middleware/slash/')
+ 'http://www.testserver/middleware/slash/')
# The following tests examine expected behavior given a custom urlconf that
# overrides the default one through the request object.
@@ -228,7 +228,7 @@ class CommonMiddlewareTest(TestCase):
r = CommonMiddleware().process_request(request)
self.assertEqual(r.status_code, 301)
self.assertEqual(r.url,
- 'http://www.testserver/middleware/customurlconf/slash/')
+ 'http://www.testserver/middleware/customurlconf/slash/')
@override_settings(APPEND_SLASH=True, PREPEND_WWW=True)
def test_prepend_www_append_slash_slashless_custom_urlconf(self):
@@ -237,7 +237,7 @@ class CommonMiddlewareTest(TestCase):
r = CommonMiddleware().process_request(request)
self.assertEqual(r.status_code, 301)
self.assertEqual(r.url,
- 'http://www.testserver/middleware/customurlconf/slash/')
+ 'http://www.testserver/middleware/customurlconf/slash/')
# Legacy tests for the 404 error reporting via email (to be removed in 1.8)
@@ -336,7 +336,7 @@ class BrokenLinkEmailsMiddlewareTest(TestCase):
return True
user_agent = request.META['HTTP_USER_AGENT']
return any(pattern.search(user_agent) for pattern in
- self.ignored_user_agent_patterns)
+ self.ignored_user_agent_patterns)
self.req.META['HTTP_REFERER'] = '/another/url/'
self.req.META['HTTP_USER_AGENT'] = 'Spider machine 3.4'
@@ -346,6 +346,7 @@ class BrokenLinkEmailsMiddlewareTest(TestCase):
SubclassedMiddleware().process_response(self.req, self.resp)
self.assertEqual(len(mail.outbox), 1)
+
class ConditionalGetMiddlewareTest(TestCase):
urls = 'middleware.cond_get_urls'
@@ -704,6 +705,7 @@ class ETagGZipMiddlewareTest(TestCase):
self.assertNotEqual(gzip_etag, nogzip_etag)
+
class TransactionMiddlewareTest(IgnoreDeprecationWarningsMixin, TransactionTestCase):
"""
Test the transaction middleware.
diff --git a/tests/middleware_exceptions/tests.py b/tests/middleware_exceptions/tests.py
index 02e53a00e8..83c6118c9d 100644
--- a/tests/middleware_exceptions/tests.py
+++ b/tests/middleware_exceptions/tests.py
@@ -778,6 +778,8 @@ class BadMiddlewareTests(BaseMiddlewareExceptionTest):
_missing = object()
+
+
class RootUrlconfTests(TestCase):
urls = 'middleware_exceptions.urls'
diff --git a/tests/middleware_exceptions/views.py b/tests/middleware_exceptions/views.py
index ddf28c46a3..59abe26bff 100644
--- a/tests/middleware_exceptions/views.py
+++ b/tests/middleware_exceptions/views.py
@@ -7,20 +7,26 @@ from django.template.response import TemplateResponse
def normal_view(request):
return http.HttpResponse('OK')
+
def template_response(request):
return TemplateResponse(request, Template('OK'))
+
def template_response_error(request):
return TemplateResponse(request, Template('{%'))
+
def not_found(request):
raise http.Http404()
+
def server_error(request):
raise Exception('Error in view')
+
def null_view(request):
return None
+
def permission_denied(request):
raise PermissionDenied()
diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py
index f3ef83a39c..d78f3d7c2d 100644
--- a/tests/model_fields/tests.py
+++ b/tests/model_fields/tests.py
@@ -133,6 +133,7 @@ class DecimalFieldTests(test.TestCase):
# This should not crash. That counts as a win for our purposes.
Foo.objects.filter(d__gte=100000000000)
+
class ForeignKeyTests(test.TestCase):
def test_callable_default(self):
"""Test the use of a lazy callable for ForeignKey.default"""
@@ -140,6 +141,7 @@ class ForeignKeyTests(test.TestCase):
b = Bar.objects.create(b="bcd")
self.assertEqual(b.a, a)
+
class DateTimeFieldTests(unittest.TestCase):
def test_datetimefield_to_python_usecs(self):
"""DateTimeField.to_python should support usecs"""
@@ -157,6 +159,7 @@ class DateTimeFieldTests(unittest.TestCase):
self.assertEqual(f.to_python('01:02:03.999999'),
datetime.time(1, 2, 3, 999999))
+
class BooleanFieldTests(unittest.TestCase):
def _test_get_db_prep_lookup(self, f):
from django.db import connection
@@ -294,6 +297,7 @@ class BooleanFieldTests(unittest.TestCase):
self.assertIsNone(nb.nbfield)
nb.save() # no error
+
class ChoicesTests(test.TestCase):
def test_choices_and_field_display(self):
"""
@@ -306,6 +310,7 @@ class ChoicesTests(test.TestCase):
self.assertEqual(Whiz(c=None).get_c_display(), None) # Blank value
self.assertEqual(Whiz(c='').get_c_display(), '') # Empty value
+
class SlugFieldTests(test.TestCase):
def test_slugfield_max_length(self):
"""
@@ -409,6 +414,7 @@ class BigIntegerFieldTests(test.TestCase):
b = BigInt.objects.get(value='10')
self.assertEqual(b.value, 10)
+
class TypeCoercionTests(test.TestCase):
"""
Test that database lookups can accept the wrong types and convert
@@ -422,6 +428,7 @@ class TypeCoercionTests(test.TestCase):
def test_lookup_integer_in_textfield(self):
self.assertEqual(Post.objects.filter(body=24).count(), 0)
+
class FileFieldTests(unittest.TestCase):
def test_clearable(self):
"""
@@ -496,6 +503,7 @@ class BinaryFieldTests(test.TestCase):
dm = DataModel(short_data=self.binary_data * 4)
self.assertRaises(ValidationError, dm.full_clean)
+
class GenericIPAddressFieldTests(test.TestCase):
def test_genericipaddressfield_formfield_protocol(self):
"""
diff --git a/tests/model_forms/models.py b/tests/model_forms/models.py
index 34644a4bb9..72bf1ff26a 100644
--- a/tests/model_forms/models.py
+++ b/tests/model_forms/models.py
@@ -34,6 +34,7 @@ ARTICLE_STATUS_CHAR = (
('l', 'Live'),
)
+
@python_2_unicode_compatible
class Category(models.Model):
name = models.CharField(max_length=20)
@@ -46,6 +47,7 @@ class Category(models.Model):
def __repr__(self):
return self.__str__()
+
@python_2_unicode_compatible
class Writer(models.Model):
name = models.CharField(max_length=50, help_text='Use both first and last names.')
@@ -56,6 +58,7 @@ class Writer(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=50)
@@ -76,15 +79,19 @@ class Article(models.Model):
def __str__(self):
return self.headline
+
class ImprovedArticle(models.Model):
article = models.OneToOneField(Article)
+
class ImprovedArticleWithParentLink(models.Model):
article = models.OneToOneField(Article, parent_link=True)
+
class BetterWriter(Writer):
score = models.IntegerField()
+
@python_2_unicode_compatible
class WriterProfile(models.Model):
writer = models.OneToOneField(Writer, primary_key=True)
@@ -93,6 +100,7 @@ class WriterProfile(models.Model):
def __str__(self):
return "%s is %s" % (self.writer, self.age)
+
@python_2_unicode_compatible
class TextFile(models.Model):
description = models.CharField(max_length=20)
@@ -144,6 +152,7 @@ try:
except ImproperlyConfigured:
test_images = False
+
@python_2_unicode_compatible
class CommaSeparatedInteger(models.Model):
field = models.CommaSeparatedIntegerField(max_length=20)
@@ -151,6 +160,7 @@ class CommaSeparatedInteger(models.Model):
def __str__(self):
return self.field
+
@python_2_unicode_compatible
class Product(models.Model):
slug = models.SlugField(unique=True)
@@ -158,6 +168,7 @@ class Product(models.Model):
def __str__(self):
return self.slug
+
@python_2_unicode_compatible
class Price(models.Model):
price = models.DecimalField(max_digits=10, decimal_places=2)
@@ -169,9 +180,11 @@ class Price(models.Model):
class Meta:
unique_together = (('price', 'quantity'),)
+
class ArticleStatus(models.Model):
status = models.CharField(max_length=2, choices=ARTICLE_STATUS_CHAR, blank=True, null=True)
+
@python_2_unicode_compatible
class Inventory(models.Model):
barcode = models.PositiveIntegerField(unique=True)
@@ -187,6 +200,7 @@ class Inventory(models.Model):
def __repr__(self):
return self.__str__()
+
class Book(models.Model):
title = models.CharField(max_length=40)
author = models.ForeignKey(Writer, blank=True, null=True)
@@ -195,6 +209,7 @@ class Book(models.Model):
class Meta:
unique_together = ('title', 'author')
+
class BookXtra(models.Model):
isbn = models.CharField(max_length=16, unique=True)
suffix1 = models.IntegerField(blank=True, default=0)
@@ -204,9 +219,11 @@ class BookXtra(models.Model):
unique_together = (('suffix1', 'suffix2'))
abstract = True
+
class DerivedBook(Book, BookXtra):
pass
+
@python_2_unicode_compatible
class ExplicitPK(models.Model):
key = models.CharField(max_length=20, primary_key=True)
@@ -218,6 +235,7 @@ class ExplicitPK(models.Model):
def __str__(self):
return self.key
+
@python_2_unicode_compatible
class Post(models.Model):
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
@@ -228,6 +246,7 @@ class Post(models.Model):
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class DateTimePost(models.Model):
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
@@ -238,9 +257,11 @@ class DateTimePost(models.Model):
def __str__(self):
return self.title
+
class DerivedPost(Post):
pass
+
@python_2_unicode_compatible
class BigInt(models.Model):
biggie = models.BigIntegerField()
@@ -248,6 +269,7 @@ class BigInt(models.Model):
def __str__(self):
return six.text_type(self.biggie)
+
class MarkupField(models.CharField):
def __init__(self, *args, **kwargs):
kwargs["max_length"] = 20
@@ -260,16 +282,19 @@ class MarkupField(models.CharField):
# regressed at r10062
return None
+
class CustomFieldForExclusionModel(models.Model):
name = models.CharField(max_length=10)
markup = MarkupField()
+
class FlexibleDatePost(models.Model):
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
slug = models.CharField(max_length=50, unique_for_year='posted', blank=True)
subtitle = models.CharField(max_length=50, unique_for_month='posted', blank=True)
posted = models.DateField(blank=True, null=True)
+
@python_2_unicode_compatible
class Colour(models.Model):
name = models.CharField(max_length=50)
@@ -281,14 +306,17 @@ class Colour(models.Model):
def __str__(self):
return self.name
+
class ColourfulItem(models.Model):
name = models.CharField(max_length=50)
colours = models.ManyToManyField(Colour)
+
class ArticleStatusNote(models.Model):
name = models.CharField(max_length=20)
status = models.ManyToManyField(ArticleStatus)
+
class CustomErrorMessage(models.Model):
name1 = models.CharField(max_length=50,
validators=[validators.validate_slug],
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index a71f716264..95092c2b7a 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -185,6 +185,7 @@ class BetterWriterForm(forms.ModelForm):
model = BetterWriter
fields = '__all__'
+
class WriterProfileForm(forms.ModelForm):
class Meta:
model = WriterProfile
@@ -234,6 +235,7 @@ class ColourfulItemForm(forms.ModelForm):
# model forms for testing work on #9321:
+
class StatusNoteForm(forms.ModelForm):
class Meta:
model = ArticleStatusNote
@@ -295,7 +297,7 @@ class ModelFormBaseTest(TestCase):
fields = '__all__'
self.assertIsInstance(ReplaceField.base_fields['url'],
- forms.fields.BooleanField)
+ forms.fields.BooleanField)
def test_replace_field_variant_2(self):
# Should have the same result as before,
@@ -308,7 +310,7 @@ class ModelFormBaseTest(TestCase):
fields = ['url']
self.assertIsInstance(ReplaceField.base_fields['url'],
- forms.fields.BooleanField)
+ forms.fields.BooleanField)
def test_replace_field_variant_3(self):
# Should have the same result as before,
@@ -321,7 +323,7 @@ class ModelFormBaseTest(TestCase):
fields = [] # url will still appear, since it is explicit above
self.assertIsInstance(ReplaceField.base_fields['url'],
- forms.fields.BooleanField)
+ forms.fields.BooleanField)
def test_override_field(self):
class WriterForm(forms.ModelForm):
@@ -583,6 +585,7 @@ class IncompleteCategoryFormWithFields(forms.ModelForm):
fields = ('name', 'slug')
model = Category
+
class IncompleteCategoryFormWithExclude(forms.ModelForm):
"""
A form that replaces the model's url field with a custom one. This should
@@ -788,6 +791,7 @@ class UniqueTest(TestCase):
"slug": "Django 1.0"}, instance=p)
self.assertTrue(form.is_valid())
+
class ModelToDictTests(TestCase):
"""
Tests for forms.models.model_to_dict
@@ -859,6 +863,7 @@ class ModelToDictTests(TestCase):
#Ensure many-to-many relation appears as a list
self.assertIsInstance(d['categories'], list)
+
class OldFormForXTests(TestCase):
def test_base_form(self):
self.assertEqual(Category.objects.count(), 0)
diff --git a/tests/model_forms_regress/models.py b/tests/model_forms_regress/models.py
index 2c2fd39158..396bd1eaa4 100644
--- a/tests/model_forms_regress/models.py
+++ b/tests/model_forms_regress/models.py
@@ -11,6 +11,7 @@ from django.utils._os import upath
class Person(models.Model):
name = models.CharField(max_length=100)
+
class Triple(models.Model):
left = models.IntegerField()
middle = models.IntegerField()
@@ -19,9 +20,11 @@ class Triple(models.Model):
class Meta:
unique_together = (('left', 'middle'), ('middle', 'right'))
+
class FilePathModel(models.Model):
path = models.FilePathField(path=os.path.dirname(upath(__file__)), match=".*\.py$", blank=True)
+
@python_2_unicode_compatible
class Publication(models.Model):
title = models.CharField(max_length=30)
@@ -30,6 +33,7 @@ class Publication(models.Model):
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
@@ -38,15 +42,18 @@ class Article(models.Model):
def __str__(self):
return self.headline
+
class CustomFileField(models.FileField):
def save_form_data(self, instance, data):
been_here = getattr(self, 'been_saved', False)
assert not been_here, "save_form_data called more than once"
setattr(self, 'been_saved', True)
+
class CustomFF(models.Model):
f = CustomFileField(upload_to='unused', blank=True)
+
class RealPerson(models.Model):
name = models.CharField(max_length=100)
@@ -54,20 +61,25 @@ class RealPerson(models.Model):
if self.name.lower() == 'anonymous':
raise ValidationError("Please specify a real name.")
+
class Author(models.Model):
publication = models.OneToOneField(Publication, null=True, blank=True)
full_name = models.CharField(max_length=255)
+
class Author1(models.Model):
publication = models.OneToOneField(Publication, null=False)
full_name = models.CharField(max_length=255)
+
class Homepage(models.Model):
url = models.URLField()
+
class Document(models.Model):
myfile = models.FileField(upload_to='unused', blank=True)
+
class Edition(models.Model):
author = models.ForeignKey(Person)
publication = models.ForeignKey(Publication)
diff --git a/tests/model_forms_regress/tests.py b/tests/model_forms_regress/tests.py
index b7f4cf5979..963c7e552d 100644
--- a/tests/model_forms_regress/tests.py
+++ b/tests/model_forms_regress/tests.py
@@ -106,6 +106,7 @@ class FullyLocalizedTripleForm(forms.ModelForm):
localized_fields = '__all__'
fields = '__all__'
+
class LocalizedModelFormTest(TestCase):
def test_model_form_applies_localize_to_some_fields(self):
f = PartiallyLocalizedTripleForm({'left': 10, 'middle': 10, 'right': 10})
@@ -167,6 +168,7 @@ class FilePathFieldTests(TestCase):
names.sort()
self.assertEqual(names, ['---------', '__init__.py', 'models.py', 'tests.py'])
+
class ManyToManyCallableInitialTests(TestCase):
def test_callable(self):
"Regression for #10349: A callable can be provided as the initial value for an m2m field"
@@ -207,9 +209,10 @@ class CustomFieldSaveTests(TestCase):
# It's enough that the form saves without error -- the custom save routine will
# generate an AssertionError if it is called more than once during save.
- form = CFFForm(data = {'f': None})
+ form = CFFForm(data={'f': None})
form.save()
+
class ModelChoiceIteratorTests(TestCase):
def test_len(self):
class Form(forms.ModelForm):
@@ -236,12 +239,14 @@ class CustomModelFormSaveMethod(TestCase):
self.assertEqual(form.is_valid(), False)
self.assertEqual(form.errors['__all__'], ['Please specify a real name.'])
+
class ModelClassTests(TestCase):
def test_no_model_class(self):
class NoModelModelForm(forms.ModelForm):
pass
self.assertRaises(ValueError, NoModelModelForm)
+
class OneToOneFieldTests(TestCase):
def test_assignment_of_none(self):
class AuthorForm(forms.ModelForm):
diff --git a/tests/model_formsets/models.py b/tests/model_formsets/models.py
index adeb3455a4..da79c6a573 100644
--- a/tests/model_formsets/models.py
+++ b/tests/model_formsets/models.py
@@ -17,9 +17,11 @@ class Author(models.Model):
def __str__(self):
return self.name
+
class BetterAuthor(Author):
write_speed = models.IntegerField()
+
@python_2_unicode_compatible
class Book(models.Model):
author = models.ForeignKey(Author)
@@ -34,6 +36,7 @@ class Book(models.Model):
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class BookWithCustomPK(models.Model):
my_pk = models.DecimalField(max_digits=5, decimal_places=0, primary_key=True)
@@ -43,9 +46,11 @@ class BookWithCustomPK(models.Model):
def __str__(self):
return '%s: %s' % (self.my_pk, self.title)
+
class Editor(models.Model):
name = models.CharField(max_length=100)
+
@python_2_unicode_compatible
class BookWithOptionalAltEditor(models.Model):
author = models.ForeignKey(Author)
@@ -61,6 +66,7 @@ class BookWithOptionalAltEditor(models.Model):
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class AlternateBook(Book):
notes = models.CharField(max_length=100)
@@ -68,6 +74,7 @@ class AlternateBook(Book):
def __str__(self):
return '%s - %s' % (self.title, self.notes)
+
@python_2_unicode_compatible
class AuthorMeeting(models.Model):
name = models.CharField(max_length=100)
@@ -77,6 +84,7 @@ class AuthorMeeting(models.Model):
def __str__(self):
return self.name
+
class CustomPrimaryKey(models.Model):
my_pk = models.CharField(max_length=10, primary_key=True)
some_field = models.CharField(max_length=100)
@@ -84,6 +92,7 @@ class CustomPrimaryKey(models.Model):
# models for inheritance tests.
+
@python_2_unicode_compatible
class Place(models.Model):
name = models.CharField(max_length=50)
@@ -92,6 +101,7 @@ class Place(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Owner(models.Model):
auto_id = models.AutoField(primary_key=True)
@@ -101,12 +111,14 @@ class Owner(models.Model):
def __str__(self):
return "%s at %s" % (self.name, self.place)
+
class Location(models.Model):
place = models.ForeignKey(Place, unique=True)
# this is purely for testing the data doesn't matter here :)
lat = models.CharField(max_length=100)
lon = models.CharField(max_length=100)
+
@python_2_unicode_compatible
class OwnerProfile(models.Model):
owner = models.OneToOneField(Owner, primary_key=True)
@@ -115,6 +127,7 @@ class OwnerProfile(models.Model):
def __str__(self):
return "%s is %d" % (self.owner.name, self.age)
+
@python_2_unicode_compatible
class Restaurant(Place):
serves_pizza = models.BooleanField(default=False)
@@ -122,6 +135,7 @@ class Restaurant(Place):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Product(models.Model):
slug = models.SlugField(unique=True)
@@ -129,6 +143,7 @@ class Product(models.Model):
def __str__(self):
return self.slug
+
@python_2_unicode_compatible
class Price(models.Model):
price = models.DecimalField(max_digits=10, decimal_places=2)
@@ -140,13 +155,16 @@ class Price(models.Model):
class Meta:
unique_together = (('price', 'quantity'),)
+
class MexicanRestaurant(Restaurant):
serves_tacos = models.BooleanField(default=False)
+
class ClassyMexicanRestaurant(MexicanRestaurant):
restaurant = models.OneToOneField(MexicanRestaurant, parent_link=True, primary_key=True)
tacos_are_yummy = models.BooleanField(default=False)
+
# models for testing unique_together validation when a fk is involved and
# using inlineformset_factory.
@python_2_unicode_compatible
@@ -156,6 +174,7 @@ class Repository(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Revision(models.Model):
repository = models.ForeignKey(Repository)
@@ -167,21 +186,25 @@ class Revision(models.Model):
def __str__(self):
return "%s (%s)" % (self.revision, six.text_type(self.repository))
+
# models for testing callable defaults (see bug #7975). If you define a model
# with a callable default value, you cannot rely on the initial value in a
# form.
class Person(models.Model):
name = models.CharField(max_length=128)
+
class Membership(models.Model):
person = models.ForeignKey(Person)
date_joined = models.DateTimeField(default=datetime.datetime.now)
karma = models.IntegerField()
+
# models for testing a null=True fk to a parent
class Team(models.Model):
name = models.CharField(max_length=100)
+
@python_2_unicode_compatible
class Player(models.Model):
team = models.ForeignKey(Team, null=True)
@@ -190,6 +213,7 @@ class Player(models.Model):
def __str__(self):
return self.name
+
# Models for testing custom ModelForm save methods in formsets and inline formsets
@python_2_unicode_compatible
class Poet(models.Model):
@@ -198,6 +222,7 @@ class Poet(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Poem(models.Model):
poet = models.ForeignKey(Poet)
@@ -206,6 +231,7 @@ class Poem(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Post(models.Model):
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
diff --git a/tests/model_formsets_regress/models.py b/tests/model_formsets_regress/models.py
index f94ad51929..58eed6a22b 100644
--- a/tests/model_formsets_regress/models.py
+++ b/tests/model_formsets_regress/models.py
@@ -6,23 +6,29 @@ class User(models.Model):
username = models.CharField(max_length=12, unique=True)
serial = models.IntegerField()
+
class UserSite(models.Model):
user = models.ForeignKey(User, to_field="username")
data = models.IntegerField()
+
class Place(models.Model):
name = models.CharField(max_length=50)
+
class Restaurant(Place):
pass
+
class Manager(models.Model):
retaurant = models.ForeignKey(Restaurant)
name = models.CharField(max_length=50)
+
class Network(models.Model):
name = models.CharField(max_length=15)
+
@python_2_unicode_compatible
class Host(models.Model):
network = models.ForeignKey(Network)
diff --git a/tests/model_formsets_regress/tests.py b/tests/model_formsets_regress/tests.py
index f8a5b7b3ac..7d400d2f87 100644
--- a/tests/model_formsets_regress/tests.py
+++ b/tests/model_formsets_regress/tests.py
@@ -330,6 +330,7 @@ class FormfieldCallbackTests(TestCase):
formfield_callback=callback)
self.assertCallbackCalled(callback)
+
class BaseCustomDeleteFormSet(BaseFormSet):
"""
A formset mix-in that lets a form decide if it's to be deleted.
diff --git a/tests/model_inheritance/models.py b/tests/model_inheritance/models.py
index 020bb35bc7..7f5702da59 100644
--- a/tests/model_inheritance/models.py
+++ b/tests/model_inheritance/models.py
@@ -20,6 +20,7 @@ from django.utils.encoding import python_2_unicode_compatible
# Abstract base classes
#
+
@python_2_unicode_compatible
class CommonInfo(models.Model):
name = models.CharField(max_length=50)
@@ -32,18 +33,22 @@ class CommonInfo(models.Model):
def __str__(self):
return '%s %s' % (self.__class__.__name__, self.name)
+
class Worker(CommonInfo):
job = models.CharField(max_length=50)
+
class Student(CommonInfo):
school_class = models.CharField(max_length=10)
class Meta:
pass
+
class StudentWorker(Student, Worker):
pass
+
#
# Abstract base classes with related models
#
@@ -51,6 +56,7 @@ class StudentWorker(Student, Worker):
class Post(models.Model):
title = models.CharField(max_length=50)
+
@python_2_unicode_compatible
class Attachment(models.Model):
post = models.ForeignKey(Post, related_name='attached_%(class)s_set')
@@ -62,12 +68,15 @@ class Attachment(models.Model):
def __str__(self):
return self.content
+
class Comment(Attachment):
is_spam = models.BooleanField(default=False)
+
class Link(Attachment):
url = models.URLField()
+
#
# Multi-table inheritance
#
@@ -79,6 +88,7 @@ class Chef(models.Model):
def __str__(self):
return "%s the chef" % self.name
+
@python_2_unicode_compatible
class Place(models.Model):
name = models.CharField(max_length=50)
@@ -87,6 +97,7 @@ class Place(models.Model):
def __str__(self):
return "%s the place" % self.name
+
class Rating(models.Model):
rating = models.IntegerField(null=True, blank=True)
@@ -94,6 +105,7 @@ class Rating(models.Model):
abstract = True
ordering = ['-rating']
+
@python_2_unicode_compatible
class Restaurant(Place, Rating):
serves_hot_dogs = models.BooleanField(default=False)
@@ -106,6 +118,7 @@ class Restaurant(Place, Rating):
def __str__(self):
return "%s the restaurant" % self.name
+
@python_2_unicode_compatible
class ItalianRestaurant(Restaurant):
serves_gnocchi = models.BooleanField(default=False)
@@ -113,6 +126,7 @@ class ItalianRestaurant(Restaurant):
def __str__(self):
return "%s the italian restaurant" % self.name
+
@python_2_unicode_compatible
class Supplier(Place):
customers = models.ManyToManyField(Restaurant, related_name='provider')
@@ -120,6 +134,7 @@ class Supplier(Place):
def __str__(self):
return "%s the supplier" % self.name
+
@python_2_unicode_compatible
class ParkingLot(Place):
# An explicit link to the parent (we can control the attribute name).
@@ -129,6 +144,7 @@ class ParkingLot(Place):
def __str__(self):
return "%s the parking lot" % self.name
+
#
# Abstract base classes with related models where the sub-class has the
# same name in a different app and inherits from the same abstract base
@@ -141,6 +157,7 @@ class ParkingLot(Place):
class Title(models.Model):
title = models.CharField(max_length=50)
+
class NamedURL(models.Model):
title = models.ForeignKey(Title, related_name='attached_%(app_label)s_%(class)s_set')
url = models.URLField()
@@ -148,6 +165,7 @@ class NamedURL(models.Model):
class Meta:
abstract = True
+
@python_2_unicode_compatible
class Copy(NamedURL):
content = models.TextField()
@@ -155,16 +173,20 @@ class Copy(NamedURL):
def __str__(self):
return self.content
+
class Mixin(object):
def __init__(self):
self.other_attr = 1
super(Mixin, self).__init__()
+
class MixinModel(models.Model, Mixin):
pass
+
class Base(models.Model):
titles = models.ManyToManyField(Title)
+
class SubBase(Base):
sub_id = models.IntegerField(primary_key=True)
diff --git a/tests/model_inheritance_regress/models.py b/tests/model_inheritance_regress/models.py
index 04febf54a6..53752b6948 100644
--- a/tests/model_inheritance_regress/models.py
+++ b/tests/model_inheritance_regress/models.py
@@ -5,6 +5,7 @@ import datetime
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
+
@python_2_unicode_compatible
class Place(models.Model):
name = models.CharField(max_length=50)
@@ -16,6 +17,7 @@ class Place(models.Model):
def __str__(self):
return "%s the place" % self.name
+
@python_2_unicode_compatible
class Restaurant(Place):
serves_hot_dogs = models.BooleanField(default=False)
@@ -24,6 +26,7 @@ class Restaurant(Place):
def __str__(self):
return "%s the restaurant" % self.name
+
@python_2_unicode_compatible
class ItalianRestaurant(Restaurant):
serves_gnocchi = models.BooleanField(default=False)
@@ -31,6 +34,7 @@ class ItalianRestaurant(Restaurant):
def __str__(self):
return "%s the italian restaurant" % self.name
+
@python_2_unicode_compatible
class ParkingLot(Place):
# An explicit link to the parent (we can control the attribute name).
@@ -40,16 +44,19 @@ class ParkingLot(Place):
def __str__(self):
return "%s the parking lot" % self.name
+
class ParkingLot2(Place):
# In lieu of any other connector, an existing OneToOneField will be
# promoted to the primary key.
parent = models.OneToOneField(Place)
+
class ParkingLot3(Place):
# The parent_link connector need not be the pk on the model.
primary_key = models.AutoField(primary_key=True)
parent = models.OneToOneField(Place, parent_link=True)
+
class ParkingLot4(models.Model):
# Test parent_link connector can be discovered in abstract classes.
parent = models.OneToOneField(Place, parent_link=True)
@@ -57,31 +64,40 @@ class ParkingLot4(models.Model):
class Meta:
abstract = True
+
class ParkingLot4A(ParkingLot4, Place):
pass
+
class ParkingLot4B(Place, ParkingLot4):
pass
+
class Supplier(models.Model):
restaurant = models.ForeignKey(Restaurant)
+
class Wholesaler(Supplier):
retailer = models.ForeignKey(Supplier, related_name='wholesale_supplier')
+
class Parent(models.Model):
created = models.DateTimeField(default=datetime.datetime.now)
+
class Child(Parent):
name = models.CharField(max_length=10)
+
class SelfRefParent(models.Model):
parent_data = models.IntegerField()
self_data = models.ForeignKey('self', null=True)
+
class SelfRefChild(SelfRefParent):
child_data = models.IntegerField()
+
@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
@@ -93,24 +109,30 @@ class Article(models.Model):
def __str__(self):
return self.headline
+
class ArticleWithAuthor(Article):
author = models.CharField(max_length=100)
+
class M2MBase(models.Model):
articles = models.ManyToManyField(Article)
+
class M2MChild(M2MBase):
name = models.CharField(max_length=50)
+
class Evaluation(Article):
quality = models.IntegerField()
class Meta:
abstract = True
+
class QualityControl(Evaluation):
assignee = models.CharField(max_length=50)
+
@python_2_unicode_compatible
class BaseM(models.Model):
base_name = models.CharField(max_length=100)
@@ -118,6 +140,7 @@ class BaseM(models.Model):
def __str__(self):
return self.base_name
+
@python_2_unicode_compatible
class DerivedM(BaseM):
customPK = models.IntegerField(primary_key=True)
@@ -127,6 +150,7 @@ class DerivedM(BaseM):
return "PK = %d, base_name = %s, derived_name = %s" % (
self.customPK, self.base_name, self.derived_name)
+
class AuditBase(models.Model):
planned_date = models.DateField()
@@ -134,13 +158,16 @@ class AuditBase(models.Model):
abstract = True
verbose_name_plural = 'Audits'
+
class CertificationAudit(AuditBase):
class Meta(AuditBase.Meta):
abstract = True
+
class InternalCertificationAudit(CertificationAudit):
auditing_dept = models.CharField(max_length=20)
+
# Check that abstract classes don't get m2m tables autocreated.
@python_2_unicode_compatible
class Person(models.Model):
@@ -152,6 +179,7 @@ class Person(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class AbstractEvent(models.Model):
name = models.CharField(max_length=100)
@@ -164,35 +192,44 @@ class AbstractEvent(models.Model):
def __str__(self):
return self.name
+
class BirthdayParty(AbstractEvent):
pass
+
class BachelorParty(AbstractEvent):
pass
+
class MessyBachelorParty(BachelorParty):
pass
+
# Check concrete -> abstract -> concrete inheritance
class SearchableLocation(models.Model):
keywords = models.CharField(max_length=256)
+
class Station(SearchableLocation):
name = models.CharField(max_length=128)
class Meta:
abstract = True
+
class BusStation(Station):
bus_routes = models.CommaSeparatedIntegerField(max_length=128)
inbound = models.BooleanField(default=False)
+
class TrainStation(Station):
zone = models.IntegerField()
+
class User(models.Model):
username = models.CharField(max_length=30, unique=True)
+
class Profile(User):
profile_id = models.AutoField(primary_key=True)
extra = models.CharField(max_length=30, blank=True)
diff --git a/tests/model_inheritance_same_model_name/models.py b/tests/model_inheritance_same_model_name/models.py
index 8b02b08668..a8c051facf 100644
--- a/tests/model_inheritance_same_model_name/models.py
+++ b/tests/model_inheritance_same_model_name/models.py
@@ -11,6 +11,7 @@ from django.db import models
from model_inheritance.models import NamedURL
from django.utils.encoding import python_2_unicode_compatible
+
#
# Abstract base classes with related models
#
diff --git a/tests/model_inheritance_select_related/models.py b/tests/model_inheritance_select_related/models.py
index 46c67cf07d..81f267589c 100644
--- a/tests/model_inheritance_select_related/models.py
+++ b/tests/model_inheritance_select_related/models.py
@@ -18,6 +18,7 @@ class Place(models.Model):
def __str__(self):
return "%s the place" % self.name
+
@python_2_unicode_compatible
class Restaurant(Place):
serves_sushi = models.BooleanField(default=False)
@@ -26,6 +27,7 @@ class Restaurant(Place):
def __str__(self):
return "%s the restaurant" % self.name
+
@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=50)
diff --git a/tests/model_validation/models.py b/tests/model_validation/models.py
index d2e77cbccc..dfe6d62996 100644
--- a/tests/model_validation/models.py
+++ b/tests/model_validation/models.py
@@ -39,6 +39,7 @@ class ManyToManyRel(models.Model):
# Models created as unmanaged as these aren't ever queried
managed = False
+
class FKRel(models.Model):
thing1 = models.ForeignKey(ThingWithIterableChoices, related_name='+')
thing2 = models.ForeignKey(ThingWithIterableChoices, related_name='+')
diff --git a/tests/modeladmin/models.py b/tests/modeladmin/models.py
index 27f54821d6..8f57a9fa82 100644
--- a/tests/modeladmin/models.py
+++ b/tests/modeladmin/models.py
@@ -16,6 +16,7 @@ class Band(models.Model):
def __str__(self):
return self.name
+
class Concert(models.Model):
main_band = models.ForeignKey(Band, related_name='main_concerts')
opening_band = models.ForeignKey(Band, related_name='opening_concerts',
@@ -27,6 +28,7 @@ class Concert(models.Model):
(3, 'Bus')
), blank=True)
+
class ValidationTestModel(models.Model):
name = models.CharField(max_length=100)
slug = models.SlugField()
@@ -40,5 +42,6 @@ class ValidationTestModel(models.Model):
def decade_published_in(self):
return self.pub_date.strftime('%Y')[:3] + "0's"
+
class ValidationTestInlineModel(models.Model):
parent = models.ForeignKey(ValidationTestModel)
diff --git a/tests/multiple_database/models.py b/tests/multiple_database/models.py
index 00534c870c..fc5b28ad92 100644
--- a/tests/multiple_database/models.py
+++ b/tests/multiple_database/models.py
@@ -18,10 +18,12 @@ class Review(models.Model):
class Meta:
ordering = ('source',)
+
class PersonManager(models.Manager):
def get_by_natural_key(self, name):
return self.get(name=name)
+
@python_2_unicode_compatible
class Person(models.Model):
objects = PersonManager()
@@ -33,6 +35,7 @@ class Person(models.Model):
class Meta:
ordering = ('name',)
+
# This book manager doesn't do anything interesting; it just
# exists to strip out the 'extra_arg' argument to certain
# calls. This argument is used to establish that the BookManager
@@ -46,6 +49,7 @@ class BookManager(models.Manager):
kwargs.pop('extra_arg', None)
return super(BookManager, self).get_or_create(*args, **kwargs)
+
@python_2_unicode_compatible
class Book(models.Model):
objects = BookManager()
@@ -62,6 +66,7 @@ class Book(models.Model):
class Meta:
ordering = ('title',)
+
@python_2_unicode_compatible
class Pet(models.Model):
name = models.CharField(max_length=100)
@@ -73,6 +78,7 @@ class Pet(models.Model):
class Meta:
ordering = ('name',)
+
class UserProfile(models.Model):
user = models.OneToOneField(User, null=True)
flavor = models.CharField(max_length=100)
diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py
index 679c7e33f5..222d236bb0 100644
--- a/tests/multiple_database/tests.py
+++ b/tests/multiple_database/tests.py
@@ -50,7 +50,8 @@ class QueryTestCase(TestCase):
except Book.DoesNotExist:
self.fail('"Pro Django" should exist on default database')
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.using('other').get,
title="Pro Django"
)
@@ -61,7 +62,8 @@ class QueryTestCase(TestCase):
except Book.DoesNotExist:
self.fail('"Dive into Python" should exist on default database')
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.using('other').get,
title="Dive into Python"
)
@@ -84,11 +86,13 @@ class QueryTestCase(TestCase):
except Book.DoesNotExist:
self.fail('"Pro Django" should exist on other database')
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.get,
title="Pro Django"
)
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.using('default').get,
title="Pro Django"
)
@@ -98,11 +102,13 @@ class QueryTestCase(TestCase):
except Book.DoesNotExist:
self.fail('"Dive into Python" should exist on other database')
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.get,
title="Dive into Python"
)
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.using('default').get,
title="Dive into Python"
)
@@ -164,14 +170,14 @@ class QueryTestCase(TestCase):
# Check that queries work across m2m joins
self.assertEqual(list(Book.objects.using('default').filter(authors__name='Marty Alchin').values_list('title', flat=True)),
- ['Pro Django'])
+ ['Pro Django'])
self.assertEqual(list(Book.objects.using('other').filter(authors__name='Marty Alchin').values_list('title', flat=True)),
- [])
+ [])
self.assertEqual(list(Book.objects.using('default').filter(authors__name='Mark Pilgrim').values_list('title', flat=True)),
- [])
+ [])
self.assertEqual(list(Book.objects.using('other').filter(authors__name='Mark Pilgrim').values_list('title', flat=True)),
- ['Dive into Python'])
+ ['Dive into Python'])
# Reget the objects to clear caches
dive = Book.objects.using('other').get(title="Dive into Python")
@@ -179,10 +185,10 @@ class QueryTestCase(TestCase):
# Retrive related object by descriptor. Related objects should be database-baound
self.assertEqual(list(dive.authors.all().values_list('name', flat=True)),
- ['Mark Pilgrim'])
+ ['Mark Pilgrim'])
self.assertEqual(list(mark.book_set.all().values_list('title', flat=True)),
- ['Dive into Python'])
+ ['Dive into Python'])
def test_m2m_forward_operations(self):
"M2M forward manipulations are all constrained to a single DB"
@@ -198,34 +204,34 @@ class QueryTestCase(TestCase):
# Add a second author
john = Person.objects.using('other').create(name="John Smith")
self.assertEqual(list(Book.objects.using('other').filter(authors__name='John Smith').values_list('title', flat=True)),
- [])
+ [])
dive.authors.add(john)
self.assertEqual(list(Book.objects.using('other').filter(authors__name='Mark Pilgrim').values_list('title', flat=True)),
- ['Dive into Python'])
+ ['Dive into Python'])
self.assertEqual(list(Book.objects.using('other').filter(authors__name='John Smith').values_list('title', flat=True)),
- ['Dive into Python'])
+ ['Dive into Python'])
# Remove the second author
dive.authors.remove(john)
self.assertEqual(list(Book.objects.using('other').filter(authors__name='Mark Pilgrim').values_list('title', flat=True)),
- ['Dive into Python'])
+ ['Dive into Python'])
self.assertEqual(list(Book.objects.using('other').filter(authors__name='John Smith').values_list('title', flat=True)),
- [])
+ [])
# Clear all authors
dive.authors.clear()
self.assertEqual(list(Book.objects.using('other').filter(authors__name='Mark Pilgrim').values_list('title', flat=True)),
- [])
+ [])
self.assertEqual(list(Book.objects.using('other').filter(authors__name='John Smith').values_list('title', flat=True)),
- [])
+ [])
# Create an author through the m2m interface
dive.authors.create(name='Jane Brown')
self.assertEqual(list(Book.objects.using('other').filter(authors__name='Mark Pilgrim').values_list('title', flat=True)),
- [])
+ [])
self.assertEqual(list(Book.objects.using('other').filter(authors__name='Jane Brown').values_list('title', flat=True)),
- ['Dive into Python'])
+ ['Dive into Python'])
def test_m2m_reverse_operations(self):
"M2M reverse manipulations are all constrained to a single DB"
@@ -245,42 +251,42 @@ class QueryTestCase(TestCase):
# Add a books to the m2m
mark.book_set.add(grease)
self.assertEqual(list(Person.objects.using('other').filter(book__title='Dive into Python').values_list('name', flat=True)),
- ['Mark Pilgrim'])
+ ['Mark Pilgrim'])
self.assertEqual(list(Person.objects.using('other').filter(book__title='Greasemonkey Hacks').values_list('name', flat=True)),
- ['Mark Pilgrim'])
+ ['Mark Pilgrim'])
# Remove a book from the m2m
mark.book_set.remove(grease)
self.assertEqual(list(Person.objects.using('other').filter(book__title='Dive into Python').values_list('name', flat=True)),
- ['Mark Pilgrim'])
+ ['Mark Pilgrim'])
self.assertEqual(list(Person.objects.using('other').filter(book__title='Greasemonkey Hacks').values_list('name', flat=True)),
- [])
+ [])
# Clear the books associated with mark
mark.book_set.clear()
self.assertEqual(list(Person.objects.using('other').filter(book__title='Dive into Python').values_list('name', flat=True)),
- [])
+ [])
self.assertEqual(list(Person.objects.using('other').filter(book__title='Greasemonkey Hacks').values_list('name', flat=True)),
- [])
+ [])
# Create a book through the m2m interface
mark.book_set.create(title="Dive into HTML5", published=datetime.date(2020, 1, 1))
self.assertEqual(list(Person.objects.using('other').filter(book__title='Dive into Python').values_list('name', flat=True)),
- [])
+ [])
self.assertEqual(list(Person.objects.using('other').filter(book__title='Dive into HTML5').values_list('name', flat=True)),
- ['Mark Pilgrim'])
+ ['Mark Pilgrim'])
def test_m2m_cross_database_protection(self):
"Operations that involve sharing M2M objects across databases raise an error"
# Create a book and author on the default database
pro = Book.objects.create(title="Pro Django",
- published=datetime.date(2008, 12, 16))
+ published=datetime.date(2008, 12, 16))
marty = Person.objects.create(name="Marty Alchin")
# Create a book and author on the other database
dive = Book.objects.using('other').create(title="Dive into Python",
- published=datetime.date(2009, 5, 4))
+ published=datetime.date(2009, 5, 4))
mark = Person.objects.using('other').create(name="Mark Pilgrim")
# Set a foreign key set with an object from a different database
@@ -407,14 +413,14 @@ class QueryTestCase(TestCase):
# Check that queries work across foreign key joins
self.assertEqual(list(Person.objects.using('default').filter(edited__title='Pro Django').values_list('name', flat=True)),
- ['George Vilches'])
+ ['George Vilches'])
self.assertEqual(list(Person.objects.using('other').filter(edited__title='Pro Django').values_list('name', flat=True)),
- [])
+ [])
self.assertEqual(list(Person.objects.using('default').filter(edited__title='Dive into Python').values_list('name', flat=True)),
- [])
+ [])
self.assertEqual(list(Person.objects.using('other').filter(edited__title='Dive into Python').values_list('name', flat=True)),
- ['Chris Mills'])
+ ['Chris Mills'])
# Reget the objects to clear caches
chris = Person.objects.using('other').get(name="Chris Mills")
@@ -422,12 +428,12 @@ class QueryTestCase(TestCase):
# Retrive related object by descriptor. Related objects should be database-baound
self.assertEqual(list(chris.edited.values_list('title', flat=True)),
- ['Dive into Python'])
+ ['Dive into Python'])
def test_foreign_key_reverse_operations(self):
"FK reverse manipulations are all constrained to a single DB"
dive = Book.objects.using('other').create(title="Dive into Python",
- published=datetime.date(2009, 5, 4))
+ published=datetime.date(2009, 5, 4))
chris = Person.objects.using('other').create(name="Chris Mills")
@@ -438,48 +444,48 @@ class QueryTestCase(TestCase):
# Add a second book edited by chris
html5 = Book.objects.using('other').create(title="Dive into HTML5", published=datetime.date(2010, 3, 15))
self.assertEqual(list(Person.objects.using('other').filter(edited__title='Dive into HTML5').values_list('name', flat=True)),
- [])
+ [])
chris.edited.add(html5)
self.assertEqual(list(Person.objects.using('other').filter(edited__title='Dive into HTML5').values_list('name', flat=True)),
- ['Chris Mills'])
+ ['Chris Mills'])
self.assertEqual(list(Person.objects.using('other').filter(edited__title='Dive into Python').values_list('name', flat=True)),
- ['Chris Mills'])
+ ['Chris Mills'])
# Remove the second editor
chris.edited.remove(html5)
self.assertEqual(list(Person.objects.using('other').filter(edited__title='Dive into HTML5').values_list('name', flat=True)),
- [])
+ [])
self.assertEqual(list(Person.objects.using('other').filter(edited__title='Dive into Python').values_list('name', flat=True)),
- ['Chris Mills'])
+ ['Chris Mills'])
# Clear all edited books
chris.edited.clear()
self.assertEqual(list(Person.objects.using('other').filter(edited__title='Dive into HTML5').values_list('name', flat=True)),
- [])
+ [])
self.assertEqual(list(Person.objects.using('other').filter(edited__title='Dive into Python').values_list('name', flat=True)),
- [])
+ [])
# Create an author through the m2m interface
chris.edited.create(title='Dive into Water', published=datetime.date(2010, 3, 15))
self.assertEqual(list(Person.objects.using('other').filter(edited__title='Dive into HTML5').values_list('name', flat=True)),
- [])
+ [])
self.assertEqual(list(Person.objects.using('other').filter(edited__title='Dive into Water').values_list('name', flat=True)),
- ['Chris Mills'])
+ ['Chris Mills'])
self.assertEqual(list(Person.objects.using('other').filter(edited__title='Dive into Python').values_list('name', flat=True)),
- [])
+ [])
def test_foreign_key_cross_database_protection(self):
"Operations that involve sharing FK objects across databases raise an error"
# Create a book and author on the default database
pro = Book.objects.create(title="Pro Django",
- published=datetime.date(2008, 12, 16))
+ published=datetime.date(2008, 12, 16))
marty = Person.objects.create(name="Marty Alchin")
# Create a book and author on the other database
dive = Book.objects.using('other').create(title="Dive into Python",
- published=datetime.date(2009, 5, 4))
+ published=datetime.date(2009, 5, 4))
mark = Person.objects.using('other').create(name="Mark Pilgrim")
@@ -523,37 +529,37 @@ class QueryTestCase(TestCase):
self.assertEqual(html5._state.db, 'other')
# ... but it isn't saved yet
self.assertEqual(list(Person.objects.using('other').values_list('name', flat=True)),
- ['Mark Pilgrim'])
+ ['Mark Pilgrim'])
self.assertEqual(list(Book.objects.using('other').values_list('title', flat=True)),
- ['Dive into Python'])
+ ['Dive into Python'])
# When saved (no using required), new objects goes to 'other'
chris.save()
html5.save()
self.assertEqual(list(Person.objects.using('default').values_list('name', flat=True)),
- ['Marty Alchin'])
+ ['Marty Alchin'])
self.assertEqual(list(Person.objects.using('other').values_list('name', flat=True)),
- ['Chris Mills', 'Mark Pilgrim'])
+ ['Chris Mills', 'Mark Pilgrim'])
self.assertEqual(list(Book.objects.using('default').values_list('title', flat=True)),
- ['Pro Django'])
+ ['Pro Django'])
self.assertEqual(list(Book.objects.using('other').values_list('title', flat=True)),
- ['Dive into HTML5', 'Dive into Python'])
+ ['Dive into HTML5', 'Dive into Python'])
# This also works if you assign the FK in the constructor
water = Book(title="Dive into Water", published=datetime.date(2001, 1, 1), editor=mark)
self.assertEqual(water._state.db, 'other')
# ... but it isn't saved yet
self.assertEqual(list(Book.objects.using('default').values_list('title', flat=True)),
- ['Pro Django'])
+ ['Pro Django'])
self.assertEqual(list(Book.objects.using('other').values_list('title', flat=True)),
- ['Dive into HTML5', 'Dive into Python'])
+ ['Dive into HTML5', 'Dive into Python'])
# When saved, the new book goes to 'other'
water.save()
self.assertEqual(list(Book.objects.using('default').values_list('title', flat=True)),
- ['Pro Django'])
+ ['Pro Django'])
self.assertEqual(list(Book.objects.using('other').values_list('title', flat=True)),
- ['Dive into HTML5', 'Dive into Python', 'Dive into Water'])
+ ['Dive into HTML5', 'Dive into Python', 'Dive into Water'])
def test_foreign_key_deletion(self):
"Cascaded deletions of Foreign Key relations issue queries on the right database"
@@ -602,14 +608,14 @@ class QueryTestCase(TestCase):
# Check that queries work across joins
self.assertEqual(list(User.objects.using('default').filter(userprofile__flavor='chocolate').values_list('username', flat=True)),
- ['alice'])
+ ['alice'])
self.assertEqual(list(User.objects.using('other').filter(userprofile__flavor='chocolate').values_list('username', flat=True)),
- [])
+ [])
self.assertEqual(list(User.objects.using('default').filter(userprofile__flavor='crunchy frog').values_list('username', flat=True)),
- [])
+ [])
self.assertEqual(list(User.objects.using('other').filter(userprofile__flavor='crunchy frog').values_list('username', flat=True)),
- ['bob'])
+ ['bob'])
# Reget the objects to clear caches
alice_profile = UserProfile.objects.using('default').get(flavor='chocolate')
@@ -658,22 +664,22 @@ class QueryTestCase(TestCase):
# ... but it isn't saved yet
self.assertEqual(list(User.objects.using('other').values_list('username', flat=True)),
- ['bob'])
+ ['bob'])
self.assertEqual(list(UserProfile.objects.using('other').values_list('flavor', flat=True)),
- ['crunchy frog'])
+ ['crunchy frog'])
# When saved (no using required), new objects goes to 'other'
charlie.save()
bob_profile.save()
new_bob_profile.save()
self.assertEqual(list(User.objects.using('default').values_list('username', flat=True)),
- ['alice'])
+ ['alice'])
self.assertEqual(list(User.objects.using('other').values_list('username', flat=True)),
- ['bob', 'charlie'])
+ ['bob', 'charlie'])
self.assertEqual(list(UserProfile.objects.using('default').values_list('flavor', flat=True)),
- ['chocolate'])
+ ['chocolate'])
self.assertEqual(list(UserProfile.objects.using('other').values_list('flavor', flat=True)),
- ['crunchy frog', 'spring surprise'])
+ ['crunchy frog', 'spring surprise'])
# This also works if you assign the O2O relation in the constructor
denise = User.objects.db_manager('other').create_user('denise', 'denise@example.com')
@@ -682,16 +688,16 @@ class QueryTestCase(TestCase):
self.assertEqual(denise_profile._state.db, 'other')
# ... but it isn't saved yet
self.assertEqual(list(UserProfile.objects.using('default').values_list('flavor', flat=True)),
- ['chocolate'])
+ ['chocolate'])
self.assertEqual(list(UserProfile.objects.using('other').values_list('flavor', flat=True)),
- ['crunchy frog', 'spring surprise'])
+ ['crunchy frog', 'spring surprise'])
# When saved, the new profile goes to 'other'
denise_profile.save()
self.assertEqual(list(UserProfile.objects.using('default').values_list('flavor', flat=True)),
- ['chocolate'])
+ ['chocolate'])
self.assertEqual(list(UserProfile.objects.using('other').values_list('flavor', flat=True)),
- ['crunchy frog', 'spring surprise', 'tofu'])
+ ['crunchy frog', 'spring surprise', 'tofu'])
def test_generic_key_separation(self):
"Generic fields are constrained to a single database"
@@ -718,7 +724,7 @@ class QueryTestCase(TestCase):
# Retrive related object by descriptor. Related objects should be database-bound
self.assertEqual(list(dive.reviews.all().values_list('source', flat=True)),
- ['Python Weekly'])
+ ['Python Weekly'])
def test_generic_key_reverse_operations(self):
"Generic reverse manipulations are all constrained to a single DB"
@@ -732,37 +738,37 @@ class QueryTestCase(TestCase):
review2 = Review.objects.using('other').create(source="Python Monthly", content_object=temp)
self.assertEqual(list(Review.objects.using('default').filter(object_id=dive.pk).values_list('source', flat=True)),
- [])
+ [])
self.assertEqual(list(Review.objects.using('other').filter(object_id=dive.pk).values_list('source', flat=True)),
- ['Python Weekly'])
+ ['Python Weekly'])
# Add a second review
dive.reviews.add(review2)
self.assertEqual(list(Review.objects.using('default').filter(object_id=dive.pk).values_list('source', flat=True)),
- [])
+ [])
self.assertEqual(list(Review.objects.using('other').filter(object_id=dive.pk).values_list('source', flat=True)),
- ['Python Monthly', 'Python Weekly'])
+ ['Python Monthly', 'Python Weekly'])
# Remove the second author
dive.reviews.remove(review1)
self.assertEqual(list(Review.objects.using('default').filter(object_id=dive.pk).values_list('source', flat=True)),
- [])
+ [])
self.assertEqual(list(Review.objects.using('other').filter(object_id=dive.pk).values_list('source', flat=True)),
- ['Python Monthly'])
+ ['Python Monthly'])
# Clear all reviews
dive.reviews.clear()
self.assertEqual(list(Review.objects.using('default').filter(object_id=dive.pk).values_list('source', flat=True)),
- [])
+ [])
self.assertEqual(list(Review.objects.using('other').filter(object_id=dive.pk).values_list('source', flat=True)),
- [])
+ [])
# Create an author through the generic interface
dive.reviews.create(source='Python Daily')
self.assertEqual(list(Review.objects.using('default').filter(object_id=dive.pk).values_list('source', flat=True)),
- [])
+ [])
self.assertEqual(list(Review.objects.using('other').filter(object_id=dive.pk).values_list('source', flat=True)),
- ['Python Daily'])
+ ['Python Daily'])
def test_generic_key_cross_database_protection(self):
"Operations that involve sharing generic key objects across databases raise an error"
@@ -804,16 +810,16 @@ class QueryTestCase(TestCase):
self.assertEqual(review3._state.db, 'other')
# ... but it isn't saved yet
self.assertEqual(list(Review.objects.using('default').filter(object_id=pro.pk).values_list('source', flat=True)),
- ['Python Monthly'])
+ ['Python Monthly'])
self.assertEqual(list(Review.objects.using('other').filter(object_id=dive.pk).values_list('source', flat=True)),
- ['Python Weekly'])
+ ['Python Weekly'])
# When saved, John goes to 'other'
review3.save()
self.assertEqual(list(Review.objects.using('default').filter(object_id=pro.pk).values_list('source', flat=True)),
- ['Python Monthly'])
+ ['Python Monthly'])
self.assertEqual(list(Review.objects.using('other').filter(object_id=dive.pk).values_list('source', flat=True)),
- ['Python Daily', 'Python Weekly'])
+ ['Python Daily', 'Python Weekly'])
def test_generic_key_deletion(self):
"Cascaded deletions of Generic Key relations issue queries on the right database"
@@ -1354,18 +1360,18 @@ class RouterTestCase(TestCase):
def test_generic_key_cross_database_protection(self):
"Generic Key operations can span databases if they share a source"
# Create a book and author on the default database
- pro = Book.objects.using('default'
- ).create(title="Pro Django", published=datetime.date(2008, 12, 16))
+ pro = Book.objects.using(
+ 'default').create(title="Pro Django", published=datetime.date(2008, 12, 16))
- review1 = Review.objects.using('default'
- ).create(source="Python Monthly", content_object=pro)
+ review1 = Review.objects.using(
+ 'default').create(source="Python Monthly", content_object=pro)
# Create a book and author on the other database
- dive = Book.objects.using('other'
- ).create(title="Dive into Python", published=datetime.date(2009, 5, 4))
+ dive = Book.objects.using(
+ 'other').create(title="Dive into Python", published=datetime.date(2009, 5, 4))
- review2 = Review.objects.using('other'
- ).create(source="Python Weekly", content_object=dive)
+ review2 = Review.objects.using(
+ 'other').create(source="Python Weekly", content_object=dive)
# Set a generic foreign key with an object from a different database
try:
@@ -1565,6 +1571,7 @@ class AuthTestCase(TestCase):
command_output = new_io.getvalue().strip()
self.assertTrue('"email": "alice@example.com"' in command_output)
+
class AntiPetRouter(object):
# A router that only expresses an opinion on migrate,
# passing pets to the 'other' database
@@ -1576,6 +1583,7 @@ class AntiPetRouter(object):
else:
return model._meta.object_name != 'Pet'
+
class FixtureTestCase(TestCase):
multi_db = True
fixtures = ['multidb-common', 'multidb']
@@ -1598,7 +1606,8 @@ class FixtureTestCase(TestCase):
except Book.DoesNotExist:
self.fail('"Pro Django" should exist on default database')
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.using('other').get,
title="Pro Django"
)
@@ -1609,11 +1618,13 @@ class FixtureTestCase(TestCase):
except Book.DoesNotExist:
self.fail('"Dive into Python" should exist on other database')
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.get,
title="Dive into Python"
)
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.using('default').get,
title="Dive into Python"
)
@@ -1634,6 +1645,7 @@ class FixtureTestCase(TestCase):
# No objects will actually be loaded
self.assertEqual(command_output, "Installed 0 object(s) (of 2) from 1 fixture(s)")
+
class PickleQuerySetTestCase(TestCase):
multi_db = True
@@ -1651,6 +1663,7 @@ class DatabaseReceiver(object):
def __call__(self, signal, sender, **kwargs):
self._database = kwargs['using']
+
class WriteToOtherRouter(object):
"""
A router that sends all writes to the other database.
@@ -1658,6 +1671,7 @@ class WriteToOtherRouter(object):
def db_for_write(self, model, **hints):
return "other"
+
class SignalTests(TestCase):
multi_db = True
@@ -1765,6 +1779,7 @@ class SignalTests(TestCase):
self._write_to_default()
self.assertEqual(receiver._database, "other")
+
class AttributeErrorRouter(object):
"A router to test the exception handling of ConnectionRouter"
def db_for_read(self, model, **hints):
@@ -1773,6 +1788,7 @@ class AttributeErrorRouter(object):
def db_for_write(self, model, **hints):
raise AttributeError
+
class RouterAttributeErrorTestCase(TestCase):
multi_db = True
@@ -1818,12 +1834,14 @@ class RouterAttributeErrorTestCase(TestCase):
router.routers = [AttributeErrorRouter()] # Install our router
self.assertRaises(AttributeError, setattr, b, 'authors', [p])
+
class ModelMetaRouter(object):
"A router to ensure model arguments are real model classes"
def db_for_write(self, model, **hints):
if not hasattr(model, '_meta'):
raise ValueError
+
class RouterModelArgumentTestCase(TestCase):
multi_db = True
diff --git a/tests/mutually_referential/models.py b/tests/mutually_referential/models.py
index 0f1bd65cb1..25bc45731f 100644
--- a/tests/mutually_referential/models.py
+++ b/tests/mutually_referential/models.py
@@ -13,6 +13,7 @@ class Parent(models.Model):
# Use a simple string for forward declarations.
bestchild = models.ForeignKey("Child", null=True, related_name="favoured_by")
+
class Child(models.Model):
name = models.CharField(max_length=100)
diff --git a/tests/nested_foreign_keys/models.py b/tests/nested_foreign_keys/models.py
index 50d447951b..3b99cfcb67 100644
--- a/tests/nested_foreign_keys/models.py
+++ b/tests/nested_foreign_keys/models.py
@@ -17,6 +17,7 @@ class Event(models.Model):
class Screening(Event):
movie = models.ForeignKey(Movie)
+
class ScreeningNullFK(Event):
movie = models.ForeignKey(Movie, null=True)
@@ -24,5 +25,6 @@ class ScreeningNullFK(Event):
class Package(models.Model):
screening = models.ForeignKey(Screening, null=True)
+
class PackageNullFK(models.Model):
screening = models.ForeignKey(ScreeningNullFK, null=True)
diff --git a/tests/null_fk/models.py b/tests/null_fk/models.py
index c86ee8a5a9..9309ae940f 100644
--- a/tests/null_fk/models.py
+++ b/tests/null_fk/models.py
@@ -9,14 +9,17 @@ from django.utils.encoding import python_2_unicode_compatible
class SystemDetails(models.Model):
details = models.TextField()
+
class SystemInfo(models.Model):
system_details = models.ForeignKey(SystemDetails)
system_name = models.CharField(max_length=32)
+
class Forum(models.Model):
system_info = models.ForeignKey(SystemInfo)
forum_name = models.CharField(max_length=32)
+
@python_2_unicode_compatible
class Post(models.Model):
forum = models.ForeignKey(Forum, null=True)
@@ -25,6 +28,7 @@ class Post(models.Model):
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class Comment(models.Model):
post = models.ForeignKey(Post, null=True)
@@ -38,12 +42,15 @@ class Comment(models.Model):
# Ticket 15823
+
class Item(models.Model):
title = models.CharField(max_length=100)
+
class PropertyValue(models.Model):
label = models.CharField(max_length=100)
+
class Property(models.Model):
item = models.ForeignKey(Item, related_name='props')
key = models.CharField(max_length=100)
diff --git a/tests/null_fk_ordering/models.py b/tests/null_fk_ordering/models.py
index 3caff0d594..dac1c4f6ae 100644
--- a/tests/null_fk_ordering/models.py
+++ b/tests/null_fk_ordering/models.py
@@ -15,6 +15,7 @@ from django.utils.encoding import python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=150)
+
@python_2_unicode_compatible
class Article(models.Model):
title = models.CharField(max_length=150)
@@ -31,10 +32,12 @@ class Article(models.Model):
class SystemInfo(models.Model):
system_name = models.CharField(max_length=32)
+
class Forum(models.Model):
system_info = models.ForeignKey(SystemInfo)
forum_name = models.CharField(max_length=32)
+
@python_2_unicode_compatible
class Post(models.Model):
forum = models.ForeignKey(Forum, null=True)
@@ -43,6 +46,7 @@ class Post(models.Model):
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class Comment(models.Model):
post = models.ForeignKey(Post, null=True)
diff --git a/tests/null_queries/models.py b/tests/null_queries/models.py
index 9070dd4873..1c3808f407 100644
--- a/tests/null_queries/models.py
+++ b/tests/null_queries/models.py
@@ -11,6 +11,7 @@ class Poll(models.Model):
def __str__(self):
return "Q: %s " % self.question
+
@python_2_unicode_compatible
class Choice(models.Model):
poll = models.ForeignKey(Poll)
@@ -20,12 +21,16 @@ class Choice(models.Model):
return "Choice: %s in poll %s" % (self.choice, self.poll)
# A set of models with an inner one pointing to two outer ones.
+
+
class OuterA(models.Model):
pass
+
class OuterB(models.Model):
data = models.CharField(max_length=10)
+
class Inner(models.Model):
first = models.ForeignKey(OuterA)
# second would clash with the __second lookup.
diff --git a/tests/one_to_one/models.py b/tests/one_to_one/models.py
index ff809be22d..b54cabbaa3 100644
--- a/tests/one_to_one/models.py
+++ b/tests/one_to_one/models.py
@@ -19,6 +19,7 @@ class Place(models.Model):
def __str__(self):
return "%s the place" % self.name
+
@python_2_unicode_compatible
class Restaurant(models.Model):
place = models.OneToOneField(Place, primary_key=True)
@@ -28,6 +29,7 @@ class Restaurant(models.Model):
def __str__(self):
return "%s the restaurant" % self.place.name
+
@python_2_unicode_compatible
class Waiter(models.Model):
restaurant = models.ForeignKey(Restaurant)
@@ -36,13 +38,16 @@ class Waiter(models.Model):
def __str__(self):
return "%s the waiter at %s" % (self.name, self.restaurant)
+
class ManualPrimaryKey(models.Model):
primary_key = models.CharField(max_length=10, primary_key=True)
- name = models.CharField(max_length = 50)
+ name = models.CharField(max_length=50)
+
class RelatedModel(models.Model):
link = models.OneToOneField(ManualPrimaryKey)
- name = models.CharField(max_length = 50)
+ name = models.CharField(max_length=50)
+
@python_2_unicode_compatible
class MultiModel(models.Model):
diff --git a/tests/one_to_one/tests.py b/tests/one_to_one/tests.py
index da36908d28..84ada2cc51 100644
--- a/tests/one_to_one/tests.py
+++ b/tests/one_to_one/tests.py
@@ -6,6 +6,7 @@ from django.test import TestCase
from .models import (Place, Restaurant, Waiter, ManualPrimaryKey, RelatedModel,
MultiModel)
+
class OneToOneTests(TestCase):
def setUp(self):
diff --git a/tests/order_with_respect_to/models.py b/tests/order_with_respect_to/models.py
index 06bb56b141..18dbd08dbc 100644
--- a/tests/order_with_respect_to/models.py
+++ b/tests/order_with_respect_to/models.py
@@ -10,6 +10,7 @@ from django.utils.encoding import python_2_unicode_compatible
class Question(models.Model):
text = models.CharField(max_length=200)
+
@python_2_unicode_compatible
class Answer(models.Model):
text = models.CharField(max_length=200)
@@ -21,6 +22,7 @@ class Answer(models.Model):
def __str__(self):
return six.text_type(self.text)
+
@python_2_unicode_compatible
class Post(models.Model):
title = models.CharField(max_length=200)
diff --git a/tests/ordering/models.py b/tests/ordering/models.py
index e516c2f5a8..415b28bb41 100644
--- a/tests/ordering/models.py
+++ b/tests/ordering/models.py
@@ -28,6 +28,7 @@ class Article(models.Model):
def __str__(self):
return self.headline
+
@python_2_unicode_compatible
class ArticlePKOrdering(models.Model):
headline = models.CharField(max_length=100)
diff --git a/tests/prefetch_related/models.py b/tests/prefetch_related/models.py
index 307cee1900..5e4bf4a3e4 100644
--- a/tests/prefetch_related/models.py
+++ b/tests/prefetch_related/models.py
@@ -5,6 +5,7 @@ from django.utils.encoding import python_2_unicode_compatible
## Basic tests
+
@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=50, unique=True)
@@ -55,6 +56,7 @@ class Book(models.Model):
class Meta:
ordering = ['id']
+
class BookWithYear(Book):
book = models.OneToOneField(Book, parent_link=True)
published_year = models.IntegerField()
@@ -73,12 +75,14 @@ class Reader(models.Model):
class Meta:
ordering = ['id']
+
class BookReview(models.Model):
book = models.ForeignKey(BookWithYear)
notes = models.TextField(null=True, blank=True)
## Models for default manager tests
+
class Qualification(models.Model):
name = models.CharField(max_length=10)
@@ -161,6 +165,7 @@ class House(models.Model):
class Meta:
ordering = ['id']
+
class Room(models.Model):
name = models.CharField(max_length=50)
house = models.ForeignKey(House, related_name='rooms')
diff --git a/tests/proxy_model_inheritance/models.py b/tests/proxy_model_inheritance/models.py
index ef9ac6b0d3..7a10b77c90 100644
--- a/tests/proxy_model_inheritance/models.py
+++ b/tests/proxy_model_inheritance/models.py
@@ -5,9 +5,11 @@ from django.db import models
class ConcreteModel(models.Model):
pass
+
class ConcreteModelSubclass(ConcreteModel):
pass
+
class ConcreteModelSubclassProxy(ConcreteModelSubclass):
class Meta:
proxy = True
diff --git a/tests/proxy_models/models.py b/tests/proxy_models/models.py
index 2e5741ab6b..2e28c3b996 100644
--- a/tests/proxy_models/models.py
+++ b/tests/proxy_models/models.py
@@ -9,14 +9,17 @@ from django.utils.encoding import python_2_unicode_compatible
# A couple of managers for testing managing overriding in proxy model cases.
+
class PersonManager(models.Manager):
def get_queryset(self):
return super(PersonManager, self).get_queryset().exclude(name="fred")
+
class SubManager(models.Manager):
def get_queryset(self):
return super(SubManager, self).get_queryset().exclude(name="wilma")
+
@python_2_unicode_compatible
class Person(models.Model):
"""
@@ -29,6 +32,7 @@ class Person(models.Model):
def __str__(self):
return self.name
+
class Abstract(models.Model):
"""
A simple abstract base class, to be used for error checking.
@@ -38,6 +42,7 @@ class Abstract(models.Model):
class Meta:
abstract = True
+
class MyPerson(Person):
"""
A proxy subclass, this should not get a new table. Overrides the default
@@ -56,12 +61,14 @@ class MyPerson(Person):
def has_special_name(self):
return self.name.lower() == "special"
+
class ManagerMixin(models.Model):
excluder = SubManager()
class Meta:
abstract = True
+
class OtherPerson(Person, ManagerMixin):
"""
A class with the default manager from Person, plus an secondary manager.
@@ -70,6 +77,7 @@ class OtherPerson(Person, ManagerMixin):
proxy = True
ordering = ["name"]
+
class StatusPerson(MyPerson):
"""
A non-proxy subclass of a proxy, it should get a new table.
@@ -77,13 +85,17 @@ class StatusPerson(MyPerson):
status = models.CharField(max_length=80)
# We can even have proxies of proxies (and subclass of those).
+
+
class MyPersonProxy(MyPerson):
class Meta:
proxy = True
+
class LowerStatusPerson(MyPersonProxy):
status = models.CharField(max_length=80)
+
@python_2_unicode_compatible
class User(models.Model):
name = models.CharField(max_length=100)
@@ -91,18 +103,23 @@ class User(models.Model):
def __str__(self):
return self.name
+
class UserProxy(User):
class Meta:
proxy = True
+
class UserProxyProxy(UserProxy):
class Meta:
proxy = True
# We can still use `select_related()` to include related models in our querysets.
+
+
class Country(models.Model):
name = models.CharField(max_length=50)
+
@python_2_unicode_compatible
class State(models.Model):
name = models.CharField(max_length=50)
@@ -111,12 +128,15 @@ class State(models.Model):
def __str__(self):
return self.name
+
class StateProxy(State):
class Meta:
proxy = True
# Proxy models still works with filters (on related fields)
# and select_related, even when mixed with model inheritance
+
+
@python_2_unicode_compatible
class BaseUser(models.Model):
name = models.CharField(max_length=255)
@@ -124,9 +144,11 @@ class BaseUser(models.Model):
def __str__(self):
return ':'.join((self.__class__.__name__, self.name,))
+
class TrackerUser(BaseUser):
status = models.CharField(max_length=50)
+
class ProxyTrackerUser(TrackerUser):
class Meta:
proxy = True
@@ -140,10 +162,12 @@ class Issue(models.Model):
def __str__(self):
return ':'.join((self.__class__.__name__, self.summary,))
+
class Bug(Issue):
version = models.CharField(max_length=50)
reporter = models.ForeignKey(BaseUser)
+
class ProxyBug(Bug):
"""
Proxy of an inherited class
@@ -159,6 +183,7 @@ class ProxyProxyBug(ProxyBug):
class Meta:
proxy = True
+
class Improvement(Issue):
"""
A model that has relation to a proxy model
@@ -168,6 +193,7 @@ class Improvement(Issue):
reporter = models.ForeignKey(ProxyTrackerUser)
associated_bug = models.ForeignKey(ProxyProxyBug)
+
class ProxyImprovement(Improvement):
class Meta:
proxy = True
diff --git a/tests/queries/models.py b/tests/queries/models.py
index 53b716abd1..ec924c03c2 100644
--- a/tests/queries/models.py
+++ b/tests/queries/models.py
@@ -13,10 +13,12 @@ from django.utils.encoding import python_2_unicode_compatible
class DumbCategory(models.Model):
pass
+
class ProxyCategory(DumbCategory):
class Meta:
proxy = True
+
@python_2_unicode_compatible
class NamedCategory(DumbCategory):
name = models.CharField(max_length=10)
@@ -24,6 +26,7 @@ class NamedCategory(DumbCategory):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Tag(models.Model):
name = models.CharField(max_length=10)
@@ -37,6 +40,7 @@ class Tag(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Note(models.Model):
note = models.CharField(max_length=100)
@@ -55,6 +59,7 @@ class Note(models.Model):
# that use objects of that type as an argument.
self.lock = threading.Lock()
+
@python_2_unicode_compatible
class Annotation(models.Model):
name = models.CharField(max_length=10)
@@ -64,6 +69,7 @@ class Annotation(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class ExtraInfo(models.Model):
info = models.CharField(max_length=100)
@@ -76,6 +82,7 @@ class ExtraInfo(models.Model):
def __str__(self):
return self.info
+
@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=10)
@@ -88,6 +95,7 @@ class Author(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Item(models.Model):
name = models.CharField(max_length=10)
@@ -103,6 +111,7 @@ class Item(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Report(models.Model):
name = models.CharField(max_length=10)
@@ -111,6 +120,7 @@ class Report(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Ranking(models.Model):
rank = models.IntegerField()
@@ -123,6 +133,7 @@ class Ranking(models.Model):
def __str__(self):
return '%d: %s' % (self.rank, self.author.name)
+
@python_2_unicode_compatible
class Cover(models.Model):
title = models.CharField(max_length=50)
@@ -134,6 +145,7 @@ class Cover(models.Model):
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class Number(models.Model):
num = models.IntegerField()
@@ -143,6 +155,8 @@ class Number(models.Model):
# Symmetrical m2m field with a normal field using the reverse accesor name
# ("valid").
+
+
class Valid(models.Model):
valid = models.CharField(max_length=10)
parent = models.ManyToManyField('self')
@@ -152,38 +166,49 @@ class Valid(models.Model):
# Some funky cross-linked models for testing a couple of infinite recursion
# cases.
+
+
class X(models.Model):
y = models.ForeignKey('Y')
+
class Y(models.Model):
x1 = models.ForeignKey(X, related_name='y1')
# Some models with a cycle in the default ordering. This would be bad if we
# didn't catch the infinite loop.
+
+
class LoopX(models.Model):
y = models.ForeignKey('LoopY')
class Meta:
ordering = ['y']
+
class LoopY(models.Model):
x = models.ForeignKey(LoopX)
class Meta:
ordering = ['x']
+
class LoopZ(models.Model):
z = models.ForeignKey('self')
class Meta:
ordering = ['z']
+
# A model and custom default manager combination.
+
+
class CustomManager(models.Manager):
def get_queryset(self):
qs = super(CustomManager, self).get_queryset()
return qs.filter(public=True, tag__name='t1')
+
@python_2_unicode_compatible
class ManagedModel(models.Model):
data = models.CharField(max_length=10)
@@ -197,24 +222,31 @@ class ManagedModel(models.Model):
return self.data
# An inter-related setup with multiple paths from Child to Detail.
+
+
class Detail(models.Model):
data = models.CharField(max_length=10)
+
class MemberManager(models.Manager):
def get_queryset(self):
return super(MemberManager, self).get_queryset().select_related("details")
+
class Member(models.Model):
name = models.CharField(max_length=10)
details = models.OneToOneField(Detail, primary_key=True)
objects = MemberManager()
+
class Child(models.Model):
person = models.OneToOneField(Member, primary_key=True)
parent = models.ForeignKey(Member, related_name="children")
# Custom primary keys interfered with ordering in the past.
+
+
class CustomPk(models.Model):
name = models.CharField(max_length=10, primary_key=True)
extra = models.CharField(max_length=10)
@@ -222,12 +254,14 @@ class CustomPk(models.Model):
class Meta:
ordering = ['name', 'extra']
+
class Related(models.Model):
custom = models.ForeignKey(CustomPk)
# An inter-related setup with a model subclass that has a nullable
# path to another model, and a return path from that model.
+
@python_2_unicode_compatible
class Celebrity(models.Model):
name = models.CharField("Name", max_length=20)
@@ -236,13 +270,17 @@ class Celebrity(models.Model):
def __str__(self):
return self.name
+
class TvChef(Celebrity):
pass
+
class Fan(models.Model):
fan_of = models.ForeignKey(Celebrity)
# Multiple foreign keys
+
+
@python_2_unicode_compatible
class LeafA(models.Model):
data = models.CharField(max_length=10)
@@ -250,13 +288,16 @@ class LeafA(models.Model):
def __str__(self):
return self.data
+
class LeafB(models.Model):
data = models.CharField(max_length=10)
+
class Join(models.Model):
a = models.ForeignKey(LeafA)
b = models.ForeignKey(LeafB)
+
@python_2_unicode_compatible
class ReservedName(models.Model):
name = models.CharField(max_length=20)
@@ -266,6 +307,8 @@ class ReservedName(models.Model):
return self.name
# A simpler shared-foreign-key setup that can expose some problems.
+
+
@python_2_unicode_compatible
class SharedConnection(models.Model):
data = models.CharField(max_length=10)
@@ -273,13 +316,17 @@ class SharedConnection(models.Model):
def __str__(self):
return self.data
+
class PointerA(models.Model):
connection = models.ForeignKey(SharedConnection)
+
class PointerB(models.Model):
connection = models.ForeignKey(SharedConnection)
# Multi-layer ordering
+
+
@python_2_unicode_compatible
class SingleObject(models.Model):
name = models.CharField(max_length=10)
@@ -290,6 +337,7 @@ class SingleObject(models.Model):
def __str__(self):
return self.name
+
class RelatedObject(models.Model):
single = models.ForeignKey(SingleObject, null=True)
f = models.IntegerField(null=True)
@@ -297,6 +345,7 @@ class RelatedObject(models.Model):
class Meta:
ordering = ['single']
+
@python_2_unicode_compatible
class Plaything(models.Model):
name = models.CharField(max_length=10)
@@ -308,10 +357,12 @@ class Plaything(models.Model):
def __str__(self):
return self.name
+
class Article(models.Model):
name = models.CharField(max_length=20)
created = models.DateTimeField()
+
@python_2_unicode_compatible
class Food(models.Model):
name = models.CharField(max_length=20, unique=True)
@@ -319,6 +370,7 @@ class Food(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Eaten(models.Model):
food = models.ForeignKey(Food, to_field="name", null=True)
@@ -327,6 +379,7 @@ class Eaten(models.Model):
def __str__(self):
return "%s at %s" % (self.food, self.meal)
+
@python_2_unicode_compatible
class Node(models.Model):
num = models.IntegerField(unique=True)
@@ -336,6 +389,8 @@ class Node(models.Model):
return "%s" % self.num
# Bug #12252
+
+
@python_2_unicode_compatible
class ObjectA(models.Model):
name = models.CharField(max_length=50)
@@ -343,6 +398,7 @@ class ObjectA(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class ObjectB(models.Model):
name = models.CharField(max_length=50)
@@ -352,6 +408,7 @@ class ObjectB(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class ObjectC(models.Model):
name = models.CharField(max_length=50)
@@ -361,6 +418,7 @@ class ObjectC(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class SimpleCategory(models.Model):
name = models.CharField(max_length=15)
@@ -368,6 +426,7 @@ class SimpleCategory(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class SpecialCategory(SimpleCategory):
special_name = models.CharField(max_length=15)
@@ -375,6 +434,7 @@ class SpecialCategory(SimpleCategory):
def __str__(self):
return self.name + " " + self.special_name
+
@python_2_unicode_compatible
class CategoryItem(models.Model):
category = models.ForeignKey(SimpleCategory)
@@ -382,6 +442,7 @@ class CategoryItem(models.Model):
def __str__(self):
return "category item: " + str(self.category)
+
@python_2_unicode_compatible
class OneToOneCategory(models.Model):
new_name = models.CharField(max_length=15)
@@ -390,31 +451,38 @@ class OneToOneCategory(models.Model):
def __str__(self):
return "one2one " + self.new_name
+
class CategoryRelationship(models.Model):
first = models.ForeignKey(SimpleCategory, related_name='first_rel')
second = models.ForeignKey(SimpleCategory, related_name='second_rel')
+
class NullableName(models.Model):
name = models.CharField(max_length=20, null=True)
class Meta:
ordering = ['id']
+
class ModelD(models.Model):
name = models.TextField()
+
class ModelC(models.Model):
name = models.TextField()
+
class ModelB(models.Model):
name = models.TextField()
c = models.ForeignKey(ModelC)
+
class ModelA(models.Model):
name = models.TextField()
b = models.ForeignKey(ModelB, null=True)
d = models.ForeignKey(ModelD)
+
@python_2_unicode_compatible
class Job(models.Model):
name = models.CharField(max_length=20, unique=True)
@@ -422,10 +490,12 @@ class Job(models.Model):
def __str__(self):
return self.name
+
class JobResponsibilities(models.Model):
job = models.ForeignKey(Job, to_field='name')
responsibility = models.ForeignKey('Responsibility', to_field='description')
+
@python_2_unicode_compatible
class Responsibility(models.Model):
description = models.CharField(max_length=20, unique=True)
@@ -436,23 +506,29 @@ class Responsibility(models.Model):
return self.description
# Models for disjunction join promotion low level testing.
+
+
class FK1(models.Model):
f1 = models.TextField()
f2 = models.TextField()
+
class FK2(models.Model):
f1 = models.TextField()
f2 = models.TextField()
+
class FK3(models.Model):
f1 = models.TextField()
f2 = models.TextField()
+
class BaseA(models.Model):
a = models.ForeignKey(FK1, null=True)
b = models.ForeignKey(FK2, null=True)
c = models.ForeignKey(FK3, null=True)
+
@python_2_unicode_compatible
class Identifier(models.Model):
name = models.CharField(max_length=100)
@@ -460,17 +536,21 @@ class Identifier(models.Model):
def __str__(self):
return self.name
+
class Program(models.Model):
identifier = models.OneToOneField(Identifier)
+
class Channel(models.Model):
programs = models.ManyToManyField(Program)
identifier = models.OneToOneField(Identifier)
+
class Book(models.Model):
title = models.TextField()
chapter = models.ForeignKey('Chapter')
+
class Chapter(models.Model):
title = models.TextField()
paragraph = models.ForeignKey('Paragraph')
@@ -480,15 +560,19 @@ class Paragraph(models.Model):
text = models.TextField()
page = models.ManyToManyField('Page')
+
class Page(models.Model):
text = models.TextField()
+
class MyObject(models.Model):
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
data = models.CharField(max_length=100)
created_at = models.DateTimeField(auto_now_add=True)
# Models for #17600 regressions
+
+
@python_2_unicode_compatible
class Order(models.Model):
id = models.IntegerField(primary_key=True)
@@ -499,6 +583,7 @@ class Order(models.Model):
def __str__(self):
return '%s' % self.pk
+
@python_2_unicode_compatible
class OrderItem(models.Model):
order = models.ForeignKey(Order, related_name='items')
@@ -510,9 +595,11 @@ class OrderItem(models.Model):
def __str__(self):
return '%s' % self.pk
+
class BaseUser(models.Model):
pass
+
@python_2_unicode_compatible
class Task(models.Model):
title = models.CharField(max_length=10)
@@ -522,6 +609,7 @@ class Task(models.Model):
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class Staff(models.Model):
name = models.CharField(max_length=10)
@@ -529,6 +617,7 @@ class Staff(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class StaffUser(BaseUser):
staff = models.OneToOneField(Staff, related_name='user')
@@ -536,11 +625,13 @@ class StaffUser(BaseUser):
def __str__(self):
return self.staff
+
class Ticket21203Parent(models.Model):
parentid = models.AutoField(primary_key=True)
parent_bool = models.BooleanField(default=True)
created = models.DateTimeField(auto_now=True)
+
class Ticket21203Child(models.Model):
childid = models.AutoField(primary_key=True)
parent = models.ForeignKey(Ticket21203Parent)
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index bdff134b27..d1e9bd7363 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -28,6 +28,7 @@ from .models import (
CategoryRelationship, Ticket21203Parent, Ticket21203Child, Person,
Company, Employment)
+
class BaseQuerysetTest(TestCase):
def assertValueQuerysetEqual(self, qs, values):
return self.assertQuerysetEqual(qs, values, transform=lambda x: x)
@@ -827,7 +828,7 @@ class Queries1Tests(BaseQuerysetTest):
qs = Tag.objects.values_list('id', flat=True).order_by('id')
qs.query.bump_prefix(qs.query)
first = qs[0]
- self.assertEqual(list(qs), list(range(first, first+5)))
+ self.assertEqual(list(qs), list(range(first, first + 5)))
def test_ticket8439(self):
# Complex combinations of conjunctions, disjunctions and nullable
@@ -1262,6 +1263,7 @@ class Queries3Tests(BaseQuerysetTest):
Item.objects.datetimes, 'name', 'month'
)
+
class Queries4Tests(BaseQuerysetTest):
def setUp(self):
generic = NamedCategory.objects.create(name="Generic")
@@ -1445,8 +1447,8 @@ class Queries4Tests(BaseQuerysetTest):
c0 = SimpleCategory.objects.create(name="cat0")
c1 = SimpleCategory.objects.create(name="category1")
- OneToOneCategory.objects.create(category = c1, new_name="new1")
- OneToOneCategory.objects.create(category = c0, new_name="new2")
+ OneToOneCategory.objects.create(category=c1, new_name="new1")
+ OneToOneCategory.objects.create(category=c0, new_name="new2")
CategoryItem.objects.create(category=c)
ci2 = CategoryItem.objects.create(category=c0)
@@ -1461,8 +1463,8 @@ class Queries4Tests(BaseQuerysetTest):
c0 = SimpleCategory.objects.create(name="cat0")
c1 = SimpleCategory.objects.create(name="category1")
- OneToOneCategory.objects.create(category = c1, new_name="new1")
- OneToOneCategory.objects.create(category = c0, new_name="new2")
+ OneToOneCategory.objects.create(category=c1, new_name="new1")
+ OneToOneCategory.objects.create(category=c0, new_name="new2")
ci1 = CategoryItem.objects.create(category=c)
CategoryItem.objects.create(category=c0)
@@ -1477,8 +1479,8 @@ class Queries4Tests(BaseQuerysetTest):
c0 = SimpleCategory.objects.create(name="cat0")
c1 = SimpleCategory.objects.create(name="category1")
- OneToOneCategory.objects.create(category = c1, new_name="new1")
- OneToOneCategory.objects.create(category = c0, new_name="new2")
+ OneToOneCategory.objects.create(category=c1, new_name="new1")
+ OneToOneCategory.objects.create(category=c0, new_name="new2")
ci1 = CategoryItem.objects.create(category=c)
CategoryItem.objects.create(category=c0)
@@ -1493,8 +1495,8 @@ class Queries4Tests(BaseQuerysetTest):
c0 = SimpleCategory.objects.create(name="cat0")
c1 = SimpleCategory.objects.create(name="category1")
- OneToOneCategory.objects.create(category = c1, new_name="new1")
- OneToOneCategory.objects.create(category = c0, new_name="new2")
+ OneToOneCategory.objects.create(category=c1, new_name="new1")
+ OneToOneCategory.objects.create(category=c0, new_name="new2")
CategoryItem.objects.create(category=c)
ci2 = CategoryItem.objects.create(category=c0)
@@ -2019,6 +2021,7 @@ class CloneTests(TestCase):
else:
opts_class.__deepcopy__ = note_deepcopy
+
class EmptyQuerySetTests(TestCase):
def test_emptyqueryset_values(self):
# #14366 -- Calling .values() on an empty QuerySet and then cloning
@@ -2353,6 +2356,7 @@ class DefaultValuesInsertTest(TestCase):
except TypeError:
self.fail("Creation of an instance of a model with only the PK field shouldn't error out after bulk insert refactoring (#17056)")
+
class ExcludeTests(TestCase):
def setUp(self):
f1 = Food.objects.create(name='apples')
@@ -2504,6 +2508,7 @@ class ExcludeTest17600(TestCase):
Order.objects.exclude(~Q(items__status=1)).distinct(),
[''])
+
class Exclude15786(TestCase):
"""Regression test for #15786"""
def test_ticket15786(self):
@@ -2562,6 +2567,7 @@ class NullInExcludeTest(TestCase):
'IS NOT NULL',
str(NullableName.objects.filter(~~Q(name='i1')).query))
+
class EmptyStringsAsNullTest(TestCase):
"""
Test that filtering on non-null character fields works as expected.
@@ -2591,6 +2597,7 @@ class EmptyStringsAsNullTest(TestCase):
[foo.pk], attrgetter('pk')
)
+
class ProxyQueryCleanupTest(TestCase):
def test_evaluated_proxy_count(self):
"""
@@ -2603,6 +2610,7 @@ class ProxyQueryCleanupTest(TestCase):
str(qs.query)
self.assertEqual(qs.count(), 1)
+
class WhereNodeTest(TestCase):
class DummyNode(object):
def as_sql(self, qn, connection):
@@ -2768,6 +2776,7 @@ class NullJoinPromotionOrTest(TestCase):
self.assertQuerysetEqual(
qs.order_by('name'), [r2, r1], lambda x: x)
+
class ReverseJoinTrimmingTest(TestCase):
def test_reverse_trimming(self):
# Check that we don't accidentally trim reverse joins - we can't know
@@ -2778,6 +2787,7 @@ class ReverseJoinTrimmingTest(TestCase):
self.assertIn('INNER JOIN', str(qs.query))
self.assertEqual(list(qs), [])
+
class JoinReuseTest(TestCase):
"""
Test that the queries reuse joins sensibly (for example, direct joins
@@ -2811,6 +2821,7 @@ class JoinReuseTest(TestCase):
qs = Author.objects.filter(report__name='r4').filter(report__name='r1')
self.assertEqual(str(qs.query).count('JOIN'), 2)
+
class DisjunctionPromotionTests(TestCase):
def test_disjuction_promotion_select_related(self):
fk1 = FK1.objects.create(f1='f1', f2='f2')
@@ -2986,6 +2997,7 @@ class ManyToManyExcludeTest(TestCase):
self.assertIn(b2, q)
self.assertIn(b3, q)
+
class RelabelCloneTest(TestCase):
def test_ticket_19964(self):
my1 = MyObject.objects.create(data='foo')
@@ -3000,6 +3012,7 @@ class RelabelCloneTest(TestCase):
self.assertEqual(list(children), [my2])
self.assertEqual(list(parents), [my1])
+
class Ticket20101Tests(TestCase):
def test_ticket_20101(self):
"""
@@ -3016,6 +3029,7 @@ class Ticket20101Tests(TestCase):
self.assertFalse(n in qs2)
self.assertTrue(n in (qs1 | qs2))
+
class EmptyStringPromotionTests(TestCase):
def test_empty_string_promotion(self):
qs = RelatedObject.objects.filter(single__name='')
@@ -3024,6 +3038,7 @@ class EmptyStringPromotionTests(TestCase):
else:
self.assertNotIn('LEFT OUTER JOIN', str(qs.query))
+
class ValuesSubqueryTests(TestCase):
def test_values_in_subquery(self):
# Check that if a values() queryset is used, then the given values
@@ -3041,6 +3056,7 @@ class ValuesSubqueryTests(TestCase):
Order.objects.filter(items__in=OrderItem.objects.values_list('status')),
[o1.pk], lambda x: x.pk)
+
class DoubleInSubqueryTests(TestCase):
def test_double_subquery_in(self):
lfa1 = LeafA.objects.create(data='foo')
@@ -3055,6 +3071,7 @@ class DoubleInSubqueryTests(TestCase):
self.assertQuerysetEqual(
qs, [lfb1], lambda x: x)
+
class Ticket18785Tests(TestCase):
def test_ticket_18785(self):
# Test join trimming from ticket18785
@@ -3085,6 +3102,7 @@ class Ticket20788Tests(TestCase):
self.assertQuerysetEqual(
sentences_not_in_pub, [book2], lambda x: x)
+
class Ticket12807Tests(TestCase):
def test_ticket_12807(self):
p1 = Paragraph.objects.create()
@@ -3111,6 +3129,7 @@ class RelatedLookupTypeTests(TestCase):
ObjectB.objects.filter(objecta__in=[wrong_type]),
[ob], lambda x: x)
+
class Ticket14056Tests(TestCase):
def test_ticket_14056(self):
s1 = SharedConnection.objects.create(data='s1')
@@ -3126,6 +3145,7 @@ class Ticket14056Tests(TestCase):
expected_ordering, lambda x: x
)
+
class Ticket20955Tests(TestCase):
def test_ticket_20955(self):
jack = Staff.objects.create(name='jackstaff')
@@ -3146,6 +3166,7 @@ class Ticket20955Tests(TestCase):
self.assertEqual(task_select_related.owner.staffuser.staff,
task_get.owner.staffuser.staff)
+
class Ticket21203Tests(TestCase):
def test_ticket_21203(self):
p = Ticket21203Parent.objects.create(parent_bool=True)
@@ -3154,6 +3175,7 @@ class Ticket21203Tests(TestCase):
self.assertQuerysetEqual(qs, [c], lambda x: x)
self.assertIs(qs[0].parent.parent_bool, True)
+
class ValuesJoinPromotionTests(TestCase):
def test_values_no_promotion_for_existing(self):
qs = Node.objects.filter(parent__parent__isnull=False)
diff --git a/tests/queryset_pickle/models.py b/tests/queryset_pickle/models.py
index 10d34180e4..1e73774cd2 100644
--- a/tests/queryset_pickle/models.py
+++ b/tests/queryset_pickle/models.py
@@ -7,6 +7,7 @@ from django.utils.translation import ugettext_lazy as _
def standalone_number():
return 1
+
class Numbers(object):
@staticmethod
def get_static_number():
@@ -21,12 +22,15 @@ class Numbers(object):
nn = Numbers()
+
class Group(models.Model):
name = models.CharField(_('name'), max_length=100)
+
class Event(models.Model):
group = models.ForeignKey(Group)
+
class Happening(models.Model):
when = models.DateTimeField(blank=True, default=datetime.datetime.now)
name = models.CharField(blank=True, max_length=100, default=lambda: "test")
@@ -35,6 +39,7 @@ class Happening(models.Model):
number3 = models.IntegerField(blank=True, default=Numbers.get_class_number)
number4 = models.IntegerField(blank=True, default=nn.get_member_number)
+
class Container(object):
# To test pickling we need a class that isn't defined on module, but
# is still available from app-cache. So, the Container class moves
@@ -42,5 +47,6 @@ class Container(object):
class SomeModel(models.Model):
somefield = models.IntegerField()
+
class M2MModel(models.Model):
groups = models.ManyToManyField(Group)
diff --git a/tests/raw_query/models.py b/tests/raw_query/models.py
index 33f754958e..1e5e176bcf 100644
--- a/tests/raw_query/models.py
+++ b/tests/raw_query/models.py
@@ -15,17 +15,21 @@ class Author(models.Model):
assert k in [f.attname for f in self._meta.fields], \
"Author.__init__ got an unexpected parameter: %s" % k
+
class Book(models.Model):
title = models.CharField(max_length=255)
author = models.ForeignKey(Author)
paperback = models.BooleanField(default=False)
opening_line = models.TextField()
+
class Coffee(models.Model):
brand = models.CharField(max_length=255, db_column="name")
+
class Reviewer(models.Model):
reviewed = models.ManyToManyField(Book)
+
class FriendlyAuthor(Author):
pass
diff --git a/tests/responses/tests.py b/tests/responses/tests.py
index e5320f5af9..afdd4220fb 100644
--- a/tests/responses/tests.py
+++ b/tests/responses/tests.py
@@ -1,6 +1,7 @@
from django.http import HttpResponse
import unittest
+
class HttpResponseTests(unittest.TestCase):
def test_status_code(self):
diff --git a/tests/reverse_lookup/models.py b/tests/reverse_lookup/models.py
index ed58177770..b216c03120 100644
--- a/tests/reverse_lookup/models.py
+++ b/tests/reverse_lookup/models.py
@@ -15,6 +15,7 @@ class User(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Poll(models.Model):
question = models.CharField(max_length=200)
@@ -23,6 +24,7 @@ class Poll(models.Model):
def __str__(self):
return self.question
+
@python_2_unicode_compatible
class Choice(models.Model):
name = models.CharField(max_length=100)
diff --git a/tests/reverse_single_related/models.py b/tests/reverse_single_related/models.py
index 5d53e04772..c7ec2edc6b 100644
--- a/tests/reverse_single_related/models.py
+++ b/tests/reverse_single_related/models.py
@@ -5,9 +5,11 @@ class SourceManager(models.Manager):
def get_queryset(self):
return super(SourceManager, self).get_queryset().filter(is_public=True)
+
class Source(models.Model):
is_public = models.BooleanField(default=False)
objects = SourceManager()
+
class Item(models.Model):
source = models.ForeignKey(Source)
diff --git a/tests/select_related/models.py b/tests/select_related/models.py
index 3b796acdaf..93d699f73e 100644
--- a/tests/select_related/models.py
+++ b/tests/select_related/models.py
@@ -12,6 +12,7 @@ from django.utils.encoding import python_2_unicode_compatible
# Who remembers high school biology?
+
@python_2_unicode_compatible
class Domain(models.Model):
name = models.CharField(max_length=50)
@@ -19,6 +20,7 @@ class Domain(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Kingdom(models.Model):
name = models.CharField(max_length=50)
@@ -27,6 +29,7 @@ class Kingdom(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Phylum(models.Model):
name = models.CharField(max_length=50)
@@ -35,6 +38,7 @@ class Phylum(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Klass(models.Model):
name = models.CharField(max_length=50)
@@ -43,6 +47,7 @@ class Klass(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Order(models.Model):
name = models.CharField(max_length=50)
@@ -51,6 +56,7 @@ class Order(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Family(models.Model):
name = models.CharField(max_length=50)
@@ -59,6 +65,7 @@ class Family(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Genus(models.Model):
name = models.CharField(max_length=50)
@@ -67,6 +74,7 @@ class Genus(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Species(models.Model):
name = models.CharField(max_length=50)
@@ -76,6 +84,8 @@ class Species(models.Model):
return self.name
# and we'll invent a new thing so we have a model with two foreign keys
+
+
@python_2_unicode_compatible
class HybridSpecies(models.Model):
name = models.CharField(max_length=50)
diff --git a/tests/select_related_onetoone/models.py b/tests/select_related_onetoone/models.py
index d32faafbb9..9af1b3f31b 100644
--- a/tests/select_related_onetoone/models.py
+++ b/tests/select_related_onetoone/models.py
@@ -95,8 +95,10 @@ class Child2(Parent1):
def __str__(self):
return self.name1
+
class Child3(Child2):
value3 = models.IntegerField()
+
class Child4(Child1):
value4 = models.IntegerField()
diff --git a/tests/select_related_regress/models.py b/tests/select_related_regress/models.py
index 0858c8fc2c..c2611b4843 100644
--- a/tests/select_related_regress/models.py
+++ b/tests/select_related_regress/models.py
@@ -11,6 +11,7 @@ class Building(models.Model):
def __str__(self):
return "Building: %s" % self.name
+
@python_2_unicode_compatible
class Device(models.Model):
building = models.ForeignKey('Building')
@@ -19,6 +20,7 @@ class Device(models.Model):
def __str__(self):
return "device '%s' in building %s" % (self.name, self.building)
+
@python_2_unicode_compatible
class Port(models.Model):
device = models.ForeignKey('Device')
@@ -27,6 +29,7 @@ class Port(models.Model):
def __str__(self):
return "%s/%s" % (self.device.name, self.port_number)
+
@python_2_unicode_compatible
class Connection(models.Model):
start = models.ForeignKey(Port, related_name='connection_start',
@@ -38,45 +41,60 @@ class Connection(models.Model):
# Another non-tree hierarchy that exercises code paths similar to the above
# example, but in a slightly different configuration.
+
+
class TUser(models.Model):
name = models.CharField(max_length=200)
+
class Person(models.Model):
user = models.ForeignKey(TUser, unique=True)
+
class Organizer(models.Model):
person = models.ForeignKey(Person)
+
class Student(models.Model):
person = models.ForeignKey(Person)
+
class Class(models.Model):
org = models.ForeignKey(Organizer)
+
class Enrollment(models.Model):
std = models.ForeignKey(Student)
cls = models.ForeignKey(Class)
# Models for testing bug #8036.
+
+
class Country(models.Model):
name = models.CharField(max_length=50)
+
class State(models.Model):
name = models.CharField(max_length=50)
country = models.ForeignKey(Country)
+
class ClientStatus(models.Model):
name = models.CharField(max_length=50)
+
class Client(models.Model):
name = models.CharField(max_length=50)
state = models.ForeignKey(State, null=True)
status = models.ForeignKey(ClientStatus)
+
class SpecialClient(Client):
value = models.IntegerField()
# Some model inheritance exercises
+
+
@python_2_unicode_compatible
class Parent(models.Model):
name = models.CharField(max_length=10)
@@ -84,9 +102,11 @@ class Parent(models.Model):
def __str__(self):
return self.name
+
class Child(Parent):
value = models.IntegerField()
+
@python_2_unicode_compatible
class Item(models.Model):
name = models.CharField(max_length=10)
@@ -96,6 +116,8 @@ class Item(models.Model):
return self.name
# Models for testing bug #19870.
+
+
@python_2_unicode_compatible
class Fowl(models.Model):
name = models.CharField(max_length=10)
@@ -103,12 +125,15 @@ class Fowl(models.Model):
def __str__(self):
return self.name
+
class Hen(Fowl):
pass
+
class Chick(Fowl):
mother = models.ForeignKey(Hen)
+
class Base(models.Model):
name = models.CharField(max_length=10)
lots_of_text = models.TextField()
@@ -116,12 +141,15 @@ class Base(models.Model):
class Meta:
abstract = True
+
class A(Base):
a_field = models.CharField(max_length=10)
+
class B(Base):
b_field = models.CharField(max_length=10)
+
class C(Base):
c_a = models.ForeignKey(A)
c_b = models.ForeignKey(B)
diff --git a/tests/serializers/tests.py b/tests/serializers/tests.py
index a381396b40..b9e3bb543f 100644
--- a/tests/serializers/tests.py
+++ b/tests/serializers/tests.py
@@ -26,7 +26,7 @@ from .models import (Category, Author, Article, AuthorProfile, Actor, Movie,
@override_settings(
- SERIALIZATION_MODULES = {
+ SERIALIZATION_MODULES={
"json2": "django.core.serializers.json",
}
)
@@ -71,6 +71,7 @@ class SerializerRegistrationTests(TestCase):
self.assertIn('python', all_formats)
self.assertNotIn('python', public_formats)
+
class SerializersTestBase(object):
@staticmethod
def _comparison_value(value):
@@ -241,9 +242,9 @@ class SerializersTestBase(object):
# Regression for #12524 -- dates before 1000AD get prefixed
# 0's on the year
a = Article.objects.create(
- author = self.jane,
- headline = "Nobody remembers the early years",
- pub_date = datetime(1, 2, 3, 4, 5, 6))
+ author=self.jane,
+ headline="Nobody remembers the early years",
+ pub_date=datetime(1, 2, 3, 4, 5, 6))
serial_str = serializers.serialize(self.serializer_name, [a])
date_values = self._get_field_values(serial_str, "pub_date")
@@ -338,6 +339,7 @@ class XmlSerializerTestCase(SerializersTestBase, TestCase):
ret_list.append("".join(temp))
return ret_list
+
class XmlSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
serializer_name = "xml"
fwd_ref_str = """
@@ -438,6 +440,8 @@ class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, Transact
YAML_IMPORT_ERROR_MESSAGE = r'No module named yaml'
+
+
class YamlImportModuleMock(object):
"""Provides a wrapped import_module function to simulate yaml ImportError
diff --git a/tests/serializers_regress/models.py b/tests/serializers_regress/models.py
index 9403a2d534..2c4a43123e 100644
--- a/tests/serializers_regress/models.py
+++ b/tests/serializers_regress/models.py
@@ -13,74 +13,96 @@ from django.contrib.contenttypes.models import ContentType
# The following classes are for testing basic data
# marshalling, including NULL values, where allowed.
+
class BinaryData(models.Model):
data = models.BinaryField(null=True)
+
class BooleanData(models.Model):
data = models.BooleanField(default=False)
+
class CharData(models.Model):
data = models.CharField(max_length=30, null=True)
+
class DateData(models.Model):
data = models.DateField(null=True)
+
class DateTimeData(models.Model):
data = models.DateTimeField(null=True)
+
class DecimalData(models.Model):
data = models.DecimalField(null=True, decimal_places=3, max_digits=5)
+
class EmailData(models.Model):
data = models.EmailField(null=True)
+
class FileData(models.Model):
data = models.FileField(null=True, upload_to='/foo/bar')
+
class FilePathData(models.Model):
data = models.FilePathField(null=True)
+
class FloatData(models.Model):
data = models.FloatField(null=True)
+
class IntegerData(models.Model):
data = models.IntegerField(null=True)
+
class BigIntegerData(models.Model):
data = models.BigIntegerField(null=True)
# class ImageData(models.Model):
# data = models.ImageField(null=True)
+
class IPAddressData(models.Model):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
data = models.IPAddressField(null=True)
+
class GenericIPAddressData(models.Model):
data = models.GenericIPAddressField(null=True)
+
class NullBooleanData(models.Model):
data = models.NullBooleanField(null=True)
+
class PositiveIntegerData(models.Model):
data = models.PositiveIntegerField(null=True)
+
class PositiveSmallIntegerData(models.Model):
data = models.PositiveSmallIntegerField(null=True)
+
class SlugData(models.Model):
data = models.SlugField(null=True)
+
class SmallData(models.Model):
data = models.SmallIntegerField(null=True)
+
class TextData(models.Model):
data = models.TextField(null=True)
+
class TimeData(models.Model):
data = models.TimeField(null=True)
+
class Tag(models.Model):
"""A tag on an item."""
data = models.SlugField()
@@ -92,6 +114,7 @@ class Tag(models.Model):
class Meta:
ordering = ["data"]
+
class GenericData(models.Model):
data = models.CharField(max_length=30)
@@ -101,6 +124,7 @@ class GenericData(models.Model):
# of related objects; in particular, forward, backward,
# and self references.
+
class Anchor(models.Model):
"""This is a model that can be used as
something for other models to point at"""
@@ -110,10 +134,12 @@ class Anchor(models.Model):
class Meta:
ordering = ('id',)
+
class NaturalKeyAnchorManager(models.Manager):
def get_by_natural_key(self, data):
return self.get(data=data)
+
class NaturalKeyAnchor(models.Model):
objects = NaturalKeyAnchorManager()
@@ -123,40 +149,51 @@ class NaturalKeyAnchor(models.Model):
def natural_key(self):
return (self.data,)
+
class UniqueAnchor(models.Model):
"""This is a model that can be used as
something for other models to point at"""
data = models.CharField(unique=True, max_length=30)
+
class FKData(models.Model):
data = models.ForeignKey(Anchor, null=True)
+
class FKDataNaturalKey(models.Model):
data = models.ForeignKey(NaturalKeyAnchor, null=True)
+
class M2MData(models.Model):
data = models.ManyToManyField(Anchor, null=True)
+
class O2OData(models.Model):
# One to one field can't be null here, since it is a PK.
data = models.OneToOneField(Anchor, primary_key=True)
+
class FKSelfData(models.Model):
data = models.ForeignKey('self', null=True)
+
class M2MSelfData(models.Model):
data = models.ManyToManyField('self', null=True, symmetrical=False)
+
class FKDataToField(models.Model):
data = models.ForeignKey(UniqueAnchor, null=True, to_field='data')
+
class FKDataToO2O(models.Model):
data = models.ForeignKey(O2OData, null=True)
+
class M2MIntermediateData(models.Model):
data = models.ManyToManyField(Anchor, null=True, through='Intermediate')
+
class Intermediate(models.Model):
left = models.ForeignKey(M2MIntermediateData)
right = models.ForeignKey(Anchor)
@@ -169,9 +206,11 @@ class Intermediate(models.Model):
# because they can't be used as a primary key on one
# or all database backends.
+
class BooleanPKData(models.Model):
data = models.BooleanField(primary_key=True, default=False)
+
class CharPKData(models.Model):
data = models.CharField(max_length=30, primary_key=True)
@@ -181,32 +220,39 @@ class CharPKData(models.Model):
# class DateTimePKData(models.Model):
# data = models.DateTimeField(primary_key=True)
+
class DecimalPKData(models.Model):
data = models.DecimalField(primary_key=True, decimal_places=3, max_digits=5)
+
class EmailPKData(models.Model):
data = models.EmailField(primary_key=True)
# class FilePKData(models.Model):
# data = models.FileField(primary_key=True, upload_to='/foo/bar')
+
class FilePathPKData(models.Model):
data = models.FilePathField(primary_key=True)
+
class FloatPKData(models.Model):
data = models.FloatField(primary_key=True)
+
class IntegerPKData(models.Model):
data = models.IntegerField(primary_key=True)
# class ImagePKData(models.Model):
# data = models.ImageField(primary_key=True)
+
class IPAddressPKData(models.Model):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
data = models.IPAddressField(primary_key=True)
+
class GenericIPAddressPKData(models.Model):
data = models.GenericIPAddressField(primary_key=True)
@@ -214,15 +260,19 @@ class GenericIPAddressPKData(models.Model):
# class NullBooleanPKData(models.Model):
# data = models.NullBooleanField(primary_key=True)
+
class PositiveIntegerPKData(models.Model):
data = models.PositiveIntegerField(primary_key=True)
+
class PositiveSmallIntegerPKData(models.Model):
data = models.PositiveSmallIntegerField(primary_key=True)
+
class SlugPKData(models.Model):
data = models.SlugField(primary_key=True)
+
class SmallPKData(models.Model):
data = models.SmallIntegerField(primary_key=True)
@@ -232,6 +282,7 @@ class SmallPKData(models.Model):
# class TimePKData(models.Model):
# data = models.TimeField(primary_key=True)
+
class ComplexModel(models.Model):
field1 = models.CharField(max_length=10)
field2 = models.CharField(max_length=10)
@@ -239,9 +290,12 @@ class ComplexModel(models.Model):
# Tests for handling fields with pre_save functions, or
# models with save functions that modify data
+
+
class AutoNowDateTimeData(models.Model):
data = models.DateTimeField(null=True, auto_now=True)
+
class ModifyingSaveData(models.Model):
data = models.IntegerField(null=True)
@@ -256,33 +310,42 @@ class ModifyingSaveData(models.Model):
# Tests for serialization of models using inheritance.
# Regression for #7202, #7350
+
+
class AbstractBaseModel(models.Model):
parent_data = models.IntegerField()
class Meta:
abstract = True
+
class InheritAbstractModel(AbstractBaseModel):
child_data = models.IntegerField()
+
class BaseModel(models.Model):
parent_data = models.IntegerField()
+
class InheritBaseModel(BaseModel):
child_data = models.IntegerField()
+
class ExplicitInheritBaseModel(BaseModel):
parent = models.OneToOneField(BaseModel)
child_data = models.IntegerField()
+
class ProxyBaseModel(BaseModel):
class Meta:
proxy = True
+
class ProxyProxyBaseModel(ProxyBaseModel):
class Meta:
proxy = True
+
class LengthModel(models.Model):
data = models.IntegerField()
diff --git a/tests/serializers_regress/tests.py b/tests/serializers_regress/tests.py
index 7f65921aff..d71dd8c406 100644
--- a/tests/serializers_regress/tests.py
+++ b/tests/serializers_regress/tests.py
@@ -48,12 +48,15 @@ from .models import (BinaryData, BooleanData, CharData, DateData, DateTimeData,
# The save method is a raw base model save, to make
# sure that the data in the database matches the
# exact test case.
+
+
def data_create(pk, klass, data):
instance = klass(id=pk)
instance.data = data
models.Model.save_base(instance, raw=True)
return [instance]
+
def generic_create(pk, klass, data):
instance = klass(id=pk)
instance.data = data[0]
@@ -62,23 +65,27 @@ def generic_create(pk, klass, data):
instance.tags.create(data=tag)
return [instance]
+
def fk_create(pk, klass, data):
instance = klass(id=pk)
setattr(instance, 'data_id', data)
models.Model.save_base(instance, raw=True)
return [instance]
+
def m2m_create(pk, klass, data):
instance = klass(id=pk)
models.Model.save_base(instance, raw=True)
instance.data = data
return [instance]
+
def im2m_create(pk, klass, data):
instance = klass(id=pk)
models.Model.save_base(instance, raw=True)
return [instance]
+
def im_create(pk, klass, data):
instance = klass(id=pk)
instance.right_id = data['right']
@@ -88,18 +95,21 @@ def im_create(pk, klass, data):
models.Model.save_base(instance, raw=True)
return [instance]
+
def o2o_create(pk, klass, data):
instance = klass()
instance.data_id = data
models.Model.save_base(instance, raw=True)
return [instance]
+
def pk_create(pk, klass, data):
instance = klass()
instance.data = data
models.Model.save_base(instance, raw=True)
return [instance]
+
def inherited_create(pk, klass, data):
instance = klass(id=pk, **data)
# This isn't a raw save because:
@@ -115,6 +125,8 @@ def inherited_create(pk, klass, data):
# A set of functions that can be used to compare
# test data objects of various kinds
+
+
def data_compare(testcase, pk, klass, data):
instance = klass.objects.get(id=pk)
if klass == BinaryData and data is not None:
@@ -129,23 +141,28 @@ def data_compare(testcase, pk, klass, data):
pk, data, type(data), instance, type(instance.data))
)
+
def generic_compare(testcase, pk, klass, data):
instance = klass.objects.get(id=pk)
testcase.assertEqual(data[0], instance.data)
testcase.assertEqual(data[1:], [t.data for t in instance.tags.order_by('id')])
+
def fk_compare(testcase, pk, klass, data):
instance = klass.objects.get(id=pk)
testcase.assertEqual(data, instance.data_id)
+
def m2m_compare(testcase, pk, klass, data):
instance = klass.objects.get(id=pk)
testcase.assertEqual(data, [obj.id for obj in instance.data.order_by('id')])
+
def im2m_compare(testcase, pk, klass, data):
klass.objects.get(id=pk)
# actually nothing else to check, the instance just should exist
+
def im_compare(testcase, pk, klass, data):
instance = klass.objects.get(id=pk)
testcase.assertEqual(data['left'], instance.left_id)
@@ -155,14 +172,17 @@ def im_compare(testcase, pk, klass, data):
else:
testcase.assertEqual("doesn't matter", instance.extra)
+
def o2o_compare(testcase, pk, klass, data):
instance = klass.objects.get(data=data)
testcase.assertEqual(data, instance.data_id)
+
def pk_compare(testcase, pk, klass, data):
instance = klass.objects.get(data=data)
testcase.assertEqual(data, instance.data)
+
def inherited_compare(testcase, pk, klass, data):
instance = klass.objects.get(id=pk)
for key, value in data.items():
@@ -380,6 +400,8 @@ if connection.features.allows_primary_key_0:
# Dynamically create serializer tests to ensure that all
# registered serializers are automatically tested.
+
+
class SerializerTests(TestCase):
def test_get_unknown_serializer(self):
"""
@@ -496,6 +518,7 @@ def naturalKeySerializerTest(format, self):
for klass, count in instance_count.items():
self.assertEqual(count, klass.objects.count())
+
def fieldsTest(format, self):
obj = ComplexModel(field1='first', field2='second', field3='third')
obj.save_base(raw=True)
@@ -509,6 +532,7 @@ def fieldsTest(format, self):
self.assertEqual(result.object.field2, '')
self.assertEqual(result.object.field3, 'third')
+
def streamTest(format, self):
obj = ComplexModel(field1='first', field2='second', field3='third')
obj.save_base(raw=True)
diff --git a/tests/servers/tests.py b/tests/servers/tests.py
index 77c2e39521..5ce86d3529 100644
--- a/tests/servers/tests.py
+++ b/tests/servers/tests.py
@@ -107,6 +107,7 @@ class LiveServerAddress(LiveServerBase):
# test runner and the overridden setUpClass() method is executed.
pass
+
class LiveServerViews(LiveServerBase):
def test_404(self):
"""
diff --git a/tests/settings_tests/tests.py b/tests/settings_tests/tests.py
index b1321d50f3..3597982457 100644
--- a/tests/settings_tests/tests.py
+++ b/tests/settings_tests/tests.py
@@ -76,6 +76,7 @@ class ClassDecoratedTestCase(ClassDecoratedTestCaseSuper):
class ParentDecoratedTestCase(TestCase):
pass
+
@override_settings(TEST='override-child')
class ChildDecoratedTestCase(ParentDecoratedTestCase):
def test_override_settings_inheritance(self):
diff --git a/tests/signals/models.py b/tests/signals/models.py
index e54a22fce9..765230a44e 100644
--- a/tests/signals/models.py
+++ b/tests/signals/models.py
@@ -15,6 +15,7 @@ class Person(models.Model):
def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
+
@python_2_unicode_compatible
class Car(models.Model):
make = models.CharField(max_length=20)
diff --git a/tests/signals/tests.py b/tests/signals/tests.py
index b7ee222c94..1eb2ffb4a3 100644
--- a/tests/signals/tests.py
+++ b/tests/signals/tests.py
@@ -18,6 +18,7 @@ class PostDeleteHandler(object):
(instance, instance.id is None)
)
+
class MyReceiver(object):
def __init__(self, param):
self.param = param
@@ -27,6 +28,7 @@ class MyReceiver(object):
self._run = True
signal.disconnect(receiver=self, sender=sender)
+
class SignalTests(TestCase):
def test_basic(self):
# Save up the number of connected signals so that we can check at the
diff --git a/tests/signals_regress/models.py b/tests/signals_regress/models.py
index 829314c06c..5c28b76669 100644
--- a/tests/signals_regress/models.py
+++ b/tests/signals_regress/models.py
@@ -9,6 +9,7 @@ class Author(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Book(models.Model):
name = models.CharField(max_length=20)
diff --git a/tests/signing/tests.py b/tests/signing/tests.py
index 3486cf0591..fc8390e9e8 100644
--- a/tests/signing/tests.py
+++ b/tests/signing/tests.py
@@ -105,6 +105,7 @@ class TestSigner(TestCase):
self.assertRaises(
signing.BadSignature, signing.loads, transform(encoded))
+
class TestTimestampSigner(TestCase):
def test_timestamp_signer(self):
diff --git a/tests/sites_framework/models.py b/tests/sites_framework/models.py
index 55c4f4992e..12b1d08dd8 100644
--- a/tests/sites_framework/models.py
+++ b/tests/sites_framework/models.py
@@ -3,6 +3,7 @@ from django.contrib.sites.models import Site
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
+
@python_2_unicode_compatible
class AbstractArticle(models.Model):
title = models.CharField(max_length=50)
@@ -16,23 +17,28 @@ class AbstractArticle(models.Model):
def __str__(self):
return self.title
+
class SyndicatedArticle(AbstractArticle):
sites = models.ManyToManyField(Site)
+
class ExclusiveArticle(AbstractArticle):
site = models.ForeignKey(Site)
+
class CustomArticle(AbstractArticle):
places_this_article_should_appear = models.ForeignKey(Site)
objects = models.Manager()
on_site = CurrentSiteManager("places_this_article_should_appear")
+
class InvalidArticle(AbstractArticle):
site = models.ForeignKey(Site)
objects = models.Manager()
on_site = CurrentSiteManager("places_this_article_should_appear")
+
class ConfusedArticle(AbstractArticle):
site = models.IntegerField()
diff --git a/tests/staticfiles_tests/storage.py b/tests/staticfiles_tests/storage.py
index 4d49e6fbb2..e47af18b22 100644
--- a/tests/staticfiles_tests/storage.py
+++ b/tests/staticfiles_tests/storage.py
@@ -2,6 +2,7 @@ from datetime import datetime
from django.core.files import storage
from django.contrib.staticfiles.storage import CachedStaticFilesStorage
+
class DummyStorage(storage.Storage):
"""
A storage class that does implement modified_time() but raises
diff --git a/tests/str/models.py b/tests/str/models.py
index 488012e861..e203de411e 100644
--- a/tests/str/models.py
+++ b/tests/str/models.py
@@ -27,6 +27,7 @@ class Article(models.Model):
# in ASCII.
return self.headline
+
@python_2_unicode_compatible
class InternationalArticle(models.Model):
headline = models.CharField(max_length=100)
diff --git a/tests/string_lookup/models.py b/tests/string_lookup/models.py
index 43ed90a462..4037c2950e 100644
--- a/tests/string_lookup/models.py
+++ b/tests/string_lookup/models.py
@@ -14,6 +14,7 @@ class Foo(models.Model):
def __str__(self):
return "Foo %s" % self.name
+
@python_2_unicode_compatible
class Bar(models.Model):
name = models.CharField(max_length=50)
@@ -24,6 +25,7 @@ class Bar(models.Model):
def __str__(self):
return "Bar %s" % self.place.name
+
@python_2_unicode_compatible
class Whiz(models.Model):
name = models.CharField(max_length=50)
@@ -31,6 +33,7 @@ class Whiz(models.Model):
def __str__(self):
return "Whiz %s" % self.name
+
@python_2_unicode_compatible
class Child(models.Model):
parent = models.OneToOneField('Base')
@@ -39,6 +42,7 @@ class Child(models.Model):
def __str__(self):
return "Child %s" % self.name
+
@python_2_unicode_compatible
class Base(models.Model):
name = models.CharField(max_length=50)
@@ -46,6 +50,7 @@ class Base(models.Model):
def __str__(self):
return "Base %s" % self.name
+
@python_2_unicode_compatible
class Article(models.Model):
name = models.CharField(max_length=50)
diff --git a/tests/syndication/tests.py b/tests/syndication/tests.py
index eeadf85600..a3b75369be 100644
--- a/tests/syndication/tests.py
+++ b/tests/syndication/tests.py
@@ -49,6 +49,7 @@ class FeedTestCase(TestCase):
# Feed view
######################################
+
class SyndicationFeedTest(FeedTestCase):
"""
Tests for the high-level syndication feed framework.
diff --git a/tests/tablespaces/models.py b/tests/tablespaces/models.py
index d5d179303f..ecd1944294 100644
--- a/tests/tablespaces/models.py
+++ b/tests/tablespaces/models.py
@@ -7,15 +7,18 @@ from django.db import models
# "reference" models to avoid errors when other tests run 'migrate'
# (proxy_models_inheritance does).
+
class ScientistRef(models.Model):
name = models.CharField(max_length=50)
+
class ArticleRef(models.Model):
title = models.CharField(max_length=50, unique=True)
code = models.CharField(max_length=50, unique=True)
authors = models.ManyToManyField(ScientistRef, related_name='articles_written_set')
reviewers = models.ManyToManyField(ScientistRef, related_name='articles_reviewed_set')
+
class Scientist(models.Model):
name = models.CharField(max_length=50)
@@ -24,6 +27,7 @@ class Scientist(models.Model):
db_tablespace = 'tbl_tbsp'
managed = False
+
class Article(models.Model):
title = models.CharField(max_length=50, unique=True)
code = models.CharField(max_length=50, unique=True, db_tablespace='idx_tbsp')
diff --git a/tests/tablespaces/tests.py b/tests/tablespaces/tests.py
index f04bf29611..6a81643a0c 100644
--- a/tests/tablespaces/tests.py
+++ b/tests/tablespaces/tests.py
@@ -14,9 +14,11 @@ from .models import Article, ArticleRef, Authors, Reviewers, Scientist, Scientis
# because they're evaluated when the model class is defined. As a consequence,
# @override_settings doesn't work, and the tests depend
+
def sql_for_table(model):
return '\n'.join(connection.creation.sql_create_model(model, no_style())[0])
+
def sql_for_index(model):
return '\n'.join(connection.creation.sql_indexes_for_model(model, no_style()))
diff --git a/tests/template_tests/filters.py b/tests/template_tests/filters.py
index f9e59fd542..ad85d0cb0b 100644
--- a/tests/template_tests/filters.py
+++ b/tests/template_tests/filters.py
@@ -16,11 +16,14 @@ from django.utils.safestring import mark_safe
from django.utils import timezone
# These two classes are used to test auto-escaping of __unicode__ output.
+
+
@python_2_unicode_compatible
class UnsafeClass:
def __str__(self):
return 'you & me'
+
@python_2_unicode_compatible
class SafeClass:
def __str__(self):
@@ -29,6 +32,8 @@ class SafeClass:
# RESULT SYNTAX --
# 'template_name': ('template contents', 'context dict',
# 'expected string output' or Exception class)
+
+
def get_filter_tests():
now = datetime.now()
now_tz = timezone.make_aware(now, timezone.get_default_timezone())
@@ -38,9 +43,9 @@ def get_filter_tests():
# NOTE: \xa0 avoids wrapping between value and unit
return {
# Default compare with datetime.now()
- 'filter-timesince01': ('{{ a|timesince }}', {'a': datetime.now() + timedelta(minutes=-1, seconds = -10)}, '1\xa0minute'),
- 'filter-timesince02': ('{{ a|timesince }}', {'a': datetime.now() - timedelta(days=1, minutes = 1)}, '1\xa0day'),
- 'filter-timesince03': ('{{ a|timesince }}', {'a': datetime.now() - timedelta(hours=1, minutes=25, seconds = 10)}, '1\xa0hour, 25\xa0minutes'),
+ 'filter-timesince01': ('{{ a|timesince }}', {'a': datetime.now() + timedelta(minutes=-1, seconds=-10)}, '1\xa0minute'),
+ 'filter-timesince02': ('{{ a|timesince }}', {'a': datetime.now() - timedelta(days=1, minutes=1)}, '1\xa0day'),
+ 'filter-timesince03': ('{{ a|timesince }}', {'a': datetime.now() - timedelta(hours=1, minutes=25, seconds=10)}, '1\xa0hour, 25\xa0minutes'),
# Compare to a given parameter
'filter-timesince04': ('{{ a|timesince:b }}', {'a': now - timedelta(days=2), 'b': now - timedelta(days=1)}, '1\xa0day'),
@@ -71,7 +76,7 @@ def get_filter_tests():
# Default compare with datetime.now()
'filter-timeuntil01': ('{{ a|timeuntil }}', {'a': datetime.now() + timedelta(minutes=2, seconds=10)}, '2\xa0minutes'),
'filter-timeuntil02': ('{{ a|timeuntil }}', {'a': (datetime.now() + timedelta(days=1, seconds=10))}, '1\xa0day'),
- 'filter-timeuntil03': ('{{ a|timeuntil }}', {'a': (datetime.now() + timedelta(hours=8, minutes=10, seconds = 10))}, '8\xa0hours, 10\xa0minutes'),
+ 'filter-timeuntil03': ('{{ a|timeuntil }}', {'a': (datetime.now() + timedelta(hours=8, minutes=10, seconds=10))}, '8\xa0hours, 10\xa0minutes'),
# Compare to a given parameter
'filter-timeuntil04': ('{{ a|timeuntil:b }}', {'a': now - timedelta(days=1), 'b': now - timedelta(days=2)}, '1\xa0day'),
diff --git a/tests/template_tests/templatetags/bad_tag.py b/tests/template_tests/templatetags/bad_tag.py
index 3cceb31eb0..b806423df3 100644
--- a/tests/template_tests/templatetags/bad_tag.py
+++ b/tests/template_tests/templatetags/bad_tag.py
@@ -3,10 +3,12 @@ from django import template
register = template.Library()
+
@register.tag
def badtag(parser, token):
raise RuntimeError("I am a bad tag")
+
@register.simple_tag
def badsimpletag():
raise RuntimeError("I am a bad simpletag")
diff --git a/tests/template_tests/templatetags/custom.py b/tests/template_tests/templatetags/custom.py
index 9d328f8d54..9aa51931e0 100644
--- a/tests/template_tests/templatetags/custom.py
+++ b/tests/template_tests/templatetags/custom.py
@@ -7,11 +7,13 @@ from django.utils import six
register = template.Library()
+
@register.filter
@stringfilter
def trim(value, num):
return value[:num]
+
@register.filter
def noop(value, param=None):
"""A noop filter that always return its first argument and does nothing with
@@ -19,60 +21,70 @@ def noop(value, param=None):
Useful for testing out whitespace in filter arguments (see #19882)."""
return value
+
@register.simple_tag
def no_params():
"""Expected no_params __doc__"""
return "no_params - Expected result"
no_params.anything = "Expected no_params __dict__"
+
@register.simple_tag
def one_param(arg):
"""Expected one_param __doc__"""
return "one_param - Expected result: %s" % arg
one_param.anything = "Expected one_param __dict__"
+
@register.simple_tag(takes_context=False)
def explicit_no_context(arg):
"""Expected explicit_no_context __doc__"""
return "explicit_no_context - Expected result: %s" % arg
explicit_no_context.anything = "Expected explicit_no_context __dict__"
+
@register.simple_tag(takes_context=True)
def no_params_with_context(context):
"""Expected no_params_with_context __doc__"""
return "no_params_with_context - Expected result (context value: %s)" % context['value']
no_params_with_context.anything = "Expected no_params_with_context __dict__"
+
@register.simple_tag(takes_context=True)
def params_and_context(context, arg):
"""Expected params_and_context __doc__"""
return "params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)
params_and_context.anything = "Expected params_and_context __dict__"
+
@register.simple_tag
def simple_two_params(one, two):
"""Expected simple_two_params __doc__"""
return "simple_two_params - Expected result: %s, %s" % (one, two)
simple_two_params.anything = "Expected simple_two_params __dict__"
+
@register.simple_tag
def simple_one_default(one, two='hi'):
"""Expected simple_one_default __doc__"""
return "simple_one_default - Expected result: %s, %s" % (one, two)
simple_one_default.anything = "Expected simple_one_default __dict__"
+
@register.simple_tag
def simple_unlimited_args(one, two='hi', *args):
"""Expected simple_unlimited_args __doc__"""
return "simple_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args)))
simple_unlimited_args.anything = "Expected simple_unlimited_args __dict__"
+
@register.simple_tag
def simple_only_unlimited_args(*args):
"""Expected simple_only_unlimited_args __doc__"""
return "simple_only_unlimited_args - Expected result: %s" % ', '.join(six.text_type(arg) for arg in args)
simple_only_unlimited_args.anything = "Expected simple_only_unlimited_args __dict__"
+
@register.simple_tag
def simple_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
"""Expected simple_unlimited_args_kwargs __doc__"""
@@ -84,146 +96,171 @@ def simple_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
)
simple_unlimited_args_kwargs.anything = "Expected simple_unlimited_args_kwargs __dict__"
+
@register.simple_tag(takes_context=True)
def simple_tag_without_context_parameter(arg):
"""Expected simple_tag_without_context_parameter __doc__"""
return "Expected result"
simple_tag_without_context_parameter.anything = "Expected simple_tag_without_context_parameter __dict__"
+
@register.simple_tag(takes_context=True)
def current_app(context):
return "%s" % context.current_app
+
@register.simple_tag(takes_context=True)
def use_l10n(context):
return "%s" % context.use_l10n
+
@register.simple_tag(name='minustwo')
def minustwo_overridden_name(value):
return value - 2
register.simple_tag(lambda x: x - 1, name='minusone')
+
@register.inclusion_tag('inclusion.html')
def inclusion_no_params():
"""Expected inclusion_no_params __doc__"""
return {"result": "inclusion_no_params - Expected result"}
inclusion_no_params.anything = "Expected inclusion_no_params __dict__"
+
@register.inclusion_tag(get_template('inclusion.html'))
def inclusion_no_params_from_template():
"""Expected inclusion_no_params_from_template __doc__"""
return {"result": "inclusion_no_params_from_template - Expected result"}
inclusion_no_params_from_template.anything = "Expected inclusion_no_params_from_template __dict__"
+
@register.inclusion_tag('inclusion.html')
def inclusion_one_param(arg):
"""Expected inclusion_one_param __doc__"""
return {"result": "inclusion_one_param - Expected result: %s" % arg}
inclusion_one_param.anything = "Expected inclusion_one_param __dict__"
+
@register.inclusion_tag(get_template('inclusion.html'))
def inclusion_one_param_from_template(arg):
"""Expected inclusion_one_param_from_template __doc__"""
return {"result": "inclusion_one_param_from_template - Expected result: %s" % arg}
inclusion_one_param_from_template.anything = "Expected inclusion_one_param_from_template __dict__"
+
@register.inclusion_tag('inclusion.html', takes_context=False)
def inclusion_explicit_no_context(arg):
"""Expected inclusion_explicit_no_context __doc__"""
return {"result": "inclusion_explicit_no_context - Expected result: %s" % arg}
inclusion_explicit_no_context.anything = "Expected inclusion_explicit_no_context __dict__"
+
@register.inclusion_tag(get_template('inclusion.html'), takes_context=False)
def inclusion_explicit_no_context_from_template(arg):
"""Expected inclusion_explicit_no_context_from_template __doc__"""
return {"result": "inclusion_explicit_no_context_from_template - Expected result: %s" % arg}
inclusion_explicit_no_context_from_template.anything = "Expected inclusion_explicit_no_context_from_template __dict__"
+
@register.inclusion_tag('inclusion.html', takes_context=True)
def inclusion_no_params_with_context(context):
"""Expected inclusion_no_params_with_context __doc__"""
return {"result": "inclusion_no_params_with_context - Expected result (context value: %s)" % context['value']}
inclusion_no_params_with_context.anything = "Expected inclusion_no_params_with_context __dict__"
+
@register.inclusion_tag(get_template('inclusion.html'), takes_context=True)
def inclusion_no_params_with_context_from_template(context):
"""Expected inclusion_no_params_with_context_from_template __doc__"""
return {"result": "inclusion_no_params_with_context_from_template - Expected result (context value: %s)" % context['value']}
inclusion_no_params_with_context_from_template.anything = "Expected inclusion_no_params_with_context_from_template __dict__"
+
@register.inclusion_tag('inclusion.html', takes_context=True)
def inclusion_params_and_context(context, arg):
"""Expected inclusion_params_and_context __doc__"""
return {"result": "inclusion_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)}
inclusion_params_and_context.anything = "Expected inclusion_params_and_context __dict__"
+
@register.inclusion_tag(get_template('inclusion.html'), takes_context=True)
def inclusion_params_and_context_from_template(context, arg):
"""Expected inclusion_params_and_context_from_template __doc__"""
return {"result": "inclusion_params_and_context_from_template - Expected result (context value: %s): %s" % (context['value'], arg)}
inclusion_params_and_context_from_template.anything = "Expected inclusion_params_and_context_from_template __dict__"
+
@register.inclusion_tag('inclusion.html')
def inclusion_two_params(one, two):
"""Expected inclusion_two_params __doc__"""
return {"result": "inclusion_two_params - Expected result: %s, %s" % (one, two)}
inclusion_two_params.anything = "Expected inclusion_two_params __dict__"
+
@register.inclusion_tag(get_template('inclusion.html'))
def inclusion_two_params_from_template(one, two):
"""Expected inclusion_two_params_from_template __doc__"""
return {"result": "inclusion_two_params_from_template - Expected result: %s, %s" % (one, two)}
inclusion_two_params_from_template.anything = "Expected inclusion_two_params_from_template __dict__"
+
@register.inclusion_tag('inclusion.html')
def inclusion_one_default(one, two='hi'):
"""Expected inclusion_one_default __doc__"""
return {"result": "inclusion_one_default - Expected result: %s, %s" % (one, two)}
inclusion_one_default.anything = "Expected inclusion_one_default __dict__"
+
@register.inclusion_tag(get_template('inclusion.html'))
def inclusion_one_default_from_template(one, two='hi'):
"""Expected inclusion_one_default_from_template __doc__"""
return {"result": "inclusion_one_default_from_template - Expected result: %s, %s" % (one, two)}
inclusion_one_default_from_template.anything = "Expected inclusion_one_default_from_template __dict__"
+
@register.inclusion_tag('inclusion.html')
def inclusion_unlimited_args(one, two='hi', *args):
"""Expected inclusion_unlimited_args __doc__"""
return {"result": "inclusion_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args)))}
inclusion_unlimited_args.anything = "Expected inclusion_unlimited_args __dict__"
+
@register.inclusion_tag(get_template('inclusion.html'))
def inclusion_unlimited_args_from_template(one, two='hi', *args):
"""Expected inclusion_unlimited_args_from_template __doc__"""
return {"result": "inclusion_unlimited_args_from_template - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args)))}
inclusion_unlimited_args_from_template.anything = "Expected inclusion_unlimited_args_from_template __dict__"
+
@register.inclusion_tag('inclusion.html')
def inclusion_only_unlimited_args(*args):
"""Expected inclusion_only_unlimited_args __doc__"""
return {"result": "inclusion_only_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in args))}
inclusion_only_unlimited_args.anything = "Expected inclusion_only_unlimited_args __dict__"
+
@register.inclusion_tag(get_template('inclusion.html'))
def inclusion_only_unlimited_args_from_template(*args):
"""Expected inclusion_only_unlimited_args_from_template __doc__"""
return {"result": "inclusion_only_unlimited_args_from_template - Expected result: %s" % (', '.join(six.text_type(arg) for arg in args))}
inclusion_only_unlimited_args_from_template.anything = "Expected inclusion_only_unlimited_args_from_template __dict__"
+
@register.inclusion_tag('test_incl_tag_current_app.html', takes_context=True)
def inclusion_tag_current_app(context):
"""Expected inclusion_tag_current_app __doc__"""
return {}
inclusion_tag_current_app.anything = "Expected inclusion_tag_current_app __dict__"
+
@register.inclusion_tag('test_incl_tag_use_l10n.html', takes_context=True)
def inclusion_tag_use_l10n(context):
"""Expected inclusion_tag_use_l10n __doc__"""
return {}
inclusion_tag_use_l10n.anything = "Expected inclusion_tag_use_l10n __dict__"
+
@register.inclusion_tag('inclusion.html')
def inclusion_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
"""Expected inclusion_unlimited_args_kwargs __doc__"""
@@ -235,66 +272,77 @@ def inclusion_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
)}
inclusion_unlimited_args_kwargs.anything = "Expected inclusion_unlimited_args_kwargs __dict__"
+
@register.inclusion_tag('inclusion.html', takes_context=True)
def inclusion_tag_without_context_parameter(arg):
"""Expected inclusion_tag_without_context_parameter __doc__"""
return {}
inclusion_tag_without_context_parameter.anything = "Expected inclusion_tag_without_context_parameter __dict__"
+
@register.assignment_tag
def assignment_no_params():
"""Expected assignment_no_params __doc__"""
return "assignment_no_params - Expected result"
assignment_no_params.anything = "Expected assignment_no_params __dict__"
+
@register.assignment_tag
def assignment_one_param(arg):
"""Expected assignment_one_param __doc__"""
return "assignment_one_param - Expected result: %s" % arg
assignment_one_param.anything = "Expected assignment_one_param __dict__"
+
@register.assignment_tag(takes_context=False)
def assignment_explicit_no_context(arg):
"""Expected assignment_explicit_no_context __doc__"""
return "assignment_explicit_no_context - Expected result: %s" % arg
assignment_explicit_no_context.anything = "Expected assignment_explicit_no_context __dict__"
+
@register.assignment_tag(takes_context=True)
def assignment_no_params_with_context(context):
"""Expected assignment_no_params_with_context __doc__"""
return "assignment_no_params_with_context - Expected result (context value: %s)" % context['value']
assignment_no_params_with_context.anything = "Expected assignment_no_params_with_context __dict__"
+
@register.assignment_tag(takes_context=True)
def assignment_params_and_context(context, arg):
"""Expected assignment_params_and_context __doc__"""
return "assignment_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)
assignment_params_and_context.anything = "Expected assignment_params_and_context __dict__"
+
@register.assignment_tag
def assignment_two_params(one, two):
"""Expected assignment_two_params __doc__"""
return "assignment_two_params - Expected result: %s, %s" % (one, two)
assignment_two_params.anything = "Expected assignment_two_params __dict__"
+
@register.assignment_tag
def assignment_one_default(one, two='hi'):
"""Expected assignment_one_default __doc__"""
return "assignment_one_default - Expected result: %s, %s" % (one, two)
assignment_one_default.anything = "Expected assignment_one_default __dict__"
+
@register.assignment_tag
def assignment_unlimited_args(one, two='hi', *args):
"""Expected assignment_unlimited_args __doc__"""
return "assignment_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args)))
assignment_unlimited_args.anything = "Expected assignment_unlimited_args __dict__"
+
@register.assignment_tag
def assignment_only_unlimited_args(*args):
"""Expected assignment_only_unlimited_args __doc__"""
return "assignment_only_unlimited_args - Expected result: %s" % ', '.join(six.text_type(arg) for arg in args)
assignment_only_unlimited_args.anything = "Expected assignment_only_unlimited_args __dict__"
+
@register.assignment_tag
def assignment_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
"""Expected assignment_unlimited_args_kwargs __doc__"""
@@ -306,6 +354,7 @@ def assignment_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
)
assignment_unlimited_args_kwargs.anything = "Expected assignment_unlimited_args_kwargs __dict__"
+
@register.assignment_tag(takes_context=True)
def assignment_tag_without_context_parameter(arg):
"""Expected assignment_tag_without_context_parameter __doc__"""
diff --git a/tests/template_tests/templatetags/subpackage/echo.py b/tests/template_tests/templatetags/subpackage/echo.py
index 0e4e862887..43cf107b3d 100644
--- a/tests/template_tests/templatetags/subpackage/echo.py
+++ b/tests/template_tests/templatetags/subpackage/echo.py
@@ -2,6 +2,7 @@ from django import template
register = template.Library()
+
@register.simple_tag
def echo2(arg):
return arg
diff --git a/tests/template_tests/test_callables.py b/tests/template_tests/test_callables.py
index d4e551e1df..9a47a5b96f 100644
--- a/tests/template_tests/test_callables.py
+++ b/tests/template_tests/test_callables.py
@@ -4,6 +4,7 @@ from unittest import TestCase
from django import template
+
class CallableVariablesTests(TestCase):
def test_callable(self):
diff --git a/tests/template_tests/test_loaders.py b/tests/template_tests/test_loaders.py
index 1eef3942a6..57da0af56e 100644
--- a/tests/template_tests/test_loaders.py
+++ b/tests/template_tests/test_loaders.py
@@ -34,6 +34,7 @@ from django.utils.six import StringIO
class MockLoader(object):
pass
+
def create_egg(name, resources):
"""
Creates a mock egg with a list of resources.
@@ -105,7 +106,7 @@ class EggLoaderTest(TestCase):
@override_settings(
- TEMPLATE_LOADERS = (
+ TEMPLATE_LOADERS=(
('django.template.loaders.cached.Loader', (
'django.template.loaders.filesystem.Loader',
)),
@@ -139,7 +140,7 @@ class CachedLoader(TestCase):
@override_settings(
- TEMPLATE_DIRS = (
+ TEMPLATE_DIRS=(
os.path.join(os.path.dirname(upath(__file__)), 'templates'),
)
)
@@ -160,13 +161,13 @@ class RenderToStringTest(TestCase):
def test_empty_list(self):
six.assertRaisesRegex(self, TemplateDoesNotExist,
- 'No template names provided$',
- loader.render_to_string, [])
+ 'No template names provided$',
+ loader.render_to_string, [])
def test_select_templates_from_empty_list(self):
six.assertRaisesRegex(self, TemplateDoesNotExist,
- 'No template names provided$',
- loader.select_template, [])
+ 'No template names provided$',
+ loader.select_template, [])
class TemplateDirsOverrideTest(unittest.TestCase):
diff --git a/tests/template_tests/test_nodelist.py b/tests/template_tests/test_nodelist.py
index 755c0c3bea..12abd20331 100644
--- a/tests/template_tests/test_nodelist.py
+++ b/tests/template_tests/test_nodelist.py
@@ -4,6 +4,7 @@ from django.template import VariableNode, Context
from django.template.loader import get_template_from_string
from django.test.utils import override_settings
+
class NodelistTest(TestCase):
def test_for(self):
@@ -36,7 +37,7 @@ class ErrorIndexTest(TestCase):
Checks whether index of error is calculated correctly in
template debugger in for loops. Refs ticket #5831
"""
- @override_settings(DEBUG=True, TEMPLATE_DEBUG = True)
+ @override_settings(DEBUG=True, TEMPLATE_DEBUG=True)
def test_correct_exception_index(self):
tests = [
('{% load bad_tag %}{% for i in range %}{% badsimpletag %}{% endfor %}', (38, 56)),
diff --git a/tests/template_tests/test_response.py b/tests/template_tests/test_response.py
index dc8ffd1a0a..f5f6158b2f 100644
--- a/tests/template_tests/test_response.py
+++ b/tests/template_tests/test_response.py
@@ -13,6 +13,7 @@ from django.template.response import (TemplateResponse, SimpleTemplateResponse,
from django.test.utils import override_settings
from django.utils._os import upath
+
def test_processor(request):
return {'processors': 'yes'}
test_processor_name = 'template_tests.test_response.test_processor'
@@ -119,7 +120,7 @@ class SimpleTemplateResponseTest(TestCase):
self.assertEqual(response.content, b'bar')
def test_kwargs(self):
- response = self._response(content_type = 'application/json', status=504)
+ response = self._response(content_type='application/json', status=504)
self.assertEqual(response['content-type'], 'application/json')
self.assertEqual(response.status_code, 504)
@@ -233,7 +234,7 @@ class TemplateResponseTest(TestCase):
self.assertEqual(response.content, b'bar')
def test_kwargs(self):
- response = self._response(content_type = 'application/json',
+ response = self._response(content_type='application/json',
status=504)
self.assertEqual(response['content-type'], 'application/json')
self.assertEqual(response.status_code, 504)
diff --git a/tests/template_tests/test_smartif.py b/tests/template_tests/test_smartif.py
index d23a023708..9115acef4e 100644
--- a/tests/template_tests/test_smartif.py
+++ b/tests/template_tests/test_smartif.py
@@ -2,6 +2,7 @@ import unittest
from django.template.smartif import IfParser
+
class SmartIfTests(unittest.TestCase):
def assertCalcEqual(self, expected, tokens):
diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py
index 041a17c9f1..bad15e2834 100644
--- a/tests/template_tests/tests.py
+++ b/tests/template_tests/tests.py
@@ -45,6 +45,7 @@ from . import filters
register = template.Library()
+
class EchoNode(template.Node):
def __init__(self, contents):
self.contents = contents
@@ -52,9 +53,11 @@ class EchoNode(template.Node):
def render(self, context):
return " ".join(self.contents)
+
def do_echo(parser, token):
return EchoNode(token.contents.split()[1:])
+
def do_upper(value):
return value.upper()
@@ -68,18 +71,23 @@ template.libraries['testtags'] = register
# Helper objects for template tests #
#####################################
+
class SomeException(Exception):
silent_variable_failure = True
+
class SomeOtherException(Exception):
pass
+
class ContextStackException(Exception):
pass
+
class ShouldNotExecuteException(Exception):
pass
+
class SomeClass:
def __init__(self):
self.otherclass = OtherClass()
@@ -114,10 +122,12 @@ class SomeClass:
raise SomeOtherException
noisy_fail_attribute = property(noisy_fail_attribute)
+
class OtherClass:
def method(self):
return "OtherClass.method"
+
class TestObj(object):
def is_true(self):
return True
@@ -128,15 +138,18 @@ class TestObj(object):
def is_bad(self):
raise ShouldNotExecuteException()
+
class SilentGetItemClass(object):
def __getitem__(self, key):
raise SomeException
+
class SilentAttrClass(object):
def b(self):
raise SomeException
b = property(b)
+
@python_2_unicode_compatible
class UTF8Class:
"Class whose __str__ returns non-ASCII data on Python 2"
@@ -643,7 +656,7 @@ class TemplateTests(TransRealMixin, TestCase):
settings.ALLOWED_INCLUDE_ROOTS = old_allowed_include_roots
self.assertEqual(failures, [], "Tests failed:\n%s\n%s" %
- ('-'*70, ("\n%s\n" % ('-'*70)).join(failures)))
+ ('-' * 70, ("\n%s\n" % ('-' * 70)).join(failures)))
def render(self, test_template, vals):
context = template.Context(vals[1])
@@ -1538,10 +1551,10 @@ class TemplateTests(TransRealMixin, TestCase):
'{% endfor %},'
'{% endfor %}',
{'data': [{'foo': 'c', 'bar': 1},
- {'foo': 'd', 'bar': 1},
- {'foo': 'a', 'bar': 2},
- {'foo': 'b', 'bar': 2},
- {'foo': 'x', 'bar': 3}]},
+ {'foo': 'd', 'bar': 1},
+ {'foo': 'a', 'bar': 2},
+ {'foo': 'b', 'bar': 2},
+ {'foo': 'x', 'bar': 3}]},
'1:cd,2:ab,3:x,'),
# Test for silent failure when target variable isn't found
@@ -1582,13 +1595,13 @@ class TemplateTests(TransRealMixin, TestCase):
# Test syntax
'regroup05': ('{% regroup data by bar as %}', {},
- template.TemplateSyntaxError),
+ template.TemplateSyntaxError),
'regroup06': ('{% regroup data by bar thisaintright grouped %}', {},
- template.TemplateSyntaxError),
+ template.TemplateSyntaxError),
'regroup07': ('{% regroup data thisaintright bar as grouped %}', {},
- template.TemplateSyntaxError),
+ template.TemplateSyntaxError),
'regroup08': ('{% regroup data by bar as grouped toomanyargs %}', {},
- template.TemplateSyntaxError),
+ template.TemplateSyntaxError),
### SSI TAG ########################################################
diff --git a/tests/template_tests/views.py b/tests/template_tests/views.py
index ed15893239..d031bdc2b6 100644
--- a/tests/template_tests/views.py
+++ b/tests/template_tests/views.py
@@ -6,17 +6,22 @@ from django.template.response import TemplateResponse
def index(request):
pass
+
def client(request, id):
pass
+
def client_action(request, id, action):
pass
+
def client2(request, tag):
pass
+
def template_response_view(request):
return TemplateResponse(request, 'response.html', {})
+
def snark(request):
return HttpResponse('Found him!')
diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py
index 5e4673c3c5..14191306c4 100644
--- a/tests/test_client/tests.py
+++ b/tests/test_client/tests.py
@@ -28,6 +28,7 @@ from django.test.utils import override_settings
from .views import get_view
+
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class ClientTest(TestCase):
fixtures = ['testdata.json']
@@ -479,7 +480,7 @@ class ClientTest(TestCase):
@override_settings(
- MIDDLEWARE_CLASSES = ('django.middleware.csrf.CsrfViewMiddleware',)
+ MIDDLEWARE_CLASSES=('django.middleware.csrf.CsrfViewMiddleware',)
)
class CSRFEnabledClientTests(TestCase):
def test_csrf_enabled_client(self):
@@ -498,6 +499,7 @@ class CSRFEnabledClientTests(TestCase):
class CustomTestClient(Client):
i_am_customized = "Yes"
+
class CustomTestClientTest(TestCase):
client_class = CustomTestClient
diff --git a/tests/test_client/views.py b/tests/test_client/views.py
index 85aefd47bb..53d008d5b1 100644
--- a/tests/test_client/views.py
+++ b/tests/test_client/views.py
@@ -11,6 +11,7 @@ from django.template import Context, Template
from django.utils.decorators import method_decorator
from django.utils.six.moves.urllib.parse import urlencode
+
def get_view(request):
"A simple view that expects a GET request, and returns a rendered template"
t = Template('This is a test. {{ var }} is the value.', name='GET Template')
@@ -18,6 +19,7 @@ def get_view(request):
return HttpResponse(t.render(c))
+
def post_view(request):
"""A view that expects a POST, and returns a different template depending
on whether any POST data is available
@@ -35,12 +37,14 @@ def post_view(request):
return HttpResponse(t.render(c))
+
def view_with_header(request):
"A view that has a custom header"
response = HttpResponse()
response['X-DJANGO-TEST'] = 'Slartibartfast'
return response
+
def raw_post_view(request):
"""A view which expects raw XML to be posted and returns content extracted
from the XML"""
@@ -56,6 +60,7 @@ def raw_post_view(request):
return HttpResponse(t.render(c))
+
def redirect_view(request):
"A view that redirects all requests to the GET view"
if request.GET:
@@ -64,6 +69,7 @@ def redirect_view(request):
query = ''
return HttpResponseRedirect('/test_client/get_view/' + query)
+
def view_with_secure(request):
"A view that indicates if the request was secure"
response = HttpResponse()
@@ -71,10 +77,12 @@ def view_with_secure(request):
response.test_server_port = request.META.get('SERVER_PORT', 80)
return response
+
def double_redirect_view(request):
"A view that redirects all requests to a redirection view"
return HttpResponseRedirect('/test_client/permanent_redirect_view/')
+
def bad_view(request):
"A view that returns a 404 with some error content"
return HttpResponseNotFound('Not found!. This page contains some MAGIC content')
@@ -87,6 +95,7 @@ TestChoices = (
('e', 'Fifth Choice')
)
+
class TestForm(Form):
text = fields.CharField()
email = fields.EmailField()
@@ -100,6 +109,7 @@ class TestForm(Form):
raise ValidationError("Non-field error.")
return cleaned_data
+
def form_view(request):
"A view that tests a simple form"
if request.method == 'POST':
@@ -117,6 +127,7 @@ def form_view(request):
return HttpResponse(t.render(c))
+
def form_view_with_template(request):
"A view that tests a simple form"
if request.method == 'POST':
@@ -135,6 +146,7 @@ def form_view_with_template(request):
}
)
+
class BaseTestFormSet(BaseFormSet):
def clean(self):
"""Checks that no two email addresses are the same."""
@@ -154,6 +166,7 @@ class BaseTestFormSet(BaseFormSet):
TestFormSet = formset_factory(TestForm, BaseTestFormSet)
+
def formset_view(request):
"A view that tests a simple formset"
if request.method == 'POST':
@@ -172,6 +185,7 @@ def formset_view(request):
c = Context({'my_formset': formset})
return HttpResponse(t.render(c))
+
def login_protected_view(request):
"A simple view that is login protected."
t = Template('This is a login protected test. Username is {{ user.username }}.', name='Login Template')
@@ -180,6 +194,7 @@ def login_protected_view(request):
return HttpResponse(t.render(c))
login_protected_view = login_required(login_protected_view)
+
def login_protected_view_changed_redirect(request):
"A simple view that is login protected with a custom redirect field set"
t = Template('This is a login protected test. Username is {{ user.username }}.', name='Login Template')
@@ -188,6 +203,7 @@ def login_protected_view_changed_redirect(request):
return HttpResponse(t.render(c))
login_protected_view_changed_redirect = login_required(redirect_field_name="redirect_to")(login_protected_view_changed_redirect)
+
def _permission_protected_view(request):
"A simple view that is permission protected."
t = Template('This is a permission protected test. '
@@ -199,6 +215,7 @@ def _permission_protected_view(request):
permission_protected_view = permission_required('permission_not_granted')(_permission_protected_view)
permission_protected_view_exception = permission_required('permission_not_granted', raise_exception=True)(_permission_protected_view)
+
class _ViewManager(object):
@method_decorator(login_required)
def login_protected_view(self, request):
@@ -221,6 +238,7 @@ _view_manager = _ViewManager()
login_protected_method_view = _view_manager.login_protected_view
permission_protected_method_view = _view_manager.permission_protected_view
+
def session_view(request):
"A view that modifies the session"
request.session['tobacconist'] = 'hovercraft'
@@ -230,10 +248,12 @@ def session_view(request):
c = Context()
return HttpResponse(t.render(c))
+
def broken_view(request):
"""A view which just raises an exception, simulating a broken view."""
raise KeyError("Oops! Looks like you wrote some bad code.")
+
def mail_sending_view(request):
mail.EmailMessage(
"Test message",
@@ -242,6 +262,7 @@ def mail_sending_view(request):
['first@example.com', 'second@example.com']).send()
return HttpResponse("Mail sent")
+
def mass_mail_sending_view(request):
m1 = mail.EmailMessage(
'First Test message',
@@ -259,5 +280,6 @@ def mass_mail_sending_view(request):
return HttpResponse("Mail sent")
+
def django_project_redirect(request):
return HttpResponseRedirect('https://www.djangoproject.com/')
diff --git a/tests/test_client_regress/session.py b/tests/test_client_regress/session.py
index 665729cf00..47c192718b 100644
--- a/tests/test_client_regress/session.py
+++ b/tests/test_client_regress/session.py
@@ -1,5 +1,6 @@
from django.contrib.sessions.backends.base import SessionBase
+
class SessionStore(SessionBase):
"""
A simple cookie-based session storage implementation.
diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py
index 459c110803..04fa734ddc 100644
--- a/tests/test_client_regress/tests.py
+++ b/tests/test_client_regress/tests.py
@@ -23,6 +23,7 @@ from django.contrib.auth.models import User
from .models import CustomUser
from .views import CustomTestException
+
@override_settings(
TEMPLATE_DIRS=(os.path.join(os.path.dirname(upath(__file__)), 'templates'),)
)
@@ -185,6 +186,7 @@ class AssertContainsTests(TestCase):
response = HttpResponse('Hello')
self.assertNotContains(response, 'Bye')
+
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AssertTemplateUsedTests(TestCase):
fixtures = ['testdata.json']
@@ -256,6 +258,7 @@ class AssertTemplateUsedTests(TestCase):
except AssertionError as e:
self.assertIn("Template 'Valid POST Template' was not a template used to render the response. Actual template(s) used: form_view.html, base.html", str(e))
+
class AssertRedirectsTests(TestCase):
def test_redirect_page(self):
"An assertion is raised if the original page couldn't be retrieved as expected"
@@ -545,6 +548,7 @@ class AssertFormErrorTests(TestCase):
except AssertionError as e:
self.assertIn("abc: The form 'form' in context 0 does not contain the non-field error 'Some error.' (actual errors: )", str(e))
+
class AssertFormsetErrorTests(TestCase):
msg_prefixes = [("", {}), ("abc: ", {"msg_prefix": "abc"})]
@@ -737,6 +741,7 @@ class AssertFormsetErrorTests(TestCase):
'addresses.',
**kwargs)
+
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class LoginTests(TestCase):
fixtures = ['testdata']
@@ -801,6 +806,7 @@ class URLEscapingTests(TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b'Hi, Arthur')
+
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class ExceptionTests(TestCase):
fixtures = ['testdata.json']
@@ -846,6 +852,7 @@ class TemplateExceptionTests(TestCase):
except TemplateSyntaxError:
pass
+
# We need two different tests to check URLconf substitution - one to check
# it was changed, and another one (without self.urls) to check it was reverted on
# teardown. This pair of tests relies upon the alphabetical ordering of test execution.
@@ -857,6 +864,7 @@ class UrlconfSubstitutionTests(TestCase):
url = reverse('arg_view', args=['somename'])
self.assertEqual(url, '/arg_view/somename/')
+
# This test needs to run *after* UrlconfSubstitutionTests; the zz prefix in the
# name is to ensure alphabetical ordering.
class zzUrlconfSubstitutionTests(TestCase):
@@ -865,6 +873,7 @@ class zzUrlconfSubstitutionTests(TestCase):
url = reverse('arg_view', args=['somename'])
self.assertEqual(url, '/test_client_regress/arg_view/somename/')
+
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class ContextTests(TestCase):
fixtures = ['testdata']
@@ -1114,6 +1123,7 @@ class RequestMethodStringDataTests(TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b'request method: PATCH')
+
class QueryStringTests(TestCase):
def test_get_like_requests(self):
# See: https://code.djangoproject.com/ticket/10571.
@@ -1166,6 +1176,7 @@ class QueryStringTests(TestCase):
self.assertEqual(response.context['request-foo'], 'whiz')
self.assertEqual(response.context['request-bar'], 'bang')
+
class UnicodePayloadTests(TestCase):
def test_simple_unicode_payload(self):
"A simple ASCII-only unicode JSON document can be POSTed"
@@ -1199,6 +1210,7 @@ class UnicodePayloadTests(TestCase):
content_type="application/json; charset=koi8-r")
self.assertEqual(response.content, json.encode('koi8-r'))
+
class DummyFile(object):
def __init__(self, filename):
self.name = filename
@@ -1206,6 +1218,7 @@ class DummyFile(object):
def read(self):
return b'TEST_FILE_CONTENT'
+
class UploadedFileEncodingTest(TestCase):
def test_file_encoding(self):
encoded_file = encode_file('TEST_BOUNDARY', 'TEST_KEY', DummyFile('test_name.bin'))
@@ -1226,6 +1239,7 @@ class UploadedFileEncodingTest(TestCase):
self.assertEqual(b'Content-Type: application/octet-stream',
encode_file('IGNORE', 'IGNORE', DummyFile("file.unknown"))[2])
+
class RequestHeadersTest(TestCase):
def test_client_headers(self):
"A test client can receive custom headers"
@@ -1268,17 +1282,19 @@ class ReadLimitedStreamTest(TestCase):
"""HttpRequest.read() on a test client PUT request with some payload
should return that payload."""
payload = b'foobar'
- self.assertEqual(self.client.put("/test_client_regress/read_all/",
- data=payload,
- content_type='text/plain').content, payload)
+ self.assertEqual(self.client.put(
+ "/test_client_regress/read_all/",
+ data=payload,
+ content_type='text/plain').content, payload)
def test_read_numbytes_from_nonempty_request(self):
"""HttpRequest.read(LARGE_BUFFER) on a test client PUT request with
some payload should return that payload."""
payload = b'foobar'
- self.assertEqual(self.client.put("/test_client_regress/read_buffer/",
- data=payload,
- content_type='text/plain').content, payload)
+ self.assertEqual(
+ self.client.put("/test_client_regress/read_buffer/",
+ data=payload,
+ content_type='text/plain').content, payload)
class RequestFactoryStateTest(TestCase):
diff --git a/tests/test_client_regress/views.py b/tests/test_client_regress/views.py
index d4bbd55b6f..2fbbce0c43 100644
--- a/tests/test_client_regress/views.py
+++ b/tests/test_client_regress/views.py
@@ -15,10 +15,12 @@ from django.test.utils import setup_test_environment
class CustomTestException(Exception):
pass
+
def no_template_view(request):
"A simple view that expects a GET request, and returns a rendered template"
return HttpResponse("No template used. Sample content: twice once twice. Content ends.")
+
def staff_only_view(request):
"A view that can only be visited by staff. Non staff members get an exception"
if request.user.is_staff:
@@ -26,11 +28,13 @@ def staff_only_view(request):
else:
raise CustomTestException()
+
def get_view(request):
"A simple login protected view"
return HttpResponse("Hello world")
get_view = login_required(get_view)
+
def request_data(request, template='base.html', data='sausage'):
"A simple view that returns the request data in the context"
@@ -50,6 +54,7 @@ def request_data(request, template='base.html', data='sausage'):
'data': data,
})
+
def view_with_argument(request, name):
"""A view that takes a string argument
@@ -62,6 +67,7 @@ def view_with_argument(request, name):
else:
return HttpResponse('Howdy, %s' % name)
+
def nested_view(request):
"""
A view that uses test client to call another view.
@@ -71,32 +77,39 @@ def nested_view(request):
c.get("/test_client_regress/no_template_view")
return render_to_response('base.html', {'nested': 'yes'})
+
def login_protected_redirect_view(request):
"A view that redirects all requests to the GET view"
return HttpResponseRedirect('/test_client_regress/get_view/')
login_protected_redirect_view = login_required(login_protected_redirect_view)
+
def set_session_view(request):
"A view that sets a session variable"
request.session['session_var'] = 'YES'
return HttpResponse('set_session')
+
def check_session_view(request):
"A view that reads a session variable"
return HttpResponse(request.session.get('session_var', 'NO'))
+
def request_methods_view(request):
"A view that responds with the request method"
return HttpResponse('request method: %s' % request.method)
+
def return_unicode(request):
return render_to_response('unicode.html')
+
def return_undecodable_binary(request):
return HttpResponse(
b'%PDF-1.4\r\n%\x93\x8c\x8b\x9e ReportLab Generated PDF document http://www.reportlab.com'
)
+
def return_json_file(request):
"A view that parses and returns a JSON string as a file."
match = CONTENT_TYPE_RE.match(request.META['CONTENT_TYPE'])
@@ -113,22 +126,27 @@ def return_json_file(request):
response['Content-Disposition'] = 'attachment; filename=testfile.json'
return response
+
def check_headers(request):
"A view that responds with value of the X-ARG-CHECK header"
return HttpResponse('HTTP_X_ARG_CHECK: %s' % request.META.get('HTTP_X_ARG_CHECK', 'Undefined'))
+
def body(request):
"A view that is requested with GET and accesses request.body. Refs #14753."
return HttpResponse(request.body)
+
def read_all(request):
"A view that is requested with accesses request.read()."
return HttpResponse(request.read())
+
def read_buffer(request):
"A view that is requested with accesses request.read(LARGE_BUFFER)."
return HttpResponse(request.read(99999))
+
def request_context_view(request):
# Special attribute that won't be present on a plain HttpRequest
request.special_path = request.path
diff --git a/tests/test_runner/models.py b/tests/test_runner/models.py
index 9a072e627c..20cb384b03 100644
--- a/tests/test_runner/models.py
+++ b/tests/test_runner/models.py
@@ -1,5 +1,6 @@
from django.db import models
+
class Person(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
diff --git a/tests/test_runner_deprecation_app/tests.py b/tests/test_runner_deprecation_app/tests.py
index 24d716f2bb..0d947c35c2 100644
--- a/tests/test_runner_deprecation_app/tests.py
+++ b/tests/test_runner_deprecation_app/tests.py
@@ -4,6 +4,7 @@ from django.test import TestCase
warnings.warn("module-level warning from deprecation_app", DeprecationWarning)
+
class DummyTest(TestCase):
def test_warn(self):
warnings.warn("warning from test", DeprecationWarning)
diff --git a/tests/test_utils/models.py b/tests/test_utils/models.py
index 85a1031c02..4c6ee0d19a 100644
--- a/tests/test_utils/models.py
+++ b/tests/test_utils/models.py
@@ -1,6 +1,7 @@
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
+
@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=100)
diff --git a/tests/timezones/admin.py b/tests/timezones/admin.py
index 81b49a4ab6..bd6c4e10c8 100644
--- a/tests/timezones/admin.py
+++ b/tests/timezones/admin.py
@@ -2,11 +2,13 @@ from django.contrib import admin
from .models import Event, Timestamp
+
class EventAdmin(admin.ModelAdmin):
list_display = ('dt',)
admin.site.register(Event, EventAdmin)
+
class TimestampAdmin(admin.ModelAdmin):
readonly_fields = ('created', 'updated')
diff --git a/tests/timezones/forms.py b/tests/timezones/forms.py
index d99c9b77d5..b92562396e 100644
--- a/tests/timezones/forms.py
+++ b/tests/timezones/forms.py
@@ -2,20 +2,25 @@ from django import forms
from .models import Event
+
class EventForm(forms.Form):
dt = forms.DateTimeField()
+
class EventSplitForm(forms.Form):
dt = forms.SplitDateTimeField()
+
class EventLocalizedForm(forms.Form):
dt = forms.DateTimeField(localize=True)
+
class EventModelForm(forms.ModelForm):
class Meta:
model = Event
fields = '__all__'
+
class EventLocalizedModelForm(forms.ModelForm):
class Meta:
model = Event
diff --git a/tests/timezones/models.py b/tests/timezones/models.py
index c49e42f887..73b198f32c 100644
--- a/tests/timezones/models.py
+++ b/tests/timezones/models.py
@@ -1,21 +1,27 @@
from django.db import models
+
class Event(models.Model):
dt = models.DateTimeField()
+
class MaybeEvent(models.Model):
dt = models.DateTimeField(blank=True, null=True)
+
class Session(models.Model):
name = models.CharField(max_length=20)
+
class SessionEvent(models.Model):
dt = models.DateTimeField()
session = models.ForeignKey(Session, related_name='events')
+
class Timestamp(models.Model):
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
+
class AllDayEvent(models.Model):
day = models.DateField()
diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py
index 8c0c535d31..5c38bc8ef2 100644
--- a/tests/transactions/tests.py
+++ b/tests/transactions/tests.py
@@ -395,7 +395,8 @@ class TransactionTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
"""
The default behavior is to autocommit after each save() action.
"""
- self.assertRaises(Exception,
+ self.assertRaises(
+ Exception,
self.create_a_reporter_then_fail,
"Alice", "Smith"
)
@@ -411,7 +412,8 @@ class TransactionTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
autocomitted_create_then_fail = transaction.autocommit(
self.create_a_reporter_then_fail
)
- self.assertRaises(Exception,
+ self.assertRaises(
+ Exception,
autocomitted_create_then_fail,
"Alice", "Smith"
)
@@ -426,7 +428,8 @@ class TransactionTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
autocomitted_create_then_fail = transaction.autocommit(using='default')(
self.create_a_reporter_then_fail
)
- self.assertRaises(Exception,
+ self.assertRaises(
+ Exception,
autocomitted_create_then_fail,
"Alice", "Smith"
)
@@ -453,7 +456,8 @@ class TransactionTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
using_committed_on_success = transaction.commit_on_success(using='default')(
self.create_a_reporter_then_fail
)
- self.assertRaises(Exception,
+ self.assertRaises(
+ Exception,
using_committed_on_success,
"Dirk", "Gently"
)
@@ -519,7 +523,8 @@ class TransactionTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
using_manually_managed_mistake = transaction.commit_manually(using='default')(
self.manually_managed_mistake
)
- self.assertRaises(transaction.TransactionManagementError,
+ self.assertRaises(
+ transaction.TransactionManagementError,
using_manually_managed_mistake
)
@@ -544,6 +549,7 @@ class TransactionRollbackTests(IgnoreDeprecationWarningsMixin, TransactionTestCa
self.assertRaises(IntegrityError, execute_bad_sql)
transaction.rollback()
+
class TransactionContextManagerTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
available_apps = ['transactions']
diff --git a/tests/transactions_regress/models.py b/tests/transactions_regress/models.py
index e09e81d93d..32234d9ba4 100644
--- a/tests/transactions_regress/models.py
+++ b/tests/transactions_regress/models.py
@@ -4,9 +4,11 @@ from django.db import models
class Mod(models.Model):
fld = models.IntegerField()
+
class SubMod(Mod):
cnt = models.IntegerField(unique=True)
+
class M2mA(models.Model):
others = models.ManyToManyField('M2mB')
diff --git a/tests/transactions_regress/tests.py b/tests/transactions_regress/tests.py
index a67d36e4eb..24bd860731 100644
--- a/tests/transactions_regress/tests.py
+++ b/tests/transactions_regress/tests.py
@@ -10,6 +10,7 @@ from django.test.utils import override_settings, IgnoreDeprecationWarningsMixin
from .models import Mod, M2mA, M2mB, SubMod
+
class ModelInheritanceTests(TransactionTestCase):
available_apps = ['transactions_regress']
@@ -31,6 +32,7 @@ class ModelInheritanceTests(TransactionTestCase):
self.assertEqual(SubMod.objects.count(), 1)
self.assertEqual(Mod.objects.count(), 1)
+
class TestTransactionClosing(IgnoreDeprecationWarningsMixin, TransactionTestCase):
"""
Tests to make sure that transactions are properly closed
@@ -191,6 +193,7 @@ class TestTransactionClosing(IgnoreDeprecationWarningsMixin, TransactionTestCase
"""
self.test_failing_query_transaction_closed()
+
@skipIf(connection.vendor == 'sqlite'
and connection.settings_dict['TEST_NAME'] in (None, '', ':memory:'),
"Cannot establish two connections to an in-memory SQLite database.")
@@ -372,7 +375,7 @@ class SavepointTest(IgnoreDeprecationWarningsMixin, TransactionTestCase):
# _mysql_storage_engine issues a query and as such can't be applied in
# a skipIf decorator since that would execute the query on module load.
if (connection.vendor == 'mysql' and
- connection.features._mysql_storage_engine == 'MyISAM'):
+ connection.features._mysql_storage_engine == 'MyISAM'):
raise SkipTest("MyISAM MySQL storage engine doesn't support savepoints")
@commit_manually
diff --git a/tests/unmanaged_models/models.py b/tests/unmanaged_models/models.py
index 0eef69977c..b0dd5c8719 100644
--- a/tests/unmanaged_models/models.py
+++ b/tests/unmanaged_models/models.py
@@ -8,6 +8,7 @@ from django.utils.encoding import python_2_unicode_compatible
# All of these models are created in the database by Django.
+
@python_2_unicode_compatible
class A01(models.Model):
f_a = models.CharField(max_length=10, db_index=True)
@@ -19,6 +20,7 @@ class A01(models.Model):
def __str__(self):
return self.f_a
+
@python_2_unicode_compatible
class B01(models.Model):
fk_a = models.ForeignKey(A01)
@@ -33,6 +35,7 @@ class B01(models.Model):
def __str__(self):
return self.f_a
+
@python_2_unicode_compatible
class C01(models.Model):
mm_a = models.ManyToManyField(A01, db_table='d01')
@@ -49,6 +52,7 @@ class C01(models.Model):
# of possibly a subset of the columns). There should be no creation errors,
# since we have told Django they aren't managed by Django.
+
@python_2_unicode_compatible
class A02(models.Model):
f_a = models.CharField(max_length=10, db_index=True)
@@ -60,6 +64,7 @@ class A02(models.Model):
def __str__(self):
return self.f_a
+
@python_2_unicode_compatible
class B02(models.Model):
class Meta:
@@ -73,6 +78,7 @@ class B02(models.Model):
def __str__(self):
return self.f_a
+
# To re-use the many-to-many intermediate table, we need to manually set up
# things up.
@python_2_unicode_compatible
@@ -88,6 +94,7 @@ class C02(models.Model):
def __str__(self):
return self.f_a
+
class Intermediate(models.Model):
a02 = models.ForeignKey(A02, db_column="a01_id")
c02 = models.ForeignKey(C02, db_column="c01_id")
@@ -96,7 +103,7 @@ class Intermediate(models.Model):
db_table = 'd01'
managed = False
-#
+
# These next models test the creation (or not) of many to many join tables
# between managed and unmanaged models. A join table between two unmanaged
# models shouldn't be automatically created (see #10647).
@@ -109,15 +116,18 @@ class Proxy1(models.Model):
class Meta:
db_table = "unmanaged_models_proxy1"
+
class Proxy2(models.Model):
class Meta:
db_table = "unmanaged_models_proxy2"
+
class Unmanaged1(models.Model):
class Meta:
managed = False
db_table = "unmanaged_models_proxy1"
+
# Unmanged with an m2m to unmanaged: the intermediary table won't be created.
class Unmanaged2(models.Model):
mm = models.ManyToManyField(Unmanaged1)
@@ -126,6 +136,7 @@ class Unmanaged2(models.Model):
managed = False
db_table = "unmanaged_models_proxy2"
+
# Here's an unmanaged model with an m2m to a managed one; the intermediary
# table *will* be created (unless given a custom `through` as for C02 above).
class Managed1(models.Model):
diff --git a/tests/update/models.py b/tests/update/models.py
index 08472d98b1..ebc9c3353c 100644
--- a/tests/update/models.py
+++ b/tests/update/models.py
@@ -17,6 +17,7 @@ class DataPoint(models.Model):
def __str__(self):
return six.text_type(self.name)
+
@python_2_unicode_compatible
class RelatedPoint(models.Model):
name = models.CharField(max_length=20)
@@ -29,12 +30,15 @@ class RelatedPoint(models.Model):
class A(models.Model):
x = models.IntegerField(default=10)
+
class B(models.Model):
a = models.ForeignKey(A)
y = models.IntegerField(default=10)
+
class C(models.Model):
y = models.IntegerField(default=10)
+
class D(C):
a = models.ForeignKey(A)
diff --git a/tests/update_only_fields/models.py b/tests/update_only_fields/models.py
index bf5dd99166..ea319834c0 100644
--- a/tests/update_only_fields/models.py
+++ b/tests/update_only_fields/models.py
@@ -7,6 +7,7 @@ GENDER_CHOICES = (
('F', 'Female'),
)
+
class Account(models.Model):
num = models.IntegerField()
diff --git a/tests/urlpatterns_reverse/erroneous_views_module.py b/tests/urlpatterns_reverse/erroneous_views_module.py
index 52b9bc5163..3f7f5b2ac7 100644
--- a/tests/urlpatterns_reverse/erroneous_views_module.py
+++ b/tests/urlpatterns_reverse/erroneous_views_module.py
@@ -1,4 +1,5 @@
import non_existent # NOQA
+
def erroneous_view(request):
pass
diff --git a/tests/urlpatterns_reverse/middleware.py b/tests/urlpatterns_reverse/middleware.py
index 0de692835f..cc80f14145 100644
--- a/tests/urlpatterns_reverse/middleware.py
+++ b/tests/urlpatterns_reverse/middleware.py
@@ -8,24 +8,29 @@ class ChangeURLconfMiddleware(object):
def process_request(self, request):
request.urlconf = urlconf_inner.__name__
+
class NullChangeURLconfMiddleware(object):
def process_request(self, request):
request.urlconf = None
+
class ReverseInnerInResponseMiddleware(object):
def process_response(self, *args, **kwargs):
return HttpResponse(reverse('inner'))
+
class ReverseOuterInResponseMiddleware(object):
def process_response(self, *args, **kwargs):
return HttpResponse(reverse('outer'))
+
class ReverseInnerInStreaming(object):
def process_view(self, *args, **kwargs):
def stream():
yield reverse('inner')
return StreamingHttpResponse(stream())
+
class ReverseOuterInStreaming(object):
def process_view(self, *args, **kwargs):
def stream():
diff --git a/tests/urlpatterns_reverse/tests.py b/tests/urlpatterns_reverse/tests.py
index 4134057b23..b2a6d83443 100644
--- a/tests/urlpatterns_reverse/tests.py
+++ b/tests/urlpatterns_reverse/tests.py
@@ -148,6 +148,7 @@ test_data = (
('defaults', NoReverseMatch, [], {'arg2': 1}),
)
+
class NoURLPatternsTests(TestCase):
urls = 'urlpatterns_reverse.no_urls'
@@ -161,6 +162,7 @@ class NoURLPatternsTests(TestCase):
"The included urlconf urlpatterns_reverse.no_urls "
"doesn't have any patterns in it", getattr, resolver, 'url_patterns')
+
class URLPatternReverse(TestCase):
urls = 'urlpatterns_reverse.urls'
@@ -282,6 +284,7 @@ class ResolverTests(unittest.TestCase):
else:
self.assertEqual(t.name, e['name'], 'Wrong URL name. Expected "%s", got "%s".' % (e['name'], t.name))
+
class ReverseLazyTest(TestCase):
urls = 'urlpatterns_reverse.reverse_lazy_urls'
@@ -297,6 +300,7 @@ class ReverseLazyTest(TestCase):
response = self.client.get('/login_required_view/')
self.assertEqual(response.status_code, 200)
+
class ReverseShortcutTests(TestCase):
urls = 'urlpatterns_reverse.urls'
@@ -454,7 +458,7 @@ class NamespaceTests(TestCase):
self.assertEqual('/inc78/extra/foobar/', reverse('inc-ns5:inner-extra', args=['78', 'foobar']))
-@override_settings(ROOT_URLCONF = urlconf_outer.__name__)
+@override_settings(ROOT_URLCONF=urlconf_outer.__name__)
class RequestURLconfTests(TestCase):
def test_urlconf(self):
response = self.client.get('/test/me/')
@@ -549,6 +553,7 @@ class RequestURLconfTests(TestCase):
self.client.get('/second_test/')
b''.join(self.client.get('/second_test/'))
+
class ErrorHandlerResolutionTests(TestCase):
"""Tests for handler400, handler404 and handler500"""
@@ -573,6 +578,7 @@ class ErrorHandlerResolutionTests(TestCase):
self.assertEqual(self.callable_resolver.resolve404(), handler)
self.assertEqual(self.callable_resolver.resolve500(), handler)
+
class DefaultErrorHandlerTests(TestCase):
urls = 'urlpatterns_reverse.urls_without_full_import'
@@ -589,6 +595,7 @@ class DefaultErrorHandlerTests(TestCase):
except AttributeError:
self.fail("Shouldn't get an AttributeError due to undefined 500 handler")
+
class NoRootUrlConfTests(TestCase):
"""Tests for handler404 and handler500 if urlconf is None"""
urls = None
@@ -596,6 +603,7 @@ class NoRootUrlConfTests(TestCase):
def test_no_handler_exception(self):
self.assertRaises(ImproperlyConfigured, self.client.get, '/test/me/')
+
class ResolverMatchTests(TestCase):
urls = 'urlpatterns_reverse.namespace_urls'
@@ -631,6 +639,7 @@ class ResolverMatchTests(TestCase):
request = HttpRequest()
self.assertIsNone(request.resolver_match)
+
class ErroneousViewTests(TestCase):
urls = 'urlpatterns_reverse.erroneous_urls'
@@ -650,6 +659,7 @@ class ErroneousViewTests(TestCase):
# The regex error will be hit before NoReverseMatch can be raised
self.assertRaises(ImproperlyConfigured, reverse, 'whatever blah blah')
+
class ViewLoadingTests(TestCase):
def test_view_loading(self):
# A missing view (identified by an AttributeError) should raise
diff --git a/tests/urlpatterns_reverse/urlconf_inner.py b/tests/urlpatterns_reverse/urlconf_inner.py
index 6d9d2346f7..6d5cd27b35 100644
--- a/tests/urlpatterns_reverse/urlconf_inner.py
+++ b/tests/urlpatterns_reverse/urlconf_inner.py
@@ -2,6 +2,7 @@ from django.conf.urls import patterns, url
from django.template import Template, Context
from django.http import HttpResponse
+
def inner_view(request):
content = Template('{% url "outer" as outer_url %}outer:{{ outer_url }},'
'{% url "inner" as inner_url %}inner:{{ inner_url }}').render(Context())
diff --git a/tests/urlpatterns_reverse/views.py b/tests/urlpatterns_reverse/views.py
index 6bb8849472..f23b4bf257 100644
--- a/tests/urlpatterns_reverse/views.py
+++ b/tests/urlpatterns_reverse/views.py
@@ -4,21 +4,27 @@ from django.core.urlresolvers import reverse_lazy
from django.contrib.auth.decorators import user_passes_test
+
def empty_view(request, *args, **kwargs):
return HttpResponse('')
+
def kwargs_view(request, arg1=1, arg2=2):
return HttpResponse('')
+
def absolute_kwargs_view(request, arg1=1, arg2=2):
return HttpResponse('')
+
def defaults_view(request, arg1, arg2):
pass
+
def erroneous_view(request):
import non_existent # NOQA
+
def pass_resolver_match_view(request, *args, **kwargs):
response = HttpResponse('')
response.resolver_match = request.resolver_match
@@ -26,18 +32,22 @@ def pass_resolver_match_view(request, *args, **kwargs):
uncallable = "Can I be a view? Pleeeease?"
+
class ViewClass(object):
def __call__(self, request, *args, **kwargs):
return HttpResponse('')
view_class_instance = ViewClass()
+
class LazyRedirectView(RedirectView):
url = reverse_lazy('named-lazy-url-redirected-to')
+
@user_passes_test(lambda u: u.is_authenticated(), login_url=reverse_lazy('some-login-page'))
def login_required_view(request):
return HttpResponse('Hello you')
+
def bad_view(request, *args, **kwargs):
raise ValueError("I don't think I'm getting good value for this view")
diff --git a/tests/user_commands/management/commands/leave_locale_alone_false.py b/tests/user_commands/management/commands/leave_locale_alone_false.py
index 8ebb607d5a..e03ad1cab0 100644
--- a/tests/user_commands/management/commands/leave_locale_alone_false.py
+++ b/tests/user_commands/management/commands/leave_locale_alone_false.py
@@ -1,6 +1,7 @@
from django.core.management.base import BaseCommand
from django.utils import translation
+
class Command(BaseCommand):
can_import_settings = True
diff --git a/tests/user_commands/management/commands/leave_locale_alone_true.py b/tests/user_commands/management/commands/leave_locale_alone_true.py
index e0f923591e..9861221e39 100644
--- a/tests/user_commands/management/commands/leave_locale_alone_true.py
+++ b/tests/user_commands/management/commands/leave_locale_alone_true.py
@@ -1,6 +1,7 @@
from django.core.management.base import BaseCommand
from django.utils import translation
+
class Command(BaseCommand):
can_import_settings = True
diff --git a/tests/utils_tests/test_baseconv.py b/tests/utils_tests/test_baseconv.py
index d49dde1092..0af1c4e3f0 100644
--- a/tests/utils_tests/test_baseconv.py
+++ b/tests/utils_tests/test_baseconv.py
@@ -3,6 +3,7 @@ from unittest import TestCase
from django.utils.baseconv import base2, base16, base36, base56, base62, base64, BaseConverter
from django.utils.six.moves import xrange
+
class TestBaseConv(TestCase):
def test_baseconv(self):
diff --git a/tests/utils_tests/test_checksums.py b/tests/utils_tests/test_checksums.py
index cee6dca2a8..9c9f244b6c 100644
--- a/tests/utils_tests/test_checksums.py
+++ b/tests/utils_tests/test_checksums.py
@@ -2,6 +2,7 @@ import unittest
from django.utils import checksums
+
class TestUtilsChecksums(unittest.TestCase):
def check_output(self, function, value, output=None):
diff --git a/tests/utils_tests/test_datetime_safe.py b/tests/utils_tests/test_datetime_safe.py
index c9c34dbf40..3a8d31d6d8 100644
--- a/tests/utils_tests/test_datetime_safe.py
+++ b/tests/utils_tests/test_datetime_safe.py
@@ -3,6 +3,7 @@ import unittest
from datetime import date as original_date, datetime as original_datetime
from django.utils.datetime_safe import date, datetime
+
class DatetimeTests(unittest.TestCase):
def setUp(self):
diff --git a/tests/utils_tests/test_decorators.py b/tests/utils_tests/test_decorators.py
index 2d8af0a6e9..a05a736c30 100644
--- a/tests/utils_tests/test_decorators.py
+++ b/tests/utils_tests/test_decorators.py
@@ -11,6 +11,7 @@ class ProcessViewMiddleware(object):
process_view_dec = decorator_from_middleware(ProcessViewMiddleware)
+
@process_view_dec
def process_view(request):
return HttpResponse()
diff --git a/tests/utils_tests/test_ipv6.py b/tests/utils_tests/test_ipv6.py
index 662e8b4135..6cd0cebc84 100644
--- a/tests/utils_tests/test_ipv6.py
+++ b/tests/utils_tests/test_ipv6.py
@@ -4,6 +4,7 @@ import unittest
from django.utils.ipv6 import is_valid_ipv6_address, clean_ipv6_address
+
class TestUtilsIPv6(unittest.TestCase):
def test_validates_correct_plain_address(self):
diff --git a/tests/utils_tests/test_jslex.py b/tests/utils_tests/test_jslex.py
index 084e2feb5b..97e6dbc109 100644
--- a/tests/utils_tests/test_jslex.py
+++ b/tests/utils_tests/test_jslex.py
@@ -5,6 +5,7 @@
from django.test import TestCase
from django.utils.jslex import JsLexer, prepare_js_for_gettext
+
class JsTokensTest(TestCase):
LEX_CASES = [
# ids
@@ -105,6 +106,7 @@ class JsTokensTest(TestCase):
r'string "\")"', "punct ;"]),
]
+
def make_function(input, toks):
def test_func(self):
lexer = JsLexer()
@@ -207,6 +209,7 @@ GETTEXT_CASES = (
class JsToCForGettextTest(TestCase):
pass
+
def make_function(js, c):
def test_func(self):
self.assertMultiLineEqual(prepare_js_for_gettext(js), c)
diff --git a/tests/utils_tests/test_module_loading.py b/tests/utils_tests/test_module_loading.py
index 1886631006..5a7eadcedf 100644
--- a/tests/utils_tests/test_module_loading.py
+++ b/tests/utils_tests/test_module_loading.py
@@ -52,6 +52,7 @@ class DefaultLoader(unittest.TestCase):
self.assertRaises(ImportError, import_module,
'utils_tests.test_no_submodule.anything')
+
class EggLoader(unittest.TestCase):
def setUp(self):
self.old_path = sys.path[:]
@@ -133,6 +134,7 @@ class ModuleImportTestCase(unittest.TestCase):
self.assertIsNotNone(traceback.tb_next.tb_next,
'Should have more than the calling frame in the traceback.')
+
@override_settings(INSTALLED_APPS=('utils_tests.test_module',))
class AutodiscoverModulesTestCase(SimpleTestCase):
@@ -188,6 +190,7 @@ class ProxyFinder(object):
if fd:
fd.close()
+
class TestFinder(object):
def __init__(self, *args, **kwargs):
self.importer = zipimporter(*args, **kwargs)
@@ -198,6 +201,7 @@ class TestFinder(object):
return
return TestLoader(importer)
+
class TestLoader(object):
def __init__(self, importer):
self.importer = importer
@@ -207,6 +211,7 @@ class TestLoader(object):
mod.__loader__ = self
return mod
+
class CustomLoader(EggLoader):
"""The Custom Loader test is exactly the same as the EggLoader, but
it uses a custom defined Loader and Finder that is intentionally
diff --git a/tests/utils_tests/test_simplelazyobject.py b/tests/utils_tests/test_simplelazyobject.py
index 072db52e9e..14ad393bfa 100644
--- a/tests/utils_tests/test_simplelazyobject.py
+++ b/tests/utils_tests/test_simplelazyobject.py
@@ -177,6 +177,7 @@ class TestUtilsSimpleLazyObject(TestCase):
self.assertEqual(len(lazy_list), 5)
self.assertEqual(len(lazy_set), 4)
+
class TestUtilsSimpleLazyObjectDjangoTestCase(DjangoTestCase):
def test_pickle_py2_regression(self):
diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py
index 441898c0b4..62e792fab6 100644
--- a/tests/utils_tests/test_text.py
+++ b/tests/utils_tests/test_text.py
@@ -4,6 +4,7 @@ from __future__ import unicode_literals
from django.test import SimpleTestCase
from django.utils import text
+
class TestUtilsText(SimpleTestCase):
def test_truncate_chars(self):
diff --git a/tests/utils_tests/test_tzinfo.py b/tests/utils_tests/test_tzinfo.py
index 43522bb1d0..85d6b673bb 100644
--- a/tests/utils_tests/test_tzinfo.py
+++ b/tests/utils_tests/test_tzinfo.py
@@ -13,6 +13,7 @@ with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=PendingDeprecationWarning)
from django.utils.tzinfo import FixedOffset, LocalTimezone
+
class TzinfoTests(IgnorePendingDeprecationWarningsMixin, unittest.TestCase):
@classmethod
@@ -47,10 +48,10 @@ class TzinfoTests(IgnorePendingDeprecationWarningsMixin, unittest.TestCase):
self.assertEqual(repr(FixedOffset(-280)), '-0440')
self.assertEqual(repr(FixedOffset(-78.4)), '-0118')
self.assertEqual(repr(FixedOffset(78.4)), '+0118')
- self.assertEqual(repr(FixedOffset(-5.5*60)), '-0530')
- self.assertEqual(repr(FixedOffset(5.5*60)), '+0530')
- self.assertEqual(repr(FixedOffset(-.5*60)), '-0030')
- self.assertEqual(repr(FixedOffset(.5*60)), '+0030')
+ self.assertEqual(repr(FixedOffset(-5.5 * 60)), '-0530')
+ self.assertEqual(repr(FixedOffset(5.5 * 60)), '+0530')
+ self.assertEqual(repr(FixedOffset(-.5 * 60)), '-0030')
+ self.assertEqual(repr(FixedOffset(.5 * 60)), '+0030')
def test_16899(self):
if not self.tz_tests:
diff --git a/tests/validation/models.py b/tests/validation/models.py
index ee5bcfc9aa..157b8cb158 100644
--- a/tests/validation/models.py
+++ b/tests/validation/models.py
@@ -11,6 +11,7 @@ def validate_answer_to_universe(value):
if value != 42:
raise ValidationError('This is not the answer to life, universe and everything!', code='not42')
+
class ModelToValidate(models.Model):
name = models.CharField(max_length=100)
created = models.DateTimeField(default=datetime.now)
@@ -26,14 +27,17 @@ class ModelToValidate(models.Model):
if self.number == 11:
raise ValidationError('Invalid number supplied!')
+
class UniqueFieldsModel(models.Model):
unique_charfield = models.CharField(max_length=100, unique=True)
unique_integerfield = models.IntegerField(unique=True)
non_unique_field = models.IntegerField()
+
class CustomPKModel(models.Model):
my_pk_field = models.CharField(max_length=100, primary_key=True)
+
class UniqueTogetherModel(models.Model):
cfield = models.CharField(max_length=100)
ifield = models.IntegerField()
@@ -42,6 +46,7 @@ class UniqueTogetherModel(models.Model):
class Meta:
unique_together = (('ifield', 'cfield',), ['ifield', 'efield'])
+
class UniqueForDateModel(models.Model):
start_date = models.DateField()
end_date = models.DateTimeField()
@@ -49,6 +54,7 @@ class UniqueForDateModel(models.Model):
order = models.IntegerField(unique_for_month="end_date")
name = models.CharField(max_length=100)
+
class CustomMessagesModel(models.Model):
other = models.IntegerField(blank=True, null=True)
number = models.IntegerField(db_column='number_val',
@@ -56,9 +62,11 @@ class CustomMessagesModel(models.Model):
validators=[validate_answer_to_universe]
)
+
class Author(models.Model):
name = models.CharField(max_length=100)
+
class Article(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(Author)
@@ -68,6 +76,7 @@ class Article(models.Model):
if self.pub_date is None:
self.pub_date = datetime.now()
+
@python_2_unicode_compatible
class Post(models.Model):
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
@@ -78,16 +87,19 @@ class Post(models.Model):
def __str__(self):
return self.name
+
class FlexibleDatePost(models.Model):
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
slug = models.CharField(max_length=50, unique_for_year='posted', blank=True)
subtitle = models.CharField(max_length=50, unique_for_month='posted', blank=True)
posted = models.DateField(blank=True, null=True)
+
class UniqueErrorsModel(models.Model):
name = models.CharField(max_length=100, unique=True, error_messages={'unique': 'Custom unique name message.'})
no = models.IntegerField(unique=True, error_messages={'unique': 'Custom unique number message.'})
+
class GenericIPAddressTestModel(models.Model):
generic_ip = models.GenericIPAddressField(blank=True, null=True, unique=True)
v4_ip = models.GenericIPAddressField(blank=True, null=True, protocol="ipv4")
@@ -95,6 +107,7 @@ class GenericIPAddressTestModel(models.Model):
ip_verbose_name = models.GenericIPAddressField("IP Address Verbose",
blank=True, null=True)
+
class GenericIPAddrUnpackUniqueTest(models.Model):
generic_v4unpack_ip = models.GenericIPAddressField(null=True, blank=True, unique=True, unpack_ipv4=True)
diff --git a/tests/validation/test_unique.py b/tests/validation/test_unique.py
index 7d4ba26ff0..14ac5a2471 100644
--- a/tests/validation/test_unique.py
+++ b/tests/validation/test_unique.py
@@ -55,6 +55,7 @@ class GetUniqueCheckTests(unittest.TestCase):
), m._get_unique_checks(exclude='start_date')
)
+
class PerformUniqueChecksTest(TestCase):
def test_primary_key_unique_check_not_performed_when_adding_and_pk_not_specified(self):
# Regression test for #12560
diff --git a/tests/validation/tests.py b/tests/validation/tests.py
index 02839eaf26..7f81cafccf 100644
--- a/tests/validation/tests.py
+++ b/tests/validation/tests.py
@@ -52,7 +52,7 @@ class BaseModelValidationTests(ValidationTestCase):
self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', ['Enter a valid URL.'])
def test_text_greater_that_charfields_max_length_raises_erros(self):
- mtv = ModelToValidate(number=10, name='Some Name'*100)
+ mtv = ModelToValidate(number=10, name='Some Name' * 100)
self.assertFailsValidation(mtv.full_clean, ['name'])
def test_malformed_slug_raises_error(self):
@@ -65,6 +65,7 @@ class ArticleForm(forms.ModelForm):
model = Article
exclude = ['author']
+
class ModelFormsTests(TestCase):
def setUp(self):
self.author = Author.objects.create(name='Joseph Kocherhans')
diff --git a/tests/validators/tests.py b/tests/validators/tests.py
index e3f418ee73..b0d1376aee 100644
--- a/tests/validators/tests.py
+++ b/tests/validators/tests.py
@@ -131,12 +131,12 @@ TEST_DATA = (
(MinValueValidator(NOW), NOW - timedelta(days=1), ValidationError),
(MaxLengthValidator(10), '', None),
- (MaxLengthValidator(10), 10*'x', None),
+ (MaxLengthValidator(10), 10 * 'x', None),
- (MaxLengthValidator(10), 15*'x', ValidationError),
+ (MaxLengthValidator(10), 15 * 'x', ValidationError),
- (MinLengthValidator(10), 15*'x', None),
- (MinLengthValidator(10), 10*'x', None),
+ (MinLengthValidator(10), 15 * 'x', None),
+ (MinLengthValidator(10), 10 * 'x', None),
(MinLengthValidator(10), '', ValidationError),
@@ -182,6 +182,7 @@ TEST_DATA = (
(RegexValidator(re.compile('x')), 'y', ValidationError),
)
+
def create_simple_test_method(validator, expected, value, num):
if expected is not None and issubclass(expected, Exception):
test_mask = 'test_%s_raises_error_%d'
@@ -214,6 +215,7 @@ def create_simple_test_method(validator, expected, value, num):
# Dynamically assemble a test class with the contents of TEST_DATA
+
class TestSimpleValidators(TestCase):
def test_single_message(self):
v = ValidationError('Not Valid')
diff --git a/tests/version/tests.py b/tests/version/tests.py
index 8663d52cc5..b4c4283c04 100644
--- a/tests/version/tests.py
+++ b/tests/version/tests.py
@@ -3,6 +3,7 @@ from unittest import TestCase
from django import get_version
from django.utils import six
+
class VersionTests(TestCase):
def test_development(self):
diff --git a/tests/view_tests/__init__.py b/tests/view_tests/__init__.py
index 9030f07239..371ab40b40 100644
--- a/tests/view_tests/__init__.py
+++ b/tests/view_tests/__init__.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
+
class BrokenException(Exception):
pass
diff --git a/tests/view_tests/models.py b/tests/view_tests/models.py
index 461f98c028..f2707b1796 100644
--- a/tests/view_tests/models.py
+++ b/tests/view_tests/models.py
@@ -5,6 +5,7 @@ Regression tests for Django built-in views.
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
+
@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=100)
@@ -15,6 +16,7 @@ class Author(models.Model):
def get_absolute_url(self):
return '/views/authors/%s/' % self.id
+
@python_2_unicode_compatible
class BaseArticle(models.Model):
"""
@@ -31,9 +33,11 @@ class BaseArticle(models.Model):
def __str__(self):
return self.title
+
class Article(BaseArticle):
date_created = models.DateTimeField()
+
class UrlArticle(BaseArticle):
"""
An Article class with a get_absolute_url defined.
@@ -44,6 +48,7 @@ class UrlArticle(BaseArticle):
return '/urlarticles/%s/' % self.slug
get_absolute_url.purge = True
+
class DateArticle(BaseArticle):
"""
An article Model with a DateField instead of DateTimeField,
diff --git a/tests/view_tests/templatetags/debugtags.py b/tests/view_tests/templatetags/debugtags.py
index 5aafc3a9e0..1b9f3f9828 100644
--- a/tests/view_tests/templatetags/debugtags.py
+++ b/tests/view_tests/templatetags/debugtags.py
@@ -5,6 +5,7 @@ from ..views import BrokenException
register = template.Library()
+
@register.simple_tag
def go_boom(arg):
raise BrokenException(arg)
diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
index 225215e475..fbbcdc9a40 100644
--- a/tests/view_tests/tests/test_debug.py
+++ b/tests/view_tests/tests/test_debug.py
@@ -185,7 +185,7 @@ class ExceptionReporterTests(TestCase):
for newline in ['\n', '\r\n', '\r']:
fd, filename = mkstemp(text=False)
- os.write(fd, force_bytes(newline.join(LINES)+newline))
+ os.write(fd, force_bytes(newline.join(LINES) + newline))
os.close(fd)
try:
@@ -641,6 +641,7 @@ class ExceptionReporterFilterTests(TestCase, ExceptionReportTestMixin):
response = self.client.get('/views/raises500/')
self.assertNotContains(response, 'should not be displayed', status_code=500)
+
class AjaxResponseExceptionReporterFilter(TestCase, ExceptionReportTestMixin):
"""
Ensure that sensitive information can be filtered out of error reports.
diff --git a/tests/view_tests/tests/test_shortcuts.py b/tests/view_tests/tests/test_shortcuts.py
index 707df5ee7e..eb08433a44 100644
--- a/tests/view_tests/tests/test_shortcuts.py
+++ b/tests/view_tests/tests/test_shortcuts.py
@@ -1,6 +1,7 @@
from django.test import TestCase
from django.test.utils import override_settings
+
@override_settings(
TEMPLATE_CONTEXT_PROCESSORS=('django.core.context_processors.static',),
STATIC_URL='/path/to/static/media/',
diff --git a/tests/view_tests/views.py b/tests/view_tests/views.py
index ed4e98a4c7..4373ef12f9 100644
--- a/tests/view_tests/views.py
+++ b/tests/view_tests/views.py
@@ -23,6 +23,7 @@ def index_page(request):
"""Dummy index page"""
return HttpResponse('Dummy page')
+
def raises(request):
# Make sure that a callable that raises an exception in the stack frame's
# local vars won't hijack the technical 500 response. See:
@@ -34,6 +35,7 @@ def raises(request):
except Exception:
return technical_500_response(request, *sys.exc_info())
+
def raises500(request):
# We need to inspect the HTML generated by the fancy 500 debug view but
# the test client ignores it, so we send it explicitly.
@@ -42,85 +44,102 @@ def raises500(request):
except Exception:
return technical_500_response(request, *sys.exc_info())
+
def raises400(request):
raise SuspiciousOperation
+
def raises403(request):
raise PermissionDenied
+
def raises404(request):
resolver = get_resolver(None)
resolver.resolve('')
+
def redirect(request):
"""
Forces an HTTP redirect.
"""
return HttpResponseRedirect("target/")
+
def view_exception(request, n):
raise BrokenException(except_args[int(n)])
+
def template_exception(request, n):
return render_to_response('debug/template_exception.html',
{'arg': except_args[int(n)]})
+
def jsi18n(request):
return render_to_response('jsi18n.html')
# Some views to exercise the shortcuts
+
def render_to_response_view(request):
return render_to_response('debug/render_test.html', {
'foo': 'FOO',
'bar': 'BAR',
})
+
def render_to_response_view_with_request_context(request):
return render_to_response('debug/render_test.html', {
'foo': 'FOO',
'bar': 'BAR',
}, context_instance=RequestContext(request))
+
def render_to_response_view_with_content_type(request):
return render_to_response('debug/render_test.html', {
'foo': 'FOO',
'bar': 'BAR',
}, content_type='application/x-rendertest')
+
def render_to_response_view_with_dirs(request):
return render_to_response('render_dirs_test.html', dirs=dirs)
+
def render_view(request):
return render(request, 'debug/render_test.html', {
'foo': 'FOO',
'bar': 'BAR',
})
+
def render_view_with_base_context(request):
return render(request, 'debug/render_test.html', {
'foo': 'FOO',
'bar': 'BAR',
}, context_instance=Context())
+
def render_view_with_content_type(request):
return render(request, 'debug/render_test.html', {
'foo': 'FOO',
'bar': 'BAR',
}, content_type='application/x-rendertest')
+
def render_view_with_status(request):
return render(request, 'debug/render_test.html', {
'foo': 'FOO',
'bar': 'BAR',
}, status=403)
+
def render_view_with_current_app(request):
return render(request, 'debug/render_test.html', {
'foo': 'FOO',
'bar': 'BAR',
}, current_app="foobar_app")
+
def render_view_with_current_app_conflict(request):
# This should fail because we don't passing both a current_app and
# context_instance:
@@ -129,9 +148,11 @@ def render_view_with_current_app_conflict(request):
'bar': 'BAR',
}, current_app="foobar_app", context_instance=RequestContext(request))
+
def render_with_dirs(request):
return render(request, 'render_dirs_test.html', dirs=dirs)
+
def raises_template_does_not_exist(request, path='i_dont_exist.html'):
# We need to inspect the HTML generated by the fancy 500 debug view but
# the test client ignores it, so we send it explicitly.
@@ -140,11 +161,13 @@ def raises_template_does_not_exist(request, path='i_dont_exist.html'):
except TemplateDoesNotExist:
return technical_500_response(request, *sys.exc_info())
+
def render_no_template(request):
# If we do not specify a template, we need to make sure the debug
# view doesn't blow up.
return render(request, [], {})
+
def send_log(request, exc_info):
logger = getLogger('django.request')
# The default logging config has a logging filter to ensure admin emails are
@@ -167,6 +190,7 @@ def send_log(request, exc_info):
)
admin_email_handler.filters = orig_filters
+
def non_sensitive_view(request):
# Do not just use plain strings for the variables' values in the code
# so that the tests don't return false positives when the function's source
@@ -180,6 +204,7 @@ def non_sensitive_view(request):
send_log(request, exc_info)
return technical_500_response(request, *exc_info)
+
@sensitive_variables('sauce')
@sensitive_post_parameters('bacon-key', 'sausage-key')
def sensitive_view(request):
@@ -195,6 +220,7 @@ def sensitive_view(request):
send_log(request, exc_info)
return technical_500_response(request, *exc_info)
+
@sensitive_variables()
@sensitive_post_parameters()
def paranoid_view(request):
@@ -210,6 +236,7 @@ def paranoid_view(request):
send_log(request, exc_info)
return technical_500_response(request, *exc_info)
+
def sensitive_args_function_caller(request):
try:
sensitive_args_function(''.join(['w', 'o', 'r', 'c', 'e', 's', 't', 'e', 'r', 's', 'h', 'i', 'r', 'e']))
@@ -218,6 +245,7 @@ def sensitive_args_function_caller(request):
send_log(request, exc_info)
return technical_500_response(request, *exc_info)
+
@sensitive_variables('sauce')
def sensitive_args_function(sauce):
# Do not just use plain strings for the variables' values in the code
@@ -226,6 +254,7 @@ def sensitive_args_function(sauce):
cooked_eggs = ''.join(['s', 'c', 'r', 'a', 'm', 'b', 'l', 'e', 'd']) # NOQA
raise Exception
+
def sensitive_kwargs_function_caller(request):
try:
sensitive_kwargs_function(''.join(['w', 'o', 'r', 'c', 'e', 's', 't', 'e', 'r', 's', 'h', 'i', 'r', 'e']))
@@ -234,6 +263,7 @@ def sensitive_kwargs_function_caller(request):
send_log(request, exc_info)
return technical_500_response(request, *exc_info)
+
@sensitive_variables('sauce')
def sensitive_kwargs_function(sauce=None):
# Do not just use plain strings for the variables' values in the code
@@ -242,6 +272,7 @@ def sensitive_kwargs_function(sauce=None):
cooked_eggs = ''.join(['s', 'c', 'r', 'a', 'm', 'b', 'l', 'e', 'd']) # NOQA
raise Exception
+
class UnsafeExceptionReporterFilter(SafeExceptionReporterFilter):
"""
Ignores all the filtering done by its parent class.
@@ -287,6 +318,7 @@ class Klass(object):
send_log(request, exc_info)
return technical_500_response(request, *exc_info)
+
def sensitive_method_view(request):
return Klass().method(request)
diff --git a/tests/wsgi/urls.py b/tests/wsgi/urls.py
index 7c6701adec..563b7238af 100644
--- a/tests/wsgi/urls.py
+++ b/tests/wsgi/urls.py
@@ -1,6 +1,7 @@
from django.conf.urls import url, patterns
from django.http import HttpResponse
+
def helloworld(request):
return HttpResponse("Hello World!")