From 67988f47d3be8b854fb56409b7d85498f63d30a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Fantone?= Date: Wed, 4 Sep 2024 16:01:40 +0100 Subject: [PATCH] Add unit test for checking annotate returned instance --- tests/test_query.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_query.py b/tests/test_query.py index a5bfc71..2b37d42 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -1090,6 +1090,13 @@ def test_annotate(self): self.assertEqual(qs[2].color_or_car, 'kia') + def test_annotate_returns_current_class_instance(self): + class CustomMockSet(MockSet): + pass + + qs = CustomMockSet(Car(model='golf', id=1)) + self.assertIsInstance(qs.annotate(model=models.F('model')), CustomMockSet) + def test_query_values_raises_attribute_error_when_field_is_not_in_meta_concrete_fields(self): qs = MockSet(MockModel(foo=1), MockModel(foo=2)) self.assertRaises(FieldError, qs.values, 'bar')