Skip to content
Closed
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
31 changes: 30 additions & 1 deletion tests/openedx_tagging/core/tagging/import_export/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import openedx_tagging.core.tagging.import_export.api as import_export_api
from openedx_tagging.core.tagging.import_export import ParserFormat
from openedx_tagging.core.tagging.models import LanguageTaxonomy, TagImportTask, TagImportTaskState, Taxonomy
from openedx_tagging.core.tagging.models import LanguageTaxonomy, Tag, TagImportTask, TagImportTaskState, Taxonomy

from .mixins import TestImportExportMixin

Expand Down Expand Up @@ -197,3 +197,32 @@ def test_import_with_export_output(self) -> None:
if tag.parent:
assert new_tag.parent
assert tag.parent.external_id == new_tag.parent.external_id

def test_import_removing_with_childs(self) -> None:
"""
Test import need to remove childs with parents that will also be removed
"""
new_taxonomy = Taxonomy(name="New taxonomy")
new_taxonomy.save()
parent = Tag.objects.create(
id=-1,
external_id="tag_1",
value="Tag 1",
taxonomy=new_taxonomy,
)
Tag.objects.create(
id=-2,
external_id="tag_2",
value="Tag 2",
parent=parent,
taxonomy=new_taxonomy,
)

# Import with empty tags, to remove all tags
importFile = BytesIO(json.dumps({"tags": []}).encode())
assert import_export_api.import_tags(
new_taxonomy,
importFile,
ParserFormat.JSON,
replace=True,
)