From f84b8f370f77d2168b9a18321c7540fc9e2bb6f9 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Thu, 11 Jan 2018 08:16:05 +0000 Subject: [PATCH] Add basic test that defaults are carried through --- opentech/apply/categories/tests.py | 3 --- opentech/apply/categories/tests/__init__.py | 0 opentech/apply/categories/tests/factories.py | 11 ++++++++ .../apply/categories/tests/test_blocks.py | 25 +++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) delete mode 100644 opentech/apply/categories/tests.py create mode 100644 opentech/apply/categories/tests/__init__.py create mode 100644 opentech/apply/categories/tests/factories.py create mode 100644 opentech/apply/categories/tests/test_blocks.py diff --git a/opentech/apply/categories/tests.py b/opentech/apply/categories/tests.py deleted file mode 100644 index a79ca8be5..000000000 --- a/opentech/apply/categories/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.test import TestCase - -# Create your tests here. diff --git a/opentech/apply/categories/tests/__init__.py b/opentech/apply/categories/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/opentech/apply/categories/tests/factories.py b/opentech/apply/categories/tests/factories.py new file mode 100644 index 000000000..f1bba28f7 --- /dev/null +++ b/opentech/apply/categories/tests/factories.py @@ -0,0 +1,11 @@ +import factory + +from ..models import Category + + +class CategoryFactory(factory.DjangoModelFactory): + class Meta: + model = Category + + name = factory.Faker('word') + help_text = factory.Faker('sentence') diff --git a/opentech/apply/categories/tests/test_blocks.py b/opentech/apply/categories/tests/test_blocks.py new file mode 100644 index 000000000..19c3aff8d --- /dev/null +++ b/opentech/apply/categories/tests/test_blocks.py @@ -0,0 +1,25 @@ +from django.test import TestCase + +from opentech.apply.categories.blocks import CategoryQuestionBlock + +from .factories import CategoryFactory + + +class TestCategoryQuestionBlock(TestCase): + @classmethod + def setUp(self): + self.category = CategoryFactory() + self.block = CategoryQuestionBlock() + + def test_field_and_help_default(self): + block = self.block.to_python({ + 'field_label': '', + 'help_text': '', + 'category': self.category.id, + 'multi': False, + }) + + field = self.block.get_field(block) + + self.assertEqual(self.category.name, field.label) + self.assertEqual(self.category.help_text, field.help_text) -- GitLab