From 2455e2a328dfb40d9008675499457c441032beb8 Mon Sep 17 00:00:00 2001 From: Bruno Bord Date: Wed, 3 Mar 2021 11:00:00 +0100 Subject: [PATCH 1/2] [unrelated] removed pytest cache file that shouldn't have been committed --- docs/.pytest_cache/v/cache/lastfailed | 1 - 1 file changed, 1 deletion(-) delete mode 100644 docs/.pytest_cache/v/cache/lastfailed diff --git a/docs/.pytest_cache/v/cache/lastfailed b/docs/.pytest_cache/v/cache/lastfailed deleted file mode 100644 index 9e26dfee..00000000 --- a/docs/.pytest_cache/v/cache/lastfailed +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file From 4bf683e97003da9628ef8f67bcf3173b3f0308c8 Mon Sep 17 00:00:00 2001 From: Samuel Hamard Date: Wed, 3 Mar 2021 15:58:09 +0100 Subject: [PATCH 2/2] Allow to set a blank description on Formidable model --- CHANGELOG.rst | 2 +- demo/tests/test_forms.py | 20 ++++++++++++++++++- docs/source/_static/specs/formidable.json | 2 +- docs/source/deprecations.rst | 7 +++++++ docs/swagger/formidable.yml | 2 +- .../0021_id_label_description_null.json | 5 +++++ .../0022_id_label_description_empty.json | 5 +++++ docs/tests/test_forms.py | 15 ++++++++++++++ .../0011_allow_empty_description.py | 18 +++++++++++++++++ formidable/models.py | 2 +- 10 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 docs/tests/fixtures/0021_id_label_description_null.json create mode 100644 docs/tests/fixtures/0022_id_label_description_empty.json create mode 100644 formidable/migrations/0011_allow_empty_description.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3e98dfe7..a9ec6c60 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,7 +5,7 @@ ChangeLog master (unreleased) =================== -Nothing here yet. +- Allow empty description on ``Formidable`` model Release 6.1.0 (2020-10-07) ========================== diff --git a/demo/tests/test_forms.py b/demo/tests/test_forms.py index 48f46328..4ecbc76f 100644 --- a/demo/tests/test_forms.py +++ b/demo/tests/test_forms.py @@ -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.') @@ -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) diff --git a/docs/source/_static/specs/formidable.json b/docs/source/_static/specs/formidable.json index 19bd6111..933dceaa 100644 --- a/docs/source/_static/specs/formidable.json +++ b/docs/source/_static/specs/formidable.json @@ -291,7 +291,7 @@ "type": "array" }, "description": { - "description": "Description of the form", + "description": "Description of the form - can be empty", "type": "string" }, "id": { diff --git a/docs/source/deprecations.rst b/docs/source/deprecations.rst index e4d7d42c..4d29619a 100644 --- a/docs/source/deprecations.rst +++ b/docs/source/deprecations.rst @@ -2,6 +2,13 @@ Deprecation timeline ==================== +From 6.1.0 to +===================== + +.. versionadded:: + + The `description` field in the ``Formidable`` model class would now allow empty values. + From 5.0.0 to 6.0.0 =================== diff --git a/docs/swagger/formidable.yml b/docs/swagger/formidable.yml index ebc7497a..2d11ddee 100644 --- a/docs/swagger/formidable.yml +++ b/docs/swagger/formidable.yml @@ -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: diff --git a/docs/tests/fixtures/0021_id_label_description_null.json b/docs/tests/fixtures/0021_id_label_description_null.json new file mode 100644 index 00000000..5454b60f --- /dev/null +++ b/docs/tests/fixtures/0021_id_label_description_null.json @@ -0,0 +1,5 @@ +{ + "id": 1, + "label": "This is my form title", + "description": null +} diff --git a/docs/tests/fixtures/0022_id_label_description_empty.json b/docs/tests/fixtures/0022_id_label_description_empty.json new file mode 100644 index 00000000..31f4eee1 --- /dev/null +++ b/docs/tests/fixtures/0022_id_label_description_empty.json @@ -0,0 +1,5 @@ +{ + "id": 1, + "label": "This is my form title", + "description": "" +} diff --git a/docs/tests/test_forms.py b/docs/tests/test_forms.py index c6b5aa35..cb6db9ef 100644 --- a/docs/tests/test_forms.py +++ b/docs/tests/test_forms.py @@ -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 diff --git a/formidable/migrations/0011_allow_empty_description.py b/formidable/migrations/0011_allow_empty_description.py new file mode 100644 index 00000000..a46217af --- /dev/null +++ b/formidable/migrations/0011_allow_empty_description.py @@ -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), + ), + ] diff --git a/formidable/models.py b/formidable/models.py index b0653533..5e5a9257 100644 --- a/formidable/models.py +++ b/formidable/models.py @@ -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: