-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #285 from peopledoc/json-migrations
FORM-13: Fix JSON migrations
- Loading branch information
Showing
5 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"description": "Some description for the tests", | ||
"fields": [ | ||
{ | ||
"accesses": [ | ||
{ | ||
"access_id": "first-access-group", | ||
"level": "EDITABLE" | ||
}, | ||
{ | ||
"access_id": "second-access-group", | ||
"level": "EDITABLE" | ||
}, | ||
{ | ||
"access_id": "third-access-group", | ||
"level": "EDITABLE" | ||
} | ||
], | ||
"defaults": [], | ||
"help_text": "", | ||
"items": [], | ||
"label": "There is my label field label", | ||
"multiple": false, | ||
"placeholder": null, | ||
"slug": "multiline-text", | ||
"type_id": "paragraph", | ||
"validations": [] | ||
} | ||
], | ||
"id": 0, | ||
"label": "And my form label", | ||
"presets": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"first-access-group": { | ||
"description": "Some description for the tests", | ||
"fields": [ | ||
{ | ||
"defaults": [], | ||
"disabled": false, | ||
"help_text": "", | ||
"items": [], | ||
"label": "There is my label field label", | ||
"multiple": false, | ||
"placeholder": null, | ||
"required": false, | ||
"slug": "multiline-text", | ||
"type_id": "paragraph", | ||
"validations": [] | ||
} | ||
], | ||
"id": 0, | ||
"label": "And my form label", | ||
"presets": [] | ||
}, | ||
"second-access-group": { | ||
"description": "Some description for the tests", | ||
"fields": [ | ||
{ | ||
"defaults": [], | ||
"disabled": false, | ||
"help_text": "", | ||
"items": [], | ||
"label": "There is my label field label", | ||
"multiple": false, | ||
"placeholder": null, | ||
"required": false, | ||
"slug": "multiline-text", | ||
"type_id": "paragraph", | ||
"validations": [] | ||
} | ||
], | ||
"id": 0, | ||
"label": "And my form label", | ||
"presets": [] | ||
}, | ||
"third-access-group": { | ||
"description": "Some description for the tests", | ||
"fields": [ | ||
{ | ||
"defaults": [], | ||
"disabled": false, | ||
"help_text": "", | ||
"items": [], | ||
"label": "There is my label field label", | ||
"multiple": false, | ||
"placeholder": null, | ||
"required": false, | ||
"slug": "multiline-text", | ||
"type_id": "paragraph", | ||
"validations": [] | ||
} | ||
], | ||
"id": 0, | ||
"label": "And my form label", | ||
"presets": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import os | ||
import json | ||
from django.test import TestCase | ||
|
||
from formidable.json_migrations.utils import merge_context_forms | ||
|
||
TESTS_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
|
||
class JSONMigrationUtilsTestCase(TestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.expected_form = json.load(open( | ||
os.path.join( | ||
TESTS_DIR, 'fixtures', 'migration-form-data-expected.json' | ||
) | ||
)) | ||
cls.base_form = json.load(open( | ||
os.path.join( | ||
TESTS_DIR, | ||
'fixtures', | ||
'migration-form-data-input.json' | ||
) | ||
)) | ||
|
||
def get_base_form(self, version=None): | ||
form = self.base_form.copy() | ||
if version is not None: | ||
form['version'] = version | ||
return form | ||
|
||
def get_expected_form(self, version=None): | ||
form = self.expected_form.copy() | ||
if version is not None: | ||
form['version'] = version | ||
return form | ||
|
||
def test_merge_context_forms_without_version(self): | ||
base_form = self.get_base_form() | ||
expected_form = self.get_expected_form() | ||
expected_form['fields'][0]['accesses'].sort(key=self.dict_sort_key) | ||
|
||
result = merge_context_forms(base_form) | ||
result['fields'][0]['accesses'].sort(key=self.dict_sort_key) | ||
|
||
self.assertDictEqual(expected_form, result) | ||
|
||
def test_merge_context_forms_with_version(self): | ||
version = 2 | ||
base_form = self.get_base_form(version=version) | ||
expected_form = self.get_expected_form(version=version) | ||
expected_form['fields'][0]['accesses'].sort(key=self.dict_sort_key) | ||
|
||
result = merge_context_forms(base_form) | ||
result['fields'][0]['accesses'].sort(key=self.dict_sort_key) | ||
|
||
self.assertDictEqual(expected_form, result) | ||
|
||
def dict_sort_key(self, obj): | ||
return obj['access_id'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters