Ticket #10977: 10977_testcase.diff
File 10977_testcase.diff, 3.5 KB (added by , 16 years ago) |
---|
-
tests/regressiontests/queries/tests.py
1 1 import unittest 2 from models import Tag, Annotation 2 from models import Tag, Annotation, Recommendation, Recommender 3 from django.db.models.query import QuerySet, Q 3 4 from django.db.models import Count 5 import operator 6 from django import test 4 7 5 8 class QuerysetOrderedTests(unittest.TestCase): 6 9 """ … … 24 27 qs = Annotation.objects.annotate(num_notes=Count('notes')) 25 28 self.assertEqual(qs.ordered, False) 26 29 self.assertEqual(qs.order_by('num_notes').ordered, True) 27 28 No newline at end of file 30 31 class QuerysetMergingTests(test.TestCase): 32 """ 33 Tests for merging Querysets that have been filtered on multiple elements from the same 34 base class 35 """ 36 37 fixtures = ['multiple_child_classes'] 38 39 def test_merging_models_with_same_parent(self): 40 match = Recommendation.objects.get(recommender__titletranslation__text__icontains='ar') 41 42 qs = Recommendation._default_manager.get_query_set() 43 44 search_fields = [ 45 'titletranslation__text__icontains', 46 'recommender__titletranslation__text__icontains' 47 ] 48 49 or_queries = [Q(**{field: u'ar'}) for field in search_fields] 50 51 other_qs = QuerySet(Recommendation) 52 other_qs = other_qs.filter(reduce(operator.or_, or_queries)) 53 self.assert_(match in qs & other_qs) 54 No newline at end of file -
tests/regressiontests/queries/fixtures/multiple_child_classes.json
1 [{"pk": 1, "model": "queries.title", "fields": {}}, {"pk": 2, "model": "queries.title", "fields": {}}, {"pk": 3, "model": "queries.title", "fields": {}}, {"pk": 4, "model": "queries.title", "fields": {}}, {"pk": 1, "model": "queries.titletranslation", "fields": {"text": "Bar", "title": 1}}, {"pk": 2, "model": "queries.titletranslation", "fields": {"text": "Foo", "title": 2}}, {"pk": 3, "model": "queries.titletranslation", "fields": {"text": "Few", "title": 3}}, {"pk": 4, "model": "queries.titletranslation", "fields": {"text": "Bas", "title": 4}}, {"pk": 1, "model": "queries.recommender", "fields": {}}, {"pk": 4, "model": "queries.recommender", "fields": {}}, {"pk": 2, "model": "queries.recommendation", "fields": {"recommender": 1}}, {"pk": 3, "model": "queries.recommendation", "fields": {"recommender": 4}}] -
tests/regressiontests/queries/models.py
271 271 def __unicode__(self): 272 272 return self.name 273 273 274 # a base class for Recommender and Recommendation 275 class Title(models.Model): 276 pass 274 277 278 class TitleTranslation(models.Model): 279 title = models.ForeignKey(Title) 280 text = models.CharField(max_length=100) 281 282 class Recommender(Title): 283 pass 284 285 class Recommendation(Title): 286 recommender = models.ForeignKey(Recommender) 287 288 275 289 __test__ = {'API_TESTS':""" 276 290 >>> generic = NamedCategory.objects.create(name="Generic") 277 291 >>> t1 = Tag.objects.create(name='t1', category=generic)