Skip to content

Commit

Permalink
fix: allow export of system defined and open taxonomies (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido authored Oct 27, 2023
1 parent 0d533b8 commit fcc57cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
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

0 comments on commit fcc57cd

Please sign in to comment.