Fixing E302 Errors
Signed-off-by: Jason Myers <jason@jasonamyers.com>
This commit is contained in:
parent
2a03a9a9a1
commit
c3791463a5
|
@ -104,6 +104,7 @@ class Media(object):
|
||||||
getattr(combined, 'add_' + name)(getattr(other, '_' + name, None))
|
getattr(combined, 'add_' + name)(getattr(other, '_' + name, None))
|
||||||
return combined
|
return combined
|
||||||
|
|
||||||
|
|
||||||
def media_property(cls):
|
def media_property(cls):
|
||||||
def _media(self):
|
def _media(self):
|
||||||
# Get the media property of the superclass, if it exists
|
# Get the media property of the superclass, if it exists
|
||||||
|
@ -131,6 +132,7 @@ def media_property(cls):
|
||||||
return base
|
return base
|
||||||
return property(_media)
|
return property(_media)
|
||||||
|
|
||||||
|
|
||||||
class MediaDefiningClass(type):
|
class MediaDefiningClass(type):
|
||||||
"""
|
"""
|
||||||
Metaclass for classes that can have media definitions.
|
Metaclass for classes that can have media definitions.
|
||||||
|
@ -162,6 +164,7 @@ class SubWidget(object):
|
||||||
args.append(self.choices)
|
args.append(self.choices)
|
||||||
return self.parent_widget.render(*args)
|
return self.parent_widget.render(*args)
|
||||||
|
|
||||||
|
|
||||||
class Widget(six.with_metaclass(MediaDefiningClass)):
|
class Widget(six.with_metaclass(MediaDefiningClass)):
|
||||||
is_hidden = False # Determines whether this corresponds to an <input type="hidden">.
|
is_hidden = False # Determines whether this corresponds to an <input type="hidden">.
|
||||||
needs_multipart_form = False # Determines does this widget need multipart form
|
needs_multipart_form = False # Determines does this widget need multipart form
|
||||||
|
@ -224,6 +227,7 @@ class Widget(six.with_metaclass(MediaDefiningClass)):
|
||||||
"""
|
"""
|
||||||
return id_
|
return id_
|
||||||
|
|
||||||
|
|
||||||
class Input(Widget):
|
class Input(Widget):
|
||||||
"""
|
"""
|
||||||
Base class for all <input> widgets (except type='checkbox' and
|
Base class for all <input> widgets (except type='checkbox' and
|
||||||
|
@ -279,10 +283,12 @@ class PasswordInput(TextInput):
|
||||||
value = None
|
value = None
|
||||||
return super(PasswordInput, self).render(name, value, attrs)
|
return super(PasswordInput, self).render(name, value, attrs)
|
||||||
|
|
||||||
|
|
||||||
class HiddenInput(Input):
|
class HiddenInput(Input):
|
||||||
input_type = 'hidden'
|
input_type = 'hidden'
|
||||||
is_hidden = True
|
is_hidden = True
|
||||||
|
|
||||||
|
|
||||||
class MultipleHiddenInput(HiddenInput):
|
class MultipleHiddenInput(HiddenInput):
|
||||||
"""
|
"""
|
||||||
A widget that handles <input type="hidden"> for fields that have a list
|
A widget that handles <input type="hidden"> for fields that have a list
|
||||||
|
@ -313,6 +319,7 @@ class MultipleHiddenInput(HiddenInput):
|
||||||
return data.getlist(name)
|
return data.getlist(name)
|
||||||
return data.get(name, None)
|
return data.get(name, None)
|
||||||
|
|
||||||
|
|
||||||
class FileInput(Input):
|
class FileInput(Input):
|
||||||
input_type = 'file'
|
input_type = 'file'
|
||||||
needs_multipart_form = True
|
needs_multipart_form = True
|
||||||
|
@ -327,6 +334,7 @@ class FileInput(Input):
|
||||||
|
|
||||||
FILE_INPUT_CONTRADICTION = object()
|
FILE_INPUT_CONTRADICTION = object()
|
||||||
|
|
||||||
|
|
||||||
class ClearableFileInput(FileInput):
|
class ClearableFileInput(FileInput):
|
||||||
initial_text = ugettext_lazy('Currently')
|
initial_text = ugettext_lazy('Currently')
|
||||||
input_text = ugettext_lazy('Change')
|
input_text = ugettext_lazy('Change')
|
||||||
|
@ -379,7 +387,8 @@ class ClearableFileInput(FileInput):
|
||||||
def value_from_datadict(self, data, files, name):
|
def value_from_datadict(self, data, files, name):
|
||||||
upload = super(ClearableFileInput, self).value_from_datadict(data, files, name)
|
upload = super(ClearableFileInput, self).value_from_datadict(data, files, name)
|
||||||
if not self.is_required and CheckboxInput().value_from_datadict(
|
if not self.is_required and CheckboxInput().value_from_datadict(
|
||||||
data, files, self.clear_checkbox_name(name)):
|
data, files, self.clear_checkbox_name(name)):
|
||||||
|
|
||||||
if upload:
|
if upload:
|
||||||
# If the user contradicts themselves (uploads a new file AND
|
# If the user contradicts themselves (uploads a new file AND
|
||||||
# checks the "clear" checkbox), we return a unique marker
|
# checks the "clear" checkbox), we return a unique marker
|
||||||
|
@ -389,6 +398,7 @@ class ClearableFileInput(FileInput):
|
||||||
return False
|
return False
|
||||||
return upload
|
return upload
|
||||||
|
|
||||||
|
|
||||||
class Textarea(Widget):
|
class Textarea(Widget):
|
||||||
def __init__(self, attrs=None):
|
def __init__(self, attrs=None):
|
||||||
# The 'rows' and 'cols' attributes are required for HTML correctness.
|
# The 'rows' and 'cols' attributes are required for HTML correctness.
|
||||||
|
@ -515,6 +525,7 @@ class Select(Widget):
|
||||||
output.append(self.render_option(selected_choices, option_value, option_label))
|
output.append(self.render_option(selected_choices, option_value, option_label))
|
||||||
return '\n'.join(output)
|
return '\n'.join(output)
|
||||||
|
|
||||||
|
|
||||||
class NullBooleanSelect(Select):
|
class NullBooleanSelect(Select):
|
||||||
"""
|
"""
|
||||||
A Select Widget intended to be used with NullBooleanField.
|
A Select Widget intended to be used with NullBooleanField.
|
||||||
|
@ -849,6 +860,7 @@ class SplitDateTimeWidget(MultiWidget):
|
||||||
return [value.date(), value.time().replace(microsecond=0)]
|
return [value.date(), value.time().replace(microsecond=0)]
|
||||||
return [None, None]
|
return [None, None]
|
||||||
|
|
||||||
|
|
||||||
class SplitHiddenDateTimeWidget(SplitDateTimeWidget):
|
class SplitHiddenDateTimeWidget(SplitDateTimeWidget):
|
||||||
"""
|
"""
|
||||||
A Widget that splits datetime input into two <input type="hidden"> inputs.
|
A Widget that splits datetime input into two <input type="hidden"> inputs.
|
||||||
|
|
|
@ -4,7 +4,7 @@ install-script = scripts/rpm-install.sh
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
exclude=./django/utils/dictconfig.py,./django/contrib/comments/*,./django/utils/unittest.py,./tests/comment_tests/*,./django/test/_doctest.py,./django/utils/six.py,./django/conf/app_template/*
|
exclude=./django/utils/dictconfig.py,./django/contrib/comments/*,./django/utils/unittest.py,./tests/comment_tests/*,./django/test/_doctest.py,./django/utils/six.py,./django/conf/app_template/*
|
||||||
ignore=E124,E125,E127,E128,E226,E251,E302,E501,E261,W601
|
ignore=E124,E125,E127,E128,E226,E251,E501,E261,W601
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
license-file = LICENSE
|
license-file = LICENSE
|
||||||
|
|
|
@ -50,7 +50,8 @@ class QueryTestCase(TestCase):
|
||||||
except Book.DoesNotExist:
|
except Book.DoesNotExist:
|
||||||
self.fail('"Pro Django" should exist on default database')
|
self.fail('"Pro Django" should exist on default database')
|
||||||
|
|
||||||
self.assertRaises(Book.DoesNotExist,
|
self.assertRaises(
|
||||||
|
Book.DoesNotExist,
|
||||||
Book.objects.using('other').get,
|
Book.objects.using('other').get,
|
||||||
title="Pro Django"
|
title="Pro Django"
|
||||||
)
|
)
|
||||||
|
@ -61,7 +62,8 @@ class QueryTestCase(TestCase):
|
||||||
except Book.DoesNotExist:
|
except Book.DoesNotExist:
|
||||||
self.fail('"Dive into Python" should exist on default database')
|
self.fail('"Dive into Python" should exist on default database')
|
||||||
|
|
||||||
self.assertRaises(Book.DoesNotExist,
|
self.assertRaises(
|
||||||
|
Book.DoesNotExist,
|
||||||
Book.objects.using('other').get,
|
Book.objects.using('other').get,
|
||||||
title="Dive into Python"
|
title="Dive into Python"
|
||||||
)
|
)
|
||||||
|
@ -84,11 +86,13 @@ class QueryTestCase(TestCase):
|
||||||
except Book.DoesNotExist:
|
except Book.DoesNotExist:
|
||||||
self.fail('"Pro Django" should exist on other database')
|
self.fail('"Pro Django" should exist on other database')
|
||||||
|
|
||||||
self.assertRaises(Book.DoesNotExist,
|
self.assertRaises(
|
||||||
|
Book.DoesNotExist,
|
||||||
Book.objects.get,
|
Book.objects.get,
|
||||||
title="Pro Django"
|
title="Pro Django"
|
||||||
)
|
)
|
||||||
self.assertRaises(Book.DoesNotExist,
|
self.assertRaises(
|
||||||
|
Book.DoesNotExist,
|
||||||
Book.objects.using('default').get,
|
Book.objects.using('default').get,
|
||||||
title="Pro Django"
|
title="Pro Django"
|
||||||
)
|
)
|
||||||
|
@ -98,11 +102,13 @@ class QueryTestCase(TestCase):
|
||||||
except Book.DoesNotExist:
|
except Book.DoesNotExist:
|
||||||
self.fail('"Dive into Python" should exist on other database')
|
self.fail('"Dive into Python" should exist on other database')
|
||||||
|
|
||||||
self.assertRaises(Book.DoesNotExist,
|
self.assertRaises(
|
||||||
|
Book.DoesNotExist,
|
||||||
Book.objects.get,
|
Book.objects.get,
|
||||||
title="Dive into Python"
|
title="Dive into Python"
|
||||||
)
|
)
|
||||||
self.assertRaises(Book.DoesNotExist,
|
self.assertRaises(
|
||||||
|
Book.DoesNotExist,
|
||||||
Book.objects.using('default').get,
|
Book.objects.using('default').get,
|
||||||
title="Dive into Python"
|
title="Dive into Python"
|
||||||
)
|
)
|
||||||
|
@ -164,14 +170,14 @@ class QueryTestCase(TestCase):
|
||||||
|
|
||||||
# Check that queries work across m2m joins
|
# Check that queries work across m2m joins
|
||||||
self.assertEqual(list(Book.objects.using('default').filter(authors__name='Marty Alchin').values_list('title', flat=True)),
|
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('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('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)),
|
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
|
# Reget the objects to clear caches
|
||||||
dive = Book.objects.using('other').get(title="Dive into Python")
|
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
|
# Retrive related object by descriptor. Related objects should be database-baound
|
||||||
self.assertEqual(list(dive.authors.all().values_list('name', flat=True)),
|
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)),
|
self.assertEqual(list(mark.book_set.all().values_list('title', flat=True)),
|
||||||
['Dive into Python'])
|
['Dive into Python'])
|
||||||
|
|
||||||
def test_m2m_forward_operations(self):
|
def test_m2m_forward_operations(self):
|
||||||
"M2M forward manipulations are all constrained to a single DB"
|
"M2M forward manipulations are all constrained to a single DB"
|
||||||
|
@ -198,13 +204,13 @@ class QueryTestCase(TestCase):
|
||||||
# Add a second author
|
# Add a second author
|
||||||
john = Person.objects.using('other').create(name="John Smith")
|
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)),
|
self.assertEqual(list(Book.objects.using('other').filter(authors__name='John Smith').values_list('title', flat=True)),
|
||||||
[])
|
[])
|
||||||
|
|
||||||
dive.authors.add(john)
|
dive.authors.add(john)
|
||||||
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='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)),
|
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
|
# Remove the second author
|
||||||
dive.authors.remove(john)
|
dive.authors.remove(john)
|
||||||
|
|
|
@ -13,6 +13,7 @@ class Parent(models.Model):
|
||||||
# Use a simple string for forward declarations.
|
# Use a simple string for forward declarations.
|
||||||
bestchild = models.ForeignKey("Child", null=True, related_name="favoured_by")
|
bestchild = models.ForeignKey("Child", null=True, related_name="favoured_by")
|
||||||
|
|
||||||
|
|
||||||
class Child(models.Model):
|
class Child(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ class Event(models.Model):
|
||||||
class Screening(Event):
|
class Screening(Event):
|
||||||
movie = models.ForeignKey(Movie)
|
movie = models.ForeignKey(Movie)
|
||||||
|
|
||||||
|
|
||||||
class ScreeningNullFK(Event):
|
class ScreeningNullFK(Event):
|
||||||
movie = models.ForeignKey(Movie, null=True)
|
movie = models.ForeignKey(Movie, null=True)
|
||||||
|
|
||||||
|
@ -24,5 +25,6 @@ class ScreeningNullFK(Event):
|
||||||
class Package(models.Model):
|
class Package(models.Model):
|
||||||
screening = models.ForeignKey(Screening, null=True)
|
screening = models.ForeignKey(Screening, null=True)
|
||||||
|
|
||||||
|
|
||||||
class PackageNullFK(models.Model):
|
class PackageNullFK(models.Model):
|
||||||
screening = models.ForeignKey(ScreeningNullFK, null=True)
|
screening = models.ForeignKey(ScreeningNullFK, null=True)
|
||||||
|
|
|
@ -9,14 +9,17 @@ from django.utils.encoding import python_2_unicode_compatible
|
||||||
class SystemDetails(models.Model):
|
class SystemDetails(models.Model):
|
||||||
details = models.TextField()
|
details = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
class SystemInfo(models.Model):
|
class SystemInfo(models.Model):
|
||||||
system_details = models.ForeignKey(SystemDetails)
|
system_details = models.ForeignKey(SystemDetails)
|
||||||
system_name = models.CharField(max_length=32)
|
system_name = models.CharField(max_length=32)
|
||||||
|
|
||||||
|
|
||||||
class Forum(models.Model):
|
class Forum(models.Model):
|
||||||
system_info = models.ForeignKey(SystemInfo)
|
system_info = models.ForeignKey(SystemInfo)
|
||||||
forum_name = models.CharField(max_length=32)
|
forum_name = models.CharField(max_length=32)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Post(models.Model):
|
class Post(models.Model):
|
||||||
forum = models.ForeignKey(Forum, null=True)
|
forum = models.ForeignKey(Forum, null=True)
|
||||||
|
@ -25,6 +28,7 @@ class Post(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Comment(models.Model):
|
class Comment(models.Model):
|
||||||
post = models.ForeignKey(Post, null=True)
|
post = models.ForeignKey(Post, null=True)
|
||||||
|
@ -38,12 +42,15 @@ class Comment(models.Model):
|
||||||
|
|
||||||
# Ticket 15823
|
# Ticket 15823
|
||||||
|
|
||||||
|
|
||||||
class Item(models.Model):
|
class Item(models.Model):
|
||||||
title = models.CharField(max_length=100)
|
title = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
|
||||||
class PropertyValue(models.Model):
|
class PropertyValue(models.Model):
|
||||||
label = models.CharField(max_length=100)
|
label = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
|
||||||
class Property(models.Model):
|
class Property(models.Model):
|
||||||
item = models.ForeignKey(Item, related_name='props')
|
item = models.ForeignKey(Item, related_name='props')
|
||||||
key = models.CharField(max_length=100)
|
key = models.CharField(max_length=100)
|
||||||
|
|
|
@ -15,6 +15,7 @@ from django.utils.encoding import python_2_unicode_compatible
|
||||||
class Author(models.Model):
|
class Author(models.Model):
|
||||||
name = models.CharField(max_length=150)
|
name = models.CharField(max_length=150)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Article(models.Model):
|
class Article(models.Model):
|
||||||
title = models.CharField(max_length=150)
|
title = models.CharField(max_length=150)
|
||||||
|
@ -31,10 +32,12 @@ class Article(models.Model):
|
||||||
class SystemInfo(models.Model):
|
class SystemInfo(models.Model):
|
||||||
system_name = models.CharField(max_length=32)
|
system_name = models.CharField(max_length=32)
|
||||||
|
|
||||||
|
|
||||||
class Forum(models.Model):
|
class Forum(models.Model):
|
||||||
system_info = models.ForeignKey(SystemInfo)
|
system_info = models.ForeignKey(SystemInfo)
|
||||||
forum_name = models.CharField(max_length=32)
|
forum_name = models.CharField(max_length=32)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Post(models.Model):
|
class Post(models.Model):
|
||||||
forum = models.ForeignKey(Forum, null=True)
|
forum = models.ForeignKey(Forum, null=True)
|
||||||
|
@ -43,6 +46,7 @@ class Post(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Comment(models.Model):
|
class Comment(models.Model):
|
||||||
post = models.ForeignKey(Post, null=True)
|
post = models.ForeignKey(Post, null=True)
|
||||||
|
|
|
@ -11,6 +11,7 @@ class Poll(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Q: %s " % self.question
|
return "Q: %s " % self.question
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Choice(models.Model):
|
class Choice(models.Model):
|
||||||
poll = models.ForeignKey(Poll)
|
poll = models.ForeignKey(Poll)
|
||||||
|
@ -20,12 +21,16 @@ class Choice(models.Model):
|
||||||
return "Choice: %s in poll %s" % (self.choice, self.poll)
|
return "Choice: %s in poll %s" % (self.choice, self.poll)
|
||||||
|
|
||||||
# A set of models with an inner one pointing to two outer ones.
|
# A set of models with an inner one pointing to two outer ones.
|
||||||
|
|
||||||
|
|
||||||
class OuterA(models.Model):
|
class OuterA(models.Model):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class OuterB(models.Model):
|
class OuterB(models.Model):
|
||||||
data = models.CharField(max_length=10)
|
data = models.CharField(max_length=10)
|
||||||
|
|
||||||
|
|
||||||
class Inner(models.Model):
|
class Inner(models.Model):
|
||||||
first = models.ForeignKey(OuterA)
|
first = models.ForeignKey(OuterA)
|
||||||
# second would clash with the __second lookup.
|
# second would clash with the __second lookup.
|
||||||
|
|
|
@ -19,6 +19,7 @@ class Place(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s the place" % self.name
|
return "%s the place" % self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Restaurant(models.Model):
|
class Restaurant(models.Model):
|
||||||
place = models.OneToOneField(Place, primary_key=True)
|
place = models.OneToOneField(Place, primary_key=True)
|
||||||
|
@ -28,6 +29,7 @@ class Restaurant(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s the restaurant" % self.place.name
|
return "%s the restaurant" % self.place.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Waiter(models.Model):
|
class Waiter(models.Model):
|
||||||
restaurant = models.ForeignKey(Restaurant)
|
restaurant = models.ForeignKey(Restaurant)
|
||||||
|
@ -36,13 +38,16 @@ class Waiter(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s the waiter at %s" % (self.name, self.restaurant)
|
return "%s the waiter at %s" % (self.name, self.restaurant)
|
||||||
|
|
||||||
|
|
||||||
class ManualPrimaryKey(models.Model):
|
class ManualPrimaryKey(models.Model):
|
||||||
primary_key = models.CharField(max_length=10, primary_key=True)
|
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):
|
class RelatedModel(models.Model):
|
||||||
link = models.OneToOneField(ManualPrimaryKey)
|
link = models.OneToOneField(ManualPrimaryKey)
|
||||||
name = models.CharField(max_length = 50)
|
name = models.CharField(max_length=50)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class MultiModel(models.Model):
|
class MultiModel(models.Model):
|
||||||
|
|
|
@ -6,6 +6,7 @@ from django.test import TestCase
|
||||||
from .models import (Place, Restaurant, Waiter, ManualPrimaryKey, RelatedModel,
|
from .models import (Place, Restaurant, Waiter, ManualPrimaryKey, RelatedModel,
|
||||||
MultiModel)
|
MultiModel)
|
||||||
|
|
||||||
|
|
||||||
class OneToOneTests(TestCase):
|
class OneToOneTests(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -10,6 +10,7 @@ from django.utils.encoding import python_2_unicode_compatible
|
||||||
class Question(models.Model):
|
class Question(models.Model):
|
||||||
text = models.CharField(max_length=200)
|
text = models.CharField(max_length=200)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Answer(models.Model):
|
class Answer(models.Model):
|
||||||
text = models.CharField(max_length=200)
|
text = models.CharField(max_length=200)
|
||||||
|
@ -21,6 +22,7 @@ class Answer(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return six.text_type(self.text)
|
return six.text_type(self.text)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Post(models.Model):
|
class Post(models.Model):
|
||||||
title = models.CharField(max_length=200)
|
title = models.CharField(max_length=200)
|
||||||
|
|
|
@ -28,6 +28,7 @@ class Article(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.headline
|
return self.headline
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class ArticlePKOrdering(models.Model):
|
class ArticlePKOrdering(models.Model):
|
||||||
headline = models.CharField(max_length=100)
|
headline = models.CharField(max_length=100)
|
||||||
|
|
|
@ -5,6 +5,7 @@ from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
|
||||||
## Basic tests
|
## Basic tests
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Author(models.Model):
|
class Author(models.Model):
|
||||||
name = models.CharField(max_length=50, unique=True)
|
name = models.CharField(max_length=50, unique=True)
|
||||||
|
@ -55,6 +56,7 @@ class Book(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['id']
|
ordering = ['id']
|
||||||
|
|
||||||
|
|
||||||
class BookWithYear(Book):
|
class BookWithYear(Book):
|
||||||
book = models.OneToOneField(Book, parent_link=True)
|
book = models.OneToOneField(Book, parent_link=True)
|
||||||
published_year = models.IntegerField()
|
published_year = models.IntegerField()
|
||||||
|
@ -73,12 +75,14 @@ class Reader(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['id']
|
ordering = ['id']
|
||||||
|
|
||||||
|
|
||||||
class BookReview(models.Model):
|
class BookReview(models.Model):
|
||||||
book = models.ForeignKey(BookWithYear)
|
book = models.ForeignKey(BookWithYear)
|
||||||
notes = models.TextField(null=True, blank=True)
|
notes = models.TextField(null=True, blank=True)
|
||||||
|
|
||||||
## Models for default manager tests
|
## Models for default manager tests
|
||||||
|
|
||||||
|
|
||||||
class Qualification(models.Model):
|
class Qualification(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
|
|
||||||
|
@ -161,6 +165,7 @@ class House(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['id']
|
ordering = ['id']
|
||||||
|
|
||||||
|
|
||||||
class Room(models.Model):
|
class Room(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
house = models.ForeignKey(House, related_name='rooms')
|
house = models.ForeignKey(House, related_name='rooms')
|
||||||
|
|
|
@ -5,9 +5,11 @@ from django.db import models
|
||||||
class ConcreteModel(models.Model):
|
class ConcreteModel(models.Model):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ConcreteModelSubclass(ConcreteModel):
|
class ConcreteModelSubclass(ConcreteModel):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ConcreteModelSubclassProxy(ConcreteModelSubclass):
|
class ConcreteModelSubclassProxy(ConcreteModelSubclass):
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
|
|
|
@ -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.
|
# A couple of managers for testing managing overriding in proxy model cases.
|
||||||
|
|
||||||
|
|
||||||
class PersonManager(models.Manager):
|
class PersonManager(models.Manager):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return super(PersonManager, self).get_queryset().exclude(name="fred")
|
return super(PersonManager, self).get_queryset().exclude(name="fred")
|
||||||
|
|
||||||
|
|
||||||
class SubManager(models.Manager):
|
class SubManager(models.Manager):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return super(SubManager, self).get_queryset().exclude(name="wilma")
|
return super(SubManager, self).get_queryset().exclude(name="wilma")
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Person(models.Model):
|
class Person(models.Model):
|
||||||
"""
|
"""
|
||||||
|
@ -29,6 +32,7 @@ class Person(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Abstract(models.Model):
|
class Abstract(models.Model):
|
||||||
"""
|
"""
|
||||||
A simple abstract base class, to be used for error checking.
|
A simple abstract base class, to be used for error checking.
|
||||||
|
@ -38,6 +42,7 @@ class Abstract(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
class MyPerson(Person):
|
class MyPerson(Person):
|
||||||
"""
|
"""
|
||||||
A proxy subclass, this should not get a new table. Overrides the default
|
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):
|
def has_special_name(self):
|
||||||
return self.name.lower() == "special"
|
return self.name.lower() == "special"
|
||||||
|
|
||||||
|
|
||||||
class ManagerMixin(models.Model):
|
class ManagerMixin(models.Model):
|
||||||
excluder = SubManager()
|
excluder = SubManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
class OtherPerson(Person, ManagerMixin):
|
class OtherPerson(Person, ManagerMixin):
|
||||||
"""
|
"""
|
||||||
A class with the default manager from Person, plus an secondary manager.
|
A class with the default manager from Person, plus an secondary manager.
|
||||||
|
@ -70,6 +77,7 @@ class OtherPerson(Person, ManagerMixin):
|
||||||
proxy = True
|
proxy = True
|
||||||
ordering = ["name"]
|
ordering = ["name"]
|
||||||
|
|
||||||
|
|
||||||
class StatusPerson(MyPerson):
|
class StatusPerson(MyPerson):
|
||||||
"""
|
"""
|
||||||
A non-proxy subclass of a proxy, it should get a new table.
|
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)
|
status = models.CharField(max_length=80)
|
||||||
|
|
||||||
# We can even have proxies of proxies (and subclass of those).
|
# We can even have proxies of proxies (and subclass of those).
|
||||||
|
|
||||||
|
|
||||||
class MyPersonProxy(MyPerson):
|
class MyPersonProxy(MyPerson):
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
|
|
||||||
|
|
||||||
class LowerStatusPerson(MyPersonProxy):
|
class LowerStatusPerson(MyPersonProxy):
|
||||||
status = models.CharField(max_length=80)
|
status = models.CharField(max_length=80)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class User(models.Model):
|
class User(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
|
@ -91,18 +103,23 @@ class User(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class UserProxy(User):
|
class UserProxy(User):
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
|
|
||||||
|
|
||||||
class UserProxyProxy(UserProxy):
|
class UserProxyProxy(UserProxy):
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
|
|
||||||
# We can still use `select_related()` to include related models in our querysets.
|
# We can still use `select_related()` to include related models in our querysets.
|
||||||
|
|
||||||
|
|
||||||
class Country(models.Model):
|
class Country(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class State(models.Model):
|
class State(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -111,12 +128,15 @@ class State(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class StateProxy(State):
|
class StateProxy(State):
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
|
|
||||||
# Proxy models still works with filters (on related fields)
|
# Proxy models still works with filters (on related fields)
|
||||||
# and select_related, even when mixed with model inheritance
|
# and select_related, even when mixed with model inheritance
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class BaseUser(models.Model):
|
class BaseUser(models.Model):
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
|
@ -124,9 +144,11 @@ class BaseUser(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return ':'.join((self.__class__.__name__, self.name,))
|
return ':'.join((self.__class__.__name__, self.name,))
|
||||||
|
|
||||||
|
|
||||||
class TrackerUser(BaseUser):
|
class TrackerUser(BaseUser):
|
||||||
status = models.CharField(max_length=50)
|
status = models.CharField(max_length=50)
|
||||||
|
|
||||||
|
|
||||||
class ProxyTrackerUser(TrackerUser):
|
class ProxyTrackerUser(TrackerUser):
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
|
@ -140,10 +162,12 @@ class Issue(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return ':'.join((self.__class__.__name__, self.summary,))
|
return ':'.join((self.__class__.__name__, self.summary,))
|
||||||
|
|
||||||
|
|
||||||
class Bug(Issue):
|
class Bug(Issue):
|
||||||
version = models.CharField(max_length=50)
|
version = models.CharField(max_length=50)
|
||||||
reporter = models.ForeignKey(BaseUser)
|
reporter = models.ForeignKey(BaseUser)
|
||||||
|
|
||||||
|
|
||||||
class ProxyBug(Bug):
|
class ProxyBug(Bug):
|
||||||
"""
|
"""
|
||||||
Proxy of an inherited class
|
Proxy of an inherited class
|
||||||
|
@ -159,6 +183,7 @@ class ProxyProxyBug(ProxyBug):
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
|
|
||||||
|
|
||||||
class Improvement(Issue):
|
class Improvement(Issue):
|
||||||
"""
|
"""
|
||||||
A model that has relation to a proxy model
|
A model that has relation to a proxy model
|
||||||
|
@ -168,6 +193,7 @@ class Improvement(Issue):
|
||||||
reporter = models.ForeignKey(ProxyTrackerUser)
|
reporter = models.ForeignKey(ProxyTrackerUser)
|
||||||
associated_bug = models.ForeignKey(ProxyProxyBug)
|
associated_bug = models.ForeignKey(ProxyProxyBug)
|
||||||
|
|
||||||
|
|
||||||
class ProxyImprovement(Improvement):
|
class ProxyImprovement(Improvement):
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
|
|
|
@ -13,10 +13,12 @@ from django.utils.encoding import python_2_unicode_compatible
|
||||||
class DumbCategory(models.Model):
|
class DumbCategory(models.Model):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ProxyCategory(DumbCategory):
|
class ProxyCategory(DumbCategory):
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class NamedCategory(DumbCategory):
|
class NamedCategory(DumbCategory):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
|
@ -24,6 +26,7 @@ class NamedCategory(DumbCategory):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Tag(models.Model):
|
class Tag(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
|
@ -37,6 +40,7 @@ class Tag(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Note(models.Model):
|
class Note(models.Model):
|
||||||
note = models.CharField(max_length=100)
|
note = models.CharField(max_length=100)
|
||||||
|
@ -55,6 +59,7 @@ class Note(models.Model):
|
||||||
# that use objects of that type as an argument.
|
# that use objects of that type as an argument.
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Annotation(models.Model):
|
class Annotation(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
|
@ -64,6 +69,7 @@ class Annotation(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class ExtraInfo(models.Model):
|
class ExtraInfo(models.Model):
|
||||||
info = models.CharField(max_length=100)
|
info = models.CharField(max_length=100)
|
||||||
|
@ -76,6 +82,7 @@ class ExtraInfo(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.info
|
return self.info
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Author(models.Model):
|
class Author(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
|
@ -88,6 +95,7 @@ class Author(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Item(models.Model):
|
class Item(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
|
@ -103,6 +111,7 @@ class Item(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Report(models.Model):
|
class Report(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
|
@ -111,6 +120,7 @@ class Report(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Ranking(models.Model):
|
class Ranking(models.Model):
|
||||||
rank = models.IntegerField()
|
rank = models.IntegerField()
|
||||||
|
@ -123,6 +133,7 @@ class Ranking(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '%d: %s' % (self.rank, self.author.name)
|
return '%d: %s' % (self.rank, self.author.name)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Cover(models.Model):
|
class Cover(models.Model):
|
||||||
title = models.CharField(max_length=50)
|
title = models.CharField(max_length=50)
|
||||||
|
@ -134,6 +145,7 @@ class Cover(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Number(models.Model):
|
class Number(models.Model):
|
||||||
num = models.IntegerField()
|
num = models.IntegerField()
|
||||||
|
@ -143,6 +155,8 @@ class Number(models.Model):
|
||||||
|
|
||||||
# Symmetrical m2m field with a normal field using the reverse accesor name
|
# Symmetrical m2m field with a normal field using the reverse accesor name
|
||||||
# ("valid").
|
# ("valid").
|
||||||
|
|
||||||
|
|
||||||
class Valid(models.Model):
|
class Valid(models.Model):
|
||||||
valid = models.CharField(max_length=10)
|
valid = models.CharField(max_length=10)
|
||||||
parent = models.ManyToManyField('self')
|
parent = models.ManyToManyField('self')
|
||||||
|
@ -152,38 +166,49 @@ class Valid(models.Model):
|
||||||
|
|
||||||
# Some funky cross-linked models for testing a couple of infinite recursion
|
# Some funky cross-linked models for testing a couple of infinite recursion
|
||||||
# cases.
|
# cases.
|
||||||
|
|
||||||
|
|
||||||
class X(models.Model):
|
class X(models.Model):
|
||||||
y = models.ForeignKey('Y')
|
y = models.ForeignKey('Y')
|
||||||
|
|
||||||
|
|
||||||
class Y(models.Model):
|
class Y(models.Model):
|
||||||
x1 = models.ForeignKey(X, related_name='y1')
|
x1 = models.ForeignKey(X, related_name='y1')
|
||||||
|
|
||||||
# Some models with a cycle in the default ordering. This would be bad if we
|
# Some models with a cycle in the default ordering. This would be bad if we
|
||||||
# didn't catch the infinite loop.
|
# didn't catch the infinite loop.
|
||||||
|
|
||||||
|
|
||||||
class LoopX(models.Model):
|
class LoopX(models.Model):
|
||||||
y = models.ForeignKey('LoopY')
|
y = models.ForeignKey('LoopY')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['y']
|
ordering = ['y']
|
||||||
|
|
||||||
|
|
||||||
class LoopY(models.Model):
|
class LoopY(models.Model):
|
||||||
x = models.ForeignKey(LoopX)
|
x = models.ForeignKey(LoopX)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['x']
|
ordering = ['x']
|
||||||
|
|
||||||
|
|
||||||
class LoopZ(models.Model):
|
class LoopZ(models.Model):
|
||||||
z = models.ForeignKey('self')
|
z = models.ForeignKey('self')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['z']
|
ordering = ['z']
|
||||||
|
|
||||||
|
|
||||||
# A model and custom default manager combination.
|
# A model and custom default manager combination.
|
||||||
|
|
||||||
|
|
||||||
class CustomManager(models.Manager):
|
class CustomManager(models.Manager):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
qs = super(CustomManager, self).get_queryset()
|
qs = super(CustomManager, self).get_queryset()
|
||||||
return qs.filter(public=True, tag__name='t1')
|
return qs.filter(public=True, tag__name='t1')
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class ManagedModel(models.Model):
|
class ManagedModel(models.Model):
|
||||||
data = models.CharField(max_length=10)
|
data = models.CharField(max_length=10)
|
||||||
|
@ -197,24 +222,31 @@ class ManagedModel(models.Model):
|
||||||
return self.data
|
return self.data
|
||||||
|
|
||||||
# An inter-related setup with multiple paths from Child to Detail.
|
# An inter-related setup with multiple paths from Child to Detail.
|
||||||
|
|
||||||
|
|
||||||
class Detail(models.Model):
|
class Detail(models.Model):
|
||||||
data = models.CharField(max_length=10)
|
data = models.CharField(max_length=10)
|
||||||
|
|
||||||
|
|
||||||
class MemberManager(models.Manager):
|
class MemberManager(models.Manager):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return super(MemberManager, self).get_queryset().select_related("details")
|
return super(MemberManager, self).get_queryset().select_related("details")
|
||||||
|
|
||||||
|
|
||||||
class Member(models.Model):
|
class Member(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
details = models.OneToOneField(Detail, primary_key=True)
|
details = models.OneToOneField(Detail, primary_key=True)
|
||||||
|
|
||||||
objects = MemberManager()
|
objects = MemberManager()
|
||||||
|
|
||||||
|
|
||||||
class Child(models.Model):
|
class Child(models.Model):
|
||||||
person = models.OneToOneField(Member, primary_key=True)
|
person = models.OneToOneField(Member, primary_key=True)
|
||||||
parent = models.ForeignKey(Member, related_name="children")
|
parent = models.ForeignKey(Member, related_name="children")
|
||||||
|
|
||||||
# Custom primary keys interfered with ordering in the past.
|
# Custom primary keys interfered with ordering in the past.
|
||||||
|
|
||||||
|
|
||||||
class CustomPk(models.Model):
|
class CustomPk(models.Model):
|
||||||
name = models.CharField(max_length=10, primary_key=True)
|
name = models.CharField(max_length=10, primary_key=True)
|
||||||
extra = models.CharField(max_length=10)
|
extra = models.CharField(max_length=10)
|
||||||
|
@ -222,12 +254,14 @@ class CustomPk(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['name', 'extra']
|
ordering = ['name', 'extra']
|
||||||
|
|
||||||
|
|
||||||
class Related(models.Model):
|
class Related(models.Model):
|
||||||
custom = models.ForeignKey(CustomPk)
|
custom = models.ForeignKey(CustomPk)
|
||||||
|
|
||||||
# An inter-related setup with a model subclass that has a nullable
|
# An inter-related setup with a model subclass that has a nullable
|
||||||
# path to another model, and a return path from that model.
|
# path to another model, and a return path from that model.
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Celebrity(models.Model):
|
class Celebrity(models.Model):
|
||||||
name = models.CharField("Name", max_length=20)
|
name = models.CharField("Name", max_length=20)
|
||||||
|
@ -236,13 +270,17 @@ class Celebrity(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class TvChef(Celebrity):
|
class TvChef(Celebrity):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Fan(models.Model):
|
class Fan(models.Model):
|
||||||
fan_of = models.ForeignKey(Celebrity)
|
fan_of = models.ForeignKey(Celebrity)
|
||||||
|
|
||||||
# Multiple foreign keys
|
# Multiple foreign keys
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class LeafA(models.Model):
|
class LeafA(models.Model):
|
||||||
data = models.CharField(max_length=10)
|
data = models.CharField(max_length=10)
|
||||||
|
@ -250,13 +288,16 @@ class LeafA(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.data
|
return self.data
|
||||||
|
|
||||||
|
|
||||||
class LeafB(models.Model):
|
class LeafB(models.Model):
|
||||||
data = models.CharField(max_length=10)
|
data = models.CharField(max_length=10)
|
||||||
|
|
||||||
|
|
||||||
class Join(models.Model):
|
class Join(models.Model):
|
||||||
a = models.ForeignKey(LeafA)
|
a = models.ForeignKey(LeafA)
|
||||||
b = models.ForeignKey(LeafB)
|
b = models.ForeignKey(LeafB)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class ReservedName(models.Model):
|
class ReservedName(models.Model):
|
||||||
name = models.CharField(max_length=20)
|
name = models.CharField(max_length=20)
|
||||||
|
@ -266,6 +307,8 @@ class ReservedName(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
# A simpler shared-foreign-key setup that can expose some problems.
|
# A simpler shared-foreign-key setup that can expose some problems.
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class SharedConnection(models.Model):
|
class SharedConnection(models.Model):
|
||||||
data = models.CharField(max_length=10)
|
data = models.CharField(max_length=10)
|
||||||
|
@ -273,13 +316,17 @@ class SharedConnection(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.data
|
return self.data
|
||||||
|
|
||||||
|
|
||||||
class PointerA(models.Model):
|
class PointerA(models.Model):
|
||||||
connection = models.ForeignKey(SharedConnection)
|
connection = models.ForeignKey(SharedConnection)
|
||||||
|
|
||||||
|
|
||||||
class PointerB(models.Model):
|
class PointerB(models.Model):
|
||||||
connection = models.ForeignKey(SharedConnection)
|
connection = models.ForeignKey(SharedConnection)
|
||||||
|
|
||||||
# Multi-layer ordering
|
# Multi-layer ordering
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class SingleObject(models.Model):
|
class SingleObject(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
|
@ -290,6 +337,7 @@ class SingleObject(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class RelatedObject(models.Model):
|
class RelatedObject(models.Model):
|
||||||
single = models.ForeignKey(SingleObject, null=True)
|
single = models.ForeignKey(SingleObject, null=True)
|
||||||
f = models.IntegerField(null=True)
|
f = models.IntegerField(null=True)
|
||||||
|
@ -297,6 +345,7 @@ class RelatedObject(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['single']
|
ordering = ['single']
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Plaything(models.Model):
|
class Plaything(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
|
@ -308,10 +357,12 @@ class Plaything(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Article(models.Model):
|
class Article(models.Model):
|
||||||
name = models.CharField(max_length=20)
|
name = models.CharField(max_length=20)
|
||||||
created = models.DateTimeField()
|
created = models.DateTimeField()
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Food(models.Model):
|
class Food(models.Model):
|
||||||
name = models.CharField(max_length=20, unique=True)
|
name = models.CharField(max_length=20, unique=True)
|
||||||
|
@ -319,6 +370,7 @@ class Food(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Eaten(models.Model):
|
class Eaten(models.Model):
|
||||||
food = models.ForeignKey(Food, to_field="name", null=True)
|
food = models.ForeignKey(Food, to_field="name", null=True)
|
||||||
|
@ -327,6 +379,7 @@ class Eaten(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s at %s" % (self.food, self.meal)
|
return "%s at %s" % (self.food, self.meal)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Node(models.Model):
|
class Node(models.Model):
|
||||||
num = models.IntegerField(unique=True)
|
num = models.IntegerField(unique=True)
|
||||||
|
@ -336,6 +389,8 @@ class Node(models.Model):
|
||||||
return "%s" % self.num
|
return "%s" % self.num
|
||||||
|
|
||||||
# Bug #12252
|
# Bug #12252
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class ObjectA(models.Model):
|
class ObjectA(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -343,6 +398,7 @@ class ObjectA(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class ObjectB(models.Model):
|
class ObjectB(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -352,6 +408,7 @@ class ObjectB(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class ObjectC(models.Model):
|
class ObjectC(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -361,6 +418,7 @@ class ObjectC(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class SimpleCategory(models.Model):
|
class SimpleCategory(models.Model):
|
||||||
name = models.CharField(max_length=15)
|
name = models.CharField(max_length=15)
|
||||||
|
@ -368,6 +426,7 @@ class SimpleCategory(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class SpecialCategory(SimpleCategory):
|
class SpecialCategory(SimpleCategory):
|
||||||
special_name = models.CharField(max_length=15)
|
special_name = models.CharField(max_length=15)
|
||||||
|
@ -375,6 +434,7 @@ class SpecialCategory(SimpleCategory):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name + " " + self.special_name
|
return self.name + " " + self.special_name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class CategoryItem(models.Model):
|
class CategoryItem(models.Model):
|
||||||
category = models.ForeignKey(SimpleCategory)
|
category = models.ForeignKey(SimpleCategory)
|
||||||
|
@ -382,6 +442,7 @@ class CategoryItem(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "category item: " + str(self.category)
|
return "category item: " + str(self.category)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class OneToOneCategory(models.Model):
|
class OneToOneCategory(models.Model):
|
||||||
new_name = models.CharField(max_length=15)
|
new_name = models.CharField(max_length=15)
|
||||||
|
@ -390,31 +451,38 @@ class OneToOneCategory(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "one2one " + self.new_name
|
return "one2one " + self.new_name
|
||||||
|
|
||||||
|
|
||||||
class CategoryRelationship(models.Model):
|
class CategoryRelationship(models.Model):
|
||||||
first = models.ForeignKey(SimpleCategory, related_name='first_rel')
|
first = models.ForeignKey(SimpleCategory, related_name='first_rel')
|
||||||
second = models.ForeignKey(SimpleCategory, related_name='second_rel')
|
second = models.ForeignKey(SimpleCategory, related_name='second_rel')
|
||||||
|
|
||||||
|
|
||||||
class NullableName(models.Model):
|
class NullableName(models.Model):
|
||||||
name = models.CharField(max_length=20, null=True)
|
name = models.CharField(max_length=20, null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['id']
|
ordering = ['id']
|
||||||
|
|
||||||
|
|
||||||
class ModelD(models.Model):
|
class ModelD(models.Model):
|
||||||
name = models.TextField()
|
name = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
class ModelC(models.Model):
|
class ModelC(models.Model):
|
||||||
name = models.TextField()
|
name = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
class ModelB(models.Model):
|
class ModelB(models.Model):
|
||||||
name = models.TextField()
|
name = models.TextField()
|
||||||
c = models.ForeignKey(ModelC)
|
c = models.ForeignKey(ModelC)
|
||||||
|
|
||||||
|
|
||||||
class ModelA(models.Model):
|
class ModelA(models.Model):
|
||||||
name = models.TextField()
|
name = models.TextField()
|
||||||
b = models.ForeignKey(ModelB, null=True)
|
b = models.ForeignKey(ModelB, null=True)
|
||||||
d = models.ForeignKey(ModelD)
|
d = models.ForeignKey(ModelD)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Job(models.Model):
|
class Job(models.Model):
|
||||||
name = models.CharField(max_length=20, unique=True)
|
name = models.CharField(max_length=20, unique=True)
|
||||||
|
@ -422,10 +490,12 @@ class Job(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class JobResponsibilities(models.Model):
|
class JobResponsibilities(models.Model):
|
||||||
job = models.ForeignKey(Job, to_field='name')
|
job = models.ForeignKey(Job, to_field='name')
|
||||||
responsibility = models.ForeignKey('Responsibility', to_field='description')
|
responsibility = models.ForeignKey('Responsibility', to_field='description')
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Responsibility(models.Model):
|
class Responsibility(models.Model):
|
||||||
description = models.CharField(max_length=20, unique=True)
|
description = models.CharField(max_length=20, unique=True)
|
||||||
|
@ -436,23 +506,29 @@ class Responsibility(models.Model):
|
||||||
return self.description
|
return self.description
|
||||||
|
|
||||||
# Models for disjunction join promotion low level testing.
|
# Models for disjunction join promotion low level testing.
|
||||||
|
|
||||||
|
|
||||||
class FK1(models.Model):
|
class FK1(models.Model):
|
||||||
f1 = models.TextField()
|
f1 = models.TextField()
|
||||||
f2 = models.TextField()
|
f2 = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
class FK2(models.Model):
|
class FK2(models.Model):
|
||||||
f1 = models.TextField()
|
f1 = models.TextField()
|
||||||
f2 = models.TextField()
|
f2 = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
class FK3(models.Model):
|
class FK3(models.Model):
|
||||||
f1 = models.TextField()
|
f1 = models.TextField()
|
||||||
f2 = models.TextField()
|
f2 = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
class BaseA(models.Model):
|
class BaseA(models.Model):
|
||||||
a = models.ForeignKey(FK1, null=True)
|
a = models.ForeignKey(FK1, null=True)
|
||||||
b = models.ForeignKey(FK2, null=True)
|
b = models.ForeignKey(FK2, null=True)
|
||||||
c = models.ForeignKey(FK3, null=True)
|
c = models.ForeignKey(FK3, null=True)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Identifier(models.Model):
|
class Identifier(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
|
@ -460,17 +536,21 @@ class Identifier(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Program(models.Model):
|
class Program(models.Model):
|
||||||
identifier = models.OneToOneField(Identifier)
|
identifier = models.OneToOneField(Identifier)
|
||||||
|
|
||||||
|
|
||||||
class Channel(models.Model):
|
class Channel(models.Model):
|
||||||
programs = models.ManyToManyField(Program)
|
programs = models.ManyToManyField(Program)
|
||||||
identifier = models.OneToOneField(Identifier)
|
identifier = models.OneToOneField(Identifier)
|
||||||
|
|
||||||
|
|
||||||
class Book(models.Model):
|
class Book(models.Model):
|
||||||
title = models.TextField()
|
title = models.TextField()
|
||||||
chapter = models.ForeignKey('Chapter')
|
chapter = models.ForeignKey('Chapter')
|
||||||
|
|
||||||
|
|
||||||
class Chapter(models.Model):
|
class Chapter(models.Model):
|
||||||
title = models.TextField()
|
title = models.TextField()
|
||||||
paragraph = models.ForeignKey('Paragraph')
|
paragraph = models.ForeignKey('Paragraph')
|
||||||
|
@ -480,15 +560,19 @@ class Paragraph(models.Model):
|
||||||
text = models.TextField()
|
text = models.TextField()
|
||||||
page = models.ManyToManyField('Page')
|
page = models.ManyToManyField('Page')
|
||||||
|
|
||||||
|
|
||||||
class Page(models.Model):
|
class Page(models.Model):
|
||||||
text = models.TextField()
|
text = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
class MyObject(models.Model):
|
class MyObject(models.Model):
|
||||||
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
|
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
|
||||||
data = models.CharField(max_length=100)
|
data = models.CharField(max_length=100)
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
# Models for #17600 regressions
|
# Models for #17600 regressions
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Order(models.Model):
|
class Order(models.Model):
|
||||||
id = models.IntegerField(primary_key=True)
|
id = models.IntegerField(primary_key=True)
|
||||||
|
@ -499,6 +583,7 @@ class Order(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '%s' % self.pk
|
return '%s' % self.pk
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class OrderItem(models.Model):
|
class OrderItem(models.Model):
|
||||||
order = models.ForeignKey(Order, related_name='items')
|
order = models.ForeignKey(Order, related_name='items')
|
||||||
|
@ -510,9 +595,11 @@ class OrderItem(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '%s' % self.pk
|
return '%s' % self.pk
|
||||||
|
|
||||||
|
|
||||||
class BaseUser(models.Model):
|
class BaseUser(models.Model):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Task(models.Model):
|
class Task(models.Model):
|
||||||
title = models.CharField(max_length=10)
|
title = models.CharField(max_length=10)
|
||||||
|
@ -522,6 +609,7 @@ class Task(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Staff(models.Model):
|
class Staff(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
|
@ -529,6 +617,7 @@ class Staff(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class StaffUser(BaseUser):
|
class StaffUser(BaseUser):
|
||||||
staff = models.OneToOneField(Staff, related_name='user')
|
staff = models.OneToOneField(Staff, related_name='user')
|
||||||
|
@ -536,11 +625,13 @@ class StaffUser(BaseUser):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.staff
|
return self.staff
|
||||||
|
|
||||||
|
|
||||||
class Ticket21203Parent(models.Model):
|
class Ticket21203Parent(models.Model):
|
||||||
parentid = models.AutoField(primary_key=True)
|
parentid = models.AutoField(primary_key=True)
|
||||||
parent_bool = models.BooleanField(default=True)
|
parent_bool = models.BooleanField(default=True)
|
||||||
created = models.DateTimeField(auto_now=True)
|
created = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
|
||||||
class Ticket21203Child(models.Model):
|
class Ticket21203Child(models.Model):
|
||||||
childid = models.AutoField(primary_key=True)
|
childid = models.AutoField(primary_key=True)
|
||||||
parent = models.ForeignKey(Ticket21203Parent)
|
parent = models.ForeignKey(Ticket21203Parent)
|
||||||
|
|
|
@ -28,6 +28,7 @@ from .models import (
|
||||||
CategoryRelationship, Ticket21203Parent, Ticket21203Child, Person,
|
CategoryRelationship, Ticket21203Parent, Ticket21203Child, Person,
|
||||||
Company, Employment)
|
Company, Employment)
|
||||||
|
|
||||||
|
|
||||||
class BaseQuerysetTest(TestCase):
|
class BaseQuerysetTest(TestCase):
|
||||||
def assertValueQuerysetEqual(self, qs, values):
|
def assertValueQuerysetEqual(self, qs, values):
|
||||||
return self.assertQuerysetEqual(qs, values, transform=lambda x: x)
|
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 = Tag.objects.values_list('id', flat=True).order_by('id')
|
||||||
qs.query.bump_prefix(qs.query)
|
qs.query.bump_prefix(qs.query)
|
||||||
first = qs[0]
|
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):
|
def test_ticket8439(self):
|
||||||
# Complex combinations of conjunctions, disjunctions and nullable
|
# Complex combinations of conjunctions, disjunctions and nullable
|
||||||
|
@ -1262,6 +1263,7 @@ class Queries3Tests(BaseQuerysetTest):
|
||||||
Item.objects.datetimes, 'name', 'month'
|
Item.objects.datetimes, 'name', 'month'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Queries4Tests(BaseQuerysetTest):
|
class Queries4Tests(BaseQuerysetTest):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
generic = NamedCategory.objects.create(name="Generic")
|
generic = NamedCategory.objects.create(name="Generic")
|
||||||
|
@ -1445,8 +1447,8 @@ class Queries4Tests(BaseQuerysetTest):
|
||||||
c0 = SimpleCategory.objects.create(name="cat0")
|
c0 = SimpleCategory.objects.create(name="cat0")
|
||||||
c1 = SimpleCategory.objects.create(name="category1")
|
c1 = SimpleCategory.objects.create(name="category1")
|
||||||
|
|
||||||
OneToOneCategory.objects.create(category = c1, new_name="new1")
|
OneToOneCategory.objects.create(category=c1, new_name="new1")
|
||||||
OneToOneCategory.objects.create(category = c0, new_name="new2")
|
OneToOneCategory.objects.create(category=c0, new_name="new2")
|
||||||
|
|
||||||
CategoryItem.objects.create(category=c)
|
CategoryItem.objects.create(category=c)
|
||||||
ci2 = CategoryItem.objects.create(category=c0)
|
ci2 = CategoryItem.objects.create(category=c0)
|
||||||
|
@ -1461,8 +1463,8 @@ class Queries4Tests(BaseQuerysetTest):
|
||||||
c0 = SimpleCategory.objects.create(name="cat0")
|
c0 = SimpleCategory.objects.create(name="cat0")
|
||||||
c1 = SimpleCategory.objects.create(name="category1")
|
c1 = SimpleCategory.objects.create(name="category1")
|
||||||
|
|
||||||
OneToOneCategory.objects.create(category = c1, new_name="new1")
|
OneToOneCategory.objects.create(category=c1, new_name="new1")
|
||||||
OneToOneCategory.objects.create(category = c0, new_name="new2")
|
OneToOneCategory.objects.create(category=c0, new_name="new2")
|
||||||
|
|
||||||
ci1 = CategoryItem.objects.create(category=c)
|
ci1 = CategoryItem.objects.create(category=c)
|
||||||
CategoryItem.objects.create(category=c0)
|
CategoryItem.objects.create(category=c0)
|
||||||
|
@ -1477,8 +1479,8 @@ class Queries4Tests(BaseQuerysetTest):
|
||||||
c0 = SimpleCategory.objects.create(name="cat0")
|
c0 = SimpleCategory.objects.create(name="cat0")
|
||||||
c1 = SimpleCategory.objects.create(name="category1")
|
c1 = SimpleCategory.objects.create(name="category1")
|
||||||
|
|
||||||
OneToOneCategory.objects.create(category = c1, new_name="new1")
|
OneToOneCategory.objects.create(category=c1, new_name="new1")
|
||||||
OneToOneCategory.objects.create(category = c0, new_name="new2")
|
OneToOneCategory.objects.create(category=c0, new_name="new2")
|
||||||
|
|
||||||
ci1 = CategoryItem.objects.create(category=c)
|
ci1 = CategoryItem.objects.create(category=c)
|
||||||
CategoryItem.objects.create(category=c0)
|
CategoryItem.objects.create(category=c0)
|
||||||
|
@ -1493,8 +1495,8 @@ class Queries4Tests(BaseQuerysetTest):
|
||||||
c0 = SimpleCategory.objects.create(name="cat0")
|
c0 = SimpleCategory.objects.create(name="cat0")
|
||||||
c1 = SimpleCategory.objects.create(name="category1")
|
c1 = SimpleCategory.objects.create(name="category1")
|
||||||
|
|
||||||
OneToOneCategory.objects.create(category = c1, new_name="new1")
|
OneToOneCategory.objects.create(category=c1, new_name="new1")
|
||||||
OneToOneCategory.objects.create(category = c0, new_name="new2")
|
OneToOneCategory.objects.create(category=c0, new_name="new2")
|
||||||
|
|
||||||
CategoryItem.objects.create(category=c)
|
CategoryItem.objects.create(category=c)
|
||||||
ci2 = CategoryItem.objects.create(category=c0)
|
ci2 = CategoryItem.objects.create(category=c0)
|
||||||
|
@ -2019,6 +2021,7 @@ class CloneTests(TestCase):
|
||||||
else:
|
else:
|
||||||
opts_class.__deepcopy__ = note_deepcopy
|
opts_class.__deepcopy__ = note_deepcopy
|
||||||
|
|
||||||
|
|
||||||
class EmptyQuerySetTests(TestCase):
|
class EmptyQuerySetTests(TestCase):
|
||||||
def test_emptyqueryset_values(self):
|
def test_emptyqueryset_values(self):
|
||||||
# #14366 -- Calling .values() on an empty QuerySet and then cloning
|
# #14366 -- Calling .values() on an empty QuerySet and then cloning
|
||||||
|
@ -2224,12 +2227,12 @@ class ConditionalTests(BaseQuerysetTest):
|
||||||
self.assertRaisesMessage(
|
self.assertRaisesMessage(
|
||||||
FieldError,
|
FieldError,
|
||||||
'Infinite loop caused by ordering.',
|
'Infinite loop caused by ordering.',
|
||||||
lambda: list(LoopX.objects.all()) # Force queryset evaluation with list()
|
lambda: list(LoopX.objects.all()) # Force queryset evaluation with list()
|
||||||
)
|
)
|
||||||
self.assertRaisesMessage(
|
self.assertRaisesMessage(
|
||||||
FieldError,
|
FieldError,
|
||||||
'Infinite loop caused by ordering.',
|
'Infinite loop caused by ordering.',
|
||||||
lambda: list(LoopZ.objects.all()) # Force queryset evaluation with list()
|
lambda: list(LoopZ.objects.all()) # Force queryset evaluation with list()
|
||||||
)
|
)
|
||||||
|
|
||||||
# Note that this doesn't cause an infinite loop, since the default
|
# Note that this doesn't cause an infinite loop, since the default
|
||||||
|
@ -2353,6 +2356,7 @@ class DefaultValuesInsertTest(TestCase):
|
||||||
except TypeError:
|
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)")
|
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):
|
class ExcludeTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
f1 = Food.objects.create(name='apples')
|
f1 = Food.objects.create(name='apples')
|
||||||
|
@ -2504,6 +2508,7 @@ class ExcludeTest17600(TestCase):
|
||||||
Order.objects.exclude(~Q(items__status=1)).distinct(),
|
Order.objects.exclude(~Q(items__status=1)).distinct(),
|
||||||
['<Order: 1>'])
|
['<Order: 1>'])
|
||||||
|
|
||||||
|
|
||||||
class Exclude15786(TestCase):
|
class Exclude15786(TestCase):
|
||||||
"""Regression test for #15786"""
|
"""Regression test for #15786"""
|
||||||
def test_ticket15786(self):
|
def test_ticket15786(self):
|
||||||
|
@ -2562,6 +2567,7 @@ class NullInExcludeTest(TestCase):
|
||||||
'IS NOT NULL',
|
'IS NOT NULL',
|
||||||
str(NullableName.objects.filter(~~Q(name='i1')).query))
|
str(NullableName.objects.filter(~~Q(name='i1')).query))
|
||||||
|
|
||||||
|
|
||||||
class EmptyStringsAsNullTest(TestCase):
|
class EmptyStringsAsNullTest(TestCase):
|
||||||
"""
|
"""
|
||||||
Test that filtering on non-null character fields works as expected.
|
Test that filtering on non-null character fields works as expected.
|
||||||
|
@ -2591,6 +2597,7 @@ class EmptyStringsAsNullTest(TestCase):
|
||||||
[foo.pk], attrgetter('pk')
|
[foo.pk], attrgetter('pk')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ProxyQueryCleanupTest(TestCase):
|
class ProxyQueryCleanupTest(TestCase):
|
||||||
def test_evaluated_proxy_count(self):
|
def test_evaluated_proxy_count(self):
|
||||||
"""
|
"""
|
||||||
|
@ -2603,6 +2610,7 @@ class ProxyQueryCleanupTest(TestCase):
|
||||||
str(qs.query)
|
str(qs.query)
|
||||||
self.assertEqual(qs.count(), 1)
|
self.assertEqual(qs.count(), 1)
|
||||||
|
|
||||||
|
|
||||||
class WhereNodeTest(TestCase):
|
class WhereNodeTest(TestCase):
|
||||||
class DummyNode(object):
|
class DummyNode(object):
|
||||||
def as_sql(self, qn, connection):
|
def as_sql(self, qn, connection):
|
||||||
|
@ -2768,6 +2776,7 @@ class NullJoinPromotionOrTest(TestCase):
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
qs.order_by('name'), [r2, r1], lambda x: x)
|
qs.order_by('name'), [r2, r1], lambda x: x)
|
||||||
|
|
||||||
|
|
||||||
class ReverseJoinTrimmingTest(TestCase):
|
class ReverseJoinTrimmingTest(TestCase):
|
||||||
def test_reverse_trimming(self):
|
def test_reverse_trimming(self):
|
||||||
# Check that we don't accidentally trim reverse joins - we can't know
|
# 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.assertIn('INNER JOIN', str(qs.query))
|
||||||
self.assertEqual(list(qs), [])
|
self.assertEqual(list(qs), [])
|
||||||
|
|
||||||
|
|
||||||
class JoinReuseTest(TestCase):
|
class JoinReuseTest(TestCase):
|
||||||
"""
|
"""
|
||||||
Test that the queries reuse joins sensibly (for example, direct joins
|
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')
|
qs = Author.objects.filter(report__name='r4').filter(report__name='r1')
|
||||||
self.assertEqual(str(qs.query).count('JOIN'), 2)
|
self.assertEqual(str(qs.query).count('JOIN'), 2)
|
||||||
|
|
||||||
|
|
||||||
class DisjunctionPromotionTests(TestCase):
|
class DisjunctionPromotionTests(TestCase):
|
||||||
def test_disjuction_promotion_select_related(self):
|
def test_disjuction_promotion_select_related(self):
|
||||||
fk1 = FK1.objects.create(f1='f1', f2='f2')
|
fk1 = FK1.objects.create(f1='f1', f2='f2')
|
||||||
|
@ -2986,6 +2997,7 @@ class ManyToManyExcludeTest(TestCase):
|
||||||
self.assertIn(b2, q)
|
self.assertIn(b2, q)
|
||||||
self.assertIn(b3, q)
|
self.assertIn(b3, q)
|
||||||
|
|
||||||
|
|
||||||
class RelabelCloneTest(TestCase):
|
class RelabelCloneTest(TestCase):
|
||||||
def test_ticket_19964(self):
|
def test_ticket_19964(self):
|
||||||
my1 = MyObject.objects.create(data='foo')
|
my1 = MyObject.objects.create(data='foo')
|
||||||
|
@ -3000,6 +3012,7 @@ class RelabelCloneTest(TestCase):
|
||||||
self.assertEqual(list(children), [my2])
|
self.assertEqual(list(children), [my2])
|
||||||
self.assertEqual(list(parents), [my1])
|
self.assertEqual(list(parents), [my1])
|
||||||
|
|
||||||
|
|
||||||
class Ticket20101Tests(TestCase):
|
class Ticket20101Tests(TestCase):
|
||||||
def test_ticket_20101(self):
|
def test_ticket_20101(self):
|
||||||
"""
|
"""
|
||||||
|
@ -3016,6 +3029,7 @@ class Ticket20101Tests(TestCase):
|
||||||
self.assertFalse(n in qs2)
|
self.assertFalse(n in qs2)
|
||||||
self.assertTrue(n in (qs1 | qs2))
|
self.assertTrue(n in (qs1 | qs2))
|
||||||
|
|
||||||
|
|
||||||
class EmptyStringPromotionTests(TestCase):
|
class EmptyStringPromotionTests(TestCase):
|
||||||
def test_empty_string_promotion(self):
|
def test_empty_string_promotion(self):
|
||||||
qs = RelatedObject.objects.filter(single__name='')
|
qs = RelatedObject.objects.filter(single__name='')
|
||||||
|
@ -3024,6 +3038,7 @@ class EmptyStringPromotionTests(TestCase):
|
||||||
else:
|
else:
|
||||||
self.assertNotIn('LEFT OUTER JOIN', str(qs.query))
|
self.assertNotIn('LEFT OUTER JOIN', str(qs.query))
|
||||||
|
|
||||||
|
|
||||||
class ValuesSubqueryTests(TestCase):
|
class ValuesSubqueryTests(TestCase):
|
||||||
def test_values_in_subquery(self):
|
def test_values_in_subquery(self):
|
||||||
# Check that if a values() queryset is used, then the given values
|
# 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')),
|
Order.objects.filter(items__in=OrderItem.objects.values_list('status')),
|
||||||
[o1.pk], lambda x: x.pk)
|
[o1.pk], lambda x: x.pk)
|
||||||
|
|
||||||
|
|
||||||
class DoubleInSubqueryTests(TestCase):
|
class DoubleInSubqueryTests(TestCase):
|
||||||
def test_double_subquery_in(self):
|
def test_double_subquery_in(self):
|
||||||
lfa1 = LeafA.objects.create(data='foo')
|
lfa1 = LeafA.objects.create(data='foo')
|
||||||
|
@ -3055,6 +3071,7 @@ class DoubleInSubqueryTests(TestCase):
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
qs, [lfb1], lambda x: x)
|
qs, [lfb1], lambda x: x)
|
||||||
|
|
||||||
|
|
||||||
class Ticket18785Tests(TestCase):
|
class Ticket18785Tests(TestCase):
|
||||||
def test_ticket_18785(self):
|
def test_ticket_18785(self):
|
||||||
# Test join trimming from ticket18785
|
# Test join trimming from ticket18785
|
||||||
|
@ -3085,6 +3102,7 @@ class Ticket20788Tests(TestCase):
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
sentences_not_in_pub, [book2], lambda x: x)
|
sentences_not_in_pub, [book2], lambda x: x)
|
||||||
|
|
||||||
|
|
||||||
class Ticket12807Tests(TestCase):
|
class Ticket12807Tests(TestCase):
|
||||||
def test_ticket_12807(self):
|
def test_ticket_12807(self):
|
||||||
p1 = Paragraph.objects.create()
|
p1 = Paragraph.objects.create()
|
||||||
|
@ -3111,6 +3129,7 @@ class RelatedLookupTypeTests(TestCase):
|
||||||
ObjectB.objects.filter(objecta__in=[wrong_type]),
|
ObjectB.objects.filter(objecta__in=[wrong_type]),
|
||||||
[ob], lambda x: x)
|
[ob], lambda x: x)
|
||||||
|
|
||||||
|
|
||||||
class Ticket14056Tests(TestCase):
|
class Ticket14056Tests(TestCase):
|
||||||
def test_ticket_14056(self):
|
def test_ticket_14056(self):
|
||||||
s1 = SharedConnection.objects.create(data='s1')
|
s1 = SharedConnection.objects.create(data='s1')
|
||||||
|
@ -3126,6 +3145,7 @@ class Ticket14056Tests(TestCase):
|
||||||
expected_ordering, lambda x: x
|
expected_ordering, lambda x: x
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Ticket20955Tests(TestCase):
|
class Ticket20955Tests(TestCase):
|
||||||
def test_ticket_20955(self):
|
def test_ticket_20955(self):
|
||||||
jack = Staff.objects.create(name='jackstaff')
|
jack = Staff.objects.create(name='jackstaff')
|
||||||
|
@ -3146,6 +3166,7 @@ class Ticket20955Tests(TestCase):
|
||||||
self.assertEqual(task_select_related.owner.staffuser.staff,
|
self.assertEqual(task_select_related.owner.staffuser.staff,
|
||||||
task_get.owner.staffuser.staff)
|
task_get.owner.staffuser.staff)
|
||||||
|
|
||||||
|
|
||||||
class Ticket21203Tests(TestCase):
|
class Ticket21203Tests(TestCase):
|
||||||
def test_ticket_21203(self):
|
def test_ticket_21203(self):
|
||||||
p = Ticket21203Parent.objects.create(parent_bool=True)
|
p = Ticket21203Parent.objects.create(parent_bool=True)
|
||||||
|
@ -3154,6 +3175,7 @@ class Ticket21203Tests(TestCase):
|
||||||
self.assertQuerysetEqual(qs, [c], lambda x: x)
|
self.assertQuerysetEqual(qs, [c], lambda x: x)
|
||||||
self.assertIs(qs[0].parent.parent_bool, True)
|
self.assertIs(qs[0].parent.parent_bool, True)
|
||||||
|
|
||||||
|
|
||||||
class ValuesJoinPromotionTests(TestCase):
|
class ValuesJoinPromotionTests(TestCase):
|
||||||
def test_values_no_promotion_for_existing(self):
|
def test_values_no_promotion_for_existing(self):
|
||||||
qs = Node.objects.filter(parent__parent__isnull=False)
|
qs = Node.objects.filter(parent__parent__isnull=False)
|
||||||
|
|
|
@ -7,6 +7,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||||
def standalone_number():
|
def standalone_number():
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
class Numbers(object):
|
class Numbers(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_static_number():
|
def get_static_number():
|
||||||
|
@ -21,12 +22,15 @@ class Numbers(object):
|
||||||
|
|
||||||
nn = Numbers()
|
nn = Numbers()
|
||||||
|
|
||||||
|
|
||||||
class Group(models.Model):
|
class Group(models.Model):
|
||||||
name = models.CharField(_('name'), max_length=100)
|
name = models.CharField(_('name'), max_length=100)
|
||||||
|
|
||||||
|
|
||||||
class Event(models.Model):
|
class Event(models.Model):
|
||||||
group = models.ForeignKey(Group)
|
group = models.ForeignKey(Group)
|
||||||
|
|
||||||
|
|
||||||
class Happening(models.Model):
|
class Happening(models.Model):
|
||||||
when = models.DateTimeField(blank=True, default=datetime.datetime.now)
|
when = models.DateTimeField(blank=True, default=datetime.datetime.now)
|
||||||
name = models.CharField(blank=True, max_length=100, default=lambda: "test")
|
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)
|
number3 = models.IntegerField(blank=True, default=Numbers.get_class_number)
|
||||||
number4 = models.IntegerField(blank=True, default=nn.get_member_number)
|
number4 = models.IntegerField(blank=True, default=nn.get_member_number)
|
||||||
|
|
||||||
|
|
||||||
class Container(object):
|
class Container(object):
|
||||||
# To test pickling we need a class that isn't defined on module, but
|
# 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
|
# is still available from app-cache. So, the Container class moves
|
||||||
|
@ -42,5 +47,6 @@ class Container(object):
|
||||||
class SomeModel(models.Model):
|
class SomeModel(models.Model):
|
||||||
somefield = models.IntegerField()
|
somefield = models.IntegerField()
|
||||||
|
|
||||||
|
|
||||||
class M2MModel(models.Model):
|
class M2MModel(models.Model):
|
||||||
groups = models.ManyToManyField(Group)
|
groups = models.ManyToManyField(Group)
|
||||||
|
|
|
@ -15,17 +15,21 @@ class Author(models.Model):
|
||||||
assert k in [f.attname for f in self._meta.fields], \
|
assert k in [f.attname for f in self._meta.fields], \
|
||||||
"Author.__init__ got an unexpected parameter: %s" % k
|
"Author.__init__ got an unexpected parameter: %s" % k
|
||||||
|
|
||||||
|
|
||||||
class Book(models.Model):
|
class Book(models.Model):
|
||||||
title = models.CharField(max_length=255)
|
title = models.CharField(max_length=255)
|
||||||
author = models.ForeignKey(Author)
|
author = models.ForeignKey(Author)
|
||||||
paperback = models.BooleanField(default=False)
|
paperback = models.BooleanField(default=False)
|
||||||
opening_line = models.TextField()
|
opening_line = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
class Coffee(models.Model):
|
class Coffee(models.Model):
|
||||||
brand = models.CharField(max_length=255, db_column="name")
|
brand = models.CharField(max_length=255, db_column="name")
|
||||||
|
|
||||||
|
|
||||||
class Reviewer(models.Model):
|
class Reviewer(models.Model):
|
||||||
reviewed = models.ManyToManyField(Book)
|
reviewed = models.ManyToManyField(Book)
|
||||||
|
|
||||||
|
|
||||||
class FriendlyAuthor(Author):
|
class FriendlyAuthor(Author):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
class HttpResponseTests(unittest.TestCase):
|
class HttpResponseTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_status_code(self):
|
def test_status_code(self):
|
||||||
|
|
|
@ -15,6 +15,7 @@ class User(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Poll(models.Model):
|
class Poll(models.Model):
|
||||||
question = models.CharField(max_length=200)
|
question = models.CharField(max_length=200)
|
||||||
|
@ -23,6 +24,7 @@ class Poll(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.question
|
return self.question
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Choice(models.Model):
|
class Choice(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
|
|
|
@ -5,9 +5,11 @@ class SourceManager(models.Manager):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return super(SourceManager, self).get_queryset().filter(is_public=True)
|
return super(SourceManager, self).get_queryset().filter(is_public=True)
|
||||||
|
|
||||||
|
|
||||||
class Source(models.Model):
|
class Source(models.Model):
|
||||||
is_public = models.BooleanField(default=False)
|
is_public = models.BooleanField(default=False)
|
||||||
objects = SourceManager()
|
objects = SourceManager()
|
||||||
|
|
||||||
|
|
||||||
class Item(models.Model):
|
class Item(models.Model):
|
||||||
source = models.ForeignKey(Source)
|
source = models.ForeignKey(Source)
|
||||||
|
|
|
@ -12,6 +12,7 @@ from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
|
||||||
# Who remembers high school biology?
|
# Who remembers high school biology?
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Domain(models.Model):
|
class Domain(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -19,6 +20,7 @@ class Domain(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Kingdom(models.Model):
|
class Kingdom(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -27,6 +29,7 @@ class Kingdom(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Phylum(models.Model):
|
class Phylum(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -35,6 +38,7 @@ class Phylum(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Klass(models.Model):
|
class Klass(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -43,6 +47,7 @@ class Klass(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Order(models.Model):
|
class Order(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -51,6 +56,7 @@ class Order(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Family(models.Model):
|
class Family(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -59,6 +65,7 @@ class Family(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Genus(models.Model):
|
class Genus(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -67,6 +74,7 @@ class Genus(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Species(models.Model):
|
class Species(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -76,6 +84,8 @@ class Species(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
# and we'll invent a new thing so we have a model with two foreign keys
|
# and we'll invent a new thing so we have a model with two foreign keys
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class HybridSpecies(models.Model):
|
class HybridSpecies(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
|
|
@ -95,8 +95,10 @@ class Child2(Parent1):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name1
|
return self.name1
|
||||||
|
|
||||||
|
|
||||||
class Child3(Child2):
|
class Child3(Child2):
|
||||||
value3 = models.IntegerField()
|
value3 = models.IntegerField()
|
||||||
|
|
||||||
|
|
||||||
class Child4(Child1):
|
class Child4(Child1):
|
||||||
value4 = models.IntegerField()
|
value4 = models.IntegerField()
|
||||||
|
|
|
@ -11,6 +11,7 @@ class Building(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Building: %s" % self.name
|
return "Building: %s" % self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Device(models.Model):
|
class Device(models.Model):
|
||||||
building = models.ForeignKey('Building')
|
building = models.ForeignKey('Building')
|
||||||
|
@ -19,6 +20,7 @@ class Device(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "device '%s' in building %s" % (self.name, self.building)
|
return "device '%s' in building %s" % (self.name, self.building)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Port(models.Model):
|
class Port(models.Model):
|
||||||
device = models.ForeignKey('Device')
|
device = models.ForeignKey('Device')
|
||||||
|
@ -27,6 +29,7 @@ class Port(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s/%s" % (self.device.name, self.port_number)
|
return "%s/%s" % (self.device.name, self.port_number)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Connection(models.Model):
|
class Connection(models.Model):
|
||||||
start = models.ForeignKey(Port, related_name='connection_start',
|
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
|
# Another non-tree hierarchy that exercises code paths similar to the above
|
||||||
# example, but in a slightly different configuration.
|
# example, but in a slightly different configuration.
|
||||||
|
|
||||||
|
|
||||||
class TUser(models.Model):
|
class TUser(models.Model):
|
||||||
name = models.CharField(max_length=200)
|
name = models.CharField(max_length=200)
|
||||||
|
|
||||||
|
|
||||||
class Person(models.Model):
|
class Person(models.Model):
|
||||||
user = models.ForeignKey(TUser, unique=True)
|
user = models.ForeignKey(TUser, unique=True)
|
||||||
|
|
||||||
|
|
||||||
class Organizer(models.Model):
|
class Organizer(models.Model):
|
||||||
person = models.ForeignKey(Person)
|
person = models.ForeignKey(Person)
|
||||||
|
|
||||||
|
|
||||||
class Student(models.Model):
|
class Student(models.Model):
|
||||||
person = models.ForeignKey(Person)
|
person = models.ForeignKey(Person)
|
||||||
|
|
||||||
|
|
||||||
class Class(models.Model):
|
class Class(models.Model):
|
||||||
org = models.ForeignKey(Organizer)
|
org = models.ForeignKey(Organizer)
|
||||||
|
|
||||||
|
|
||||||
class Enrollment(models.Model):
|
class Enrollment(models.Model):
|
||||||
std = models.ForeignKey(Student)
|
std = models.ForeignKey(Student)
|
||||||
cls = models.ForeignKey(Class)
|
cls = models.ForeignKey(Class)
|
||||||
|
|
||||||
# Models for testing bug #8036.
|
# Models for testing bug #8036.
|
||||||
|
|
||||||
|
|
||||||
class Country(models.Model):
|
class Country(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
|
||||||
|
|
||||||
class State(models.Model):
|
class State(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
country = models.ForeignKey(Country)
|
country = models.ForeignKey(Country)
|
||||||
|
|
||||||
|
|
||||||
class ClientStatus(models.Model):
|
class ClientStatus(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
|
||||||
|
|
||||||
class Client(models.Model):
|
class Client(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
state = models.ForeignKey(State, null=True)
|
state = models.ForeignKey(State, null=True)
|
||||||
status = models.ForeignKey(ClientStatus)
|
status = models.ForeignKey(ClientStatus)
|
||||||
|
|
||||||
|
|
||||||
class SpecialClient(Client):
|
class SpecialClient(Client):
|
||||||
value = models.IntegerField()
|
value = models.IntegerField()
|
||||||
|
|
||||||
# Some model inheritance exercises
|
# Some model inheritance exercises
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Parent(models.Model):
|
class Parent(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
|
@ -84,9 +102,11 @@ class Parent(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Child(Parent):
|
class Child(Parent):
|
||||||
value = models.IntegerField()
|
value = models.IntegerField()
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Item(models.Model):
|
class Item(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
|
@ -96,6 +116,8 @@ class Item(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
# Models for testing bug #19870.
|
# Models for testing bug #19870.
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Fowl(models.Model):
|
class Fowl(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
|
@ -103,12 +125,15 @@ class Fowl(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Hen(Fowl):
|
class Hen(Fowl):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Chick(Fowl):
|
class Chick(Fowl):
|
||||||
mother = models.ForeignKey(Hen)
|
mother = models.ForeignKey(Hen)
|
||||||
|
|
||||||
|
|
||||||
class Base(models.Model):
|
class Base(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
lots_of_text = models.TextField()
|
lots_of_text = models.TextField()
|
||||||
|
@ -116,12 +141,15 @@ class Base(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
class A(Base):
|
class A(Base):
|
||||||
a_field = models.CharField(max_length=10)
|
a_field = models.CharField(max_length=10)
|
||||||
|
|
||||||
|
|
||||||
class B(Base):
|
class B(Base):
|
||||||
b_field = models.CharField(max_length=10)
|
b_field = models.CharField(max_length=10)
|
||||||
|
|
||||||
|
|
||||||
class C(Base):
|
class C(Base):
|
||||||
c_a = models.ForeignKey(A)
|
c_a = models.ForeignKey(A)
|
||||||
c_b = models.ForeignKey(B)
|
c_b = models.ForeignKey(B)
|
||||||
|
|
|
@ -26,7 +26,7 @@ from .models import (Category, Author, Article, AuthorProfile, Actor, Movie,
|
||||||
|
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
SERIALIZATION_MODULES = {
|
SERIALIZATION_MODULES={
|
||||||
"json2": "django.core.serializers.json",
|
"json2": "django.core.serializers.json",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -71,6 +71,7 @@ class SerializerRegistrationTests(TestCase):
|
||||||
self.assertIn('python', all_formats)
|
self.assertIn('python', all_formats)
|
||||||
self.assertNotIn('python', public_formats)
|
self.assertNotIn('python', public_formats)
|
||||||
|
|
||||||
|
|
||||||
class SerializersTestBase(object):
|
class SerializersTestBase(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _comparison_value(value):
|
def _comparison_value(value):
|
||||||
|
@ -241,9 +242,9 @@ class SerializersTestBase(object):
|
||||||
# Regression for #12524 -- dates before 1000AD get prefixed
|
# Regression for #12524 -- dates before 1000AD get prefixed
|
||||||
# 0's on the year
|
# 0's on the year
|
||||||
a = Article.objects.create(
|
a = Article.objects.create(
|
||||||
author = self.jane,
|
author=self.jane,
|
||||||
headline = "Nobody remembers the early years",
|
headline="Nobody remembers the early years",
|
||||||
pub_date = datetime(1, 2, 3, 4, 5, 6))
|
pub_date=datetime(1, 2, 3, 4, 5, 6))
|
||||||
|
|
||||||
serial_str = serializers.serialize(self.serializer_name, [a])
|
serial_str = serializers.serialize(self.serializer_name, [a])
|
||||||
date_values = self._get_field_values(serial_str, "pub_date")
|
date_values = self._get_field_values(serial_str, "pub_date")
|
||||||
|
@ -338,6 +339,7 @@ class XmlSerializerTestCase(SerializersTestBase, TestCase):
|
||||||
ret_list.append("".join(temp))
|
ret_list.append("".join(temp))
|
||||||
return ret_list
|
return ret_list
|
||||||
|
|
||||||
|
|
||||||
class XmlSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
|
class XmlSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
|
||||||
serializer_name = "xml"
|
serializer_name = "xml"
|
||||||
fwd_ref_str = """<?xml version="1.0" encoding="utf-8"?>
|
fwd_ref_str = """<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
@ -438,6 +440,8 @@ class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, Transact
|
||||||
|
|
||||||
|
|
||||||
YAML_IMPORT_ERROR_MESSAGE = r'No module named yaml'
|
YAML_IMPORT_ERROR_MESSAGE = r'No module named yaml'
|
||||||
|
|
||||||
|
|
||||||
class YamlImportModuleMock(object):
|
class YamlImportModuleMock(object):
|
||||||
"""Provides a wrapped import_module function to simulate yaml ImportError
|
"""Provides a wrapped import_module function to simulate yaml ImportError
|
||||||
|
|
||||||
|
|
|
@ -13,74 +13,96 @@ from django.contrib.contenttypes.models import ContentType
|
||||||
# The following classes are for testing basic data
|
# The following classes are for testing basic data
|
||||||
# marshalling, including NULL values, where allowed.
|
# marshalling, including NULL values, where allowed.
|
||||||
|
|
||||||
|
|
||||||
class BinaryData(models.Model):
|
class BinaryData(models.Model):
|
||||||
data = models.BinaryField(null=True)
|
data = models.BinaryField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class BooleanData(models.Model):
|
class BooleanData(models.Model):
|
||||||
data = models.BooleanField(default=False)
|
data = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
|
||||||
class CharData(models.Model):
|
class CharData(models.Model):
|
||||||
data = models.CharField(max_length=30, null=True)
|
data = models.CharField(max_length=30, null=True)
|
||||||
|
|
||||||
|
|
||||||
class DateData(models.Model):
|
class DateData(models.Model):
|
||||||
data = models.DateField(null=True)
|
data = models.DateField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class DateTimeData(models.Model):
|
class DateTimeData(models.Model):
|
||||||
data = models.DateTimeField(null=True)
|
data = models.DateTimeField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class DecimalData(models.Model):
|
class DecimalData(models.Model):
|
||||||
data = models.DecimalField(null=True, decimal_places=3, max_digits=5)
|
data = models.DecimalField(null=True, decimal_places=3, max_digits=5)
|
||||||
|
|
||||||
|
|
||||||
class EmailData(models.Model):
|
class EmailData(models.Model):
|
||||||
data = models.EmailField(null=True)
|
data = models.EmailField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class FileData(models.Model):
|
class FileData(models.Model):
|
||||||
data = models.FileField(null=True, upload_to='/foo/bar')
|
data = models.FileField(null=True, upload_to='/foo/bar')
|
||||||
|
|
||||||
|
|
||||||
class FilePathData(models.Model):
|
class FilePathData(models.Model):
|
||||||
data = models.FilePathField(null=True)
|
data = models.FilePathField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class FloatData(models.Model):
|
class FloatData(models.Model):
|
||||||
data = models.FloatField(null=True)
|
data = models.FloatField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class IntegerData(models.Model):
|
class IntegerData(models.Model):
|
||||||
data = models.IntegerField(null=True)
|
data = models.IntegerField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class BigIntegerData(models.Model):
|
class BigIntegerData(models.Model):
|
||||||
data = models.BigIntegerField(null=True)
|
data = models.BigIntegerField(null=True)
|
||||||
|
|
||||||
# class ImageData(models.Model):
|
# class ImageData(models.Model):
|
||||||
# data = models.ImageField(null=True)
|
# data = models.ImageField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class IPAddressData(models.Model):
|
class IPAddressData(models.Model):
|
||||||
with warnings.catch_warnings(record=True) as w:
|
with warnings.catch_warnings(record=True) as w:
|
||||||
warnings.simplefilter("always")
|
warnings.simplefilter("always")
|
||||||
data = models.IPAddressField(null=True)
|
data = models.IPAddressField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class GenericIPAddressData(models.Model):
|
class GenericIPAddressData(models.Model):
|
||||||
data = models.GenericIPAddressField(null=True)
|
data = models.GenericIPAddressField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class NullBooleanData(models.Model):
|
class NullBooleanData(models.Model):
|
||||||
data = models.NullBooleanField(null=True)
|
data = models.NullBooleanField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class PositiveIntegerData(models.Model):
|
class PositiveIntegerData(models.Model):
|
||||||
data = models.PositiveIntegerField(null=True)
|
data = models.PositiveIntegerField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class PositiveSmallIntegerData(models.Model):
|
class PositiveSmallIntegerData(models.Model):
|
||||||
data = models.PositiveSmallIntegerField(null=True)
|
data = models.PositiveSmallIntegerField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class SlugData(models.Model):
|
class SlugData(models.Model):
|
||||||
data = models.SlugField(null=True)
|
data = models.SlugField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class SmallData(models.Model):
|
class SmallData(models.Model):
|
||||||
data = models.SmallIntegerField(null=True)
|
data = models.SmallIntegerField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class TextData(models.Model):
|
class TextData(models.Model):
|
||||||
data = models.TextField(null=True)
|
data = models.TextField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class TimeData(models.Model):
|
class TimeData(models.Model):
|
||||||
data = models.TimeField(null=True)
|
data = models.TimeField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class Tag(models.Model):
|
class Tag(models.Model):
|
||||||
"""A tag on an item."""
|
"""A tag on an item."""
|
||||||
data = models.SlugField()
|
data = models.SlugField()
|
||||||
|
@ -92,6 +114,7 @@ class Tag(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ["data"]
|
ordering = ["data"]
|
||||||
|
|
||||||
|
|
||||||
class GenericData(models.Model):
|
class GenericData(models.Model):
|
||||||
data = models.CharField(max_length=30)
|
data = models.CharField(max_length=30)
|
||||||
|
|
||||||
|
@ -101,6 +124,7 @@ class GenericData(models.Model):
|
||||||
# of related objects; in particular, forward, backward,
|
# of related objects; in particular, forward, backward,
|
||||||
# and self references.
|
# and self references.
|
||||||
|
|
||||||
|
|
||||||
class Anchor(models.Model):
|
class Anchor(models.Model):
|
||||||
"""This is a model that can be used as
|
"""This is a model that can be used as
|
||||||
something for other models to point at"""
|
something for other models to point at"""
|
||||||
|
@ -110,10 +134,12 @@ class Anchor(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('id',)
|
ordering = ('id',)
|
||||||
|
|
||||||
|
|
||||||
class NaturalKeyAnchorManager(models.Manager):
|
class NaturalKeyAnchorManager(models.Manager):
|
||||||
def get_by_natural_key(self, data):
|
def get_by_natural_key(self, data):
|
||||||
return self.get(data=data)
|
return self.get(data=data)
|
||||||
|
|
||||||
|
|
||||||
class NaturalKeyAnchor(models.Model):
|
class NaturalKeyAnchor(models.Model):
|
||||||
objects = NaturalKeyAnchorManager()
|
objects = NaturalKeyAnchorManager()
|
||||||
|
|
||||||
|
@ -123,40 +149,51 @@ class NaturalKeyAnchor(models.Model):
|
||||||
def natural_key(self):
|
def natural_key(self):
|
||||||
return (self.data,)
|
return (self.data,)
|
||||||
|
|
||||||
|
|
||||||
class UniqueAnchor(models.Model):
|
class UniqueAnchor(models.Model):
|
||||||
"""This is a model that can be used as
|
"""This is a model that can be used as
|
||||||
something for other models to point at"""
|
something for other models to point at"""
|
||||||
|
|
||||||
data = models.CharField(unique=True, max_length=30)
|
data = models.CharField(unique=True, max_length=30)
|
||||||
|
|
||||||
|
|
||||||
class FKData(models.Model):
|
class FKData(models.Model):
|
||||||
data = models.ForeignKey(Anchor, null=True)
|
data = models.ForeignKey(Anchor, null=True)
|
||||||
|
|
||||||
|
|
||||||
class FKDataNaturalKey(models.Model):
|
class FKDataNaturalKey(models.Model):
|
||||||
data = models.ForeignKey(NaturalKeyAnchor, null=True)
|
data = models.ForeignKey(NaturalKeyAnchor, null=True)
|
||||||
|
|
||||||
|
|
||||||
class M2MData(models.Model):
|
class M2MData(models.Model):
|
||||||
data = models.ManyToManyField(Anchor, null=True)
|
data = models.ManyToManyField(Anchor, null=True)
|
||||||
|
|
||||||
|
|
||||||
class O2OData(models.Model):
|
class O2OData(models.Model):
|
||||||
# One to one field can't be null here, since it is a PK.
|
# One to one field can't be null here, since it is a PK.
|
||||||
data = models.OneToOneField(Anchor, primary_key=True)
|
data = models.OneToOneField(Anchor, primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class FKSelfData(models.Model):
|
class FKSelfData(models.Model):
|
||||||
data = models.ForeignKey('self', null=True)
|
data = models.ForeignKey('self', null=True)
|
||||||
|
|
||||||
|
|
||||||
class M2MSelfData(models.Model):
|
class M2MSelfData(models.Model):
|
||||||
data = models.ManyToManyField('self', null=True, symmetrical=False)
|
data = models.ManyToManyField('self', null=True, symmetrical=False)
|
||||||
|
|
||||||
|
|
||||||
class FKDataToField(models.Model):
|
class FKDataToField(models.Model):
|
||||||
data = models.ForeignKey(UniqueAnchor, null=True, to_field='data')
|
data = models.ForeignKey(UniqueAnchor, null=True, to_field='data')
|
||||||
|
|
||||||
|
|
||||||
class FKDataToO2O(models.Model):
|
class FKDataToO2O(models.Model):
|
||||||
data = models.ForeignKey(O2OData, null=True)
|
data = models.ForeignKey(O2OData, null=True)
|
||||||
|
|
||||||
|
|
||||||
class M2MIntermediateData(models.Model):
|
class M2MIntermediateData(models.Model):
|
||||||
data = models.ManyToManyField(Anchor, null=True, through='Intermediate')
|
data = models.ManyToManyField(Anchor, null=True, through='Intermediate')
|
||||||
|
|
||||||
|
|
||||||
class Intermediate(models.Model):
|
class Intermediate(models.Model):
|
||||||
left = models.ForeignKey(M2MIntermediateData)
|
left = models.ForeignKey(M2MIntermediateData)
|
||||||
right = models.ForeignKey(Anchor)
|
right = models.ForeignKey(Anchor)
|
||||||
|
@ -169,9 +206,11 @@ class Intermediate(models.Model):
|
||||||
# because they can't be used as a primary key on one
|
# because they can't be used as a primary key on one
|
||||||
# or all database backends.
|
# or all database backends.
|
||||||
|
|
||||||
|
|
||||||
class BooleanPKData(models.Model):
|
class BooleanPKData(models.Model):
|
||||||
data = models.BooleanField(primary_key=True, default=False)
|
data = models.BooleanField(primary_key=True, default=False)
|
||||||
|
|
||||||
|
|
||||||
class CharPKData(models.Model):
|
class CharPKData(models.Model):
|
||||||
data = models.CharField(max_length=30, primary_key=True)
|
data = models.CharField(max_length=30, primary_key=True)
|
||||||
|
|
||||||
|
@ -181,32 +220,39 @@ class CharPKData(models.Model):
|
||||||
# class DateTimePKData(models.Model):
|
# class DateTimePKData(models.Model):
|
||||||
# data = models.DateTimeField(primary_key=True)
|
# data = models.DateTimeField(primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class DecimalPKData(models.Model):
|
class DecimalPKData(models.Model):
|
||||||
data = models.DecimalField(primary_key=True, decimal_places=3, max_digits=5)
|
data = models.DecimalField(primary_key=True, decimal_places=3, max_digits=5)
|
||||||
|
|
||||||
|
|
||||||
class EmailPKData(models.Model):
|
class EmailPKData(models.Model):
|
||||||
data = models.EmailField(primary_key=True)
|
data = models.EmailField(primary_key=True)
|
||||||
|
|
||||||
# class FilePKData(models.Model):
|
# class FilePKData(models.Model):
|
||||||
# data = models.FileField(primary_key=True, upload_to='/foo/bar')
|
# data = models.FileField(primary_key=True, upload_to='/foo/bar')
|
||||||
|
|
||||||
|
|
||||||
class FilePathPKData(models.Model):
|
class FilePathPKData(models.Model):
|
||||||
data = models.FilePathField(primary_key=True)
|
data = models.FilePathField(primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class FloatPKData(models.Model):
|
class FloatPKData(models.Model):
|
||||||
data = models.FloatField(primary_key=True)
|
data = models.FloatField(primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class IntegerPKData(models.Model):
|
class IntegerPKData(models.Model):
|
||||||
data = models.IntegerField(primary_key=True)
|
data = models.IntegerField(primary_key=True)
|
||||||
|
|
||||||
# class ImagePKData(models.Model):
|
# class ImagePKData(models.Model):
|
||||||
# data = models.ImageField(primary_key=True)
|
# data = models.ImageField(primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class IPAddressPKData(models.Model):
|
class IPAddressPKData(models.Model):
|
||||||
with warnings.catch_warnings(record=True) as w:
|
with warnings.catch_warnings(record=True) as w:
|
||||||
warnings.simplefilter("always")
|
warnings.simplefilter("always")
|
||||||
data = models.IPAddressField(primary_key=True)
|
data = models.IPAddressField(primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class GenericIPAddressPKData(models.Model):
|
class GenericIPAddressPKData(models.Model):
|
||||||
data = models.GenericIPAddressField(primary_key=True)
|
data = models.GenericIPAddressField(primary_key=True)
|
||||||
|
|
||||||
|
@ -214,15 +260,19 @@ class GenericIPAddressPKData(models.Model):
|
||||||
# class NullBooleanPKData(models.Model):
|
# class NullBooleanPKData(models.Model):
|
||||||
# data = models.NullBooleanField(primary_key=True)
|
# data = models.NullBooleanField(primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class PositiveIntegerPKData(models.Model):
|
class PositiveIntegerPKData(models.Model):
|
||||||
data = models.PositiveIntegerField(primary_key=True)
|
data = models.PositiveIntegerField(primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class PositiveSmallIntegerPKData(models.Model):
|
class PositiveSmallIntegerPKData(models.Model):
|
||||||
data = models.PositiveSmallIntegerField(primary_key=True)
|
data = models.PositiveSmallIntegerField(primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class SlugPKData(models.Model):
|
class SlugPKData(models.Model):
|
||||||
data = models.SlugField(primary_key=True)
|
data = models.SlugField(primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class SmallPKData(models.Model):
|
class SmallPKData(models.Model):
|
||||||
data = models.SmallIntegerField(primary_key=True)
|
data = models.SmallIntegerField(primary_key=True)
|
||||||
|
|
||||||
|
@ -232,6 +282,7 @@ class SmallPKData(models.Model):
|
||||||
# class TimePKData(models.Model):
|
# class TimePKData(models.Model):
|
||||||
# data = models.TimeField(primary_key=True)
|
# data = models.TimeField(primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class ComplexModel(models.Model):
|
class ComplexModel(models.Model):
|
||||||
field1 = models.CharField(max_length=10)
|
field1 = models.CharField(max_length=10)
|
||||||
field2 = 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
|
# Tests for handling fields with pre_save functions, or
|
||||||
# models with save functions that modify data
|
# models with save functions that modify data
|
||||||
|
|
||||||
|
|
||||||
class AutoNowDateTimeData(models.Model):
|
class AutoNowDateTimeData(models.Model):
|
||||||
data = models.DateTimeField(null=True, auto_now=True)
|
data = models.DateTimeField(null=True, auto_now=True)
|
||||||
|
|
||||||
|
|
||||||
class ModifyingSaveData(models.Model):
|
class ModifyingSaveData(models.Model):
|
||||||
data = models.IntegerField(null=True)
|
data = models.IntegerField(null=True)
|
||||||
|
|
||||||
|
@ -256,33 +310,42 @@ class ModifyingSaveData(models.Model):
|
||||||
|
|
||||||
# Tests for serialization of models using inheritance.
|
# Tests for serialization of models using inheritance.
|
||||||
# Regression for #7202, #7350
|
# Regression for #7202, #7350
|
||||||
|
|
||||||
|
|
||||||
class AbstractBaseModel(models.Model):
|
class AbstractBaseModel(models.Model):
|
||||||
parent_data = models.IntegerField()
|
parent_data = models.IntegerField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
class InheritAbstractModel(AbstractBaseModel):
|
class InheritAbstractModel(AbstractBaseModel):
|
||||||
child_data = models.IntegerField()
|
child_data = models.IntegerField()
|
||||||
|
|
||||||
|
|
||||||
class BaseModel(models.Model):
|
class BaseModel(models.Model):
|
||||||
parent_data = models.IntegerField()
|
parent_data = models.IntegerField()
|
||||||
|
|
||||||
|
|
||||||
class InheritBaseModel(BaseModel):
|
class InheritBaseModel(BaseModel):
|
||||||
child_data = models.IntegerField()
|
child_data = models.IntegerField()
|
||||||
|
|
||||||
|
|
||||||
class ExplicitInheritBaseModel(BaseModel):
|
class ExplicitInheritBaseModel(BaseModel):
|
||||||
parent = models.OneToOneField(BaseModel)
|
parent = models.OneToOneField(BaseModel)
|
||||||
child_data = models.IntegerField()
|
child_data = models.IntegerField()
|
||||||
|
|
||||||
|
|
||||||
class ProxyBaseModel(BaseModel):
|
class ProxyBaseModel(BaseModel):
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
|
|
||||||
|
|
||||||
class ProxyProxyBaseModel(ProxyBaseModel):
|
class ProxyProxyBaseModel(ProxyBaseModel):
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
|
|
||||||
|
|
||||||
class LengthModel(models.Model):
|
class LengthModel(models.Model):
|
||||||
data = models.IntegerField()
|
data = models.IntegerField()
|
||||||
|
|
||||||
|
|
|
@ -48,12 +48,15 @@ from .models import (BinaryData, BooleanData, CharData, DateData, DateTimeData,
|
||||||
# The save method is a raw base model save, to make
|
# The save method is a raw base model save, to make
|
||||||
# sure that the data in the database matches the
|
# sure that the data in the database matches the
|
||||||
# exact test case.
|
# exact test case.
|
||||||
|
|
||||||
|
|
||||||
def data_create(pk, klass, data):
|
def data_create(pk, klass, data):
|
||||||
instance = klass(id=pk)
|
instance = klass(id=pk)
|
||||||
instance.data = data
|
instance.data = data
|
||||||
models.Model.save_base(instance, raw=True)
|
models.Model.save_base(instance, raw=True)
|
||||||
return [instance]
|
return [instance]
|
||||||
|
|
||||||
|
|
||||||
def generic_create(pk, klass, data):
|
def generic_create(pk, klass, data):
|
||||||
instance = klass(id=pk)
|
instance = klass(id=pk)
|
||||||
instance.data = data[0]
|
instance.data = data[0]
|
||||||
|
@ -62,23 +65,27 @@ def generic_create(pk, klass, data):
|
||||||
instance.tags.create(data=tag)
|
instance.tags.create(data=tag)
|
||||||
return [instance]
|
return [instance]
|
||||||
|
|
||||||
|
|
||||||
def fk_create(pk, klass, data):
|
def fk_create(pk, klass, data):
|
||||||
instance = klass(id=pk)
|
instance = klass(id=pk)
|
||||||
setattr(instance, 'data_id', data)
|
setattr(instance, 'data_id', data)
|
||||||
models.Model.save_base(instance, raw=True)
|
models.Model.save_base(instance, raw=True)
|
||||||
return [instance]
|
return [instance]
|
||||||
|
|
||||||
|
|
||||||
def m2m_create(pk, klass, data):
|
def m2m_create(pk, klass, data):
|
||||||
instance = klass(id=pk)
|
instance = klass(id=pk)
|
||||||
models.Model.save_base(instance, raw=True)
|
models.Model.save_base(instance, raw=True)
|
||||||
instance.data = data
|
instance.data = data
|
||||||
return [instance]
|
return [instance]
|
||||||
|
|
||||||
|
|
||||||
def im2m_create(pk, klass, data):
|
def im2m_create(pk, klass, data):
|
||||||
instance = klass(id=pk)
|
instance = klass(id=pk)
|
||||||
models.Model.save_base(instance, raw=True)
|
models.Model.save_base(instance, raw=True)
|
||||||
return [instance]
|
return [instance]
|
||||||
|
|
||||||
|
|
||||||
def im_create(pk, klass, data):
|
def im_create(pk, klass, data):
|
||||||
instance = klass(id=pk)
|
instance = klass(id=pk)
|
||||||
instance.right_id = data['right']
|
instance.right_id = data['right']
|
||||||
|
@ -88,18 +95,21 @@ def im_create(pk, klass, data):
|
||||||
models.Model.save_base(instance, raw=True)
|
models.Model.save_base(instance, raw=True)
|
||||||
return [instance]
|
return [instance]
|
||||||
|
|
||||||
|
|
||||||
def o2o_create(pk, klass, data):
|
def o2o_create(pk, klass, data):
|
||||||
instance = klass()
|
instance = klass()
|
||||||
instance.data_id = data
|
instance.data_id = data
|
||||||
models.Model.save_base(instance, raw=True)
|
models.Model.save_base(instance, raw=True)
|
||||||
return [instance]
|
return [instance]
|
||||||
|
|
||||||
|
|
||||||
def pk_create(pk, klass, data):
|
def pk_create(pk, klass, data):
|
||||||
instance = klass()
|
instance = klass()
|
||||||
instance.data = data
|
instance.data = data
|
||||||
models.Model.save_base(instance, raw=True)
|
models.Model.save_base(instance, raw=True)
|
||||||
return [instance]
|
return [instance]
|
||||||
|
|
||||||
|
|
||||||
def inherited_create(pk, klass, data):
|
def inherited_create(pk, klass, data):
|
||||||
instance = klass(id=pk, **data)
|
instance = klass(id=pk, **data)
|
||||||
# This isn't a raw save because:
|
# 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
|
# A set of functions that can be used to compare
|
||||||
# test data objects of various kinds
|
# test data objects of various kinds
|
||||||
|
|
||||||
|
|
||||||
def data_compare(testcase, pk, klass, data):
|
def data_compare(testcase, pk, klass, data):
|
||||||
instance = klass.objects.get(id=pk)
|
instance = klass.objects.get(id=pk)
|
||||||
if klass == BinaryData and data is not None:
|
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))
|
pk, data, type(data), instance, type(instance.data))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def generic_compare(testcase, pk, klass, data):
|
def generic_compare(testcase, pk, klass, data):
|
||||||
instance = klass.objects.get(id=pk)
|
instance = klass.objects.get(id=pk)
|
||||||
testcase.assertEqual(data[0], instance.data)
|
testcase.assertEqual(data[0], instance.data)
|
||||||
testcase.assertEqual(data[1:], [t.data for t in instance.tags.order_by('id')])
|
testcase.assertEqual(data[1:], [t.data for t in instance.tags.order_by('id')])
|
||||||
|
|
||||||
|
|
||||||
def fk_compare(testcase, pk, klass, data):
|
def fk_compare(testcase, pk, klass, data):
|
||||||
instance = klass.objects.get(id=pk)
|
instance = klass.objects.get(id=pk)
|
||||||
testcase.assertEqual(data, instance.data_id)
|
testcase.assertEqual(data, instance.data_id)
|
||||||
|
|
||||||
|
|
||||||
def m2m_compare(testcase, pk, klass, data):
|
def m2m_compare(testcase, pk, klass, data):
|
||||||
instance = klass.objects.get(id=pk)
|
instance = klass.objects.get(id=pk)
|
||||||
testcase.assertEqual(data, [obj.id for obj in instance.data.order_by('id')])
|
testcase.assertEqual(data, [obj.id for obj in instance.data.order_by('id')])
|
||||||
|
|
||||||
|
|
||||||
def im2m_compare(testcase, pk, klass, data):
|
def im2m_compare(testcase, pk, klass, data):
|
||||||
klass.objects.get(id=pk)
|
klass.objects.get(id=pk)
|
||||||
# actually nothing else to check, the instance just should exist
|
# actually nothing else to check, the instance just should exist
|
||||||
|
|
||||||
|
|
||||||
def im_compare(testcase, pk, klass, data):
|
def im_compare(testcase, pk, klass, data):
|
||||||
instance = klass.objects.get(id=pk)
|
instance = klass.objects.get(id=pk)
|
||||||
testcase.assertEqual(data['left'], instance.left_id)
|
testcase.assertEqual(data['left'], instance.left_id)
|
||||||
|
@ -155,14 +172,17 @@ def im_compare(testcase, pk, klass, data):
|
||||||
else:
|
else:
|
||||||
testcase.assertEqual("doesn't matter", instance.extra)
|
testcase.assertEqual("doesn't matter", instance.extra)
|
||||||
|
|
||||||
|
|
||||||
def o2o_compare(testcase, pk, klass, data):
|
def o2o_compare(testcase, pk, klass, data):
|
||||||
instance = klass.objects.get(data=data)
|
instance = klass.objects.get(data=data)
|
||||||
testcase.assertEqual(data, instance.data_id)
|
testcase.assertEqual(data, instance.data_id)
|
||||||
|
|
||||||
|
|
||||||
def pk_compare(testcase, pk, klass, data):
|
def pk_compare(testcase, pk, klass, data):
|
||||||
instance = klass.objects.get(data=data)
|
instance = klass.objects.get(data=data)
|
||||||
testcase.assertEqual(data, instance.data)
|
testcase.assertEqual(data, instance.data)
|
||||||
|
|
||||||
|
|
||||||
def inherited_compare(testcase, pk, klass, data):
|
def inherited_compare(testcase, pk, klass, data):
|
||||||
instance = klass.objects.get(id=pk)
|
instance = klass.objects.get(id=pk)
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
|
@ -256,21 +276,21 @@ The end."""),
|
||||||
(data_obj, 301, Anchor, "Anchor 2"),
|
(data_obj, 301, Anchor, "Anchor 2"),
|
||||||
(data_obj, 302, UniqueAnchor, "UAnchor 1"),
|
(data_obj, 302, UniqueAnchor, "UAnchor 1"),
|
||||||
|
|
||||||
(fk_obj, 400, FKData, 300), # Post reference
|
(fk_obj, 400, FKData, 300), # Post reference
|
||||||
(fk_obj, 401, FKData, 500), # Pre reference
|
(fk_obj, 401, FKData, 500), # Pre reference
|
||||||
(fk_obj, 402, FKData, None), # Empty reference
|
(fk_obj, 402, FKData, None), # Empty reference
|
||||||
|
|
||||||
(m2m_obj, 410, M2MData, []), # Empty set
|
(m2m_obj, 410, M2MData, []), # Empty set
|
||||||
(m2m_obj, 411, M2MData, [300, 301]), # Post reference
|
(m2m_obj, 411, M2MData, [300, 301]), # Post reference
|
||||||
(m2m_obj, 412, M2MData, [500, 501]), # Pre reference
|
(m2m_obj, 412, M2MData, [500, 501]), # Pre reference
|
||||||
(m2m_obj, 413, M2MData, [300, 301, 500, 501]), # Pre and Post reference
|
(m2m_obj, 413, M2MData, [300, 301, 500, 501]), # Pre and Post reference
|
||||||
|
|
||||||
(o2o_obj, None, O2OData, 300), # Post reference
|
(o2o_obj, None, O2OData, 300), # Post reference
|
||||||
(o2o_obj, None, O2OData, 500), # Pre reference
|
(o2o_obj, None, O2OData, 500), # Pre reference
|
||||||
|
|
||||||
(fk_obj, 430, FKSelfData, 431), # Pre reference
|
(fk_obj, 430, FKSelfData, 431), # Pre reference
|
||||||
(fk_obj, 431, FKSelfData, 430), # Post reference
|
(fk_obj, 431, FKSelfData, 430), # Post reference
|
||||||
(fk_obj, 432, FKSelfData, None), # Empty reference
|
(fk_obj, 432, FKSelfData, None), # Empty reference
|
||||||
|
|
||||||
(m2m_obj, 440, M2MSelfData, []),
|
(m2m_obj, 440, M2MSelfData, []),
|
||||||
(m2m_obj, 441, M2MSelfData, []),
|
(m2m_obj, 441, M2MSelfData, []),
|
||||||
|
@ -380,6 +400,8 @@ if connection.features.allows_primary_key_0:
|
||||||
|
|
||||||
# Dynamically create serializer tests to ensure that all
|
# Dynamically create serializer tests to ensure that all
|
||||||
# registered serializers are automatically tested.
|
# registered serializers are automatically tested.
|
||||||
|
|
||||||
|
|
||||||
class SerializerTests(TestCase):
|
class SerializerTests(TestCase):
|
||||||
def test_get_unknown_serializer(self):
|
def test_get_unknown_serializer(self):
|
||||||
"""
|
"""
|
||||||
|
@ -496,6 +518,7 @@ def naturalKeySerializerTest(format, self):
|
||||||
for klass, count in instance_count.items():
|
for klass, count in instance_count.items():
|
||||||
self.assertEqual(count, klass.objects.count())
|
self.assertEqual(count, klass.objects.count())
|
||||||
|
|
||||||
|
|
||||||
def fieldsTest(format, self):
|
def fieldsTest(format, self):
|
||||||
obj = ComplexModel(field1='first', field2='second', field3='third')
|
obj = ComplexModel(field1='first', field2='second', field3='third')
|
||||||
obj.save_base(raw=True)
|
obj.save_base(raw=True)
|
||||||
|
@ -509,6 +532,7 @@ def fieldsTest(format, self):
|
||||||
self.assertEqual(result.object.field2, '')
|
self.assertEqual(result.object.field2, '')
|
||||||
self.assertEqual(result.object.field3, 'third')
|
self.assertEqual(result.object.field3, 'third')
|
||||||
|
|
||||||
|
|
||||||
def streamTest(format, self):
|
def streamTest(format, self):
|
||||||
obj = ComplexModel(field1='first', field2='second', field3='third')
|
obj = ComplexModel(field1='first', field2='second', field3='third')
|
||||||
obj.save_base(raw=True)
|
obj.save_base(raw=True)
|
||||||
|
|
|
@ -107,6 +107,7 @@ class LiveServerAddress(LiveServerBase):
|
||||||
# test runner and the overridden setUpClass() method is executed.
|
# test runner and the overridden setUpClass() method is executed.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LiveServerViews(LiveServerBase):
|
class LiveServerViews(LiveServerBase):
|
||||||
def test_404(self):
|
def test_404(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -76,6 +76,7 @@ class ClassDecoratedTestCase(ClassDecoratedTestCaseSuper):
|
||||||
class ParentDecoratedTestCase(TestCase):
|
class ParentDecoratedTestCase(TestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@override_settings(TEST='override-child')
|
@override_settings(TEST='override-child')
|
||||||
class ChildDecoratedTestCase(ParentDecoratedTestCase):
|
class ChildDecoratedTestCase(ParentDecoratedTestCase):
|
||||||
def test_override_settings_inheritance(self):
|
def test_override_settings_inheritance(self):
|
||||||
|
|
|
@ -15,6 +15,7 @@ class Person(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s %s" % (self.first_name, self.last_name)
|
return "%s %s" % (self.first_name, self.last_name)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Car(models.Model):
|
class Car(models.Model):
|
||||||
make = models.CharField(max_length=20)
|
make = models.CharField(max_length=20)
|
||||||
|
|
|
@ -18,6 +18,7 @@ class PostDeleteHandler(object):
|
||||||
(instance, instance.id is None)
|
(instance, instance.id is None)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class MyReceiver(object):
|
class MyReceiver(object):
|
||||||
def __init__(self, param):
|
def __init__(self, param):
|
||||||
self.param = param
|
self.param = param
|
||||||
|
@ -27,6 +28,7 @@ class MyReceiver(object):
|
||||||
self._run = True
|
self._run = True
|
||||||
signal.disconnect(receiver=self, sender=sender)
|
signal.disconnect(receiver=self, sender=sender)
|
||||||
|
|
||||||
|
|
||||||
class SignalTests(TestCase):
|
class SignalTests(TestCase):
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
# Save up the number of connected signals so that we can check at the
|
# Save up the number of connected signals so that we can check at the
|
||||||
|
|
|
@ -9,6 +9,7 @@ class Author(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Book(models.Model):
|
class Book(models.Model):
|
||||||
name = models.CharField(max_length=20)
|
name = models.CharField(max_length=20)
|
||||||
|
|
|
@ -105,6 +105,7 @@ class TestSigner(TestCase):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
signing.BadSignature, signing.loads, transform(encoded))
|
signing.BadSignature, signing.loads, transform(encoded))
|
||||||
|
|
||||||
|
|
||||||
class TestTimestampSigner(TestCase):
|
class TestTimestampSigner(TestCase):
|
||||||
|
|
||||||
def test_timestamp_signer(self):
|
def test_timestamp_signer(self):
|
||||||
|
|
|
@ -3,6 +3,7 @@ from django.contrib.sites.models import Site
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class AbstractArticle(models.Model):
|
class AbstractArticle(models.Model):
|
||||||
title = models.CharField(max_length=50)
|
title = models.CharField(max_length=50)
|
||||||
|
@ -16,23 +17,28 @@ class AbstractArticle(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
class SyndicatedArticle(AbstractArticle):
|
class SyndicatedArticle(AbstractArticle):
|
||||||
sites = models.ManyToManyField(Site)
|
sites = models.ManyToManyField(Site)
|
||||||
|
|
||||||
|
|
||||||
class ExclusiveArticle(AbstractArticle):
|
class ExclusiveArticle(AbstractArticle):
|
||||||
site = models.ForeignKey(Site)
|
site = models.ForeignKey(Site)
|
||||||
|
|
||||||
|
|
||||||
class CustomArticle(AbstractArticle):
|
class CustomArticle(AbstractArticle):
|
||||||
places_this_article_should_appear = models.ForeignKey(Site)
|
places_this_article_should_appear = models.ForeignKey(Site)
|
||||||
|
|
||||||
objects = models.Manager()
|
objects = models.Manager()
|
||||||
on_site = CurrentSiteManager("places_this_article_should_appear")
|
on_site = CurrentSiteManager("places_this_article_should_appear")
|
||||||
|
|
||||||
|
|
||||||
class InvalidArticle(AbstractArticle):
|
class InvalidArticle(AbstractArticle):
|
||||||
site = models.ForeignKey(Site)
|
site = models.ForeignKey(Site)
|
||||||
|
|
||||||
objects = models.Manager()
|
objects = models.Manager()
|
||||||
on_site = CurrentSiteManager("places_this_article_should_appear")
|
on_site = CurrentSiteManager("places_this_article_should_appear")
|
||||||
|
|
||||||
|
|
||||||
class ConfusedArticle(AbstractArticle):
|
class ConfusedArticle(AbstractArticle):
|
||||||
site = models.IntegerField()
|
site = models.IntegerField()
|
||||||
|
|
|
@ -2,6 +2,7 @@ from datetime import datetime
|
||||||
from django.core.files import storage
|
from django.core.files import storage
|
||||||
from django.contrib.staticfiles.storage import CachedStaticFilesStorage
|
from django.contrib.staticfiles.storage import CachedStaticFilesStorage
|
||||||
|
|
||||||
|
|
||||||
class DummyStorage(storage.Storage):
|
class DummyStorage(storage.Storage):
|
||||||
"""
|
"""
|
||||||
A storage class that does implement modified_time() but raises
|
A storage class that does implement modified_time() but raises
|
||||||
|
|
|
@ -27,6 +27,7 @@ class Article(models.Model):
|
||||||
# in ASCII.
|
# in ASCII.
|
||||||
return self.headline
|
return self.headline
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class InternationalArticle(models.Model):
|
class InternationalArticle(models.Model):
|
||||||
headline = models.CharField(max_length=100)
|
headline = models.CharField(max_length=100)
|
||||||
|
|
|
@ -14,6 +14,7 @@ class Foo(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Foo %s" % self.name
|
return "Foo %s" % self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Bar(models.Model):
|
class Bar(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -24,6 +25,7 @@ class Bar(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Bar %s" % self.place.name
|
return "Bar %s" % self.place.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Whiz(models.Model):
|
class Whiz(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -31,6 +33,7 @@ class Whiz(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Whiz %s" % self.name
|
return "Whiz %s" % self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Child(models.Model):
|
class Child(models.Model):
|
||||||
parent = models.OneToOneField('Base')
|
parent = models.OneToOneField('Base')
|
||||||
|
@ -39,6 +42,7 @@ class Child(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Child %s" % self.name
|
return "Child %s" % self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Base(models.Model):
|
class Base(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
@ -46,6 +50,7 @@ class Base(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Base %s" % self.name
|
return "Base %s" % self.name
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Article(models.Model):
|
class Article(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
|
|
@ -49,6 +49,7 @@ class FeedTestCase(TestCase):
|
||||||
# Feed view
|
# Feed view
|
||||||
######################################
|
######################################
|
||||||
|
|
||||||
|
|
||||||
class SyndicationFeedTest(FeedTestCase):
|
class SyndicationFeedTest(FeedTestCase):
|
||||||
"""
|
"""
|
||||||
Tests for the high-level syndication feed framework.
|
Tests for the high-level syndication feed framework.
|
||||||
|
|
|
@ -7,15 +7,18 @@ from django.db import models
|
||||||
# "reference" models to avoid errors when other tests run 'migrate'
|
# "reference" models to avoid errors when other tests run 'migrate'
|
||||||
# (proxy_models_inheritance does).
|
# (proxy_models_inheritance does).
|
||||||
|
|
||||||
|
|
||||||
class ScientistRef(models.Model):
|
class ScientistRef(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
|
||||||
|
|
||||||
class ArticleRef(models.Model):
|
class ArticleRef(models.Model):
|
||||||
title = models.CharField(max_length=50, unique=True)
|
title = models.CharField(max_length=50, unique=True)
|
||||||
code = models.CharField(max_length=50, unique=True)
|
code = models.CharField(max_length=50, unique=True)
|
||||||
authors = models.ManyToManyField(ScientistRef, related_name='articles_written_set')
|
authors = models.ManyToManyField(ScientistRef, related_name='articles_written_set')
|
||||||
reviewers = models.ManyToManyField(ScientistRef, related_name='articles_reviewed_set')
|
reviewers = models.ManyToManyField(ScientistRef, related_name='articles_reviewed_set')
|
||||||
|
|
||||||
|
|
||||||
class Scientist(models.Model):
|
class Scientist(models.Model):
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
|
||||||
|
@ -24,6 +27,7 @@ class Scientist(models.Model):
|
||||||
db_tablespace = 'tbl_tbsp'
|
db_tablespace = 'tbl_tbsp'
|
||||||
managed = False
|
managed = False
|
||||||
|
|
||||||
|
|
||||||
class Article(models.Model):
|
class Article(models.Model):
|
||||||
title = models.CharField(max_length=50, unique=True)
|
title = models.CharField(max_length=50, unique=True)
|
||||||
code = models.CharField(max_length=50, unique=True, db_tablespace='idx_tbsp')
|
code = models.CharField(max_length=50, unique=True, db_tablespace='idx_tbsp')
|
||||||
|
|
|
@ -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,
|
# because they're evaluated when the model class is defined. As a consequence,
|
||||||
# @override_settings doesn't work, and the tests depend
|
# @override_settings doesn't work, and the tests depend
|
||||||
|
|
||||||
|
|
||||||
def sql_for_table(model):
|
def sql_for_table(model):
|
||||||
return '\n'.join(connection.creation.sql_create_model(model, no_style())[0])
|
return '\n'.join(connection.creation.sql_create_model(model, no_style())[0])
|
||||||
|
|
||||||
|
|
||||||
def sql_for_index(model):
|
def sql_for_index(model):
|
||||||
return '\n'.join(connection.creation.sql_indexes_for_model(model, no_style()))
|
return '\n'.join(connection.creation.sql_indexes_for_model(model, no_style()))
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,14 @@ from django.utils.safestring import mark_safe
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
# These two classes are used to test auto-escaping of __unicode__ output.
|
# These two classes are used to test auto-escaping of __unicode__ output.
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class UnsafeClass:
|
class UnsafeClass:
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'you & me'
|
return 'you & me'
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class SafeClass:
|
class SafeClass:
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -29,6 +32,8 @@ class SafeClass:
|
||||||
# RESULT SYNTAX --
|
# RESULT SYNTAX --
|
||||||
# 'template_name': ('template contents', 'context dict',
|
# 'template_name': ('template contents', 'context dict',
|
||||||
# 'expected string output' or Exception class)
|
# 'expected string output' or Exception class)
|
||||||
|
|
||||||
|
|
||||||
def get_filter_tests():
|
def get_filter_tests():
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
now_tz = timezone.make_aware(now, timezone.get_default_timezone())
|
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
|
# NOTE: \xa0 avoids wrapping between value and unit
|
||||||
return {
|
return {
|
||||||
# Default compare with datetime.now()
|
# Default compare with datetime.now()
|
||||||
'filter-timesince01': ('{{ a|timesince }}', {'a': datetime.now() + timedelta(minutes=-1, seconds = -10)}, '1\xa0minute'),
|
'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-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-timesince03': ('{{ a|timesince }}', {'a': datetime.now() - timedelta(hours=1, minutes=25, seconds=10)}, '1\xa0hour, 25\xa0minutes'),
|
||||||
|
|
||||||
# Compare to a given parameter
|
# Compare to a given parameter
|
||||||
'filter-timesince04': ('{{ a|timesince:b }}', {'a': now - timedelta(days=2), 'b': now - timedelta(days=1)}, '1\xa0day'),
|
'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()
|
# Default compare with datetime.now()
|
||||||
'filter-timeuntil01': ('{{ a|timeuntil }}', {'a': datetime.now() + timedelta(minutes=2, seconds=10)}, '2\xa0minutes'),
|
'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-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
|
# Compare to a given parameter
|
||||||
'filter-timeuntil04': ('{{ a|timeuntil:b }}', {'a': now - timedelta(days=1), 'b': now - timedelta(days=2)}, '1\xa0day'),
|
'filter-timeuntil04': ('{{ a|timeuntil:b }}', {'a': now - timedelta(days=1), 'b': now - timedelta(days=2)}, '1\xa0day'),
|
||||||
|
|
|
@ -3,10 +3,12 @@ from django import template
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.tag
|
@register.tag
|
||||||
def badtag(parser, token):
|
def badtag(parser, token):
|
||||||
raise RuntimeError("I am a bad tag")
|
raise RuntimeError("I am a bad tag")
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def badsimpletag():
|
def badsimpletag():
|
||||||
raise RuntimeError("I am a bad simpletag")
|
raise RuntimeError("I am a bad simpletag")
|
||||||
|
|
|
@ -7,11 +7,13 @@ from django.utils import six
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
@stringfilter
|
@stringfilter
|
||||||
def trim(value, num):
|
def trim(value, num):
|
||||||
return value[:num]
|
return value[:num]
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def noop(value, param=None):
|
def noop(value, param=None):
|
||||||
"""A noop filter that always return its first argument and does nothing with
|
"""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)."""
|
Useful for testing out whitespace in filter arguments (see #19882)."""
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def no_params():
|
def no_params():
|
||||||
"""Expected no_params __doc__"""
|
"""Expected no_params __doc__"""
|
||||||
return "no_params - Expected result"
|
return "no_params - Expected result"
|
||||||
no_params.anything = "Expected no_params __dict__"
|
no_params.anything = "Expected no_params __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def one_param(arg):
|
def one_param(arg):
|
||||||
"""Expected one_param __doc__"""
|
"""Expected one_param __doc__"""
|
||||||
return "one_param - Expected result: %s" % arg
|
return "one_param - Expected result: %s" % arg
|
||||||
one_param.anything = "Expected one_param __dict__"
|
one_param.anything = "Expected one_param __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=False)
|
@register.simple_tag(takes_context=False)
|
||||||
def explicit_no_context(arg):
|
def explicit_no_context(arg):
|
||||||
"""Expected explicit_no_context __doc__"""
|
"""Expected explicit_no_context __doc__"""
|
||||||
return "explicit_no_context - Expected result: %s" % arg
|
return "explicit_no_context - Expected result: %s" % arg
|
||||||
explicit_no_context.anything = "Expected explicit_no_context __dict__"
|
explicit_no_context.anything = "Expected explicit_no_context __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def no_params_with_context(context):
|
def no_params_with_context(context):
|
||||||
"""Expected no_params_with_context __doc__"""
|
"""Expected no_params_with_context __doc__"""
|
||||||
return "no_params_with_context - Expected result (context value: %s)" % context['value']
|
return "no_params_with_context - Expected result (context value: %s)" % context['value']
|
||||||
no_params_with_context.anything = "Expected no_params_with_context __dict__"
|
no_params_with_context.anything = "Expected no_params_with_context __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def params_and_context(context, arg):
|
def params_and_context(context, arg):
|
||||||
"""Expected params_and_context __doc__"""
|
"""Expected params_and_context __doc__"""
|
||||||
return "params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)
|
return "params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)
|
||||||
params_and_context.anything = "Expected params_and_context __dict__"
|
params_and_context.anything = "Expected params_and_context __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def simple_two_params(one, two):
|
def simple_two_params(one, two):
|
||||||
"""Expected simple_two_params __doc__"""
|
"""Expected simple_two_params __doc__"""
|
||||||
return "simple_two_params - Expected result: %s, %s" % (one, two)
|
return "simple_two_params - Expected result: %s, %s" % (one, two)
|
||||||
simple_two_params.anything = "Expected simple_two_params __dict__"
|
simple_two_params.anything = "Expected simple_two_params __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def simple_one_default(one, two='hi'):
|
def simple_one_default(one, two='hi'):
|
||||||
"""Expected simple_one_default __doc__"""
|
"""Expected simple_one_default __doc__"""
|
||||||
return "simple_one_default - Expected result: %s, %s" % (one, two)
|
return "simple_one_default - Expected result: %s, %s" % (one, two)
|
||||||
simple_one_default.anything = "Expected simple_one_default __dict__"
|
simple_one_default.anything = "Expected simple_one_default __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def simple_unlimited_args(one, two='hi', *args):
|
def simple_unlimited_args(one, two='hi', *args):
|
||||||
"""Expected simple_unlimited_args __doc__"""
|
"""Expected simple_unlimited_args __doc__"""
|
||||||
return "simple_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args)))
|
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__"
|
simple_unlimited_args.anything = "Expected simple_unlimited_args __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def simple_only_unlimited_args(*args):
|
def simple_only_unlimited_args(*args):
|
||||||
"""Expected simple_only_unlimited_args __doc__"""
|
"""Expected simple_only_unlimited_args __doc__"""
|
||||||
return "simple_only_unlimited_args - Expected result: %s" % ', '.join(six.text_type(arg) for arg in args)
|
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__"
|
simple_only_unlimited_args.anything = "Expected simple_only_unlimited_args __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def simple_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
def simple_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
||||||
"""Expected simple_unlimited_args_kwargs __doc__"""
|
"""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__"
|
simple_unlimited_args_kwargs.anything = "Expected simple_unlimited_args_kwargs __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def simple_tag_without_context_parameter(arg):
|
def simple_tag_without_context_parameter(arg):
|
||||||
"""Expected simple_tag_without_context_parameter __doc__"""
|
"""Expected simple_tag_without_context_parameter __doc__"""
|
||||||
return "Expected result"
|
return "Expected result"
|
||||||
simple_tag_without_context_parameter.anything = "Expected simple_tag_without_context_parameter __dict__"
|
simple_tag_without_context_parameter.anything = "Expected simple_tag_without_context_parameter __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def current_app(context):
|
def current_app(context):
|
||||||
return "%s" % context.current_app
|
return "%s" % context.current_app
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def use_l10n(context):
|
def use_l10n(context):
|
||||||
return "%s" % context.use_l10n
|
return "%s" % context.use_l10n
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(name='minustwo')
|
@register.simple_tag(name='minustwo')
|
||||||
def minustwo_overridden_name(value):
|
def minustwo_overridden_name(value):
|
||||||
return value - 2
|
return value - 2
|
||||||
|
|
||||||
register.simple_tag(lambda x: x - 1, name='minusone')
|
register.simple_tag(lambda x: x - 1, name='minusone')
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html')
|
@register.inclusion_tag('inclusion.html')
|
||||||
def inclusion_no_params():
|
def inclusion_no_params():
|
||||||
"""Expected inclusion_no_params __doc__"""
|
"""Expected inclusion_no_params __doc__"""
|
||||||
return {"result": "inclusion_no_params - Expected result"}
|
return {"result": "inclusion_no_params - Expected result"}
|
||||||
inclusion_no_params.anything = "Expected inclusion_no_params __dict__"
|
inclusion_no_params.anything = "Expected inclusion_no_params __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag(get_template('inclusion.html'))
|
@register.inclusion_tag(get_template('inclusion.html'))
|
||||||
def inclusion_no_params_from_template():
|
def inclusion_no_params_from_template():
|
||||||
"""Expected inclusion_no_params_from_template __doc__"""
|
"""Expected inclusion_no_params_from_template __doc__"""
|
||||||
return {"result": "inclusion_no_params_from_template - Expected result"}
|
return {"result": "inclusion_no_params_from_template - Expected result"}
|
||||||
inclusion_no_params_from_template.anything = "Expected inclusion_no_params_from_template __dict__"
|
inclusion_no_params_from_template.anything = "Expected inclusion_no_params_from_template __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html')
|
@register.inclusion_tag('inclusion.html')
|
||||||
def inclusion_one_param(arg):
|
def inclusion_one_param(arg):
|
||||||
"""Expected inclusion_one_param __doc__"""
|
"""Expected inclusion_one_param __doc__"""
|
||||||
return {"result": "inclusion_one_param - Expected result: %s" % arg}
|
return {"result": "inclusion_one_param - Expected result: %s" % arg}
|
||||||
inclusion_one_param.anything = "Expected inclusion_one_param __dict__"
|
inclusion_one_param.anything = "Expected inclusion_one_param __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag(get_template('inclusion.html'))
|
@register.inclusion_tag(get_template('inclusion.html'))
|
||||||
def inclusion_one_param_from_template(arg):
|
def inclusion_one_param_from_template(arg):
|
||||||
"""Expected inclusion_one_param_from_template __doc__"""
|
"""Expected inclusion_one_param_from_template __doc__"""
|
||||||
return {"result": "inclusion_one_param_from_template - Expected result: %s" % arg}
|
return {"result": "inclusion_one_param_from_template - Expected result: %s" % arg}
|
||||||
inclusion_one_param_from_template.anything = "Expected inclusion_one_param_from_template __dict__"
|
inclusion_one_param_from_template.anything = "Expected inclusion_one_param_from_template __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html', takes_context=False)
|
@register.inclusion_tag('inclusion.html', takes_context=False)
|
||||||
def inclusion_explicit_no_context(arg):
|
def inclusion_explicit_no_context(arg):
|
||||||
"""Expected inclusion_explicit_no_context __doc__"""
|
"""Expected inclusion_explicit_no_context __doc__"""
|
||||||
return {"result": "inclusion_explicit_no_context - Expected result: %s" % arg}
|
return {"result": "inclusion_explicit_no_context - Expected result: %s" % arg}
|
||||||
inclusion_explicit_no_context.anything = "Expected inclusion_explicit_no_context __dict__"
|
inclusion_explicit_no_context.anything = "Expected inclusion_explicit_no_context __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag(get_template('inclusion.html'), takes_context=False)
|
@register.inclusion_tag(get_template('inclusion.html'), takes_context=False)
|
||||||
def inclusion_explicit_no_context_from_template(arg):
|
def inclusion_explicit_no_context_from_template(arg):
|
||||||
"""Expected inclusion_explicit_no_context_from_template __doc__"""
|
"""Expected inclusion_explicit_no_context_from_template __doc__"""
|
||||||
return {"result": "inclusion_explicit_no_context_from_template - Expected result: %s" % arg}
|
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__"
|
inclusion_explicit_no_context_from_template.anything = "Expected inclusion_explicit_no_context_from_template __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html', takes_context=True)
|
@register.inclusion_tag('inclusion.html', takes_context=True)
|
||||||
def inclusion_no_params_with_context(context):
|
def inclusion_no_params_with_context(context):
|
||||||
"""Expected inclusion_no_params_with_context __doc__"""
|
"""Expected inclusion_no_params_with_context __doc__"""
|
||||||
return {"result": "inclusion_no_params_with_context - Expected result (context value: %s)" % context['value']}
|
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__"
|
inclusion_no_params_with_context.anything = "Expected inclusion_no_params_with_context __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag(get_template('inclusion.html'), takes_context=True)
|
@register.inclusion_tag(get_template('inclusion.html'), takes_context=True)
|
||||||
def inclusion_no_params_with_context_from_template(context):
|
def inclusion_no_params_with_context_from_template(context):
|
||||||
"""Expected inclusion_no_params_with_context_from_template __doc__"""
|
"""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']}
|
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__"
|
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)
|
@register.inclusion_tag('inclusion.html', takes_context=True)
|
||||||
def inclusion_params_and_context(context, arg):
|
def inclusion_params_and_context(context, arg):
|
||||||
"""Expected inclusion_params_and_context __doc__"""
|
"""Expected inclusion_params_and_context __doc__"""
|
||||||
return {"result": "inclusion_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)}
|
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__"
|
inclusion_params_and_context.anything = "Expected inclusion_params_and_context __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag(get_template('inclusion.html'), takes_context=True)
|
@register.inclusion_tag(get_template('inclusion.html'), takes_context=True)
|
||||||
def inclusion_params_and_context_from_template(context, arg):
|
def inclusion_params_and_context_from_template(context, arg):
|
||||||
"""Expected inclusion_params_and_context_from_template __doc__"""
|
"""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)}
|
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__"
|
inclusion_params_and_context_from_template.anything = "Expected inclusion_params_and_context_from_template __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html')
|
@register.inclusion_tag('inclusion.html')
|
||||||
def inclusion_two_params(one, two):
|
def inclusion_two_params(one, two):
|
||||||
"""Expected inclusion_two_params __doc__"""
|
"""Expected inclusion_two_params __doc__"""
|
||||||
return {"result": "inclusion_two_params - Expected result: %s, %s" % (one, two)}
|
return {"result": "inclusion_two_params - Expected result: %s, %s" % (one, two)}
|
||||||
inclusion_two_params.anything = "Expected inclusion_two_params __dict__"
|
inclusion_two_params.anything = "Expected inclusion_two_params __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag(get_template('inclusion.html'))
|
@register.inclusion_tag(get_template('inclusion.html'))
|
||||||
def inclusion_two_params_from_template(one, two):
|
def inclusion_two_params_from_template(one, two):
|
||||||
"""Expected inclusion_two_params_from_template __doc__"""
|
"""Expected inclusion_two_params_from_template __doc__"""
|
||||||
return {"result": "inclusion_two_params_from_template - Expected result: %s, %s" % (one, two)}
|
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__"
|
inclusion_two_params_from_template.anything = "Expected inclusion_two_params_from_template __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html')
|
@register.inclusion_tag('inclusion.html')
|
||||||
def inclusion_one_default(one, two='hi'):
|
def inclusion_one_default(one, two='hi'):
|
||||||
"""Expected inclusion_one_default __doc__"""
|
"""Expected inclusion_one_default __doc__"""
|
||||||
return {"result": "inclusion_one_default - Expected result: %s, %s" % (one, two)}
|
return {"result": "inclusion_one_default - Expected result: %s, %s" % (one, two)}
|
||||||
inclusion_one_default.anything = "Expected inclusion_one_default __dict__"
|
inclusion_one_default.anything = "Expected inclusion_one_default __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag(get_template('inclusion.html'))
|
@register.inclusion_tag(get_template('inclusion.html'))
|
||||||
def inclusion_one_default_from_template(one, two='hi'):
|
def inclusion_one_default_from_template(one, two='hi'):
|
||||||
"""Expected inclusion_one_default_from_template __doc__"""
|
"""Expected inclusion_one_default_from_template __doc__"""
|
||||||
return {"result": "inclusion_one_default_from_template - Expected result: %s, %s" % (one, two)}
|
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__"
|
inclusion_one_default_from_template.anything = "Expected inclusion_one_default_from_template __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html')
|
@register.inclusion_tag('inclusion.html')
|
||||||
def inclusion_unlimited_args(one, two='hi', *args):
|
def inclusion_unlimited_args(one, two='hi', *args):
|
||||||
"""Expected inclusion_unlimited_args __doc__"""
|
"""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)))}
|
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__"
|
inclusion_unlimited_args.anything = "Expected inclusion_unlimited_args __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag(get_template('inclusion.html'))
|
@register.inclusion_tag(get_template('inclusion.html'))
|
||||||
def inclusion_unlimited_args_from_template(one, two='hi', *args):
|
def inclusion_unlimited_args_from_template(one, two='hi', *args):
|
||||||
"""Expected inclusion_unlimited_args_from_template __doc__"""
|
"""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)))}
|
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__"
|
inclusion_unlimited_args_from_template.anything = "Expected inclusion_unlimited_args_from_template __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html')
|
@register.inclusion_tag('inclusion.html')
|
||||||
def inclusion_only_unlimited_args(*args):
|
def inclusion_only_unlimited_args(*args):
|
||||||
"""Expected inclusion_only_unlimited_args __doc__"""
|
"""Expected inclusion_only_unlimited_args __doc__"""
|
||||||
return {"result": "inclusion_only_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in args))}
|
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__"
|
inclusion_only_unlimited_args.anything = "Expected inclusion_only_unlimited_args __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag(get_template('inclusion.html'))
|
@register.inclusion_tag(get_template('inclusion.html'))
|
||||||
def inclusion_only_unlimited_args_from_template(*args):
|
def inclusion_only_unlimited_args_from_template(*args):
|
||||||
"""Expected inclusion_only_unlimited_args_from_template __doc__"""
|
"""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))}
|
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__"
|
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)
|
@register.inclusion_tag('test_incl_tag_current_app.html', takes_context=True)
|
||||||
def inclusion_tag_current_app(context):
|
def inclusion_tag_current_app(context):
|
||||||
"""Expected inclusion_tag_current_app __doc__"""
|
"""Expected inclusion_tag_current_app __doc__"""
|
||||||
return {}
|
return {}
|
||||||
inclusion_tag_current_app.anything = "Expected inclusion_tag_current_app __dict__"
|
inclusion_tag_current_app.anything = "Expected inclusion_tag_current_app __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('test_incl_tag_use_l10n.html', takes_context=True)
|
@register.inclusion_tag('test_incl_tag_use_l10n.html', takes_context=True)
|
||||||
def inclusion_tag_use_l10n(context):
|
def inclusion_tag_use_l10n(context):
|
||||||
"""Expected inclusion_tag_use_l10n __doc__"""
|
"""Expected inclusion_tag_use_l10n __doc__"""
|
||||||
return {}
|
return {}
|
||||||
inclusion_tag_use_l10n.anything = "Expected inclusion_tag_use_l10n __dict__"
|
inclusion_tag_use_l10n.anything = "Expected inclusion_tag_use_l10n __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html')
|
@register.inclusion_tag('inclusion.html')
|
||||||
def inclusion_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
def inclusion_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
||||||
"""Expected inclusion_unlimited_args_kwargs __doc__"""
|
"""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__"
|
inclusion_unlimited_args_kwargs.anything = "Expected inclusion_unlimited_args_kwargs __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html', takes_context=True)
|
@register.inclusion_tag('inclusion.html', takes_context=True)
|
||||||
def inclusion_tag_without_context_parameter(arg):
|
def inclusion_tag_without_context_parameter(arg):
|
||||||
"""Expected inclusion_tag_without_context_parameter __doc__"""
|
"""Expected inclusion_tag_without_context_parameter __doc__"""
|
||||||
return {}
|
return {}
|
||||||
inclusion_tag_without_context_parameter.anything = "Expected inclusion_tag_without_context_parameter __dict__"
|
inclusion_tag_without_context_parameter.anything = "Expected inclusion_tag_without_context_parameter __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.assignment_tag
|
@register.assignment_tag
|
||||||
def assignment_no_params():
|
def assignment_no_params():
|
||||||
"""Expected assignment_no_params __doc__"""
|
"""Expected assignment_no_params __doc__"""
|
||||||
return "assignment_no_params - Expected result"
|
return "assignment_no_params - Expected result"
|
||||||
assignment_no_params.anything = "Expected assignment_no_params __dict__"
|
assignment_no_params.anything = "Expected assignment_no_params __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.assignment_tag
|
@register.assignment_tag
|
||||||
def assignment_one_param(arg):
|
def assignment_one_param(arg):
|
||||||
"""Expected assignment_one_param __doc__"""
|
"""Expected assignment_one_param __doc__"""
|
||||||
return "assignment_one_param - Expected result: %s" % arg
|
return "assignment_one_param - Expected result: %s" % arg
|
||||||
assignment_one_param.anything = "Expected assignment_one_param __dict__"
|
assignment_one_param.anything = "Expected assignment_one_param __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.assignment_tag(takes_context=False)
|
@register.assignment_tag(takes_context=False)
|
||||||
def assignment_explicit_no_context(arg):
|
def assignment_explicit_no_context(arg):
|
||||||
"""Expected assignment_explicit_no_context __doc__"""
|
"""Expected assignment_explicit_no_context __doc__"""
|
||||||
return "assignment_explicit_no_context - Expected result: %s" % arg
|
return "assignment_explicit_no_context - Expected result: %s" % arg
|
||||||
assignment_explicit_no_context.anything = "Expected assignment_explicit_no_context __dict__"
|
assignment_explicit_no_context.anything = "Expected assignment_explicit_no_context __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.assignment_tag(takes_context=True)
|
@register.assignment_tag(takes_context=True)
|
||||||
def assignment_no_params_with_context(context):
|
def assignment_no_params_with_context(context):
|
||||||
"""Expected assignment_no_params_with_context __doc__"""
|
"""Expected assignment_no_params_with_context __doc__"""
|
||||||
return "assignment_no_params_with_context - Expected result (context value: %s)" % context['value']
|
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__"
|
assignment_no_params_with_context.anything = "Expected assignment_no_params_with_context __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.assignment_tag(takes_context=True)
|
@register.assignment_tag(takes_context=True)
|
||||||
def assignment_params_and_context(context, arg):
|
def assignment_params_and_context(context, arg):
|
||||||
"""Expected assignment_params_and_context __doc__"""
|
"""Expected assignment_params_and_context __doc__"""
|
||||||
return "assignment_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)
|
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__"
|
assignment_params_and_context.anything = "Expected assignment_params_and_context __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.assignment_tag
|
@register.assignment_tag
|
||||||
def assignment_two_params(one, two):
|
def assignment_two_params(one, two):
|
||||||
"""Expected assignment_two_params __doc__"""
|
"""Expected assignment_two_params __doc__"""
|
||||||
return "assignment_two_params - Expected result: %s, %s" % (one, two)
|
return "assignment_two_params - Expected result: %s, %s" % (one, two)
|
||||||
assignment_two_params.anything = "Expected assignment_two_params __dict__"
|
assignment_two_params.anything = "Expected assignment_two_params __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.assignment_tag
|
@register.assignment_tag
|
||||||
def assignment_one_default(one, two='hi'):
|
def assignment_one_default(one, two='hi'):
|
||||||
"""Expected assignment_one_default __doc__"""
|
"""Expected assignment_one_default __doc__"""
|
||||||
return "assignment_one_default - Expected result: %s, %s" % (one, two)
|
return "assignment_one_default - Expected result: %s, %s" % (one, two)
|
||||||
assignment_one_default.anything = "Expected assignment_one_default __dict__"
|
assignment_one_default.anything = "Expected assignment_one_default __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.assignment_tag
|
@register.assignment_tag
|
||||||
def assignment_unlimited_args(one, two='hi', *args):
|
def assignment_unlimited_args(one, two='hi', *args):
|
||||||
"""Expected assignment_unlimited_args __doc__"""
|
"""Expected assignment_unlimited_args __doc__"""
|
||||||
return "assignment_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args)))
|
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__"
|
assignment_unlimited_args.anything = "Expected assignment_unlimited_args __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.assignment_tag
|
@register.assignment_tag
|
||||||
def assignment_only_unlimited_args(*args):
|
def assignment_only_unlimited_args(*args):
|
||||||
"""Expected assignment_only_unlimited_args __doc__"""
|
"""Expected assignment_only_unlimited_args __doc__"""
|
||||||
return "assignment_only_unlimited_args - Expected result: %s" % ', '.join(six.text_type(arg) for arg in args)
|
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__"
|
assignment_only_unlimited_args.anything = "Expected assignment_only_unlimited_args __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.assignment_tag
|
@register.assignment_tag
|
||||||
def assignment_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
def assignment_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
||||||
"""Expected assignment_unlimited_args_kwargs __doc__"""
|
"""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__"
|
assignment_unlimited_args_kwargs.anything = "Expected assignment_unlimited_args_kwargs __dict__"
|
||||||
|
|
||||||
|
|
||||||
@register.assignment_tag(takes_context=True)
|
@register.assignment_tag(takes_context=True)
|
||||||
def assignment_tag_without_context_parameter(arg):
|
def assignment_tag_without_context_parameter(arg):
|
||||||
"""Expected assignment_tag_without_context_parameter __doc__"""
|
"""Expected assignment_tag_without_context_parameter __doc__"""
|
||||||
|
|
|
@ -2,6 +2,7 @@ from django import template
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def echo2(arg):
|
def echo2(arg):
|
||||||
return arg
|
return arg
|
||||||
|
|
|
@ -4,6 +4,7 @@ from unittest import TestCase
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
|
|
||||||
|
|
||||||
class CallableVariablesTests(TestCase):
|
class CallableVariablesTests(TestCase):
|
||||||
|
|
||||||
def test_callable(self):
|
def test_callable(self):
|
||||||
|
|
|
@ -34,6 +34,7 @@ from django.utils.six import StringIO
|
||||||
class MockLoader(object):
|
class MockLoader(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def create_egg(name, resources):
|
def create_egg(name, resources):
|
||||||
"""
|
"""
|
||||||
Creates a mock egg with a list of resources.
|
Creates a mock egg with a list of resources.
|
||||||
|
@ -105,7 +106,7 @@ class EggLoaderTest(TestCase):
|
||||||
|
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
TEMPLATE_LOADERS = (
|
TEMPLATE_LOADERS=(
|
||||||
('django.template.loaders.cached.Loader', (
|
('django.template.loaders.cached.Loader', (
|
||||||
'django.template.loaders.filesystem.Loader',
|
'django.template.loaders.filesystem.Loader',
|
||||||
)),
|
)),
|
||||||
|
@ -139,7 +140,7 @@ class CachedLoader(TestCase):
|
||||||
|
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
TEMPLATE_DIRS = (
|
TEMPLATE_DIRS=(
|
||||||
os.path.join(os.path.dirname(upath(__file__)), 'templates'),
|
os.path.join(os.path.dirname(upath(__file__)), 'templates'),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -160,13 +161,13 @@ class RenderToStringTest(TestCase):
|
||||||
|
|
||||||
def test_empty_list(self):
|
def test_empty_list(self):
|
||||||
six.assertRaisesRegex(self, TemplateDoesNotExist,
|
six.assertRaisesRegex(self, TemplateDoesNotExist,
|
||||||
'No template names provided$',
|
'No template names provided$',
|
||||||
loader.render_to_string, [])
|
loader.render_to_string, [])
|
||||||
|
|
||||||
def test_select_templates_from_empty_list(self):
|
def test_select_templates_from_empty_list(self):
|
||||||
six.assertRaisesRegex(self, TemplateDoesNotExist,
|
six.assertRaisesRegex(self, TemplateDoesNotExist,
|
||||||
'No template names provided$',
|
'No template names provided$',
|
||||||
loader.select_template, [])
|
loader.select_template, [])
|
||||||
|
|
||||||
|
|
||||||
class TemplateDirsOverrideTest(unittest.TestCase):
|
class TemplateDirsOverrideTest(unittest.TestCase):
|
||||||
|
|
|
@ -4,6 +4,7 @@ from django.template import VariableNode, Context
|
||||||
from django.template.loader import get_template_from_string
|
from django.template.loader import get_template_from_string
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
|
|
||||||
|
|
||||||
class NodelistTest(TestCase):
|
class NodelistTest(TestCase):
|
||||||
|
|
||||||
def test_for(self):
|
def test_for(self):
|
||||||
|
@ -36,7 +37,7 @@ class ErrorIndexTest(TestCase):
|
||||||
Checks whether index of error is calculated correctly in
|
Checks whether index of error is calculated correctly in
|
||||||
template debugger in for loops. Refs ticket #5831
|
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):
|
def test_correct_exception_index(self):
|
||||||
tests = [
|
tests = [
|
||||||
('{% load bad_tag %}{% for i in range %}{% badsimpletag %}{% endfor %}', (38, 56)),
|
('{% load bad_tag %}{% for i in range %}{% badsimpletag %}{% endfor %}', (38, 56)),
|
||||||
|
|
|
@ -13,6 +13,7 @@ from django.template.response import (TemplateResponse, SimpleTemplateResponse,
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
from django.utils._os import upath
|
from django.utils._os import upath
|
||||||
|
|
||||||
|
|
||||||
def test_processor(request):
|
def test_processor(request):
|
||||||
return {'processors': 'yes'}
|
return {'processors': 'yes'}
|
||||||
test_processor_name = 'template_tests.test_response.test_processor'
|
test_processor_name = 'template_tests.test_response.test_processor'
|
||||||
|
@ -119,7 +120,7 @@ class SimpleTemplateResponseTest(TestCase):
|
||||||
self.assertEqual(response.content, b'bar')
|
self.assertEqual(response.content, b'bar')
|
||||||
|
|
||||||
def test_kwargs(self):
|
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['content-type'], 'application/json')
|
||||||
self.assertEqual(response.status_code, 504)
|
self.assertEqual(response.status_code, 504)
|
||||||
|
|
||||||
|
@ -233,7 +234,7 @@ class TemplateResponseTest(TestCase):
|
||||||
self.assertEqual(response.content, b'bar')
|
self.assertEqual(response.content, b'bar')
|
||||||
|
|
||||||
def test_kwargs(self):
|
def test_kwargs(self):
|
||||||
response = self._response(content_type = 'application/json',
|
response = self._response(content_type='application/json',
|
||||||
status=504)
|
status=504)
|
||||||
self.assertEqual(response['content-type'], 'application/json')
|
self.assertEqual(response['content-type'], 'application/json')
|
||||||
self.assertEqual(response.status_code, 504)
|
self.assertEqual(response.status_code, 504)
|
||||||
|
|
|
@ -2,6 +2,7 @@ import unittest
|
||||||
|
|
||||||
from django.template.smartif import IfParser
|
from django.template.smartif import IfParser
|
||||||
|
|
||||||
|
|
||||||
class SmartIfTests(unittest.TestCase):
|
class SmartIfTests(unittest.TestCase):
|
||||||
|
|
||||||
def assertCalcEqual(self, expected, tokens):
|
def assertCalcEqual(self, expected, tokens):
|
||||||
|
|
|
@ -45,6 +45,7 @@ from . import filters
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
class EchoNode(template.Node):
|
class EchoNode(template.Node):
|
||||||
def __init__(self, contents):
|
def __init__(self, contents):
|
||||||
self.contents = contents
|
self.contents = contents
|
||||||
|
@ -52,9 +53,11 @@ class EchoNode(template.Node):
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
return " ".join(self.contents)
|
return " ".join(self.contents)
|
||||||
|
|
||||||
|
|
||||||
def do_echo(parser, token):
|
def do_echo(parser, token):
|
||||||
return EchoNode(token.contents.split()[1:])
|
return EchoNode(token.contents.split()[1:])
|
||||||
|
|
||||||
|
|
||||||
def do_upper(value):
|
def do_upper(value):
|
||||||
return value.upper()
|
return value.upper()
|
||||||
|
|
||||||
|
@ -68,18 +71,23 @@ template.libraries['testtags'] = register
|
||||||
# Helper objects for template tests #
|
# Helper objects for template tests #
|
||||||
#####################################
|
#####################################
|
||||||
|
|
||||||
|
|
||||||
class SomeException(Exception):
|
class SomeException(Exception):
|
||||||
silent_variable_failure = True
|
silent_variable_failure = True
|
||||||
|
|
||||||
|
|
||||||
class SomeOtherException(Exception):
|
class SomeOtherException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ContextStackException(Exception):
|
class ContextStackException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ShouldNotExecuteException(Exception):
|
class ShouldNotExecuteException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SomeClass:
|
class SomeClass:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.otherclass = OtherClass()
|
self.otherclass = OtherClass()
|
||||||
|
@ -114,10 +122,12 @@ class SomeClass:
|
||||||
raise SomeOtherException
|
raise SomeOtherException
|
||||||
noisy_fail_attribute = property(noisy_fail_attribute)
|
noisy_fail_attribute = property(noisy_fail_attribute)
|
||||||
|
|
||||||
|
|
||||||
class OtherClass:
|
class OtherClass:
|
||||||
def method(self):
|
def method(self):
|
||||||
return "OtherClass.method"
|
return "OtherClass.method"
|
||||||
|
|
||||||
|
|
||||||
class TestObj(object):
|
class TestObj(object):
|
||||||
def is_true(self):
|
def is_true(self):
|
||||||
return True
|
return True
|
||||||
|
@ -128,15 +138,18 @@ class TestObj(object):
|
||||||
def is_bad(self):
|
def is_bad(self):
|
||||||
raise ShouldNotExecuteException()
|
raise ShouldNotExecuteException()
|
||||||
|
|
||||||
|
|
||||||
class SilentGetItemClass(object):
|
class SilentGetItemClass(object):
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
raise SomeException
|
raise SomeException
|
||||||
|
|
||||||
|
|
||||||
class SilentAttrClass(object):
|
class SilentAttrClass(object):
|
||||||
def b(self):
|
def b(self):
|
||||||
raise SomeException
|
raise SomeException
|
||||||
b = property(b)
|
b = property(b)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class UTF8Class:
|
class UTF8Class:
|
||||||
"Class whose __str__ returns non-ASCII data on Python 2"
|
"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
|
settings.ALLOWED_INCLUDE_ROOTS = old_allowed_include_roots
|
||||||
|
|
||||||
self.assertEqual(failures, [], "Tests failed:\n%s\n%s" %
|
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):
|
def render(self, test_template, vals):
|
||||||
context = template.Context(vals[1])
|
context = template.Context(vals[1])
|
||||||
|
@ -1538,10 +1551,10 @@ class TemplateTests(TransRealMixin, TestCase):
|
||||||
'{% endfor %},'
|
'{% endfor %},'
|
||||||
'{% endfor %}',
|
'{% endfor %}',
|
||||||
{'data': [{'foo': 'c', 'bar': 1},
|
{'data': [{'foo': 'c', 'bar': 1},
|
||||||
{'foo': 'd', 'bar': 1},
|
{'foo': 'd', 'bar': 1},
|
||||||
{'foo': 'a', 'bar': 2},
|
{'foo': 'a', 'bar': 2},
|
||||||
{'foo': 'b', 'bar': 2},
|
{'foo': 'b', 'bar': 2},
|
||||||
{'foo': 'x', 'bar': 3}]},
|
{'foo': 'x', 'bar': 3}]},
|
||||||
'1:cd,2:ab,3:x,'),
|
'1:cd,2:ab,3:x,'),
|
||||||
|
|
||||||
# Test for silent failure when target variable isn't found
|
# Test for silent failure when target variable isn't found
|
||||||
|
@ -1582,13 +1595,13 @@ class TemplateTests(TransRealMixin, TestCase):
|
||||||
|
|
||||||
# Test syntax
|
# Test syntax
|
||||||
'regroup05': ('{% regroup data by bar as %}', {},
|
'regroup05': ('{% regroup data by bar as %}', {},
|
||||||
template.TemplateSyntaxError),
|
template.TemplateSyntaxError),
|
||||||
'regroup06': ('{% regroup data by bar thisaintright grouped %}', {},
|
'regroup06': ('{% regroup data by bar thisaintright grouped %}', {},
|
||||||
template.TemplateSyntaxError),
|
template.TemplateSyntaxError),
|
||||||
'regroup07': ('{% regroup data thisaintright bar as grouped %}', {},
|
'regroup07': ('{% regroup data thisaintright bar as grouped %}', {},
|
||||||
template.TemplateSyntaxError),
|
template.TemplateSyntaxError),
|
||||||
'regroup08': ('{% regroup data by bar as grouped toomanyargs %}', {},
|
'regroup08': ('{% regroup data by bar as grouped toomanyargs %}', {},
|
||||||
template.TemplateSyntaxError),
|
template.TemplateSyntaxError),
|
||||||
|
|
||||||
### SSI TAG ########################################################
|
### SSI TAG ########################################################
|
||||||
|
|
||||||
|
|
|
@ -6,17 +6,22 @@ from django.template.response import TemplateResponse
|
||||||
def index(request):
|
def index(request):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def client(request, id):
|
def client(request, id):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def client_action(request, id, action):
|
def client_action(request, id, action):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def client2(request, tag):
|
def client2(request, tag):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def template_response_view(request):
|
def template_response_view(request):
|
||||||
return TemplateResponse(request, 'response.html', {})
|
return TemplateResponse(request, 'response.html', {})
|
||||||
|
|
||||||
|
|
||||||
def snark(request):
|
def snark(request):
|
||||||
return HttpResponse('Found him!')
|
return HttpResponse('Found him!')
|
||||||
|
|
|
@ -28,6 +28,7 @@ from django.test.utils import override_settings
|
||||||
|
|
||||||
from .views import get_view
|
from .views import get_view
|
||||||
|
|
||||||
|
|
||||||
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||||
class ClientTest(TestCase):
|
class ClientTest(TestCase):
|
||||||
fixtures = ['testdata.json']
|
fixtures = ['testdata.json']
|
||||||
|
@ -479,7 +480,7 @@ class ClientTest(TestCase):
|
||||||
|
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
MIDDLEWARE_CLASSES = ('django.middleware.csrf.CsrfViewMiddleware',)
|
MIDDLEWARE_CLASSES=('django.middleware.csrf.CsrfViewMiddleware',)
|
||||||
)
|
)
|
||||||
class CSRFEnabledClientTests(TestCase):
|
class CSRFEnabledClientTests(TestCase):
|
||||||
def test_csrf_enabled_client(self):
|
def test_csrf_enabled_client(self):
|
||||||
|
@ -498,6 +499,7 @@ class CSRFEnabledClientTests(TestCase):
|
||||||
class CustomTestClient(Client):
|
class CustomTestClient(Client):
|
||||||
i_am_customized = "Yes"
|
i_am_customized = "Yes"
|
||||||
|
|
||||||
|
|
||||||
class CustomTestClientTest(TestCase):
|
class CustomTestClientTest(TestCase):
|
||||||
client_class = CustomTestClient
|
client_class = CustomTestClient
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ from django.template import Context, Template
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.utils.six.moves.urllib.parse import urlencode
|
from django.utils.six.moves.urllib.parse import urlencode
|
||||||
|
|
||||||
|
|
||||||
def get_view(request):
|
def get_view(request):
|
||||||
"A simple view that expects a GET request, and returns a rendered template"
|
"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')
|
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))
|
return HttpResponse(t.render(c))
|
||||||
|
|
||||||
|
|
||||||
def post_view(request):
|
def post_view(request):
|
||||||
"""A view that expects a POST, and returns a different template depending
|
"""A view that expects a POST, and returns a different template depending
|
||||||
on whether any POST data is available
|
on whether any POST data is available
|
||||||
|
@ -35,12 +37,14 @@ def post_view(request):
|
||||||
|
|
||||||
return HttpResponse(t.render(c))
|
return HttpResponse(t.render(c))
|
||||||
|
|
||||||
|
|
||||||
def view_with_header(request):
|
def view_with_header(request):
|
||||||
"A view that has a custom header"
|
"A view that has a custom header"
|
||||||
response = HttpResponse()
|
response = HttpResponse()
|
||||||
response['X-DJANGO-TEST'] = 'Slartibartfast'
|
response['X-DJANGO-TEST'] = 'Slartibartfast'
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def raw_post_view(request):
|
def raw_post_view(request):
|
||||||
"""A view which expects raw XML to be posted and returns content extracted
|
"""A view which expects raw XML to be posted and returns content extracted
|
||||||
from the XML"""
|
from the XML"""
|
||||||
|
@ -56,6 +60,7 @@ def raw_post_view(request):
|
||||||
|
|
||||||
return HttpResponse(t.render(c))
|
return HttpResponse(t.render(c))
|
||||||
|
|
||||||
|
|
||||||
def redirect_view(request):
|
def redirect_view(request):
|
||||||
"A view that redirects all requests to the GET view"
|
"A view that redirects all requests to the GET view"
|
||||||
if request.GET:
|
if request.GET:
|
||||||
|
@ -64,6 +69,7 @@ def redirect_view(request):
|
||||||
query = ''
|
query = ''
|
||||||
return HttpResponseRedirect('/test_client/get_view/' + query)
|
return HttpResponseRedirect('/test_client/get_view/' + query)
|
||||||
|
|
||||||
|
|
||||||
def view_with_secure(request):
|
def view_with_secure(request):
|
||||||
"A view that indicates if the request was secure"
|
"A view that indicates if the request was secure"
|
||||||
response = HttpResponse()
|
response = HttpResponse()
|
||||||
|
@ -71,10 +77,12 @@ def view_with_secure(request):
|
||||||
response.test_server_port = request.META.get('SERVER_PORT', 80)
|
response.test_server_port = request.META.get('SERVER_PORT', 80)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def double_redirect_view(request):
|
def double_redirect_view(request):
|
||||||
"A view that redirects all requests to a redirection view"
|
"A view that redirects all requests to a redirection view"
|
||||||
return HttpResponseRedirect('/test_client/permanent_redirect_view/')
|
return HttpResponseRedirect('/test_client/permanent_redirect_view/')
|
||||||
|
|
||||||
|
|
||||||
def bad_view(request):
|
def bad_view(request):
|
||||||
"A view that returns a 404 with some error content"
|
"A view that returns a 404 with some error content"
|
||||||
return HttpResponseNotFound('Not found!. This page contains some MAGIC content')
|
return HttpResponseNotFound('Not found!. This page contains some MAGIC content')
|
||||||
|
@ -87,6 +95,7 @@ TestChoices = (
|
||||||
('e', 'Fifth Choice')
|
('e', 'Fifth Choice')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestForm(Form):
|
class TestForm(Form):
|
||||||
text = fields.CharField()
|
text = fields.CharField()
|
||||||
email = fields.EmailField()
|
email = fields.EmailField()
|
||||||
|
@ -100,6 +109,7 @@ class TestForm(Form):
|
||||||
raise ValidationError("Non-field error.")
|
raise ValidationError("Non-field error.")
|
||||||
return cleaned_data
|
return cleaned_data
|
||||||
|
|
||||||
|
|
||||||
def form_view(request):
|
def form_view(request):
|
||||||
"A view that tests a simple form"
|
"A view that tests a simple form"
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
@ -117,6 +127,7 @@ def form_view(request):
|
||||||
|
|
||||||
return HttpResponse(t.render(c))
|
return HttpResponse(t.render(c))
|
||||||
|
|
||||||
|
|
||||||
def form_view_with_template(request):
|
def form_view_with_template(request):
|
||||||
"A view that tests a simple form"
|
"A view that tests a simple form"
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
@ -135,6 +146,7 @@ def form_view_with_template(request):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class BaseTestFormSet(BaseFormSet):
|
class BaseTestFormSet(BaseFormSet):
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""Checks that no two email addresses are the same."""
|
"""Checks that no two email addresses are the same."""
|
||||||
|
@ -154,6 +166,7 @@ class BaseTestFormSet(BaseFormSet):
|
||||||
|
|
||||||
TestFormSet = formset_factory(TestForm, BaseTestFormSet)
|
TestFormSet = formset_factory(TestForm, BaseTestFormSet)
|
||||||
|
|
||||||
|
|
||||||
def formset_view(request):
|
def formset_view(request):
|
||||||
"A view that tests a simple formset"
|
"A view that tests a simple formset"
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
@ -172,6 +185,7 @@ def formset_view(request):
|
||||||
c = Context({'my_formset': formset})
|
c = Context({'my_formset': formset})
|
||||||
return HttpResponse(t.render(c))
|
return HttpResponse(t.render(c))
|
||||||
|
|
||||||
|
|
||||||
def login_protected_view(request):
|
def login_protected_view(request):
|
||||||
"A simple view that is login protected."
|
"A simple view that is login protected."
|
||||||
t = Template('This is a login protected test. Username is {{ user.username }}.', name='Login Template')
|
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))
|
return HttpResponse(t.render(c))
|
||||||
login_protected_view = login_required(login_protected_view)
|
login_protected_view = login_required(login_protected_view)
|
||||||
|
|
||||||
|
|
||||||
def login_protected_view_changed_redirect(request):
|
def login_protected_view_changed_redirect(request):
|
||||||
"A simple view that is login protected with a custom redirect field set"
|
"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')
|
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))
|
return HttpResponse(t.render(c))
|
||||||
login_protected_view_changed_redirect = login_required(redirect_field_name="redirect_to")(login_protected_view_changed_redirect)
|
login_protected_view_changed_redirect = login_required(redirect_field_name="redirect_to")(login_protected_view_changed_redirect)
|
||||||
|
|
||||||
|
|
||||||
def _permission_protected_view(request):
|
def _permission_protected_view(request):
|
||||||
"A simple view that is permission protected."
|
"A simple view that is permission protected."
|
||||||
t = Template('This is a permission protected test. '
|
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 = permission_required('permission_not_granted')(_permission_protected_view)
|
||||||
permission_protected_view_exception = permission_required('permission_not_granted', raise_exception=True)(_permission_protected_view)
|
permission_protected_view_exception = permission_required('permission_not_granted', raise_exception=True)(_permission_protected_view)
|
||||||
|
|
||||||
|
|
||||||
class _ViewManager(object):
|
class _ViewManager(object):
|
||||||
@method_decorator(login_required)
|
@method_decorator(login_required)
|
||||||
def login_protected_view(self, request):
|
def login_protected_view(self, request):
|
||||||
|
@ -221,6 +238,7 @@ _view_manager = _ViewManager()
|
||||||
login_protected_method_view = _view_manager.login_protected_view
|
login_protected_method_view = _view_manager.login_protected_view
|
||||||
permission_protected_method_view = _view_manager.permission_protected_view
|
permission_protected_method_view = _view_manager.permission_protected_view
|
||||||
|
|
||||||
|
|
||||||
def session_view(request):
|
def session_view(request):
|
||||||
"A view that modifies the session"
|
"A view that modifies the session"
|
||||||
request.session['tobacconist'] = 'hovercraft'
|
request.session['tobacconist'] = 'hovercraft'
|
||||||
|
@ -230,10 +248,12 @@ def session_view(request):
|
||||||
c = Context()
|
c = Context()
|
||||||
return HttpResponse(t.render(c))
|
return HttpResponse(t.render(c))
|
||||||
|
|
||||||
|
|
||||||
def broken_view(request):
|
def broken_view(request):
|
||||||
"""A view which just raises an exception, simulating a broken view."""
|
"""A view which just raises an exception, simulating a broken view."""
|
||||||
raise KeyError("Oops! Looks like you wrote some bad code.")
|
raise KeyError("Oops! Looks like you wrote some bad code.")
|
||||||
|
|
||||||
|
|
||||||
def mail_sending_view(request):
|
def mail_sending_view(request):
|
||||||
mail.EmailMessage(
|
mail.EmailMessage(
|
||||||
"Test message",
|
"Test message",
|
||||||
|
@ -242,6 +262,7 @@ def mail_sending_view(request):
|
||||||
['first@example.com', 'second@example.com']).send()
|
['first@example.com', 'second@example.com']).send()
|
||||||
return HttpResponse("Mail sent")
|
return HttpResponse("Mail sent")
|
||||||
|
|
||||||
|
|
||||||
def mass_mail_sending_view(request):
|
def mass_mail_sending_view(request):
|
||||||
m1 = mail.EmailMessage(
|
m1 = mail.EmailMessage(
|
||||||
'First Test message',
|
'First Test message',
|
||||||
|
@ -259,5 +280,6 @@ def mass_mail_sending_view(request):
|
||||||
|
|
||||||
return HttpResponse("Mail sent")
|
return HttpResponse("Mail sent")
|
||||||
|
|
||||||
|
|
||||||
def django_project_redirect(request):
|
def django_project_redirect(request):
|
||||||
return HttpResponseRedirect('https://www.djangoproject.com/')
|
return HttpResponseRedirect('https://www.djangoproject.com/')
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from django.contrib.sessions.backends.base import SessionBase
|
from django.contrib.sessions.backends.base import SessionBase
|
||||||
|
|
||||||
|
|
||||||
class SessionStore(SessionBase):
|
class SessionStore(SessionBase):
|
||||||
"""
|
"""
|
||||||
A simple cookie-based session storage implementation.
|
A simple cookie-based session storage implementation.
|
||||||
|
|
|
@ -23,6 +23,7 @@ from django.contrib.auth.models import User
|
||||||
from .models import CustomUser
|
from .models import CustomUser
|
||||||
from .views import CustomTestException
|
from .views import CustomTestException
|
||||||
|
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
TEMPLATE_DIRS=(os.path.join(os.path.dirname(upath(__file__)), 'templates'),)
|
TEMPLATE_DIRS=(os.path.join(os.path.dirname(upath(__file__)), 'templates'),)
|
||||||
)
|
)
|
||||||
|
@ -185,6 +186,7 @@ class AssertContainsTests(TestCase):
|
||||||
response = HttpResponse('Hello')
|
response = HttpResponse('Hello')
|
||||||
self.assertNotContains(response, 'Bye')
|
self.assertNotContains(response, 'Bye')
|
||||||
|
|
||||||
|
|
||||||
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||||
class AssertTemplateUsedTests(TestCase):
|
class AssertTemplateUsedTests(TestCase):
|
||||||
fixtures = ['testdata.json']
|
fixtures = ['testdata.json']
|
||||||
|
@ -256,6 +258,7 @@ class AssertTemplateUsedTests(TestCase):
|
||||||
except AssertionError as e:
|
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))
|
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):
|
class AssertRedirectsTests(TestCase):
|
||||||
def test_redirect_page(self):
|
def test_redirect_page(self):
|
||||||
"An assertion is raised if the original page couldn't be retrieved as expected"
|
"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:
|
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))
|
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):
|
class AssertFormsetErrorTests(TestCase):
|
||||||
msg_prefixes = [("", {}), ("abc: ", {"msg_prefix": "abc"})]
|
msg_prefixes = [("", {}), ("abc: ", {"msg_prefix": "abc"})]
|
||||||
|
|
||||||
|
@ -737,6 +741,7 @@ class AssertFormsetErrorTests(TestCase):
|
||||||
'addresses.',
|
'addresses.',
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
|
|
||||||
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||||
class LoginTests(TestCase):
|
class LoginTests(TestCase):
|
||||||
fixtures = ['testdata']
|
fixtures = ['testdata']
|
||||||
|
@ -801,6 +806,7 @@ class URLEscapingTests(TestCase):
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.content, b'Hi, Arthur')
|
self.assertEqual(response.content, b'Hi, Arthur')
|
||||||
|
|
||||||
|
|
||||||
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||||
class ExceptionTests(TestCase):
|
class ExceptionTests(TestCase):
|
||||||
fixtures = ['testdata.json']
|
fixtures = ['testdata.json']
|
||||||
|
@ -846,6 +852,7 @@ class TemplateExceptionTests(TestCase):
|
||||||
except TemplateSyntaxError:
|
except TemplateSyntaxError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# We need two different tests to check URLconf substitution - one to check
|
# 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
|
# 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.
|
# 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'])
|
url = reverse('arg_view', args=['somename'])
|
||||||
self.assertEqual(url, '/arg_view/somename/')
|
self.assertEqual(url, '/arg_view/somename/')
|
||||||
|
|
||||||
|
|
||||||
# This test needs to run *after* UrlconfSubstitutionTests; the zz prefix in the
|
# This test needs to run *after* UrlconfSubstitutionTests; the zz prefix in the
|
||||||
# name is to ensure alphabetical ordering.
|
# name is to ensure alphabetical ordering.
|
||||||
class zzUrlconfSubstitutionTests(TestCase):
|
class zzUrlconfSubstitutionTests(TestCase):
|
||||||
|
@ -865,6 +873,7 @@ class zzUrlconfSubstitutionTests(TestCase):
|
||||||
url = reverse('arg_view', args=['somename'])
|
url = reverse('arg_view', args=['somename'])
|
||||||
self.assertEqual(url, '/test_client_regress/arg_view/somename/')
|
self.assertEqual(url, '/test_client_regress/arg_view/somename/')
|
||||||
|
|
||||||
|
|
||||||
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||||
class ContextTests(TestCase):
|
class ContextTests(TestCase):
|
||||||
fixtures = ['testdata']
|
fixtures = ['testdata']
|
||||||
|
@ -1114,6 +1123,7 @@ class RequestMethodStringDataTests(TestCase):
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.content, b'request method: PATCH')
|
self.assertEqual(response.content, b'request method: PATCH')
|
||||||
|
|
||||||
|
|
||||||
class QueryStringTests(TestCase):
|
class QueryStringTests(TestCase):
|
||||||
def test_get_like_requests(self):
|
def test_get_like_requests(self):
|
||||||
# See: https://code.djangoproject.com/ticket/10571.
|
# 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-foo'], 'whiz')
|
||||||
self.assertEqual(response.context['request-bar'], 'bang')
|
self.assertEqual(response.context['request-bar'], 'bang')
|
||||||
|
|
||||||
|
|
||||||
class UnicodePayloadTests(TestCase):
|
class UnicodePayloadTests(TestCase):
|
||||||
def test_simple_unicode_payload(self):
|
def test_simple_unicode_payload(self):
|
||||||
"A simple ASCII-only unicode JSON document can be POSTed"
|
"A simple ASCII-only unicode JSON document can be POSTed"
|
||||||
|
@ -1199,6 +1210,7 @@ class UnicodePayloadTests(TestCase):
|
||||||
content_type="application/json; charset=koi8-r")
|
content_type="application/json; charset=koi8-r")
|
||||||
self.assertEqual(response.content, json.encode('koi8-r'))
|
self.assertEqual(response.content, json.encode('koi8-r'))
|
||||||
|
|
||||||
|
|
||||||
class DummyFile(object):
|
class DummyFile(object):
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
self.name = filename
|
self.name = filename
|
||||||
|
@ -1206,6 +1218,7 @@ class DummyFile(object):
|
||||||
def read(self):
|
def read(self):
|
||||||
return b'TEST_FILE_CONTENT'
|
return b'TEST_FILE_CONTENT'
|
||||||
|
|
||||||
|
|
||||||
class UploadedFileEncodingTest(TestCase):
|
class UploadedFileEncodingTest(TestCase):
|
||||||
def test_file_encoding(self):
|
def test_file_encoding(self):
|
||||||
encoded_file = encode_file('TEST_BOUNDARY', 'TEST_KEY', DummyFile('test_name.bin'))
|
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',
|
self.assertEqual(b'Content-Type: application/octet-stream',
|
||||||
encode_file('IGNORE', 'IGNORE', DummyFile("file.unknown"))[2])
|
encode_file('IGNORE', 'IGNORE', DummyFile("file.unknown"))[2])
|
||||||
|
|
||||||
|
|
||||||
class RequestHeadersTest(TestCase):
|
class RequestHeadersTest(TestCase):
|
||||||
def test_client_headers(self):
|
def test_client_headers(self):
|
||||||
"A test client can receive custom headers"
|
"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
|
"""HttpRequest.read() on a test client PUT request with some payload
|
||||||
should return that payload."""
|
should return that payload."""
|
||||||
payload = b'foobar'
|
payload = b'foobar'
|
||||||
self.assertEqual(self.client.put("/test_client_regress/read_all/",
|
self.assertEqual(self.client.put(
|
||||||
data=payload,
|
"/test_client_regress/read_all/",
|
||||||
content_type='text/plain').content, payload)
|
data=payload,
|
||||||
|
content_type='text/plain').content, payload)
|
||||||
|
|
||||||
def test_read_numbytes_from_nonempty_request(self):
|
def test_read_numbytes_from_nonempty_request(self):
|
||||||
"""HttpRequest.read(LARGE_BUFFER) on a test client PUT request with
|
"""HttpRequest.read(LARGE_BUFFER) on a test client PUT request with
|
||||||
some payload should return that payload."""
|
some payload should return that payload."""
|
||||||
payload = b'foobar'
|
payload = b'foobar'
|
||||||
self.assertEqual(self.client.put("/test_client_regress/read_buffer/",
|
self.assertEqual(
|
||||||
data=payload,
|
self.client.put("/test_client_regress/read_buffer/",
|
||||||
content_type='text/plain').content, payload)
|
data=payload,
|
||||||
|
content_type='text/plain').content, payload)
|
||||||
|
|
||||||
|
|
||||||
class RequestFactoryStateTest(TestCase):
|
class RequestFactoryStateTest(TestCase):
|
||||||
|
|
|
@ -15,10 +15,12 @@ from django.test.utils import setup_test_environment
|
||||||
class CustomTestException(Exception):
|
class CustomTestException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def no_template_view(request):
|
def no_template_view(request):
|
||||||
"A simple view that expects a GET request, and returns a rendered template"
|
"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.")
|
return HttpResponse("No template used. Sample content: twice once twice. Content ends.")
|
||||||
|
|
||||||
|
|
||||||
def staff_only_view(request):
|
def staff_only_view(request):
|
||||||
"A view that can only be visited by staff. Non staff members get an exception"
|
"A view that can only be visited by staff. Non staff members get an exception"
|
||||||
if request.user.is_staff:
|
if request.user.is_staff:
|
||||||
|
@ -26,11 +28,13 @@ def staff_only_view(request):
|
||||||
else:
|
else:
|
||||||
raise CustomTestException()
|
raise CustomTestException()
|
||||||
|
|
||||||
|
|
||||||
def get_view(request):
|
def get_view(request):
|
||||||
"A simple login protected view"
|
"A simple login protected view"
|
||||||
return HttpResponse("Hello world")
|
return HttpResponse("Hello world")
|
||||||
get_view = login_required(get_view)
|
get_view = login_required(get_view)
|
||||||
|
|
||||||
|
|
||||||
def request_data(request, template='base.html', data='sausage'):
|
def request_data(request, template='base.html', data='sausage'):
|
||||||
"A simple view that returns the request data in the context"
|
"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,
|
'data': data,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def view_with_argument(request, name):
|
def view_with_argument(request, name):
|
||||||
"""A view that takes a string argument
|
"""A view that takes a string argument
|
||||||
|
|
||||||
|
@ -62,6 +67,7 @@ def view_with_argument(request, name):
|
||||||
else:
|
else:
|
||||||
return HttpResponse('Howdy, %s' % name)
|
return HttpResponse('Howdy, %s' % name)
|
||||||
|
|
||||||
|
|
||||||
def nested_view(request):
|
def nested_view(request):
|
||||||
"""
|
"""
|
||||||
A view that uses test client to call another view.
|
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")
|
c.get("/test_client_regress/no_template_view")
|
||||||
return render_to_response('base.html', {'nested': 'yes'})
|
return render_to_response('base.html', {'nested': 'yes'})
|
||||||
|
|
||||||
|
|
||||||
def login_protected_redirect_view(request):
|
def login_protected_redirect_view(request):
|
||||||
"A view that redirects all requests to the GET view"
|
"A view that redirects all requests to the GET view"
|
||||||
return HttpResponseRedirect('/test_client_regress/get_view/')
|
return HttpResponseRedirect('/test_client_regress/get_view/')
|
||||||
login_protected_redirect_view = login_required(login_protected_redirect_view)
|
login_protected_redirect_view = login_required(login_protected_redirect_view)
|
||||||
|
|
||||||
|
|
||||||
def set_session_view(request):
|
def set_session_view(request):
|
||||||
"A view that sets a session variable"
|
"A view that sets a session variable"
|
||||||
request.session['session_var'] = 'YES'
|
request.session['session_var'] = 'YES'
|
||||||
return HttpResponse('set_session')
|
return HttpResponse('set_session')
|
||||||
|
|
||||||
|
|
||||||
def check_session_view(request):
|
def check_session_view(request):
|
||||||
"A view that reads a session variable"
|
"A view that reads a session variable"
|
||||||
return HttpResponse(request.session.get('session_var', 'NO'))
|
return HttpResponse(request.session.get('session_var', 'NO'))
|
||||||
|
|
||||||
|
|
||||||
def request_methods_view(request):
|
def request_methods_view(request):
|
||||||
"A view that responds with the request method"
|
"A view that responds with the request method"
|
||||||
return HttpResponse('request method: %s' % request.method)
|
return HttpResponse('request method: %s' % request.method)
|
||||||
|
|
||||||
|
|
||||||
def return_unicode(request):
|
def return_unicode(request):
|
||||||
return render_to_response('unicode.html')
|
return render_to_response('unicode.html')
|
||||||
|
|
||||||
|
|
||||||
def return_undecodable_binary(request):
|
def return_undecodable_binary(request):
|
||||||
return HttpResponse(
|
return HttpResponse(
|
||||||
b'%PDF-1.4\r\n%\x93\x8c\x8b\x9e ReportLab Generated PDF document http://www.reportlab.com'
|
b'%PDF-1.4\r\n%\x93\x8c\x8b\x9e ReportLab Generated PDF document http://www.reportlab.com'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def return_json_file(request):
|
def return_json_file(request):
|
||||||
"A view that parses and returns a JSON string as a file."
|
"A view that parses and returns a JSON string as a file."
|
||||||
match = CONTENT_TYPE_RE.match(request.META['CONTENT_TYPE'])
|
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'
|
response['Content-Disposition'] = 'attachment; filename=testfile.json'
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def check_headers(request):
|
def check_headers(request):
|
||||||
"A view that responds with value of the X-ARG-CHECK header"
|
"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'))
|
return HttpResponse('HTTP_X_ARG_CHECK: %s' % request.META.get('HTTP_X_ARG_CHECK', 'Undefined'))
|
||||||
|
|
||||||
|
|
||||||
def body(request):
|
def body(request):
|
||||||
"A view that is requested with GET and accesses request.body. Refs #14753."
|
"A view that is requested with GET and accesses request.body. Refs #14753."
|
||||||
return HttpResponse(request.body)
|
return HttpResponse(request.body)
|
||||||
|
|
||||||
|
|
||||||
def read_all(request):
|
def read_all(request):
|
||||||
"A view that is requested with accesses request.read()."
|
"A view that is requested with accesses request.read()."
|
||||||
return HttpResponse(request.read())
|
return HttpResponse(request.read())
|
||||||
|
|
||||||
|
|
||||||
def read_buffer(request):
|
def read_buffer(request):
|
||||||
"A view that is requested with accesses request.read(LARGE_BUFFER)."
|
"A view that is requested with accesses request.read(LARGE_BUFFER)."
|
||||||
return HttpResponse(request.read(99999))
|
return HttpResponse(request.read(99999))
|
||||||
|
|
||||||
|
|
||||||
def request_context_view(request):
|
def request_context_view(request):
|
||||||
# Special attribute that won't be present on a plain HttpRequest
|
# Special attribute that won't be present on a plain HttpRequest
|
||||||
request.special_path = request.path
|
request.special_path = request.path
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
class Person(models.Model):
|
class Person(models.Model):
|
||||||
first_name = models.CharField(max_length=20)
|
first_name = models.CharField(max_length=20)
|
||||||
last_name = models.CharField(max_length=20)
|
last_name = models.CharField(max_length=20)
|
||||||
|
|
|
@ -4,6 +4,7 @@ from django.test import TestCase
|
||||||
|
|
||||||
warnings.warn("module-level warning from deprecation_app", DeprecationWarning)
|
warnings.warn("module-level warning from deprecation_app", DeprecationWarning)
|
||||||
|
|
||||||
|
|
||||||
class DummyTest(TestCase):
|
class DummyTest(TestCase):
|
||||||
def test_warn(self):
|
def test_warn(self):
|
||||||
warnings.warn("warning from test", DeprecationWarning)
|
warnings.warn("warning from test", DeprecationWarning)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Person(models.Model):
|
class Person(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
|
|
|
@ -2,11 +2,13 @@ from django.contrib import admin
|
||||||
|
|
||||||
from .models import Event, Timestamp
|
from .models import Event, Timestamp
|
||||||
|
|
||||||
|
|
||||||
class EventAdmin(admin.ModelAdmin):
|
class EventAdmin(admin.ModelAdmin):
|
||||||
list_display = ('dt',)
|
list_display = ('dt',)
|
||||||
|
|
||||||
admin.site.register(Event, EventAdmin)
|
admin.site.register(Event, EventAdmin)
|
||||||
|
|
||||||
|
|
||||||
class TimestampAdmin(admin.ModelAdmin):
|
class TimestampAdmin(admin.ModelAdmin):
|
||||||
readonly_fields = ('created', 'updated')
|
readonly_fields = ('created', 'updated')
|
||||||
|
|
||||||
|
|
|
@ -2,20 +2,25 @@ from django import forms
|
||||||
|
|
||||||
from .models import Event
|
from .models import Event
|
||||||
|
|
||||||
|
|
||||||
class EventForm(forms.Form):
|
class EventForm(forms.Form):
|
||||||
dt = forms.DateTimeField()
|
dt = forms.DateTimeField()
|
||||||
|
|
||||||
|
|
||||||
class EventSplitForm(forms.Form):
|
class EventSplitForm(forms.Form):
|
||||||
dt = forms.SplitDateTimeField()
|
dt = forms.SplitDateTimeField()
|
||||||
|
|
||||||
|
|
||||||
class EventLocalizedForm(forms.Form):
|
class EventLocalizedForm(forms.Form):
|
||||||
dt = forms.DateTimeField(localize=True)
|
dt = forms.DateTimeField(localize=True)
|
||||||
|
|
||||||
|
|
||||||
class EventModelForm(forms.ModelForm):
|
class EventModelForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Event
|
model = Event
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
|
||||||
class EventLocalizedModelForm(forms.ModelForm):
|
class EventLocalizedModelForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Event
|
model = Event
|
||||||
|
|
|
@ -1,21 +1,27 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
class Event(models.Model):
|
class Event(models.Model):
|
||||||
dt = models.DateTimeField()
|
dt = models.DateTimeField()
|
||||||
|
|
||||||
|
|
||||||
class MaybeEvent(models.Model):
|
class MaybeEvent(models.Model):
|
||||||
dt = models.DateTimeField(blank=True, null=True)
|
dt = models.DateTimeField(blank=True, null=True)
|
||||||
|
|
||||||
|
|
||||||
class Session(models.Model):
|
class Session(models.Model):
|
||||||
name = models.CharField(max_length=20)
|
name = models.CharField(max_length=20)
|
||||||
|
|
||||||
|
|
||||||
class SessionEvent(models.Model):
|
class SessionEvent(models.Model):
|
||||||
dt = models.DateTimeField()
|
dt = models.DateTimeField()
|
||||||
session = models.ForeignKey(Session, related_name='events')
|
session = models.ForeignKey(Session, related_name='events')
|
||||||
|
|
||||||
|
|
||||||
class Timestamp(models.Model):
|
class Timestamp(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
updated = models.DateTimeField(auto_now=True)
|
updated = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
|
||||||
class AllDayEvent(models.Model):
|
class AllDayEvent(models.Model):
|
||||||
day = models.DateField()
|
day = models.DateField()
|
||||||
|
|
|
@ -395,7 +395,8 @@ class TransactionTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
|
||||||
"""
|
"""
|
||||||
The default behavior is to autocommit after each save() action.
|
The default behavior is to autocommit after each save() action.
|
||||||
"""
|
"""
|
||||||
self.assertRaises(Exception,
|
self.assertRaises(
|
||||||
|
Exception,
|
||||||
self.create_a_reporter_then_fail,
|
self.create_a_reporter_then_fail,
|
||||||
"Alice", "Smith"
|
"Alice", "Smith"
|
||||||
)
|
)
|
||||||
|
@ -411,7 +412,8 @@ class TransactionTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
|
||||||
autocomitted_create_then_fail = transaction.autocommit(
|
autocomitted_create_then_fail = transaction.autocommit(
|
||||||
self.create_a_reporter_then_fail
|
self.create_a_reporter_then_fail
|
||||||
)
|
)
|
||||||
self.assertRaises(Exception,
|
self.assertRaises(
|
||||||
|
Exception,
|
||||||
autocomitted_create_then_fail,
|
autocomitted_create_then_fail,
|
||||||
"Alice", "Smith"
|
"Alice", "Smith"
|
||||||
)
|
)
|
||||||
|
@ -426,7 +428,8 @@ class TransactionTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
|
||||||
autocomitted_create_then_fail = transaction.autocommit(using='default')(
|
autocomitted_create_then_fail = transaction.autocommit(using='default')(
|
||||||
self.create_a_reporter_then_fail
|
self.create_a_reporter_then_fail
|
||||||
)
|
)
|
||||||
self.assertRaises(Exception,
|
self.assertRaises(
|
||||||
|
Exception,
|
||||||
autocomitted_create_then_fail,
|
autocomitted_create_then_fail,
|
||||||
"Alice", "Smith"
|
"Alice", "Smith"
|
||||||
)
|
)
|
||||||
|
@ -453,7 +456,8 @@ class TransactionTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
|
||||||
using_committed_on_success = transaction.commit_on_success(using='default')(
|
using_committed_on_success = transaction.commit_on_success(using='default')(
|
||||||
self.create_a_reporter_then_fail
|
self.create_a_reporter_then_fail
|
||||||
)
|
)
|
||||||
self.assertRaises(Exception,
|
self.assertRaises(
|
||||||
|
Exception,
|
||||||
using_committed_on_success,
|
using_committed_on_success,
|
||||||
"Dirk", "Gently"
|
"Dirk", "Gently"
|
||||||
)
|
)
|
||||||
|
@ -519,7 +523,8 @@ class TransactionTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
|
||||||
using_manually_managed_mistake = transaction.commit_manually(using='default')(
|
using_manually_managed_mistake = transaction.commit_manually(using='default')(
|
||||||
self.manually_managed_mistake
|
self.manually_managed_mistake
|
||||||
)
|
)
|
||||||
self.assertRaises(transaction.TransactionManagementError,
|
self.assertRaises(
|
||||||
|
transaction.TransactionManagementError,
|
||||||
using_manually_managed_mistake
|
using_manually_managed_mistake
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -544,6 +549,7 @@ class TransactionRollbackTests(IgnoreDeprecationWarningsMixin, TransactionTestCa
|
||||||
self.assertRaises(IntegrityError, execute_bad_sql)
|
self.assertRaises(IntegrityError, execute_bad_sql)
|
||||||
transaction.rollback()
|
transaction.rollback()
|
||||||
|
|
||||||
|
|
||||||
class TransactionContextManagerTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
|
class TransactionContextManagerTests(IgnoreDeprecationWarningsMixin, TransactionTestCase):
|
||||||
|
|
||||||
available_apps = ['transactions']
|
available_apps = ['transactions']
|
||||||
|
|
|
@ -4,9 +4,11 @@ from django.db import models
|
||||||
class Mod(models.Model):
|
class Mod(models.Model):
|
||||||
fld = models.IntegerField()
|
fld = models.IntegerField()
|
||||||
|
|
||||||
|
|
||||||
class SubMod(Mod):
|
class SubMod(Mod):
|
||||||
cnt = models.IntegerField(unique=True)
|
cnt = models.IntegerField(unique=True)
|
||||||
|
|
||||||
|
|
||||||
class M2mA(models.Model):
|
class M2mA(models.Model):
|
||||||
others = models.ManyToManyField('M2mB')
|
others = models.ManyToManyField('M2mB')
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ from django.test.utils import override_settings, IgnoreDeprecationWarningsMixin
|
||||||
|
|
||||||
from .models import Mod, M2mA, M2mB, SubMod
|
from .models import Mod, M2mA, M2mB, SubMod
|
||||||
|
|
||||||
|
|
||||||
class ModelInheritanceTests(TransactionTestCase):
|
class ModelInheritanceTests(TransactionTestCase):
|
||||||
|
|
||||||
available_apps = ['transactions_regress']
|
available_apps = ['transactions_regress']
|
||||||
|
@ -31,6 +32,7 @@ class ModelInheritanceTests(TransactionTestCase):
|
||||||
self.assertEqual(SubMod.objects.count(), 1)
|
self.assertEqual(SubMod.objects.count(), 1)
|
||||||
self.assertEqual(Mod.objects.count(), 1)
|
self.assertEqual(Mod.objects.count(), 1)
|
||||||
|
|
||||||
|
|
||||||
class TestTransactionClosing(IgnoreDeprecationWarningsMixin, TransactionTestCase):
|
class TestTransactionClosing(IgnoreDeprecationWarningsMixin, TransactionTestCase):
|
||||||
"""
|
"""
|
||||||
Tests to make sure that transactions are properly closed
|
Tests to make sure that transactions are properly closed
|
||||||
|
@ -191,6 +193,7 @@ class TestTransactionClosing(IgnoreDeprecationWarningsMixin, TransactionTestCase
|
||||||
"""
|
"""
|
||||||
self.test_failing_query_transaction_closed()
|
self.test_failing_query_transaction_closed()
|
||||||
|
|
||||||
|
|
||||||
@skipIf(connection.vendor == 'sqlite'
|
@skipIf(connection.vendor == 'sqlite'
|
||||||
and connection.settings_dict['TEST_NAME'] in (None, '', ':memory:'),
|
and connection.settings_dict['TEST_NAME'] in (None, '', ':memory:'),
|
||||||
"Cannot establish two connections to an in-memory SQLite database.")
|
"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
|
# _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.
|
# a skipIf decorator since that would execute the query on module load.
|
||||||
if (connection.vendor == 'mysql' and
|
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")
|
raise SkipTest("MyISAM MySQL storage engine doesn't support savepoints")
|
||||||
|
|
||||||
@commit_manually
|
@commit_manually
|
||||||
|
|
|
@ -8,6 +8,7 @@ from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
|
||||||
# All of these models are created in the database by Django.
|
# All of these models are created in the database by Django.
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class A01(models.Model):
|
class A01(models.Model):
|
||||||
f_a = models.CharField(max_length=10, db_index=True)
|
f_a = models.CharField(max_length=10, db_index=True)
|
||||||
|
@ -19,6 +20,7 @@ class A01(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.f_a
|
return self.f_a
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class B01(models.Model):
|
class B01(models.Model):
|
||||||
fk_a = models.ForeignKey(A01)
|
fk_a = models.ForeignKey(A01)
|
||||||
|
@ -33,6 +35,7 @@ class B01(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.f_a
|
return self.f_a
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class C01(models.Model):
|
class C01(models.Model):
|
||||||
mm_a = models.ManyToManyField(A01, db_table='d01')
|
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,
|
# of possibly a subset of the columns). There should be no creation errors,
|
||||||
# since we have told Django they aren't managed by Django.
|
# since we have told Django they aren't managed by Django.
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class A02(models.Model):
|
class A02(models.Model):
|
||||||
f_a = models.CharField(max_length=10, db_index=True)
|
f_a = models.CharField(max_length=10, db_index=True)
|
||||||
|
@ -60,6 +64,7 @@ class A02(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.f_a
|
return self.f_a
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class B02(models.Model):
|
class B02(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -73,6 +78,7 @@ class B02(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.f_a
|
return self.f_a
|
||||||
|
|
||||||
|
|
||||||
# To re-use the many-to-many intermediate table, we need to manually set up
|
# To re-use the many-to-many intermediate table, we need to manually set up
|
||||||
# things up.
|
# things up.
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
|
@ -88,6 +94,7 @@ class C02(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.f_a
|
return self.f_a
|
||||||
|
|
||||||
|
|
||||||
class Intermediate(models.Model):
|
class Intermediate(models.Model):
|
||||||
a02 = models.ForeignKey(A02, db_column="a01_id")
|
a02 = models.ForeignKey(A02, db_column="a01_id")
|
||||||
c02 = models.ForeignKey(C02, db_column="c01_id")
|
c02 = models.ForeignKey(C02, db_column="c01_id")
|
||||||
|
@ -96,7 +103,7 @@ class Intermediate(models.Model):
|
||||||
db_table = 'd01'
|
db_table = 'd01'
|
||||||
managed = False
|
managed = False
|
||||||
|
|
||||||
#
|
|
||||||
# These next models test the creation (or not) of many to many join tables
|
# 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
|
# between managed and unmanaged models. A join table between two unmanaged
|
||||||
# models shouldn't be automatically created (see #10647).
|
# models shouldn't be automatically created (see #10647).
|
||||||
|
@ -109,15 +116,18 @@ class Proxy1(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = "unmanaged_models_proxy1"
|
db_table = "unmanaged_models_proxy1"
|
||||||
|
|
||||||
|
|
||||||
class Proxy2(models.Model):
|
class Proxy2(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = "unmanaged_models_proxy2"
|
db_table = "unmanaged_models_proxy2"
|
||||||
|
|
||||||
|
|
||||||
class Unmanaged1(models.Model):
|
class Unmanaged1(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
managed = False
|
managed = False
|
||||||
db_table = "unmanaged_models_proxy1"
|
db_table = "unmanaged_models_proxy1"
|
||||||
|
|
||||||
|
|
||||||
# Unmanged with an m2m to unmanaged: the intermediary table won't be created.
|
# Unmanged with an m2m to unmanaged: the intermediary table won't be created.
|
||||||
class Unmanaged2(models.Model):
|
class Unmanaged2(models.Model):
|
||||||
mm = models.ManyToManyField(Unmanaged1)
|
mm = models.ManyToManyField(Unmanaged1)
|
||||||
|
@ -126,6 +136,7 @@ class Unmanaged2(models.Model):
|
||||||
managed = False
|
managed = False
|
||||||
db_table = "unmanaged_models_proxy2"
|
db_table = "unmanaged_models_proxy2"
|
||||||
|
|
||||||
|
|
||||||
# Here's an unmanaged model with an m2m to a managed one; the intermediary
|
# 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).
|
# table *will* be created (unless given a custom `through` as for C02 above).
|
||||||
class Managed1(models.Model):
|
class Managed1(models.Model):
|
||||||
|
|
|
@ -17,6 +17,7 @@ class DataPoint(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return six.text_type(self.name)
|
return six.text_type(self.name)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class RelatedPoint(models.Model):
|
class RelatedPoint(models.Model):
|
||||||
name = models.CharField(max_length=20)
|
name = models.CharField(max_length=20)
|
||||||
|
@ -29,12 +30,15 @@ class RelatedPoint(models.Model):
|
||||||
class A(models.Model):
|
class A(models.Model):
|
||||||
x = models.IntegerField(default=10)
|
x = models.IntegerField(default=10)
|
||||||
|
|
||||||
|
|
||||||
class B(models.Model):
|
class B(models.Model):
|
||||||
a = models.ForeignKey(A)
|
a = models.ForeignKey(A)
|
||||||
y = models.IntegerField(default=10)
|
y = models.IntegerField(default=10)
|
||||||
|
|
||||||
|
|
||||||
class C(models.Model):
|
class C(models.Model):
|
||||||
y = models.IntegerField(default=10)
|
y = models.IntegerField(default=10)
|
||||||
|
|
||||||
|
|
||||||
class D(C):
|
class D(C):
|
||||||
a = models.ForeignKey(A)
|
a = models.ForeignKey(A)
|
||||||
|
|
|
@ -7,6 +7,7 @@ GENDER_CHOICES = (
|
||||||
('F', 'Female'),
|
('F', 'Female'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Account(models.Model):
|
class Account(models.Model):
|
||||||
num = models.IntegerField()
|
num = models.IntegerField()
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import non_existent # NOQA
|
import non_existent # NOQA
|
||||||
|
|
||||||
|
|
||||||
def erroneous_view(request):
|
def erroneous_view(request):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -8,24 +8,29 @@ class ChangeURLconfMiddleware(object):
|
||||||
def process_request(self, request):
|
def process_request(self, request):
|
||||||
request.urlconf = urlconf_inner.__name__
|
request.urlconf = urlconf_inner.__name__
|
||||||
|
|
||||||
|
|
||||||
class NullChangeURLconfMiddleware(object):
|
class NullChangeURLconfMiddleware(object):
|
||||||
def process_request(self, request):
|
def process_request(self, request):
|
||||||
request.urlconf = None
|
request.urlconf = None
|
||||||
|
|
||||||
|
|
||||||
class ReverseInnerInResponseMiddleware(object):
|
class ReverseInnerInResponseMiddleware(object):
|
||||||
def process_response(self, *args, **kwargs):
|
def process_response(self, *args, **kwargs):
|
||||||
return HttpResponse(reverse('inner'))
|
return HttpResponse(reverse('inner'))
|
||||||
|
|
||||||
|
|
||||||
class ReverseOuterInResponseMiddleware(object):
|
class ReverseOuterInResponseMiddleware(object):
|
||||||
def process_response(self, *args, **kwargs):
|
def process_response(self, *args, **kwargs):
|
||||||
return HttpResponse(reverse('outer'))
|
return HttpResponse(reverse('outer'))
|
||||||
|
|
||||||
|
|
||||||
class ReverseInnerInStreaming(object):
|
class ReverseInnerInStreaming(object):
|
||||||
def process_view(self, *args, **kwargs):
|
def process_view(self, *args, **kwargs):
|
||||||
def stream():
|
def stream():
|
||||||
yield reverse('inner')
|
yield reverse('inner')
|
||||||
return StreamingHttpResponse(stream())
|
return StreamingHttpResponse(stream())
|
||||||
|
|
||||||
|
|
||||||
class ReverseOuterInStreaming(object):
|
class ReverseOuterInStreaming(object):
|
||||||
def process_view(self, *args, **kwargs):
|
def process_view(self, *args, **kwargs):
|
||||||
def stream():
|
def stream():
|
||||||
|
|
|
@ -148,6 +148,7 @@ test_data = (
|
||||||
('defaults', NoReverseMatch, [], {'arg2': 1}),
|
('defaults', NoReverseMatch, [], {'arg2': 1}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NoURLPatternsTests(TestCase):
|
class NoURLPatternsTests(TestCase):
|
||||||
urls = 'urlpatterns_reverse.no_urls'
|
urls = 'urlpatterns_reverse.no_urls'
|
||||||
|
|
||||||
|
@ -161,6 +162,7 @@ class NoURLPatternsTests(TestCase):
|
||||||
"The included urlconf urlpatterns_reverse.no_urls "
|
"The included urlconf urlpatterns_reverse.no_urls "
|
||||||
"doesn't have any patterns in it", getattr, resolver, 'url_patterns')
|
"doesn't have any patterns in it", getattr, resolver, 'url_patterns')
|
||||||
|
|
||||||
|
|
||||||
class URLPatternReverse(TestCase):
|
class URLPatternReverse(TestCase):
|
||||||
urls = 'urlpatterns_reverse.urls'
|
urls = 'urlpatterns_reverse.urls'
|
||||||
|
|
||||||
|
@ -282,6 +284,7 @@ class ResolverTests(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
self.assertEqual(t.name, e['name'], 'Wrong URL name. Expected "%s", got "%s".' % (e['name'], t.name))
|
self.assertEqual(t.name, e['name'], 'Wrong URL name. Expected "%s", got "%s".' % (e['name'], t.name))
|
||||||
|
|
||||||
|
|
||||||
class ReverseLazyTest(TestCase):
|
class ReverseLazyTest(TestCase):
|
||||||
urls = 'urlpatterns_reverse.reverse_lazy_urls'
|
urls = 'urlpatterns_reverse.reverse_lazy_urls'
|
||||||
|
|
||||||
|
@ -297,6 +300,7 @@ class ReverseLazyTest(TestCase):
|
||||||
response = self.client.get('/login_required_view/')
|
response = self.client.get('/login_required_view/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
class ReverseShortcutTests(TestCase):
|
class ReverseShortcutTests(TestCase):
|
||||||
urls = 'urlpatterns_reverse.urls'
|
urls = 'urlpatterns_reverse.urls'
|
||||||
|
|
||||||
|
@ -454,7 +458,7 @@ class NamespaceTests(TestCase):
|
||||||
self.assertEqual('/inc78/extra/foobar/', reverse('inc-ns5:inner-extra', args=['78', 'foobar']))
|
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):
|
class RequestURLconfTests(TestCase):
|
||||||
def test_urlconf(self):
|
def test_urlconf(self):
|
||||||
response = self.client.get('/test/me/')
|
response = self.client.get('/test/me/')
|
||||||
|
@ -549,6 +553,7 @@ class RequestURLconfTests(TestCase):
|
||||||
self.client.get('/second_test/')
|
self.client.get('/second_test/')
|
||||||
b''.join(self.client.get('/second_test/'))
|
b''.join(self.client.get('/second_test/'))
|
||||||
|
|
||||||
|
|
||||||
class ErrorHandlerResolutionTests(TestCase):
|
class ErrorHandlerResolutionTests(TestCase):
|
||||||
"""Tests for handler400, handler404 and handler500"""
|
"""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.resolve404(), handler)
|
||||||
self.assertEqual(self.callable_resolver.resolve500(), handler)
|
self.assertEqual(self.callable_resolver.resolve500(), handler)
|
||||||
|
|
||||||
|
|
||||||
class DefaultErrorHandlerTests(TestCase):
|
class DefaultErrorHandlerTests(TestCase):
|
||||||
urls = 'urlpatterns_reverse.urls_without_full_import'
|
urls = 'urlpatterns_reverse.urls_without_full_import'
|
||||||
|
|
||||||
|
@ -589,6 +595,7 @@ class DefaultErrorHandlerTests(TestCase):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
self.fail("Shouldn't get an AttributeError due to undefined 500 handler")
|
self.fail("Shouldn't get an AttributeError due to undefined 500 handler")
|
||||||
|
|
||||||
|
|
||||||
class NoRootUrlConfTests(TestCase):
|
class NoRootUrlConfTests(TestCase):
|
||||||
"""Tests for handler404 and handler500 if urlconf is None"""
|
"""Tests for handler404 and handler500 if urlconf is None"""
|
||||||
urls = None
|
urls = None
|
||||||
|
@ -596,6 +603,7 @@ class NoRootUrlConfTests(TestCase):
|
||||||
def test_no_handler_exception(self):
|
def test_no_handler_exception(self):
|
||||||
self.assertRaises(ImproperlyConfigured, self.client.get, '/test/me/')
|
self.assertRaises(ImproperlyConfigured, self.client.get, '/test/me/')
|
||||||
|
|
||||||
|
|
||||||
class ResolverMatchTests(TestCase):
|
class ResolverMatchTests(TestCase):
|
||||||
urls = 'urlpatterns_reverse.namespace_urls'
|
urls = 'urlpatterns_reverse.namespace_urls'
|
||||||
|
|
||||||
|
@ -631,6 +639,7 @@ class ResolverMatchTests(TestCase):
|
||||||
request = HttpRequest()
|
request = HttpRequest()
|
||||||
self.assertIsNone(request.resolver_match)
|
self.assertIsNone(request.resolver_match)
|
||||||
|
|
||||||
|
|
||||||
class ErroneousViewTests(TestCase):
|
class ErroneousViewTests(TestCase):
|
||||||
urls = 'urlpatterns_reverse.erroneous_urls'
|
urls = 'urlpatterns_reverse.erroneous_urls'
|
||||||
|
|
||||||
|
@ -650,6 +659,7 @@ class ErroneousViewTests(TestCase):
|
||||||
# The regex error will be hit before NoReverseMatch can be raised
|
# The regex error will be hit before NoReverseMatch can be raised
|
||||||
self.assertRaises(ImproperlyConfigured, reverse, 'whatever blah blah')
|
self.assertRaises(ImproperlyConfigured, reverse, 'whatever blah blah')
|
||||||
|
|
||||||
|
|
||||||
class ViewLoadingTests(TestCase):
|
class ViewLoadingTests(TestCase):
|
||||||
def test_view_loading(self):
|
def test_view_loading(self):
|
||||||
# A missing view (identified by an AttributeError) should raise
|
# A missing view (identified by an AttributeError) should raise
|
||||||
|
|
|
@ -2,6 +2,7 @@ from django.conf.urls import patterns, url
|
||||||
from django.template import Template, Context
|
from django.template import Template, Context
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
|
|
||||||
def inner_view(request):
|
def inner_view(request):
|
||||||
content = Template('{% url "outer" as outer_url %}outer:{{ outer_url }},'
|
content = Template('{% url "outer" as outer_url %}outer:{{ outer_url }},'
|
||||||
'{% url "inner" as inner_url %}inner:{{ inner_url }}').render(Context())
|
'{% url "inner" as inner_url %}inner:{{ inner_url }}').render(Context())
|
||||||
|
|
|
@ -4,21 +4,27 @@ from django.core.urlresolvers import reverse_lazy
|
||||||
|
|
||||||
from django.contrib.auth.decorators import user_passes_test
|
from django.contrib.auth.decorators import user_passes_test
|
||||||
|
|
||||||
|
|
||||||
def empty_view(request, *args, **kwargs):
|
def empty_view(request, *args, **kwargs):
|
||||||
return HttpResponse('')
|
return HttpResponse('')
|
||||||
|
|
||||||
|
|
||||||
def kwargs_view(request, arg1=1, arg2=2):
|
def kwargs_view(request, arg1=1, arg2=2):
|
||||||
return HttpResponse('')
|
return HttpResponse('')
|
||||||
|
|
||||||
|
|
||||||
def absolute_kwargs_view(request, arg1=1, arg2=2):
|
def absolute_kwargs_view(request, arg1=1, arg2=2):
|
||||||
return HttpResponse('')
|
return HttpResponse('')
|
||||||
|
|
||||||
|
|
||||||
def defaults_view(request, arg1, arg2):
|
def defaults_view(request, arg1, arg2):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def erroneous_view(request):
|
def erroneous_view(request):
|
||||||
import non_existent # NOQA
|
import non_existent # NOQA
|
||||||
|
|
||||||
|
|
||||||
def pass_resolver_match_view(request, *args, **kwargs):
|
def pass_resolver_match_view(request, *args, **kwargs):
|
||||||
response = HttpResponse('')
|
response = HttpResponse('')
|
||||||
response.resolver_match = request.resolver_match
|
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?"
|
uncallable = "Can I be a view? Pleeeease?"
|
||||||
|
|
||||||
|
|
||||||
class ViewClass(object):
|
class ViewClass(object):
|
||||||
def __call__(self, request, *args, **kwargs):
|
def __call__(self, request, *args, **kwargs):
|
||||||
return HttpResponse('')
|
return HttpResponse('')
|
||||||
|
|
||||||
view_class_instance = ViewClass()
|
view_class_instance = ViewClass()
|
||||||
|
|
||||||
|
|
||||||
class LazyRedirectView(RedirectView):
|
class LazyRedirectView(RedirectView):
|
||||||
url = reverse_lazy('named-lazy-url-redirected-to')
|
url = reverse_lazy('named-lazy-url-redirected-to')
|
||||||
|
|
||||||
|
|
||||||
@user_passes_test(lambda u: u.is_authenticated(), login_url=reverse_lazy('some-login-page'))
|
@user_passes_test(lambda u: u.is_authenticated(), login_url=reverse_lazy('some-login-page'))
|
||||||
def login_required_view(request):
|
def login_required_view(request):
|
||||||
return HttpResponse('Hello you')
|
return HttpResponse('Hello you')
|
||||||
|
|
||||||
|
|
||||||
def bad_view(request, *args, **kwargs):
|
def bad_view(request, *args, **kwargs):
|
||||||
raise ValueError("I don't think I'm getting good value for this view")
|
raise ValueError("I don't think I'm getting good value for this view")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
|
||||||
can_import_settings = True
|
can_import_settings = True
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
|
||||||
can_import_settings = True
|
can_import_settings = True
|
||||||
|
|
|
@ -3,6 +3,7 @@ from unittest import TestCase
|
||||||
from django.utils.baseconv import base2, base16, base36, base56, base62, base64, BaseConverter
|
from django.utils.baseconv import base2, base16, base36, base56, base62, base64, BaseConverter
|
||||||
from django.utils.six.moves import xrange
|
from django.utils.six.moves import xrange
|
||||||
|
|
||||||
|
|
||||||
class TestBaseConv(TestCase):
|
class TestBaseConv(TestCase):
|
||||||
|
|
||||||
def test_baseconv(self):
|
def test_baseconv(self):
|
||||||
|
|
|
@ -2,6 +2,7 @@ import unittest
|
||||||
|
|
||||||
from django.utils import checksums
|
from django.utils import checksums
|
||||||
|
|
||||||
|
|
||||||
class TestUtilsChecksums(unittest.TestCase):
|
class TestUtilsChecksums(unittest.TestCase):
|
||||||
|
|
||||||
def check_output(self, function, value, output=None):
|
def check_output(self, function, value, output=None):
|
||||||
|
|
|
@ -3,6 +3,7 @@ import unittest
|
||||||
from datetime import date as original_date, datetime as original_datetime
|
from datetime import date as original_date, datetime as original_datetime
|
||||||
from django.utils.datetime_safe import date, datetime
|
from django.utils.datetime_safe import date, datetime
|
||||||
|
|
||||||
|
|
||||||
class DatetimeTests(unittest.TestCase):
|
class DatetimeTests(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -11,6 +11,7 @@ class ProcessViewMiddleware(object):
|
||||||
|
|
||||||
process_view_dec = decorator_from_middleware(ProcessViewMiddleware)
|
process_view_dec = decorator_from_middleware(ProcessViewMiddleware)
|
||||||
|
|
||||||
|
|
||||||
@process_view_dec
|
@process_view_dec
|
||||||
def process_view(request):
|
def process_view(request):
|
||||||
return HttpResponse()
|
return HttpResponse()
|
||||||
|
|
|
@ -4,6 +4,7 @@ import unittest
|
||||||
|
|
||||||
from django.utils.ipv6 import is_valid_ipv6_address, clean_ipv6_address
|
from django.utils.ipv6 import is_valid_ipv6_address, clean_ipv6_address
|
||||||
|
|
||||||
|
|
||||||
class TestUtilsIPv6(unittest.TestCase):
|
class TestUtilsIPv6(unittest.TestCase):
|
||||||
|
|
||||||
def test_validates_correct_plain_address(self):
|
def test_validates_correct_plain_address(self):
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.utils.jslex import JsLexer, prepare_js_for_gettext
|
from django.utils.jslex import JsLexer, prepare_js_for_gettext
|
||||||
|
|
||||||
|
|
||||||
class JsTokensTest(TestCase):
|
class JsTokensTest(TestCase):
|
||||||
LEX_CASES = [
|
LEX_CASES = [
|
||||||
# ids
|
# ids
|
||||||
|
@ -105,6 +106,7 @@ class JsTokensTest(TestCase):
|
||||||
r'string "\")"', "punct ;"]),
|
r'string "\")"', "punct ;"]),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def make_function(input, toks):
|
def make_function(input, toks):
|
||||||
def test_func(self):
|
def test_func(self):
|
||||||
lexer = JsLexer()
|
lexer = JsLexer()
|
||||||
|
@ -207,6 +209,7 @@ GETTEXT_CASES = (
|
||||||
class JsToCForGettextTest(TestCase):
|
class JsToCForGettextTest(TestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def make_function(js, c):
|
def make_function(js, c):
|
||||||
def test_func(self):
|
def test_func(self):
|
||||||
self.assertMultiLineEqual(prepare_js_for_gettext(js), c)
|
self.assertMultiLineEqual(prepare_js_for_gettext(js), c)
|
||||||
|
|
|
@ -52,6 +52,7 @@ class DefaultLoader(unittest.TestCase):
|
||||||
self.assertRaises(ImportError, import_module,
|
self.assertRaises(ImportError, import_module,
|
||||||
'utils_tests.test_no_submodule.anything')
|
'utils_tests.test_no_submodule.anything')
|
||||||
|
|
||||||
|
|
||||||
class EggLoader(unittest.TestCase):
|
class EggLoader(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.old_path = sys.path[:]
|
self.old_path = sys.path[:]
|
||||||
|
@ -133,6 +134,7 @@ class ModuleImportTestCase(unittest.TestCase):
|
||||||
self.assertIsNotNone(traceback.tb_next.tb_next,
|
self.assertIsNotNone(traceback.tb_next.tb_next,
|
||||||
'Should have more than the calling frame in the traceback.')
|
'Should have more than the calling frame in the traceback.')
|
||||||
|
|
||||||
|
|
||||||
@override_settings(INSTALLED_APPS=('utils_tests.test_module',))
|
@override_settings(INSTALLED_APPS=('utils_tests.test_module',))
|
||||||
class AutodiscoverModulesTestCase(SimpleTestCase):
|
class AutodiscoverModulesTestCase(SimpleTestCase):
|
||||||
|
|
||||||
|
@ -188,6 +190,7 @@ class ProxyFinder(object):
|
||||||
if fd:
|
if fd:
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
|
|
||||||
class TestFinder(object):
|
class TestFinder(object):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.importer = zipimporter(*args, **kwargs)
|
self.importer = zipimporter(*args, **kwargs)
|
||||||
|
@ -198,6 +201,7 @@ class TestFinder(object):
|
||||||
return
|
return
|
||||||
return TestLoader(importer)
|
return TestLoader(importer)
|
||||||
|
|
||||||
|
|
||||||
class TestLoader(object):
|
class TestLoader(object):
|
||||||
def __init__(self, importer):
|
def __init__(self, importer):
|
||||||
self.importer = importer
|
self.importer = importer
|
||||||
|
@ -207,6 +211,7 @@ class TestLoader(object):
|
||||||
mod.__loader__ = self
|
mod.__loader__ = self
|
||||||
return mod
|
return mod
|
||||||
|
|
||||||
|
|
||||||
class CustomLoader(EggLoader):
|
class CustomLoader(EggLoader):
|
||||||
"""The Custom Loader test is exactly the same as the EggLoader, but
|
"""The Custom Loader test is exactly the same as the EggLoader, but
|
||||||
it uses a custom defined Loader and Finder that is intentionally
|
it uses a custom defined Loader and Finder that is intentionally
|
||||||
|
|
|
@ -177,6 +177,7 @@ class TestUtilsSimpleLazyObject(TestCase):
|
||||||
self.assertEqual(len(lazy_list), 5)
|
self.assertEqual(len(lazy_list), 5)
|
||||||
self.assertEqual(len(lazy_set), 4)
|
self.assertEqual(len(lazy_set), 4)
|
||||||
|
|
||||||
|
|
||||||
class TestUtilsSimpleLazyObjectDjangoTestCase(DjangoTestCase):
|
class TestUtilsSimpleLazyObjectDjangoTestCase(DjangoTestCase):
|
||||||
|
|
||||||
def test_pickle_py2_regression(self):
|
def test_pickle_py2_regression(self):
|
||||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.utils import text
|
from django.utils import text
|
||||||
|
|
||||||
|
|
||||||
class TestUtilsText(SimpleTestCase):
|
class TestUtilsText(SimpleTestCase):
|
||||||
|
|
||||||
def test_truncate_chars(self):
|
def test_truncate_chars(self):
|
||||||
|
|
|
@ -13,6 +13,7 @@ with warnings.catch_warnings():
|
||||||
warnings.filterwarnings("ignore", category=PendingDeprecationWarning)
|
warnings.filterwarnings("ignore", category=PendingDeprecationWarning)
|
||||||
from django.utils.tzinfo import FixedOffset, LocalTimezone
|
from django.utils.tzinfo import FixedOffset, LocalTimezone
|
||||||
|
|
||||||
|
|
||||||
class TzinfoTests(IgnorePendingDeprecationWarningsMixin, unittest.TestCase):
|
class TzinfoTests(IgnorePendingDeprecationWarningsMixin, unittest.TestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -47,10 +48,10 @@ class TzinfoTests(IgnorePendingDeprecationWarningsMixin, unittest.TestCase):
|
||||||
self.assertEqual(repr(FixedOffset(-280)), '-0440')
|
self.assertEqual(repr(FixedOffset(-280)), '-0440')
|
||||||
self.assertEqual(repr(FixedOffset(-78.4)), '-0118')
|
self.assertEqual(repr(FixedOffset(-78.4)), '-0118')
|
||||||
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.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*60)), '+0030')
|
self.assertEqual(repr(FixedOffset(.5 * 60)), '+0030')
|
||||||
|
|
||||||
def test_16899(self):
|
def test_16899(self):
|
||||||
if not self.tz_tests:
|
if not self.tz_tests:
|
||||||
|
|
|
@ -11,6 +11,7 @@ def validate_answer_to_universe(value):
|
||||||
if value != 42:
|
if value != 42:
|
||||||
raise ValidationError('This is not the answer to life, universe and everything!', code='not42')
|
raise ValidationError('This is not the answer to life, universe and everything!', code='not42')
|
||||||
|
|
||||||
|
|
||||||
class ModelToValidate(models.Model):
|
class ModelToValidate(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
created = models.DateTimeField(default=datetime.now)
|
created = models.DateTimeField(default=datetime.now)
|
||||||
|
@ -26,14 +27,17 @@ class ModelToValidate(models.Model):
|
||||||
if self.number == 11:
|
if self.number == 11:
|
||||||
raise ValidationError('Invalid number supplied!')
|
raise ValidationError('Invalid number supplied!')
|
||||||
|
|
||||||
|
|
||||||
class UniqueFieldsModel(models.Model):
|
class UniqueFieldsModel(models.Model):
|
||||||
unique_charfield = models.CharField(max_length=100, unique=True)
|
unique_charfield = models.CharField(max_length=100, unique=True)
|
||||||
unique_integerfield = models.IntegerField(unique=True)
|
unique_integerfield = models.IntegerField(unique=True)
|
||||||
non_unique_field = models.IntegerField()
|
non_unique_field = models.IntegerField()
|
||||||
|
|
||||||
|
|
||||||
class CustomPKModel(models.Model):
|
class CustomPKModel(models.Model):
|
||||||
my_pk_field = models.CharField(max_length=100, primary_key=True)
|
my_pk_field = models.CharField(max_length=100, primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class UniqueTogetherModel(models.Model):
|
class UniqueTogetherModel(models.Model):
|
||||||
cfield = models.CharField(max_length=100)
|
cfield = models.CharField(max_length=100)
|
||||||
ifield = models.IntegerField()
|
ifield = models.IntegerField()
|
||||||
|
@ -42,6 +46,7 @@ class UniqueTogetherModel(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = (('ifield', 'cfield',), ['ifield', 'efield'])
|
unique_together = (('ifield', 'cfield',), ['ifield', 'efield'])
|
||||||
|
|
||||||
|
|
||||||
class UniqueForDateModel(models.Model):
|
class UniqueForDateModel(models.Model):
|
||||||
start_date = models.DateField()
|
start_date = models.DateField()
|
||||||
end_date = models.DateTimeField()
|
end_date = models.DateTimeField()
|
||||||
|
@ -49,6 +54,7 @@ class UniqueForDateModel(models.Model):
|
||||||
order = models.IntegerField(unique_for_month="end_date")
|
order = models.IntegerField(unique_for_month="end_date")
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
|
||||||
class CustomMessagesModel(models.Model):
|
class CustomMessagesModel(models.Model):
|
||||||
other = models.IntegerField(blank=True, null=True)
|
other = models.IntegerField(blank=True, null=True)
|
||||||
number = models.IntegerField(db_column='number_val',
|
number = models.IntegerField(db_column='number_val',
|
||||||
|
@ -56,9 +62,11 @@ class CustomMessagesModel(models.Model):
|
||||||
validators=[validate_answer_to_universe]
|
validators=[validate_answer_to_universe]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Author(models.Model):
|
class Author(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
|
||||||
class Article(models.Model):
|
class Article(models.Model):
|
||||||
title = models.CharField(max_length=100)
|
title = models.CharField(max_length=100)
|
||||||
author = models.ForeignKey(Author)
|
author = models.ForeignKey(Author)
|
||||||
|
@ -68,6 +76,7 @@ class Article(models.Model):
|
||||||
if self.pub_date is None:
|
if self.pub_date is None:
|
||||||
self.pub_date = datetime.now()
|
self.pub_date = datetime.now()
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Post(models.Model):
|
class Post(models.Model):
|
||||||
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
|
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
|
||||||
|
@ -78,16 +87,19 @@ class Post(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class FlexibleDatePost(models.Model):
|
class FlexibleDatePost(models.Model):
|
||||||
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
|
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
|
||||||
slug = models.CharField(max_length=50, unique_for_year='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)
|
subtitle = models.CharField(max_length=50, unique_for_month='posted', blank=True)
|
||||||
posted = models.DateField(blank=True, null=True)
|
posted = models.DateField(blank=True, null=True)
|
||||||
|
|
||||||
|
|
||||||
class UniqueErrorsModel(models.Model):
|
class UniqueErrorsModel(models.Model):
|
||||||
name = models.CharField(max_length=100, unique=True, error_messages={'unique': 'Custom unique name message.'})
|
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.'})
|
no = models.IntegerField(unique=True, error_messages={'unique': 'Custom unique number message.'})
|
||||||
|
|
||||||
|
|
||||||
class GenericIPAddressTestModel(models.Model):
|
class GenericIPAddressTestModel(models.Model):
|
||||||
generic_ip = models.GenericIPAddressField(blank=True, null=True, unique=True)
|
generic_ip = models.GenericIPAddressField(blank=True, null=True, unique=True)
|
||||||
v4_ip = models.GenericIPAddressField(blank=True, null=True, protocol="ipv4")
|
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",
|
ip_verbose_name = models.GenericIPAddressField("IP Address Verbose",
|
||||||
blank=True, null=True)
|
blank=True, null=True)
|
||||||
|
|
||||||
|
|
||||||
class GenericIPAddrUnpackUniqueTest(models.Model):
|
class GenericIPAddrUnpackUniqueTest(models.Model):
|
||||||
generic_v4unpack_ip = models.GenericIPAddressField(null=True, blank=True, unique=True, unpack_ipv4=True)
|
generic_v4unpack_ip = models.GenericIPAddressField(null=True, blank=True, unique=True, unpack_ipv4=True)
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ class GetUniqueCheckTests(unittest.TestCase):
|
||||||
), m._get_unique_checks(exclude='start_date')
|
), m._get_unique_checks(exclude='start_date')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class PerformUniqueChecksTest(TestCase):
|
class PerformUniqueChecksTest(TestCase):
|
||||||
def test_primary_key_unique_check_not_performed_when_adding_and_pk_not_specified(self):
|
def test_primary_key_unique_check_not_performed_when_adding_and_pk_not_specified(self):
|
||||||
# Regression test for #12560
|
# Regression test for #12560
|
||||||
|
|
|
@ -52,7 +52,7 @@ class BaseModelValidationTests(ValidationTestCase):
|
||||||
self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', ['Enter a valid URL.'])
|
self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', ['Enter a valid URL.'])
|
||||||
|
|
||||||
def test_text_greater_that_charfields_max_length_raises_erros(self):
|
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'])
|
self.assertFailsValidation(mtv.full_clean, ['name'])
|
||||||
|
|
||||||
def test_malformed_slug_raises_error(self):
|
def test_malformed_slug_raises_error(self):
|
||||||
|
@ -65,6 +65,7 @@ class ArticleForm(forms.ModelForm):
|
||||||
model = Article
|
model = Article
|
||||||
exclude = ['author']
|
exclude = ['author']
|
||||||
|
|
||||||
|
|
||||||
class ModelFormsTests(TestCase):
|
class ModelFormsTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.author = Author.objects.create(name='Joseph Kocherhans')
|
self.author = Author.objects.create(name='Joseph Kocherhans')
|
||||||
|
|
|
@ -131,12 +131,12 @@ TEST_DATA = (
|
||||||
(MinValueValidator(NOW), NOW - timedelta(days=1), ValidationError),
|
(MinValueValidator(NOW), NOW - timedelta(days=1), ValidationError),
|
||||||
|
|
||||||
(MaxLengthValidator(10), '', None),
|
(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), 15 * 'x', None),
|
||||||
(MinLengthValidator(10), 10*'x', None),
|
(MinLengthValidator(10), 10 * 'x', None),
|
||||||
|
|
||||||
(MinLengthValidator(10), '', ValidationError),
|
(MinLengthValidator(10), '', ValidationError),
|
||||||
|
|
||||||
|
@ -182,6 +182,7 @@ TEST_DATA = (
|
||||||
(RegexValidator(re.compile('x')), 'y', ValidationError),
|
(RegexValidator(re.compile('x')), 'y', ValidationError),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_simple_test_method(validator, expected, value, num):
|
def create_simple_test_method(validator, expected, value, num):
|
||||||
if expected is not None and issubclass(expected, Exception):
|
if expected is not None and issubclass(expected, Exception):
|
||||||
test_mask = 'test_%s_raises_error_%d'
|
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
|
# Dynamically assemble a test class with the contents of TEST_DATA
|
||||||
|
|
||||||
|
|
||||||
class TestSimpleValidators(TestCase):
|
class TestSimpleValidators(TestCase):
|
||||||
def test_single_message(self):
|
def test_single_message(self):
|
||||||
v = ValidationError('Not Valid')
|
v = ValidationError('Not Valid')
|
||||||
|
|
|
@ -3,6 +3,7 @@ from unittest import TestCase
|
||||||
from django import get_version
|
from django import get_version
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
||||||
|
|
||||||
class VersionTests(TestCase):
|
class VersionTests(TestCase):
|
||||||
|
|
||||||
def test_development(self):
|
def test_development(self):
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
|
||||||
class BrokenException(Exception):
|
class BrokenException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ Regression tests for Django built-in views.
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Author(models.Model):
|
class Author(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
|
@ -15,6 +16,7 @@ class Author(models.Model):
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return '/views/authors/%s/' % self.id
|
return '/views/authors/%s/' % self.id
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class BaseArticle(models.Model):
|
class BaseArticle(models.Model):
|
||||||
"""
|
"""
|
||||||
|
@ -31,9 +33,11 @@ class BaseArticle(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
class Article(BaseArticle):
|
class Article(BaseArticle):
|
||||||
date_created = models.DateTimeField()
|
date_created = models.DateTimeField()
|
||||||
|
|
||||||
|
|
||||||
class UrlArticle(BaseArticle):
|
class UrlArticle(BaseArticle):
|
||||||
"""
|
"""
|
||||||
An Article class with a get_absolute_url defined.
|
An Article class with a get_absolute_url defined.
|
||||||
|
@ -44,6 +48,7 @@ class UrlArticle(BaseArticle):
|
||||||
return '/urlarticles/%s/' % self.slug
|
return '/urlarticles/%s/' % self.slug
|
||||||
get_absolute_url.purge = True
|
get_absolute_url.purge = True
|
||||||
|
|
||||||
|
|
||||||
class DateArticle(BaseArticle):
|
class DateArticle(BaseArticle):
|
||||||
"""
|
"""
|
||||||
An article Model with a DateField instead of DateTimeField,
|
An article Model with a DateField instead of DateTimeField,
|
||||||
|
|
|
@ -5,6 +5,7 @@ from ..views import BrokenException
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def go_boom(arg):
|
def go_boom(arg):
|
||||||
raise BrokenException(arg)
|
raise BrokenException(arg)
|
||||||
|
|
|
@ -185,7 +185,7 @@ class ExceptionReporterTests(TestCase):
|
||||||
|
|
||||||
for newline in ['\n', '\r\n', '\r']:
|
for newline in ['\n', '\r\n', '\r']:
|
||||||
fd, filename = mkstemp(text=False)
|
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)
|
os.close(fd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -375,7 +375,7 @@ class ExceptionReportTestMixin(object):
|
||||||
Asserts that potentially sensitive info are displayed in the email report.
|
Asserts that potentially sensitive info are displayed in the email report.
|
||||||
"""
|
"""
|
||||||
with self.settings(ADMINS=(('Admin', 'admin@fattie-breakie.com'),)):
|
with self.settings(ADMINS=(('Admin', 'admin@fattie-breakie.com'),)):
|
||||||
mail.outbox = [] # Empty outbox
|
mail.outbox = [] # Empty outbox
|
||||||
request = self.rf.post('/some_url/', self.breakfast_data)
|
request = self.rf.post('/some_url/', self.breakfast_data)
|
||||||
view(request)
|
view(request)
|
||||||
self.assertEqual(len(mail.outbox), 1)
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
|
@ -408,7 +408,7 @@ class ExceptionReportTestMixin(object):
|
||||||
Asserts that certain sensitive info are not displayed in the email report.
|
Asserts that certain sensitive info are not displayed in the email report.
|
||||||
"""
|
"""
|
||||||
with self.settings(ADMINS=(('Admin', 'admin@fattie-breakie.com'),)):
|
with self.settings(ADMINS=(('Admin', 'admin@fattie-breakie.com'),)):
|
||||||
mail.outbox = [] # Empty outbox
|
mail.outbox = [] # Empty outbox
|
||||||
request = self.rf.post('/some_url/', self.breakfast_data)
|
request = self.rf.post('/some_url/', self.breakfast_data)
|
||||||
view(request)
|
view(request)
|
||||||
self.assertEqual(len(mail.outbox), 1)
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
|
@ -448,7 +448,7 @@ class ExceptionReportTestMixin(object):
|
||||||
Asserts that no variables or POST parameters are displayed in the email report.
|
Asserts that no variables or POST parameters are displayed in the email report.
|
||||||
"""
|
"""
|
||||||
with self.settings(ADMINS=(('Admin', 'admin@fattie-breakie.com'),)):
|
with self.settings(ADMINS=(('Admin', 'admin@fattie-breakie.com'),)):
|
||||||
mail.outbox = [] # Empty outbox
|
mail.outbox = [] # Empty outbox
|
||||||
request = self.rf.post('/some_url/', self.breakfast_data)
|
request = self.rf.post('/some_url/', self.breakfast_data)
|
||||||
view(request)
|
view(request)
|
||||||
self.assertEqual(len(mail.outbox), 1)
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
|
@ -641,6 +641,7 @@ class ExceptionReporterFilterTests(TestCase, ExceptionReportTestMixin):
|
||||||
response = self.client.get('/views/raises500/')
|
response = self.client.get('/views/raises500/')
|
||||||
self.assertNotContains(response, 'should not be displayed', status_code=500)
|
self.assertNotContains(response, 'should not be displayed', status_code=500)
|
||||||
|
|
||||||
|
|
||||||
class AjaxResponseExceptionReporterFilter(TestCase, ExceptionReportTestMixin):
|
class AjaxResponseExceptionReporterFilter(TestCase, ExceptionReportTestMixin):
|
||||||
"""
|
"""
|
||||||
Ensure that sensitive information can be filtered out of error reports.
|
Ensure that sensitive information can be filtered out of error reports.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
|
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
TEMPLATE_CONTEXT_PROCESSORS=('django.core.context_processors.static',),
|
TEMPLATE_CONTEXT_PROCESSORS=('django.core.context_processors.static',),
|
||||||
STATIC_URL='/path/to/static/media/',
|
STATIC_URL='/path/to/static/media/',
|
||||||
|
|
|
@ -23,6 +23,7 @@ def index_page(request):
|
||||||
"""Dummy index page"""
|
"""Dummy index page"""
|
||||||
return HttpResponse('<html><body>Dummy page</body></html>')
|
return HttpResponse('<html><body>Dummy page</body></html>')
|
||||||
|
|
||||||
|
|
||||||
def raises(request):
|
def raises(request):
|
||||||
# Make sure that a callable that raises an exception in the stack frame's
|
# Make sure that a callable that raises an exception in the stack frame's
|
||||||
# local vars won't hijack the technical 500 response. See:
|
# local vars won't hijack the technical 500 response. See:
|
||||||
|
@ -34,6 +35,7 @@ def raises(request):
|
||||||
except Exception:
|
except Exception:
|
||||||
return technical_500_response(request, *sys.exc_info())
|
return technical_500_response(request, *sys.exc_info())
|
||||||
|
|
||||||
|
|
||||||
def raises500(request):
|
def raises500(request):
|
||||||
# We need to inspect the HTML generated by the fancy 500 debug view but
|
# We need to inspect the HTML generated by the fancy 500 debug view but
|
||||||
# the test client ignores it, so we send it explicitly.
|
# the test client ignores it, so we send it explicitly.
|
||||||
|
@ -42,85 +44,102 @@ def raises500(request):
|
||||||
except Exception:
|
except Exception:
|
||||||
return technical_500_response(request, *sys.exc_info())
|
return technical_500_response(request, *sys.exc_info())
|
||||||
|
|
||||||
|
|
||||||
def raises400(request):
|
def raises400(request):
|
||||||
raise SuspiciousOperation
|
raise SuspiciousOperation
|
||||||
|
|
||||||
|
|
||||||
def raises403(request):
|
def raises403(request):
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
|
|
||||||
def raises404(request):
|
def raises404(request):
|
||||||
resolver = get_resolver(None)
|
resolver = get_resolver(None)
|
||||||
resolver.resolve('')
|
resolver.resolve('')
|
||||||
|
|
||||||
|
|
||||||
def redirect(request):
|
def redirect(request):
|
||||||
"""
|
"""
|
||||||
Forces an HTTP redirect.
|
Forces an HTTP redirect.
|
||||||
"""
|
"""
|
||||||
return HttpResponseRedirect("target/")
|
return HttpResponseRedirect("target/")
|
||||||
|
|
||||||
|
|
||||||
def view_exception(request, n):
|
def view_exception(request, n):
|
||||||
raise BrokenException(except_args[int(n)])
|
raise BrokenException(except_args[int(n)])
|
||||||
|
|
||||||
|
|
||||||
def template_exception(request, n):
|
def template_exception(request, n):
|
||||||
return render_to_response('debug/template_exception.html',
|
return render_to_response('debug/template_exception.html',
|
||||||
{'arg': except_args[int(n)]})
|
{'arg': except_args[int(n)]})
|
||||||
|
|
||||||
|
|
||||||
def jsi18n(request):
|
def jsi18n(request):
|
||||||
return render_to_response('jsi18n.html')
|
return render_to_response('jsi18n.html')
|
||||||
|
|
||||||
# Some views to exercise the shortcuts
|
# Some views to exercise the shortcuts
|
||||||
|
|
||||||
|
|
||||||
def render_to_response_view(request):
|
def render_to_response_view(request):
|
||||||
return render_to_response('debug/render_test.html', {
|
return render_to_response('debug/render_test.html', {
|
||||||
'foo': 'FOO',
|
'foo': 'FOO',
|
||||||
'bar': 'BAR',
|
'bar': 'BAR',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def render_to_response_view_with_request_context(request):
|
def render_to_response_view_with_request_context(request):
|
||||||
return render_to_response('debug/render_test.html', {
|
return render_to_response('debug/render_test.html', {
|
||||||
'foo': 'FOO',
|
'foo': 'FOO',
|
||||||
'bar': 'BAR',
|
'bar': 'BAR',
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
def render_to_response_view_with_content_type(request):
|
def render_to_response_view_with_content_type(request):
|
||||||
return render_to_response('debug/render_test.html', {
|
return render_to_response('debug/render_test.html', {
|
||||||
'foo': 'FOO',
|
'foo': 'FOO',
|
||||||
'bar': 'BAR',
|
'bar': 'BAR',
|
||||||
}, content_type='application/x-rendertest')
|
}, content_type='application/x-rendertest')
|
||||||
|
|
||||||
|
|
||||||
def render_to_response_view_with_dirs(request):
|
def render_to_response_view_with_dirs(request):
|
||||||
return render_to_response('render_dirs_test.html', dirs=dirs)
|
return render_to_response('render_dirs_test.html', dirs=dirs)
|
||||||
|
|
||||||
|
|
||||||
def render_view(request):
|
def render_view(request):
|
||||||
return render(request, 'debug/render_test.html', {
|
return render(request, 'debug/render_test.html', {
|
||||||
'foo': 'FOO',
|
'foo': 'FOO',
|
||||||
'bar': 'BAR',
|
'bar': 'BAR',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def render_view_with_base_context(request):
|
def render_view_with_base_context(request):
|
||||||
return render(request, 'debug/render_test.html', {
|
return render(request, 'debug/render_test.html', {
|
||||||
'foo': 'FOO',
|
'foo': 'FOO',
|
||||||
'bar': 'BAR',
|
'bar': 'BAR',
|
||||||
}, context_instance=Context())
|
}, context_instance=Context())
|
||||||
|
|
||||||
|
|
||||||
def render_view_with_content_type(request):
|
def render_view_with_content_type(request):
|
||||||
return render(request, 'debug/render_test.html', {
|
return render(request, 'debug/render_test.html', {
|
||||||
'foo': 'FOO',
|
'foo': 'FOO',
|
||||||
'bar': 'BAR',
|
'bar': 'BAR',
|
||||||
}, content_type='application/x-rendertest')
|
}, content_type='application/x-rendertest')
|
||||||
|
|
||||||
|
|
||||||
def render_view_with_status(request):
|
def render_view_with_status(request):
|
||||||
return render(request, 'debug/render_test.html', {
|
return render(request, 'debug/render_test.html', {
|
||||||
'foo': 'FOO',
|
'foo': 'FOO',
|
||||||
'bar': 'BAR',
|
'bar': 'BAR',
|
||||||
}, status=403)
|
}, status=403)
|
||||||
|
|
||||||
|
|
||||||
def render_view_with_current_app(request):
|
def render_view_with_current_app(request):
|
||||||
return render(request, 'debug/render_test.html', {
|
return render(request, 'debug/render_test.html', {
|
||||||
'foo': 'FOO',
|
'foo': 'FOO',
|
||||||
'bar': 'BAR',
|
'bar': 'BAR',
|
||||||
}, current_app="foobar_app")
|
}, current_app="foobar_app")
|
||||||
|
|
||||||
|
|
||||||
def render_view_with_current_app_conflict(request):
|
def render_view_with_current_app_conflict(request):
|
||||||
# This should fail because we don't passing both a current_app and
|
# This should fail because we don't passing both a current_app and
|
||||||
# context_instance:
|
# context_instance:
|
||||||
|
@ -129,9 +148,11 @@ def render_view_with_current_app_conflict(request):
|
||||||
'bar': 'BAR',
|
'bar': 'BAR',
|
||||||
}, current_app="foobar_app", context_instance=RequestContext(request))
|
}, current_app="foobar_app", context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
def render_with_dirs(request):
|
def render_with_dirs(request):
|
||||||
return render(request, 'render_dirs_test.html', dirs=dirs)
|
return render(request, 'render_dirs_test.html', dirs=dirs)
|
||||||
|
|
||||||
|
|
||||||
def raises_template_does_not_exist(request, path='i_dont_exist.html'):
|
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
|
# We need to inspect the HTML generated by the fancy 500 debug view but
|
||||||
# the test client ignores it, so we send it explicitly.
|
# 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:
|
except TemplateDoesNotExist:
|
||||||
return technical_500_response(request, *sys.exc_info())
|
return technical_500_response(request, *sys.exc_info())
|
||||||
|
|
||||||
|
|
||||||
def render_no_template(request):
|
def render_no_template(request):
|
||||||
# If we do not specify a template, we need to make sure the debug
|
# If we do not specify a template, we need to make sure the debug
|
||||||
# view doesn't blow up.
|
# view doesn't blow up.
|
||||||
return render(request, [], {})
|
return render(request, [], {})
|
||||||
|
|
||||||
|
|
||||||
def send_log(request, exc_info):
|
def send_log(request, exc_info):
|
||||||
logger = getLogger('django.request')
|
logger = getLogger('django.request')
|
||||||
# The default logging config has a logging filter to ensure admin emails are
|
# 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
|
admin_email_handler.filters = orig_filters
|
||||||
|
|
||||||
|
|
||||||
def non_sensitive_view(request):
|
def non_sensitive_view(request):
|
||||||
# Do not just use plain strings for the variables' values in the code
|
# 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
|
# 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)
|
send_log(request, exc_info)
|
||||||
return technical_500_response(request, *exc_info)
|
return technical_500_response(request, *exc_info)
|
||||||
|
|
||||||
|
|
||||||
@sensitive_variables('sauce')
|
@sensitive_variables('sauce')
|
||||||
@sensitive_post_parameters('bacon-key', 'sausage-key')
|
@sensitive_post_parameters('bacon-key', 'sausage-key')
|
||||||
def sensitive_view(request):
|
def sensitive_view(request):
|
||||||
|
@ -195,6 +220,7 @@ def sensitive_view(request):
|
||||||
send_log(request, exc_info)
|
send_log(request, exc_info)
|
||||||
return technical_500_response(request, *exc_info)
|
return technical_500_response(request, *exc_info)
|
||||||
|
|
||||||
|
|
||||||
@sensitive_variables()
|
@sensitive_variables()
|
||||||
@sensitive_post_parameters()
|
@sensitive_post_parameters()
|
||||||
def paranoid_view(request):
|
def paranoid_view(request):
|
||||||
|
@ -210,6 +236,7 @@ def paranoid_view(request):
|
||||||
send_log(request, exc_info)
|
send_log(request, exc_info)
|
||||||
return technical_500_response(request, *exc_info)
|
return technical_500_response(request, *exc_info)
|
||||||
|
|
||||||
|
|
||||||
def sensitive_args_function_caller(request):
|
def sensitive_args_function_caller(request):
|
||||||
try:
|
try:
|
||||||
sensitive_args_function(''.join(['w', 'o', 'r', 'c', 'e', 's', 't', 'e', 'r', 's', 'h', 'i', 'r', 'e']))
|
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)
|
send_log(request, exc_info)
|
||||||
return technical_500_response(request, *exc_info)
|
return technical_500_response(request, *exc_info)
|
||||||
|
|
||||||
|
|
||||||
@sensitive_variables('sauce')
|
@sensitive_variables('sauce')
|
||||||
def sensitive_args_function(sauce):
|
def sensitive_args_function(sauce):
|
||||||
# Do not just use plain strings for the variables' values in the code
|
# 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
|
cooked_eggs = ''.join(['s', 'c', 'r', 'a', 'm', 'b', 'l', 'e', 'd']) # NOQA
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
|
|
||||||
def sensitive_kwargs_function_caller(request):
|
def sensitive_kwargs_function_caller(request):
|
||||||
try:
|
try:
|
||||||
sensitive_kwargs_function(''.join(['w', 'o', 'r', 'c', 'e', 's', 't', 'e', 'r', 's', 'h', 'i', 'r', 'e']))
|
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)
|
send_log(request, exc_info)
|
||||||
return technical_500_response(request, *exc_info)
|
return technical_500_response(request, *exc_info)
|
||||||
|
|
||||||
|
|
||||||
@sensitive_variables('sauce')
|
@sensitive_variables('sauce')
|
||||||
def sensitive_kwargs_function(sauce=None):
|
def sensitive_kwargs_function(sauce=None):
|
||||||
# Do not just use plain strings for the variables' values in the code
|
# 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
|
cooked_eggs = ''.join(['s', 'c', 'r', 'a', 'm', 'b', 'l', 'e', 'd']) # NOQA
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
|
|
||||||
class UnsafeExceptionReporterFilter(SafeExceptionReporterFilter):
|
class UnsafeExceptionReporterFilter(SafeExceptionReporterFilter):
|
||||||
"""
|
"""
|
||||||
Ignores all the filtering done by its parent class.
|
Ignores all the filtering done by its parent class.
|
||||||
|
@ -287,6 +318,7 @@ class Klass(object):
|
||||||
send_log(request, exc_info)
|
send_log(request, exc_info)
|
||||||
return technical_500_response(request, *exc_info)
|
return technical_500_response(request, *exc_info)
|
||||||
|
|
||||||
|
|
||||||
def sensitive_method_view(request):
|
def sensitive_method_view(request):
|
||||||
return Klass().method(request)
|
return Klass().method(request)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.conf.urls import url, patterns
|
from django.conf.urls import url, patterns
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
|
|
||||||
def helloworld(request):
|
def helloworld(request):
|
||||||
return HttpResponse("Hello World!")
|
return HttpResponse("Hello World!")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue