mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Refs #24385 -- Added tests for distinct sum issue fixed in c7fd9b242d
				
					
				
			This commit is contained in:
		
				
					committed by
					
						 Tim Graham
						Tim Graham
					
				
			
			
				
	
			
			
			
						parent
						
							d72e0178e9
						
					
				
				
					commit
					910638fc4e
				
			| @@ -441,6 +441,20 @@ class AggregateTestCase(TestCase): | ||||
|         vals = Book.objects.annotate(num_authors=Count("authors__id")).aggregate(Avg("num_authors")) | ||||
|         self.assertEqual(vals, {"num_authors__avg": Approximate(1.66, places=1)}) | ||||
|  | ||||
|     def test_sum_distinct_aggregate(self): | ||||
|         """ | ||||
|         Sum on a distict() QuerySet should aggregate only the distinct items. | ||||
|         """ | ||||
|         authors = Author.objects.filter(book__in=[5, 6]) | ||||
|         self.assertEqual(authors.count(), 3) | ||||
|  | ||||
|         distinct_authors = authors.distinct() | ||||
|         self.assertEqual(distinct_authors.count(), 2) | ||||
|  | ||||
|         # Selected author ages are 57 and 46 | ||||
|         age_sum = distinct_authors.aggregate(Sum('age')) | ||||
|         self.assertEqual(age_sum['age__sum'], 103) | ||||
|  | ||||
|     def test_filtering(self): | ||||
|         p = Publisher.objects.create(name='Expensive Publisher', num_awards=0) | ||||
|         Book.objects.create( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user