Skip to content

Commit

Permalink
Merge pull request #412 from peopledoc/allow_blank_for_description
Browse files Browse the repository at this point in the history
Allow to set a blank description on Formidable model
  • Loading branch information
brunobord authored Mar 11, 2021
2 parents df8bcd0 + 4bf683e commit b343927
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ChangeLog
master (unreleased)
===================

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

Release 6.1.0 (2020-10-07)
==========================
Expand Down
20 changes: 19 additions & 1 deletion demo/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ def test_from_json_raised_error(self):
with self.assertRaises(ValidationError) as context:
Formidable.from_json({'json_invalid': True})

self.assertEqual(len(context.exception.messages), 3)
self.assertEqual(len(context.exception.messages), 2)
for message in context.exception.messages:
self.assertEqual(message, 'This field is required.')

Expand All @@ -827,3 +827,21 @@ def test_get_serializer_with_context(self):
schema_definition,
context={"hello": "world"})
self.assertEqual(serializer.context, {"hello": "world"})

def test_duplication(self):
"""
try to duplicate a `Formidable`` object using the ``from_json``
and then it's ``to_json`` methods
"""
form = Formidable.objects.create(label='test', description='desc')
json = form.to_json()
new_form = Formidable.from_json(json)
self.assertEqual('test', new_form.label)
self.assertEqual('desc', new_form.description)

def test_duplication_empty_desc(self):
form = Formidable.objects.create(label='test', description='')
json = form.to_json()
new_form = Formidable.from_json(json)
self.assertEqual('test', new_form.label)
self.assertEqual('', new_form.description)
1 change: 0 additions & 1 deletion docs/.pytest_cache/v/cache/lastfailed

This file was deleted.

2 changes: 1 addition & 1 deletion docs/source/_static/specs/formidable.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
"type": "array"
},
"description": {
"description": "Description of the form",
"description": "Description of the form - can be empty",
"type": "string"
},
"id": {
Expand Down
7 changes: 7 additions & 0 deletions docs/source/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Deprecation timeline
====================

From 6.1.0 to <x.y.z>
=====================

.. versionadded:: <x.y.z>

The `description` field in the ``Formidable`` model class would now allow empty values.

From 5.0.0 to 6.0.0
===================

Expand Down
2 changes: 1 addition & 1 deletion docs/swagger/formidable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ definitions:
description: Title of the form
description:
type: string
description: Description of the form
description: Description of the form - can be empty
conditions:
type: array
items:
Expand Down
5 changes: 5 additions & 0 deletions docs/tests/fixtures/0021_id_label_description_null.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": 1,
"label": "This is my form title",
"description": null
}
5 changes: 5 additions & 0 deletions docs/tests/fixtures/0022_id_label_description_empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": 1,
"label": "This is my form title",
"description": ""
}
15 changes: 15 additions & 0 deletions docs/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,18 @@ def test_id_and_label_and_description():
form = _load_fixture('0004_id_label_description.json')
errors = sorted(validator.iter_errors(form), key=lambda e: e.path)
assert len(errors) == 0


def test_id_description_null():
form = _load_fixture('0021_id_label_description_null.json')
errors = sorted(validator.iter_errors(form), key=lambda e: e.path)
assert len(errors) == 1
error = errors[0]
assert error.validator == "type"
assert error.message == "None is not of type 'string'"


def test_id_description_empty():
form = _load_fixture('0022_id_label_description_empty.json')
errors = sorted(validator.iter_errors(form), key=lambda e: e.path)
assert len(errors) == 0
18 changes: 18 additions & 0 deletions formidable/migrations/0011_allow_empty_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.19 on 2021-03-04 15:31

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('formidable', '0010_auto_20200213_1010'),
]

operations = [
migrations.AlterField(
model_name='formidable',
name='description',
field=models.TextField(blank=True),
),
]
2 changes: 1 addition & 1 deletion formidable/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_serializer(definition_schema, context=None):
class Formidable(models.Model):

label = models.CharField(max_length=256)
description = models.TextField()
description = models.TextField(blank=True)
conditions = JSONField(null=False, blank=False, default=list)

class Meta:
Expand Down

0 comments on commit b343927

Please sign in to comment.