Ticket #16759: 16759_test.2.diff

File 16759_test.2.diff, 2.7 KB (added by Łukasz Rekucki, 12 years ago)

Regression tests without Query internals introspection.

  • 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  
    77from django.conf import settings
    88from django.core.exceptions import FieldError
    99from django.db import DatabaseError, connection, connections, DEFAULT_DB_ALIAS
    10 from django.db.models import Count
     10from django.db.models import Count, F
    1111from django.db.models.query import Q, ITER_CHUNK_SIZE, EmptyQuerySet
    1212from django.test import TestCase, skipUnlessDBFeature
    1313from django.utils import unittest
    class SubqueryTests(TestCase):  
    15931593
    15941594
    15951595class CloneTests(TestCase):
     1596   
    15961597    def test_evaluated_queryset_as_argument(self):
    15971598        "#13227 -- If a queryset is already evaluated, it can still be used as a query arg"
    15981599        n = Note(note='Test1', misc='misc')
    class CloneTests(TestCase):  
    16101611        except:
    16111612            self.fail('Query should be clonable')
    16121613
     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
    16131647
    16141648class EmptyQuerySetTests(TestCase):
    16151649    def test_emptyqueryset_values(self):
Back to Top