Ticket #16759: 16759_test.2.diff
File 16759_test.2.diff, 2.7 KB (added by , 13 years ago) |
---|
-
tests/regressiontests/queries/tests.py
commit 97f7c76de682a4062032195f9bfeb3b8e5e67883 Author: Łukasz Rekucki <lrekucki@gmail.com> Date: Mon Feb 6 22:44:37 2012 +0100 TESTS diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py index ded3e8f..620bb91 100644
a b import sys 7 7 from django.conf import settings 8 8 from django.core.exceptions import FieldError 9 9 from django.db import DatabaseError, connection, connections, DEFAULT_DB_ALIAS 10 from django.db.models import Count 10 from django.db.models import Count, F 11 11 from django.db.models.query import Q, ITER_CHUNK_SIZE, EmptyQuerySet 12 12 from django.test import TestCase, skipUnlessDBFeature 13 13 from django.utils import unittest … … class SubqueryTests(TestCase): 1593 1593 1594 1594 1595 1595 class CloneTests(TestCase): 1596 1596 1597 def test_evaluated_queryset_as_argument(self): 1597 1598 "#13227 -- If a queryset is already evaluated, it can still be used as a query arg" 1598 1599 n = Note(note='Test1', misc='misc') … … class CloneTests(TestCase): 1610 1611 except: 1611 1612 self.fail('Query should be clonable') 1612 1613 1614 def test_no_model_options_cloning(self): 1615 """ 1616 Test that cloning a queryset does not get out of hand. While complete 1617 testing is impossible, this is a sanity check against invalid use of 1618 deepcopy. refs #16759. 1619 """ 1620 opts_class = type(Note._meta) 1621 note_deepcopy = getattr(opts_class, "__deepcopy__", None) 1622 opts_class.__deepcopy__ = lambda obj, memo: self.fail("Model options shouldn't be cloned.") 1623 try: 1624 Note.objects.filter(pk__lte=F('pk') + 1).all() 1625 finally: 1626 if note_deepcopy is None: 1627 delattr(opts_class, "__deepcopy__") 1628 else: 1629 opts_class.__deepcopy__ = note_deepcopy 1630 1631 def test_no_fields_cloning(self): 1632 """ 1633 Test that cloning a queryset does not get out of hand. While complete 1634 testing is impossible, this is a sanity check against invalid use of 1635 deepcopy. refs #16759. 1636 """ 1637 opts_class = type(Note._meta.get_field_by_name("misc")[0]) 1638 note_deepcopy = getattr(opts_class, "__deepcopy__", None) 1639 opts_class.__deepcopy__ = lambda obj, memo: self.fail("Model fields shouldn't be cloned") 1640 try: 1641 Note.objects.filter(note=F('misc')).all() 1642 finally: 1643 if note_deepcopy is None: 1644 delattr(opts_class, "__deepcopy__") 1645 else: 1646 opts_class.__deepcopy__ = note_deepcopy 1613 1647 1614 1648 class EmptyQuerySetTests(TestCase): 1615 1649 def test_emptyqueryset_values(self):