Skip to content

Commit

Permalink
included skipped tests due to currently unknown validation-errors in …
Browse files Browse the repository at this point in the history
…the test

- those tests need fixing in the future to cover more functionality with tests
  • Loading branch information
wfehr committed Feb 28, 2024
1 parent b8830e7 commit 8daa9b6
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/transfer/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import unittest
from tempfile import mkdtemp

from django.core.files import File
Expand Down Expand Up @@ -130,6 +131,75 @@ def test_validation(self):
form = PluginImportForm(data={"import_file": file_})
self.assertEqual(["This field is required."], form.errors["language"])

# TODO: when setting the form, the `form.errors` is filled for "missing
# import_file" although it is given/set in `data`
self.skipTest("TODO: fix validation with 'import_file'")

with self.subTest("one of plugin/placeholder/page required"):
form = PluginImportForm(data={"language": "en", "import_file": file_})
self.assertEqual(["A plugin, placeholder or page is required."], form.errors["__all__"])

with self.subTest("cms_page + plugin given"):
form = PluginImportForm(data={"import_file": file_, "language": "en", "cms_page": page, "plugin": plugin})
self.assertEqual(
["Plugins can be imported to pages, plugins or placeholders. Not all three."],
form.errors["__all__"],
)

with self.subTest("cms_page + placeholder given"):
form = PluginImportForm(
data={"import_file": file_, "language": "en", "cms_page": page, "placeholder": placeholder},
)
self.assertEqual(
["Plugins can be imported to pages, plugins or placeholders. Not all three."],
form.errors["__all__"],
)

with self.subTest("plugin + placeholder given"):
form = PluginImportForm(
data={"import_file": file_, "language": "en", "plugin": plugin, "placeholder": placeholder},
)
self.assertEqual(
["Plugins can be imported to pages, plugins or placeholders. Not all three."],
form.errors["__all__"],
)

@unittest.skip("TODO: fix validation with 'import_file'")
def test_run_import(self):
# TODO: when setting the form, the `form.errors` is filled for "missing
# import_file" although it is given/set in `data`
page = self.page
placeholder = page.placeholders.get(slot="content")
plugin = self._create_plugin()
file_ = self._get_file()

data = {
"plugin": plugin,
"placeholder": None,
"cms_page": None,
"language": "en",
"import_file": file_,
}

with self.subTest("import plugin"):
form = PluginImportForm(data=data)
form.clean()
form.run_import()

with self.subTest("import placeholder"):
data["placeholder"] = placeholder
data["plugin"] = None
form = PluginImportForm(data=data)
form.clean()
form.run_import()

with self.subTest("import page"):
data["cms_page"] = page
data["placeholder"] = None
form = PluginImportForm(data=data)
form.clean()
form.run_import()

def _get_file(self):
content = json.dumps(self._get_expected_plugin_export_data())

Expand Down

0 comments on commit 8daa9b6

Please sign in to comment.