diff options
| author | Dan Moore <dan@moore.cx> | 2019-10-23 10:43:47 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-10-23 10:47:17 +0200 |
| commit | f3855a8d2d9eee7f82e412a69bf42ad2df867462 (patch) | |
| tree | 33552fc0f638fc7a2551f6b0a81d973e69253dcb /tests/model_fields | |
| parent | 0315c18fe170b1b611b7d10b5dde2f196b89a7e0 (diff) | |
Added tests for Field.get_choices()'s limit_choices_to argument.
Diffstat (limited to 'tests/model_fields')
| -rw-r--r-- | tests/model_fields/tests.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index abc5273d90..206ac8c84c 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -266,3 +266,26 @@ class GetChoicesOrderingTests(TestCase): self.field.remote_field.get_choices(include_blank=False), [self.bar2, self.bar1] ) + + +class GetChoicesLimitChoicesToTests(TestCase): + @classmethod + def setUpTestData(cls): + cls.foo1 = Foo.objects.create(a='a', d='12.34') + cls.foo2 = Foo.objects.create(a='b', d='12.34') + cls.bar1 = Bar.objects.create(a=cls.foo1, b='b') + cls.bar2 = Bar.objects.create(a=cls.foo2, b='a') + cls.field = Bar._meta.get_field('a') + + def assertChoicesEqual(self, choices, objs): + self.assertEqual(choices, [(obj.pk, str(obj)) for obj in objs]) + + def test_get_choices(self): + self.assertChoicesEqual( + self.field.get_choices(include_blank=False, limit_choices_to={'a': 'a'}), + [self.foo1], + ) + self.assertChoicesEqual( + self.field.get_choices(include_blank=False, limit_choices_to={}), + [self.foo1, self.foo2], + ) |
