Ticket #31926: test-31926.diff

File test-31926.diff, 1.3 KB (added by Mariusz Felisiak, 4 years ago)

Tests.

  • tests/queryset_pickle/tests.py

    diff --git a/tests/queryset_pickle/tests.py b/tests/queryset_pickle/tests.py
    index a58e45caed..67fd8085f8 100644
    a b class PickleabilityTestCase(TestCase):  
    219219        with self.assertNumQueries(0):
    220220            self.assert_pickles(groups)
    221221
     222    def test_pickle_filteredrelation(self):
     223        group = Group.objects.create(name='group')
     224        event_1 = Event.objects.create(title='Big event', group=group)
     225        event_2 = Event.objects.create(title='Small event', group=group)
     226        Happening.objects.create(event=event_1, number1=5)
     227        Happening.objects.create(event=event_2, number1=3)
     228        groups = Group.objects.annotate(
     229            big_events=models.FilteredRelation(
     230                'event',
     231                condition=models.Q(event__title__startswith='Big'),
     232            ),
     233        ).annotate(sum_number=models.Sum('big_events__happening__number1'))
     234        groups_query = pickle.loads(pickle.dumps(groups.query))
     235        groups = Group.objects.all()
     236        groups.query = groups_query
     237        self.assertEqual(groups.get().sum_number, 5)
     238
    222239    def test_annotation_with_callable_default(self):
    223240        # Happening.when has a callable default of datetime.datetime.now.
    224241        qs = Happening.objects.annotate(latest_time=models.Max('when'))
Back to Top