summaryrefslogtreecommitdiff
path: root/parts/django/tests/regressiontests/extra_regress/tests.py
diff options
context:
space:
mode:
authorNishanth Amuluru2011-01-08 11:20:57 +0530
committerNishanth Amuluru2011-01-08 11:20:57 +0530
commit65411d01d448ff0cd4abd14eee14cf60b5f8fc20 (patch)
treeb4c404363c4c63a61d6e2f8bd26c5b057c1fb09d /parts/django/tests/regressiontests/extra_regress/tests.py
parent2e35094d43b4cc6974172e1febf76abb50f086ec (diff)
downloadpytask-65411d01d448ff0cd4abd14eee14cf60b5f8fc20.tar.gz
pytask-65411d01d448ff0cd4abd14eee14cf60b5f8fc20.tar.bz2
pytask-65411d01d448ff0cd4abd14eee14cf60b5f8fc20.zip
Added buildout stuff and made changes accordingly
--HG-- rename : profile/management/__init__.py => eggs/djangorecipe-0.20-py2.6.egg/EGG-INFO/dependency_links.txt rename : profile/management/__init__.py => eggs/djangorecipe-0.20-py2.6.egg/EGG-INFO/not-zip-safe rename : profile/management/__init__.py => eggs/infrae.subversion-1.4.5-py2.6.egg/EGG-INFO/dependency_links.txt rename : profile/management/__init__.py => eggs/infrae.subversion-1.4.5-py2.6.egg/EGG-INFO/not-zip-safe rename : profile/management/__init__.py => eggs/mercurial-1.7.3-py2.6-linux-x86_64.egg/EGG-INFO/dependency_links.txt rename : profile/management/__init__.py => eggs/mercurial-1.7.3-py2.6-linux-x86_64.egg/EGG-INFO/not-zip-safe rename : profile/management/__init__.py => eggs/py-1.4.0-py2.6.egg/EGG-INFO/dependency_links.txt rename : profile/management/__init__.py => eggs/py-1.4.0-py2.6.egg/EGG-INFO/not-zip-safe rename : profile/management/__init__.py => eggs/zc.buildout-1.5.2-py2.6.egg/EGG-INFO/dependency_links.txt rename : profile/management/__init__.py => eggs/zc.buildout-1.5.2-py2.6.egg/EGG-INFO/not-zip-safe rename : profile/management/__init__.py => eggs/zc.recipe.egg-1.3.2-py2.6.egg/EGG-INFO/dependency_links.txt rename : profile/management/__init__.py => eggs/zc.recipe.egg-1.3.2-py2.6.egg/EGG-INFO/not-zip-safe rename : profile/management/__init__.py => parts/django/Django.egg-info/dependency_links.txt rename : taskapp/models.py => parts/django/django/conf/app_template/models.py rename : taskapp/tests.py => parts/django/django/conf/app_template/tests.py rename : taskapp/views.py => parts/django/django/conf/app_template/views.py rename : taskapp/views.py => parts/django/django/contrib/gis/tests/geo3d/views.py rename : profile/management/__init__.py => parts/django/tests/modeltests/delete/__init__.py rename : profile/management/__init__.py => parts/django/tests/modeltests/files/__init__.py rename : profile/management/__init__.py => parts/django/tests/modeltests/invalid_models/__init__.py rename : profile/management/__init__.py => parts/django/tests/modeltests/m2m_signals/__init__.py rename : profile/management/__init__.py => parts/django/tests/modeltests/model_package/__init__.py rename : profile/management/__init__.py => parts/django/tests/regressiontests/bash_completion/__init__.py rename : profile/management/__init__.py => parts/django/tests/regressiontests/bash_completion/management/__init__.py rename : profile/management/__init__.py => parts/django/tests/regressiontests/bash_completion/management/commands/__init__.py rename : profile/management/__init__.py => parts/django/tests/regressiontests/bash_completion/models.py rename : profile/management/__init__.py => parts/django/tests/regressiontests/delete_regress/__init__.py rename : profile/management/__init__.py => parts/django/tests/regressiontests/file_storage/__init__.py rename : profile/management/__init__.py => parts/django/tests/regressiontests/max_lengths/__init__.py rename : profile/forms.py => pytask/profile/forms.py rename : profile/management/__init__.py => pytask/profile/management/__init__.py rename : profile/management/commands/seed_db.py => pytask/profile/management/commands/seed_db.py rename : profile/models.py => pytask/profile/models.py rename : profile/templatetags/user_tags.py => pytask/profile/templatetags/user_tags.py rename : taskapp/tests.py => pytask/profile/tests.py rename : profile/urls.py => pytask/profile/urls.py rename : profile/utils.py => pytask/profile/utils.py rename : profile/views.py => pytask/profile/views.py rename : static/css/base.css => pytask/static/css/base.css rename : taskapp/tests.py => pytask/taskapp/tests.py rename : taskapp/views.py => pytask/taskapp/views.py rename : templates/base.html => pytask/templates/base.html rename : templates/profile/browse_notifications.html => pytask/templates/profile/browse_notifications.html rename : templates/profile/edit.html => pytask/templates/profile/edit.html rename : templates/profile/view.html => pytask/templates/profile/view.html rename : templates/profile/view_notification.html => pytask/templates/profile/view_notification.html rename : templates/registration/activate.html => pytask/templates/registration/activate.html rename : templates/registration/activation_email.txt => pytask/templates/registration/activation_email.txt rename : templates/registration/activation_email_subject.txt => pytask/templates/registration/activation_email_subject.txt rename : templates/registration/logged_out.html => pytask/templates/registration/logged_out.html rename : templates/registration/login.html => pytask/templates/registration/login.html rename : templates/registration/logout.html => pytask/templates/registration/logout.html rename : templates/registration/password_change_done.html => pytask/templates/registration/password_change_done.html rename : templates/registration/password_change_form.html => pytask/templates/registration/password_change_form.html rename : templates/registration/password_reset_complete.html => pytask/templates/registration/password_reset_complete.html rename : templates/registration/password_reset_confirm.html => pytask/templates/registration/password_reset_confirm.html rename : templates/registration/password_reset_done.html => pytask/templates/registration/password_reset_done.html rename : templates/registration/password_reset_email.html => pytask/templates/registration/password_reset_email.html rename : templates/registration/password_reset_form.html => pytask/templates/registration/password_reset_form.html rename : templates/registration/registration_complete.html => pytask/templates/registration/registration_complete.html rename : templates/registration/registration_form.html => pytask/templates/registration/registration_form.html rename : utils.py => pytask/utils.py
Diffstat (limited to 'parts/django/tests/regressiontests/extra_regress/tests.py')
-rw-r--r--parts/django/tests/regressiontests/extra_regress/tests.py314
1 files changed, 314 insertions, 0 deletions
diff --git a/parts/django/tests/regressiontests/extra_regress/tests.py b/parts/django/tests/regressiontests/extra_regress/tests.py
new file mode 100644
index 0000000..ef7cbb8
--- /dev/null
+++ b/parts/django/tests/regressiontests/extra_regress/tests.py
@@ -0,0 +1,314 @@
+from django.test import TestCase
+
+from django.utils.datastructures import SortedDict
+
+from django.contrib.auth.models import User
+from regressiontests.extra_regress.models import TestObject, Order, \
+ RevisionableModel
+
+import datetime
+
+class ExtraRegressTests(TestCase):
+
+ def setUp(self):
+ self.u = User.objects.create_user(
+ username="fred",
+ password="secret",
+ email="fred@example.com"
+ )
+
+ def test_regression_7314_7372(self):
+ """
+ Regression tests for #7314 and #7372
+ """
+ rm = RevisionableModel.objects.create(
+ title='First Revision',
+ when=datetime.datetime(2008, 9, 28, 10, 30, 0)
+ )
+ self.assertEqual(rm.pk, rm.base.pk)
+
+ rm2 = rm.new_revision()
+ rm2.title = "Second Revision"
+ rm.when = datetime.datetime(2008, 9, 28, 14, 25, 0)
+ rm2.save()
+
+ self.assertEqual(rm2.title, 'Second Revision')
+ self.assertEqual(rm2.base.title, 'First Revision')
+
+ self.assertNotEqual(rm2.pk, rm.pk)
+ self.assertEqual(rm2.base.pk, rm.pk)
+
+ # Queryset to match most recent revision:
+ qs = RevisionableModel.objects.extra(
+ where=["%(table)s.id IN (SELECT MAX(rev.id) FROM %(table)s rev GROUP BY rev.base_id)" % {
+ 'table': RevisionableModel._meta.db_table,
+ }]
+ )
+
+ self.assertQuerysetEqual(qs,
+ [('Second Revision', 'First Revision')],
+ transform=lambda r: (r.title, r.base.title)
+ )
+
+ # Queryset to search for string in title:
+ qs2 = RevisionableModel.objects.filter(title__contains="Revision")
+ self.assertQuerysetEqual(qs2,
+ [
+ ('First Revision', 'First Revision'),
+ ('Second Revision', 'First Revision'),
+ ],
+ transform=lambda r: (r.title, r.base.title)
+ )
+
+ # Following queryset should return the most recent revision:
+ self.assertQuerysetEqual(qs & qs2,
+ [('Second Revision', 'First Revision')],
+ transform=lambda r: (r.title, r.base.title)
+ )
+
+ def test_extra_stay_tied(self):
+ # Extra select parameters should stay tied to their corresponding
+ # select portions. Applies when portions are updated or otherwise
+ # moved around.
+ qs = User.objects.extra(
+ select=SortedDict((("alpha", "%s"), ("beta", "2"), ("gamma", "%s"))),
+ select_params=(1, 3)
+ )
+ qs = qs.extra(select={"beta": 4})
+ qs = qs.extra(select={"alpha": "%s"}, select_params=[5])
+ self.assertEqual(
+ list(qs.filter(id=self.u.id).values('alpha', 'beta', 'gamma')),
+ [{'alpha': 5, 'beta': 4, 'gamma': 3}]
+ )
+
+ def test_regression_7957(self):
+ """
+ Regression test for #7957: Combining extra() calls should leave the
+ corresponding parameters associated with the right extra() bit. I.e.
+ internal dictionary must remain sorted.
+ """
+ self.assertEqual(
+ User.objects.extra(select={"alpha": "%s"}, select_params=(1,)
+ ).extra(select={"beta": "%s"}, select_params=(2,))[0].alpha,
+ 1)
+
+ self.assertEqual(
+ User.objects.extra(select={"beta": "%s"}, select_params=(1,)
+ ).extra(select={"alpha": "%s"}, select_params=(2,))[0].alpha,
+ 2)
+
+ def test_regression_7961(self):
+ """
+ Regression test for #7961: When not using a portion of an
+ extra(...) in a query, remove any corresponding parameters from the
+ query as well.
+ """
+ self.assertEqual(
+ list(User.objects.extra(select={"alpha": "%s"}, select_params=(-6,)
+ ).filter(id=self.u.id).values_list('id', flat=True)),
+ [self.u.id]
+ )
+
+ def test_regression_8063(self):
+ """
+ Regression test for #8063: limiting a query shouldn't discard any
+ extra() bits.
+ """
+ qs = User.objects.all().extra(where=['id=%s'], params=[self.u.id])
+ self.assertQuerysetEqual(qs, ['<User: fred>'])
+ self.assertQuerysetEqual(qs[:1], ['<User: fred>'])
+
+ def test_regression_8039(self):
+ """
+ Regression test for #8039: Ordering sometimes removed relevant tables
+ from extra(). This test is the critical case: ordering uses a table,
+ but then removes the reference because of an optimisation. The table
+ should still be present because of the extra() call.
+ """
+ self.assertQuerysetEqual(
+ Order.objects.extra(where=["username=%s"],
+ params=["fred"],
+ tables=["auth_user"]
+ ).order_by('created_by'),
+ []
+ )
+
+ def test_regression_8819(self):
+ """
+ Regression test for #8819: Fields in the extra(select=...) list
+ should be available to extra(order_by=...).
+ """
+ self.assertQuerysetEqual(
+ User.objects.filter(pk=self.u.id).extra(select={'extra_field': 1}).distinct(),
+ ['<User: fred>']
+ )
+ self.assertQuerysetEqual(
+ User.objects.filter(pk=self.u.id).extra(select={'extra_field': 1}, order_by=['extra_field']),
+ ['<User: fred>']
+ )
+ self.assertQuerysetEqual(
+ User.objects.filter(pk=self.u.id).extra(select={'extra_field': 1}, order_by=['extra_field']).distinct(),
+ ['<User: fred>']
+ )
+
+ def test_dates_query(self):
+ """
+ When calling the dates() method on a queryset with extra selection
+ columns, we can (and should) ignore those columns. They don't change
+ the result and cause incorrect SQL to be produced otherwise.
+ """
+ rm = RevisionableModel.objects.create(
+ title='First Revision',
+ when=datetime.datetime(2008, 9, 28, 10, 30, 0)
+ )
+
+ self.assertQuerysetEqual(
+ RevisionableModel.objects.extra(select={"the_answer": 'id'}).dates('when', 'month'),
+ ['datetime.datetime(2008, 9, 1, 0, 0)']
+ )
+
+ def test_values_with_extra(self):
+ """
+ Regression test for #10256... If there is a values() clause, Extra
+ columns are only returned if they are explicitly mentioned.
+ """
+ obj = TestObject(first='first', second='second', third='third')
+ obj.save()
+
+ self.assertEqual(
+ list(TestObject.objects.extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third')))).values()),
+ [{'bar': u'second', 'third': u'third', 'second': u'second', 'whiz': u'third', 'foo': u'first', 'id': obj.pk, 'first': u'first'}]
+ )
+
+ # Extra clauses after an empty values clause are still included
+ self.assertEqual(
+ list(TestObject.objects.values().extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third'))))),
+ [{'bar': u'second', 'third': u'third', 'second': u'second', 'whiz': u'third', 'foo': u'first', 'id': obj.pk, 'first': u'first'}]
+ )
+
+ # Extra columns are ignored if not mentioned in the values() clause
+ self.assertEqual(
+ list(TestObject.objects.extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third')))).values('first', 'second')),
+ [{'second': u'second', 'first': u'first'}]
+ )
+
+ # Extra columns after a non-empty values() clause are ignored
+ self.assertEqual(
+ list(TestObject.objects.values('first', 'second').extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third'))))),
+ [{'second': u'second', 'first': u'first'}]
+ )
+
+ # Extra columns can be partially returned
+ self.assertEqual(
+ list(TestObject.objects.extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third')))).values('first', 'second', 'foo')),
+ [{'second': u'second', 'foo': u'first', 'first': u'first'}]
+ )
+
+ # Also works if only extra columns are included
+ self.assertEqual(
+ list(TestObject.objects.extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third')))).values('foo', 'whiz')),
+ [{'foo': u'first', 'whiz': u'third'}]
+ )
+
+ # Values list works the same way
+ # All columns are returned for an empty values_list()
+ self.assertEqual(
+ list(TestObject.objects.extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third')))).values_list()),
+ [(u'first', u'second', u'third', obj.pk, u'first', u'second', u'third')]
+ )
+
+ # Extra columns after an empty values_list() are still included
+ self.assertEqual(
+ list(TestObject.objects.values_list().extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third'))))),
+ [(u'first', u'second', u'third', obj.pk, u'first', u'second', u'third')]
+ )
+
+ # Extra columns ignored completely if not mentioned in values_list()
+ self.assertEqual(
+ list(TestObject.objects.extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third')))).values_list('first', 'second')),
+ [(u'first', u'second')]
+ )
+
+ # Extra columns after a non-empty values_list() clause are ignored completely
+ self.assertEqual(
+ list(TestObject.objects.values_list('first', 'second').extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third'))))),
+ [(u'first', u'second')]
+ )
+
+ self.assertEqual(
+ list(TestObject.objects.extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third')))).values_list('second', flat=True)),
+ [u'second']
+ )
+
+ # Only the extra columns specified in the values_list() are returned
+ self.assertEqual(
+ list(TestObject.objects.extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third')))).values_list('first', 'second', 'whiz')),
+ [(u'first', u'second', u'third')]
+ )
+
+ # ...also works if only extra columns are included
+ self.assertEqual(
+ list(TestObject.objects.extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third')))).values_list('foo','whiz')),
+ [(u'first', u'third')]
+ )
+
+ self.assertEqual(
+ list(TestObject.objects.extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third')))).values_list('whiz', flat=True)),
+ [u'third']
+ )
+
+ # ... and values are returned in the order they are specified
+ self.assertEqual(
+ list(TestObject.objects.extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third')))).values_list('whiz','foo')),
+ [(u'third', u'first')]
+ )
+
+ self.assertEqual(
+ list(TestObject.objects.extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third')))).values_list('first','id')),
+ [(u'first', obj.pk)]
+ )
+
+ self.assertEqual(
+ list(TestObject.objects.extra(select=SortedDict((('foo','first'), ('bar','second'), ('whiz','third')))).values_list('whiz', 'first', 'bar', 'id')),
+ [(u'third', u'first', u'second', obj.pk)]
+ )
+
+ def test_regression_10847(self):
+ """
+ Regression for #10847: the list of extra columns can always be
+ accurately evaluated. Using an inner query ensures that as_sql() is
+ producing correct output without requiring full evaluation and
+ execution of the inner query.
+ """
+ obj = TestObject(first='first', second='second', third='third')
+ obj.save()
+
+ self.assertEqual(
+ list(TestObject.objects.extra(select={'extra': 1}).values('pk')),
+ [{'pk': obj.pk}]
+ )
+
+ self.assertQuerysetEqual(
+ TestObject.objects.filter(
+ pk__in=TestObject.objects.extra(select={'extra': 1}).values('pk')
+ ),
+ ['<TestObject: TestObject: first,second,third>']
+ )
+
+ self.assertEqual(
+ list(TestObject.objects.values('pk').extra(select={'extra': 1})),
+ [{'pk': obj.pk}]
+ )
+
+ self.assertQuerysetEqual(
+ TestObject.objects.filter(
+ pk__in=TestObject.objects.values('pk').extra(select={'extra': 1})
+ ),
+ ['<TestObject: TestObject: first,second,third>']
+ )
+
+ self.assertQuerysetEqual(
+ TestObject.objects.filter(pk=obj.pk) |
+ TestObject.objects.extra(where=["id > %s"], params=[obj.pk]),
+ ['<TestObject: TestObject: first,second,third>']
+ )