Skip to content

Commit

Permalink
Merge pull request #11651 from dbnicholson/import-missing-supplementary
Browse files Browse the repository at this point in the history
Include nodes for import that are missing supplementary files
  • Loading branch information
bjester authored Dec 19, 2023
2 parents 83d797d + 198aa7f commit 11479b2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
44 changes: 44 additions & 0 deletions kolibri/core/content/test/test_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2539,3 +2539,47 @@ def test_no_uncle_thumbnail_files(self):
),
0,
)

@patch(
"kolibri.core.content.utils.import_export_content.get_channel_stats_from_peer"
)
def test_import_supplementary_files_missing(self, channel_stats_mock):
ContentNode.objects.update(available=True)
LocalFile.objects.update(available=True)
supplementary = LocalFile.objects.filter(files__supplementary=True)
supplementary_ids = set(supplementary.values_list("id", flat=True))
self.assertNotEqual(supplementary_ids, set())
supplementary.update(available=False)
stats = {
key: {} for key in ContentNode.objects.all().values_list("id", flat=True)
}
channel_stats_mock.return_value = stats
_, files_to_transfer, _ = get_import_export_data(
self.the_channel_id, None, None, False, renderable_only=False, peer_id="1"
)
transfer_ids = set([f["id"] for f in files_to_transfer])
self.assertEqual(transfer_ids, supplementary_ids)

@patch(
"kolibri.core.content.utils.import_export_content.get_channel_stats_from_peer"
)
def test_export_supplementary_files_missing(self, channel_stats_mock):
ContentNode.objects.update(available=True)
LocalFile.objects.update(available=True)
supplementary = LocalFile.objects.filter(files__supplementary=True)
self.assertNotEqual(supplementary.count(), 0)
supplementary.update(available=False)
stats = {
key: {} for key in ContentNode.objects.all().values_list("id", flat=True)
}
channel_stats_mock.return_value = stats
_, files_to_transfer, _ = get_import_export_data(
self.the_channel_id, None, None, True, renderable_only=False, peer_id="1"
)
essential_ids = set(
LocalFile.objects.filter(files__supplementary=False).values_list(
"id", flat=True
)
)
transfer_ids = set([f["id"] for f in files_to_transfer])
self.assertEqual(transfer_ids, essential_ids)
9 changes: 7 additions & 2 deletions kolibri/core/content/utils/import_export_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,13 @@ def get_import_export_nodes( # noqa: C901
kind=content_kinds.TOPIC
)

if available is not None:
nodes_to_include = nodes_to_include.filter(available=available)
# When exporting, only include available nodes. When importing, include any
# nodes that are missing files in case they have missing supplementary
# files and would be considered available.
if available is True:
nodes_to_include = nodes_to_include.filter(available=True)
elif available is False:
nodes_to_include = nodes_to_include.filter(files__local_file__available=False)

if check_file_availability:
nodes_to_include = filter_by_file_availability(
Expand Down

0 comments on commit 11479b2

Please sign in to comment.