Skip to content
Snippets Groups Projects
Commit 65abd4ed authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Add test for the passing of the chocies

parent 9879d7dc
No related branches found
No related tags found
No related merge requests found
import factory import factory
from ..models import Category from ..models import Category, Option
class CategoryFactory(factory.DjangoModelFactory): class CategoryFactory(factory.DjangoModelFactory):
...@@ -9,3 +9,11 @@ class CategoryFactory(factory.DjangoModelFactory): ...@@ -9,3 +9,11 @@ class CategoryFactory(factory.DjangoModelFactory):
name = factory.Faker('word') name = factory.Faker('word')
help_text = factory.Faker('sentence') help_text = factory.Faker('sentence')
class OptionFactory(factory.DjangoModelFactory):
class Meta:
model = Option
value = factory.Faker('word')
category = factory.SubFactory(CategoryFactory)
...@@ -3,7 +3,7 @@ from django.test import TestCase ...@@ -3,7 +3,7 @@ from django.test import TestCase
from opentech.apply.categories.blocks import CategoryQuestionBlock from opentech.apply.categories.blocks import CategoryQuestionBlock
from .factories import CategoryFactory from .factories import CategoryFactory, OptionFactory
class TestCategoryQuestionBlock(TestCase): class TestCategoryQuestionBlock(TestCase):
...@@ -43,3 +43,12 @@ class TestCategoryQuestionBlock(TestCase): ...@@ -43,3 +43,12 @@ class TestCategoryQuestionBlock(TestCase):
def test_multi_select_disabled(self): def test_multi_select_disabled(self):
field = self.get_field(multi=True) field = self.get_field(multi=True)
self.assertTrue(isinstance(field, forms.ChoiceField)) 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()]
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment