From 65abd4ed3a4c0cf950ca722f7e2ff556b5027e6e Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Thu, 11 Jan 2018 09:31:00 +0000
Subject: [PATCH] Add test for the passing of the chocies

---
 opentech/apply/categories/tests/factories.py   | 10 +++++++++-
 opentech/apply/categories/tests/test_blocks.py | 11 ++++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/opentech/apply/categories/tests/factories.py b/opentech/apply/categories/tests/factories.py
index f1bba28f7..b311c2c6d 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 17ab027e7..fa8bee4ea 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()]
+        )
-- 
GitLab