Ticket #10516: testcase.diff
File testcase.diff, 3.8 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 4 6 5 7 class QuerysetOrderedTests(unittest.TestCase): 6 8 """ … … 24 26 qs = Annotation.objects.annotate(num_notes=Count('notes')) 25 27 self.assertEqual(qs.ordered, False) 26 28 self.assertEqual(qs.order_by('num_notes').ordered, True) 27 28 No newline at end of file 29 30 class QuerysetMergingTests(unittest.TestCase): 31 """ 32 Tests for merging Querysets that have been filtered on multiple elements from the same 33 base class 34 """ 35 36 def runTest(self): 37 match = Recommendation.objects.get(recommender__titletranslation__text__icontains='ar') 38 39 qs = Recommendation._default_manager.get_query_set() 40 41 search_fields = [ 42 'titletranslation__text__icontains', 43 'recommender__titletranslation__text__icontains' 44 ] 45 46 or_queries = [Q(**{field: u'ar'}) for field in search_fields] 47 48 other_qs = QuerySet(Recommendation) 49 other_qs.dup_select_related(qs) 50 other_qs = other_qs.filter(reduce(operator.or_, or_queries)) 51 52 self.assert_(match in qs & other_qs) 53 No newline at end of file -
tests/regressiontests/queries/fixtures/initial_data.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": {"lang": "FI", "text": "Bar", "title": 1}}, {"pk": 2, "model": "queries.titletranslation", "fields": {"lang": "FI", "text": "Foo", "title": 2}}, {"pk": 3, "model": "queries.titletranslation", "fields": {"lang": "FI", "text": "Few", "title": 3}}, {"pk": 4, "model": "queries.titletranslation", "fields": {"lang": "FI", "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 def __unicode__(self): 277 try: 278 return self.titletranslation_set.filter(lang="FI")[0].text 279 except: 280 return "No finnish name defined!" 274 281 282 LANG_CHOICES = (('FI', 'Finnish'), ('EN', 'English'),) 283 284 class TitleTranslation(models.Model): 285 title = models.ForeignKey(Title) 286 text = models.CharField(max_length = 100) 287 lang = models.CharField(max_length = 2, choices = LANG_CHOICES) 288 289 class Recommender(Title): 290 pass 291 292 class Recommendation(Title): 293 recommender = models.ForeignKey(Recommender) 294 295 275 296 __test__ = {'API_TESTS':""" 276 297 >>> generic = NamedCategory.objects.create(name="Generic") 277 298 >>> t1 = Tag.objects.create(name='t1', category=generic)