|
2 | 2 |
|
3 | 3 | from __future__ import unicode_literals |
4 | 4 |
|
| 5 | +import os |
| 6 | +import json |
| 7 | + |
5 | 8 | from django.test import TestCase |
6 | 9 |
|
| 10 | + |
7 | 11 | from formidable import constants |
8 | 12 | from formidable.forms import ( |
9 | 13 | FormidableForm, fields, get_dynamic_form_class, |
|
13 | 17 | ContextFormSerializer, FormidableSerializer |
14 | 18 | ) |
15 | 19 |
|
| 20 | +TESTS_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 21 | + |
16 | 22 |
|
17 | 23 | class ConditionTestCase(TestCase): |
18 | 24 |
|
@@ -187,6 +193,32 @@ def test_readonly_field_not_displayed(self): |
187 | 193 | self.assertTrue(form.is_valid(), form.errors) |
188 | 194 | self.assertEqual(form.cleaned_data, {'checkbox': True}) |
189 | 195 |
|
| 196 | + def test_condition_field_doesnt_exist(self): |
| 197 | + """ |
| 198 | + This test checks situation when the conditional fields don't exists |
| 199 | + in the list of fields. |
| 200 | + it shows that we don't raise an Exception anymore. |
| 201 | +
|
| 202 | + You could get this situation when you specified the fields access |
| 203 | + that current user doesn't have an access to the conditional field. |
| 204 | +
|
| 205 | + In the fixture 'wrong-conditions.json' you see this situation. |
| 206 | + Conditions are configured for the 'test-field' but current user |
| 207 | + doesn't have rights to read or write to it. So can't see this field |
| 208 | + in the 'fields' section. |
| 209 | + """ |
| 210 | + schema = json.load(open( |
| 211 | + os.path.join( |
| 212 | + TESTS_DIR, 'fixtures', 'wrong-conditions.json' |
| 213 | + ) |
| 214 | + )) |
| 215 | + try: |
| 216 | + get_dynamic_form_class_from_schema(schema) |
| 217 | + except KeyError: |
| 218 | + self.fail("Doesn't have to raise an exception here ") |
| 219 | + else: |
| 220 | + self.assertTrue(True) |
| 221 | + |
190 | 222 |
|
191 | 223 | class ConditionFromSchemaTestCase(ConditionTestCase): |
192 | 224 |
|
|
0 commit comments