diff --git a/opentech/apply/categories/tests/factories.py b/opentech/apply/categories/tests/factories.py index f1bba28f7c152d4b20a1b8c5d3d743e6934054f0..b311c2c6daef14a82a394a77088e75982d092004 100644 --- a/opentech/apply/categories/tests/factories.py +++ b/opentech/apply/categories/tests/factories.py @@ -1,6 +1,6 @@ import factory -from ..models import Category +from ..models import Category, Option class CategoryFactory(factory.DjangoModelFactory): @@ -9,3 +9,11 @@ class CategoryFactory(factory.DjangoModelFactory): name = factory.Faker('word') help_text = factory.Faker('sentence') + + +class OptionFactory(factory.DjangoModelFactory): + class Meta: + model = Option + + value = factory.Faker('word') + category = factory.SubFactory(CategoryFactory) diff --git a/opentech/apply/categories/tests/test_blocks.py b/opentech/apply/categories/tests/test_blocks.py index 17ab027e7b470ad02c8df342cf5a061db0d26e9a..fa8bee4ea1240337661588cc3ccbc5215c840076 100644 --- a/opentech/apply/categories/tests/test_blocks.py +++ b/opentech/apply/categories/tests/test_blocks.py @@ -3,7 +3,7 @@ from django.test import TestCase from opentech.apply.categories.blocks import CategoryQuestionBlock -from .factories import CategoryFactory +from .factories import CategoryFactory, OptionFactory class TestCategoryQuestionBlock(TestCase): @@ -43,3 +43,12 @@ class TestCategoryQuestionBlock(TestCase): def test_multi_select_disabled(self): field = self.get_field(multi=True) self.assertTrue(isinstance(field, forms.ChoiceField)) + + def test_options_included_in_choices(self): + # Don't assign to variable as the ordering wont match choices + OptionFactory.create_batch(3, category=self.category) + field = self.get_field() + self.assertEqual( + field.choices, + [(option.id, option.value) for option in self.category.options.all()] + )