Skip to content

Commit 4bf683e

Browse files
samuelhamardbrunobord
authored andcommitted
Allow to set a blank description on Formidable model
1 parent 2455e2a commit 4bf683e

File tree

10 files changed

+73
-5
lines changed

10 files changed

+73
-5
lines changed

CHANGELOG.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ChangeLog
55
master (unreleased)
66
===================
77

8-
Nothing here yet.
8+
- Allow empty description on ``Formidable`` model
99

1010
Release 6.1.0 (2020-10-07)
1111
==========================

demo/tests/test_forms.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ def test_from_json_raised_error(self):
807807
with self.assertRaises(ValidationError) as context:
808808
Formidable.from_json({'json_invalid': True})
809809

810-
self.assertEqual(len(context.exception.messages), 3)
810+
self.assertEqual(len(context.exception.messages), 2)
811811
for message in context.exception.messages:
812812
self.assertEqual(message, 'This field is required.')
813813

@@ -827,3 +827,21 @@ def test_get_serializer_with_context(self):
827827
schema_definition,
828828
context={"hello": "world"})
829829
self.assertEqual(serializer.context, {"hello": "world"})
830+
831+
def test_duplication(self):
832+
"""
833+
try to duplicate a `Formidable`` object using the ``from_json``
834+
and then it's ``to_json`` methods
835+
"""
836+
form = Formidable.objects.create(label='test', description='desc')
837+
json = form.to_json()
838+
new_form = Formidable.from_json(json)
839+
self.assertEqual('test', new_form.label)
840+
self.assertEqual('desc', new_form.description)
841+
842+
def test_duplication_empty_desc(self):
843+
form = Formidable.objects.create(label='test', description='')
844+
json = form.to_json()
845+
new_form = Formidable.from_json(json)
846+
self.assertEqual('test', new_form.label)
847+
self.assertEqual('', new_form.description)

docs/source/_static/specs/formidable.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@
291291
"type": "array"
292292
},
293293
"description": {
294-
"description": "Description of the form",
294+
"description": "Description of the form - can be empty",
295295
"type": "string"
296296
},
297297
"id": {

docs/source/deprecations.rst

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
Deprecation timeline
33
====================
44

5+
From 6.1.0 to <x.y.z>
6+
=====================
7+
8+
.. versionadded:: <x.y.z>
9+
10+
The `description` field in the ``Formidable`` model class would now allow empty values.
11+
512
From 5.0.0 to 6.0.0
613
===================
714

docs/swagger/formidable.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ definitions:
243243
description: Title of the form
244244
description:
245245
type: string
246-
description: Description of the form
246+
description: Description of the form - can be empty
247247
conditions:
248248
type: array
249249
items:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": 1,
3+
"label": "This is my form title",
4+
"description": null
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": 1,
3+
"label": "This is my form title",
4+
"description": ""
5+
}

docs/tests/test_forms.py

+15
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,18 @@ def test_id_and_label_and_description():
5050
form = _load_fixture('0004_id_label_description.json')
5151
errors = sorted(validator.iter_errors(form), key=lambda e: e.path)
5252
assert len(errors) == 0
53+
54+
55+
def test_id_description_null():
56+
form = _load_fixture('0021_id_label_description_null.json')
57+
errors = sorted(validator.iter_errors(form), key=lambda e: e.path)
58+
assert len(errors) == 1
59+
error = errors[0]
60+
assert error.validator == "type"
61+
assert error.message == "None is not of type 'string'"
62+
63+
64+
def test_id_description_empty():
65+
form = _load_fixture('0022_id_label_description_empty.json')
66+
errors = sorted(validator.iter_errors(form), key=lambda e: e.path)
67+
assert len(errors) == 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.2.19 on 2021-03-04 15:31
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('formidable', '0010_auto_20200213_1010'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='formidable',
15+
name='description',
16+
field=models.TextField(blank=True),
17+
),
18+
]

formidable/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def get_serializer(definition_schema, context=None):
2121
class Formidable(models.Model):
2222

2323
label = models.CharField(max_length=256)
24-
description = models.TextField()
24+
description = models.TextField(blank=True)
2525
conditions = JSONField(null=False, blank=False, default=list)
2626

2727
class Meta:

0 commit comments

Comments
 (0)