diff options
| author | John Parton <john.parton.iv@gmail.com> | 2024-08-18 23:12:14 -0500 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-09-25 08:51:43 -0400 |
| commit | 1820d35b17f0a95f4ce888971b9ca0c7a3697c83 (patch) | |
| tree | 7419afb8156f7869595cc06cefe872f95597f77c /tests/composite_pk | |
| parent | 68aae8878ff90dd787db55ecc44ee712525ccdc6 (diff) | |
Fixed #36605 -- Added support for QuerySet.in_bulk() after .values() or .values_list().
co-authored-by: Adam Johnson <me@adamj.eu>
co-authored-by: Simon Charette <charette.s@gmail.com>
Diffstat (limited to 'tests/composite_pk')
| -rw-r--r-- | tests/composite_pk/tests.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/composite_pk/tests.py b/tests/composite_pk/tests.py index c4a8e6ca8c..3001847455 100644 --- a/tests/composite_pk/tests.py +++ b/tests/composite_pk/tests.py @@ -167,6 +167,67 @@ class CompositePKTests(TestCase): comment_dict = Comment.objects.in_bulk(id_list=id_list) self.assertQuerySetEqual(comment_dict, id_list) + def test_in_bulk_values(self): + result = Comment.objects.values().in_bulk([self.comment.pk]) + self.assertEqual( + result, + { + self.comment.pk: { + "tenant_id": self.comment.tenant_id, + "id": self.comment.id, + "user_id": self.comment.user_id, + "text": self.comment.text, + "integer": self.comment.integer, + } + }, + ) + + def test_in_bulk_values_field(self): + result = Comment.objects.values("text").in_bulk([self.comment.pk]) + self.assertEqual( + result, + {self.comment.pk: {"text": self.comment.text}}, + ) + + def test_in_bulk_values_fields(self): + result = Comment.objects.values("pk", "text").in_bulk([self.comment.pk]) + self.assertEqual( + result, + {self.comment.pk: {"pk": self.comment.pk, "text": self.comment.text}}, + ) + + def test_in_bulk_values_list(self): + result = Comment.objects.values_list("text").in_bulk([self.comment.pk]) + self.assertEqual(result, {self.comment.pk: (self.comment.text,)}) + + def test_in_bulk_values_list_multiple_fields(self): + result = Comment.objects.values_list("pk", "text").in_bulk([self.comment.pk]) + self.assertEqual( + result, {self.comment.pk: (self.comment.pk, self.comment.text)} + ) + + def test_in_bulk_values_list_fields_are_pk(self): + result = Comment.objects.values_list("tenant", "id").in_bulk([self.comment.pk]) + self.assertEqual( + result, {self.comment.pk: (self.comment.tenant_id, self.comment.id)} + ) + + def test_in_bulk_values_list_flat(self): + result = Comment.objects.values_list("text", flat=True).in_bulk( + [self.comment.pk] + ) + self.assertEqual(result, {self.comment.pk: self.comment.text}) + + def test_in_bulk_values_list_flat_pk(self): + result = Comment.objects.values_list("pk", flat=True).in_bulk([self.comment.pk]) + self.assertEqual(result, {self.comment.pk: self.comment.pk}) + + def test_in_bulk_values_list_flat_tenant(self): + result = Comment.objects.values_list("tenant", flat=True).in_bulk( + [self.comment.pk] + ) + self.assertEqual(result, {self.comment.pk: self.tenant.id}) + def test_iterator(self): """ Test the .iterator() method of composite_pk models. |
