From ee8e37390b8bdeac242a0d236d686b0912bbc128 Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Thu, 11 Jan 2018 08:29:08 +0000
Subject: [PATCH] Add second test for supplied values

---
 opentech/apply/categories/blocks.py           |  8 ++++----
 opentech/apply/categories/models.py           |  4 ----
 .../apply/categories/tests/test_blocks.py     | 19 +++++++++++++++----
 3 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/opentech/apply/categories/blocks.py b/opentech/apply/categories/blocks.py
index ecd61dc8c..b51e9e265 100644
--- a/opentech/apply/categories/blocks.py
+++ b/opentech/apply/categories/blocks.py
@@ -42,11 +42,11 @@ class CategoryQuestionBlock(FormFieldBlock):
             return forms.ChoiceField
 
     def use_defaults_from_category(self, kwargs, category):
-        map = {'field_label': 'label', 'help_text': 'help_text'}
+        category_fields = {'label': 'name', 'help_text': 'help_text'}
 
-        for field in ['field_label', 'help_text']:
-            if field not in kwargs:
-                kwargs[map[field]] = getattr(category, field)
+        for field in category_fields.keys():
+            if not kwargs.get(field):
+                kwargs[field] = getattr(category, category_fields[field])
 
         return kwargs
 
diff --git a/opentech/apply/categories/models.py b/opentech/apply/categories/models.py
index 525cb37f7..8b223aa5c 100644
--- a/opentech/apply/categories/models.py
+++ b/opentech/apply/categories/models.py
@@ -22,10 +22,6 @@ class Category(ClusterableModel):
     name = models.CharField(max_length=255)
     help_text = models.CharField(max_length=255, blank=True)
 
-    @property
-    def field_label(self):
-        return self.name
-
     panels = [
         FieldPanel('name'),
         InlinePanel('options', label='Options'),
diff --git a/opentech/apply/categories/tests/test_blocks.py b/opentech/apply/categories/tests/test_blocks.py
index 19c3aff8d..0e8db5613 100644
--- a/opentech/apply/categories/tests/test_blocks.py
+++ b/opentech/apply/categories/tests/test_blocks.py
@@ -11,15 +11,26 @@ class TestCategoryQuestionBlock(TestCase):
         self.category = CategoryFactory()
         self.block = CategoryQuestionBlock()
 
-    def test_field_and_help_default(self):
-        block = self.block.to_python({
+    def get_field(self, **kwargs):
+        data = {
             'field_label': '',
             'help_text': '',
             'category': self.category.id,
             'multi': False,
-        })
+        }
+        data.update(kwargs)
+
+        block = self.block.to_python(data)
 
-        field = self.block.get_field(block)
+        return self.block.get_field(block)
 
+    def test_field_and_help_default(self):
+        field = self.get_field(field_label='', help_text='')
         self.assertEqual(self.category.name, field.label)
         self.assertEqual(self.category.help_text, field.help_text)
+
+    def test_supplied_field_and_help(self):
+        values = {'field_label': 'LABEL', 'help_text': 'HELP'}
+        field = self.get_field(**values)
+        self.assertEqual(values['field_label'], field.label)
+        self.assertEqual(values['help_text'], field.help_text)
-- 
GitLab