Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #21167 - Improved queries.tests.SubqueryTests

Improve tests to cover slicing scenarios that could be handled in unique
ways by 3rd party database backends.
  • Loading branch information...
commit b0e06c36622257fc3943f3c565bdcf04bb03c732 1 parent a834bc8
Michael Manfre authored September 25, 2013 akaariai committed September 29, 2013

Showing 1 changed file with 37 additions and 8 deletions. Show diff stats Hide diff stats

  1. 45  tests/queries/tests.py
45  tests/queries/tests.py
@@ -1889,34 +1889,63 @@ def setUp(self):
1889 1889
         DumbCategory.objects.create(id=1)
1890 1890
         DumbCategory.objects.create(id=2)
1891 1891
         DumbCategory.objects.create(id=3)
  1892
+        DumbCategory.objects.create(id=4)
1892 1893
 
1893 1894
     def test_ordered_subselect(self):
1894 1895
         "Subselects honor any manual ordering"
1895 1896
         try:
1896 1897
             query = DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[0:2])
1897  
-            self.assertEqual(set(query.values_list('id', flat=True)), set([2,3]))
  1898
+            self.assertEqual(set(query.values_list('id', flat=True)), set([3,4]))
1898 1899
 
1899 1900
             query = DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[:2])
1900  
-            self.assertEqual(set(query.values_list('id', flat=True)), set([2,3]))
  1901
+            self.assertEqual(set(query.values_list('id', flat=True)), set([3,4]))
  1902
+
  1903
+            query = DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[1:2])
  1904
+            self.assertEqual(set(query.values_list('id', flat=True)), set([3]))
1901 1905
 
1902 1906
             query = DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[2:])
1903  
-            self.assertEqual(set(query.values_list('id', flat=True)), set([1]))
1904  
-        except DatabaseError:
  1907
+            self.assertEqual(set(query.values_list('id', flat=True)), set([1,2]))
  1908
+        except DatabaseError as e:
  1909
+            # Oracle and MySQL both have problems with sliced subselects.
  1910
+            # This prevents us from even evaluating this test case at all.
  1911
+            # Refs #10099
  1912
+            self.assertFalse(connections[DEFAULT_DB_ALIAS].features.allow_sliced_subqueries, str(e))
  1913
+
  1914
+    def test_slice_subquery_and_query(self):
  1915
+        """
  1916
+        Slice a query that has a sliced subquery
  1917
+        """
  1918
+        try:
  1919
+            query = DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[0:2])[0:2]
  1920
+            self.assertEqual(set([x.id for x in query]), set([3,4]))
  1921
+
  1922
+            query = DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[1:3])[1:3]
  1923
+            self.assertEqual(set([x.id for x in query]), set([3]))
  1924
+
  1925
+            query = DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[2:])[1:]
  1926
+            self.assertEqual(set([x.id for x in query]), set([2]))
  1927
+        except DatabaseError as e:
1905 1928
             # Oracle and MySQL both have problems with sliced subselects.
1906 1929
             # This prevents us from even evaluating this test case at all.
1907 1930
             # Refs #10099
1908  
-            self.assertFalse(connections[DEFAULT_DB_ALIAS].features.allow_sliced_subqueries)
  1931
+            self.assertFalse(connections[DEFAULT_DB_ALIAS].features.allow_sliced_subqueries, str(e))
1909 1932
 
1910 1933
     def test_sliced_delete(self):
1911 1934
         "Delete queries can safely contain sliced subqueries"
1912 1935
         try:
1913 1936
             DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[0:1]).delete()
1914  
-            self.assertEqual(set(DumbCategory.objects.values_list('id', flat=True)), set([1,2]))
1915  
-        except DatabaseError:
  1937
+            self.assertEqual(set(DumbCategory.objects.values_list('id', flat=True)), set([1,2,3]))
  1938
+
  1939
+            DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[1:2]).delete()
  1940
+            self.assertEqual(set(DumbCategory.objects.values_list('id', flat=True)), set([1,3]))
  1941
+
  1942
+            DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[1:]).delete()
  1943
+            self.assertEqual(set(DumbCategory.objects.values_list('id', flat=True)), set([3]))
  1944
+        except DatabaseError as e:
1916 1945
             # Oracle and MySQL both have problems with sliced subselects.
1917 1946
             # This prevents us from even evaluating this test case at all.
1918 1947
             # Refs #10099
1919  
-            self.assertFalse(connections[DEFAULT_DB_ALIAS].features.allow_sliced_subqueries)
  1948
+            self.assertFalse(connections[DEFAULT_DB_ALIAS].features.allow_sliced_subqueries, str(e))
1920 1949
 
1921 1950
 
1922 1951
 class CloneTests(TestCase):

0 notes on commit b0e06c3

Please sign in to comment.
Something went wrong with that request. Please try again.