Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow export of system defined and open taxonomies [FC-0036] #107

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions openedx_tagging/core/tagging/import_export/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def import_tags(
in the file (regardless of action), then `tag_2` and `tag_3` will be deleted
if `replace=True`
"""
_import_export_validations(taxonomy)
_import_validations(taxonomy)

# Checks that exists only one task import in progress at a time per taxonomy
if not _check_unique_import_task(taxonomy):
Expand Down Expand Up @@ -146,7 +146,6 @@ def export_tags(taxonomy: Taxonomy, output_format: ParserFormat) -> str:
"""
Returns a string with all tag data of the given taxonomy
"""
_import_export_validations(taxonomy)
parser = get_parser(output_format)
return parser.export(taxonomy)

Expand Down Expand Up @@ -178,20 +177,21 @@ def _get_last_import_task(taxonomy: Taxonomy) -> TagImportTask | None:
)


def _import_export_validations(taxonomy: Taxonomy):
def _import_validations(taxonomy: Taxonomy):
"""
Validates if the taxonomy is allowed to import or export tags
Validates if the taxonomy is allowed to import tags
"""
taxonomy = taxonomy.cast()
if taxonomy.allow_free_text:
raise NotImplementedError(
raise ValueError(
_(
"Import/export for free-form taxonomies will be implemented in the future."
)
"Invalid taxonomy ({id}): You cannot import a free-form taxonomy."
).format(id=taxonomy.id)
)

if taxonomy.system_defined:
raise ValueError(
_(
"Invalid taxonomy ({id}): You cannot import/export a system-defined taxonomy."
"Invalid taxonomy ({id}): You cannot import a system-defined taxonomy."
).format(id=taxonomy.id)
)
17 changes: 1 addition & 16 deletions tests/openedx_tagging/core/tagging/import_export/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_invalid_import_tags(self) -> None:

def test_import_export_validations(self) -> None:
# Check that import is invalid with open taxonomy
with self.assertRaises(NotImplementedError):
with self.assertRaises(ValueError):
import_export_api.import_tags(
self.open_taxonomy,
self.file,
Expand Down Expand Up @@ -174,21 +174,6 @@ def test_start_task_after_success(self) -> None:
self.parser_format,
)

def test_export_validations(self) -> None:
# Check that import is invalid with open taxonomy
with self.assertRaises(NotImplementedError):
import_export_api.export_tags(
self.open_taxonomy,
self.parser_format,
)

# Check that import is invalid with system taxonomy
with self.assertRaises(ValueError):
import_export_api.export_tags(
self.system_taxonomy,
self.parser_format,
)

def test_import_with_export_output(self) -> None:
for parser_format in ParserFormat:
output = import_export_api.export_tags(
Expand Down
Loading