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

Add regression testing for channel update deletion behaviour #11896

Merged
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
74 changes: 74 additions & 0 deletions kolibri/core/content/test/test_channel_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,3 +960,77 @@ def tearDownClass(cls):
@classmethod
def setUpClass(cls):
super(NoVersionv040ImportTestCase, cls).setUpClass()


@patch("kolibri.core.content.utils.channel_import.Bridge")
@patch("kolibri.core.content.utils.channel_import.logger")
@patch("kolibri.core.content.utils.channel_import.select")
@patch("kolibri.core.content.utils.channel_import.apps")
class ChannelImportTestCase(ContentImportTestBase, TransactionTestCase):
name = CONTENT_SCHEMA_VERSION
legacy_schema = None

def setUp(self):
super(ChannelImportTestCase, self).setUp()
self.channel_id = "6199dde695db4ee4ab392222d5af1e5c"
self.channel_version = 2
self.current_channel = None

def tearDown(self):
return super().tearDown()

def test_channel_already_exists(
self, select_mock, logger_mock, apps_mock, BridgeMock
):
self.current_channel = ChannelMetadata.objects.get(id=self.channel_id)
self.current_channel.version = self.channel_version
self.current_channel.save()
self.channel_import = ChannelImport(self.channel_id, "")
self.channel_import.channel_version = self.channel_version
result = self.channel_import.check_and_delete_existing_channel()
self.assertFalse(result)

def test_partial_import_no_deletion(
self, select_mock, logger_mock, apps_mock, BridgeMock
):
self.current_channel = ChannelMetadata.objects.get(id=self.channel_id)
self.current_channel.version = self.channel_version
self.current_channel.save()
self.channel_import = ChannelImport(self.channel_id, "")
self.channel_import.channel_version = self.channel_version
self.channel_import.partial = True

result = self.channel_import.check_and_delete_existing_channel()
self.assertTrue(result)

def test_partial_import_with_deletion(
self, select_mock, logger_mock, apps_mock, BridgeMock
):
# Simulate partial import with the same version
self.current_channel = ChannelMetadata.objects.get(id=self.channel_id)
self.current_channel.version = self.channel_version
self.current_channel.save()
self.channel_import = ChannelImport(self.channel_id, "")
self.channel_import.channel_version = self.channel_version - 1
self.channel_import.partial = True
result = self.channel_import.check_and_delete_existing_channel()
self.assertFalse(result)

def test_full_import_with_newer_version(
self, select_mock, logger_mock, apps_mock, BridgeMock
):
# Simulate full import with a newer version
self.current_channel = ChannelMetadata.objects.get(id=self.channel_id)
self.current_channel.version = self.channel_version
self.current_channel.save()
self.channel_import = ChannelImport(self.channel_id, "")
self.channel_import.channel_version = self.channel_version + 1
result = self.channel_import.check_and_delete_existing_channel()
self.assertTrue(result)

def test_channel_not_exists(self, select_mock, logger_mock, apps_mock, BridgeMock):
# Simulate channel not existing in the database
self.channel_import = ChannelImport(self.channel_id, "")
self.channel_import.channel_version = self.channel_version
result = self.channel_import.check_and_delete_existing_channel()
self.assertTrue(result)
4 changes: 3 additions & 1 deletion kolibri/core/content/utils/channel_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,9 @@ def check_and_delete_existing_channel(self):
)
return False
return True
elif current_version < self.channel_version or current_partial:
elif current_version is not None and (
current_version < self.channel_version or current_partial
):
# We have an older version of this channel, so let's clean out the old stuff first
# Or we only have a partial import of this channel.
logger.info(
Expand Down