From 54565b71cfe76318c7861019cc969248c1868af2 Mon Sep 17 00:00:00 2001
From: Navin Karkera <navin@opencraft.com>
Date: Thu, 16 Jan 2025 12:44:04 +0530
Subject: [PATCH] test: fix failing tests

---
 .../tests/test_upstream_downstream_links.py   | 24 ++++++++++++++-----
 .../tests/test_mixed_modulestore.py           | 13 +++++++---
 2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/openedx/core/djangoapps/content_libraries/tests/test_upstream_downstream_links.py b/openedx/core/djangoapps/content_libraries/tests/test_upstream_downstream_links.py
index 19734eda092d..3787d3cedcb3 100644
--- a/openedx/core/djangoapps/content_libraries/tests/test_upstream_downstream_links.py
+++ b/openedx/core/djangoapps/content_libraries/tests/test_upstream_downstream_links.py
@@ -10,12 +10,14 @@
 from django.utils import timezone
 from freezegun import freeze_time
 
+from openedx.core.djangolib.testing.utils import skip_unless_cms
 from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
 from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory
 
 from ..tasks import create_or_update_upstream_links, create_or_update_xblock_upstream_link
 
 
+@skip_unless_cms
 class TestRecreateUpstreamLinks(ModuleStoreTestCase):
     """
     Test recreate_upstream_links management command.
@@ -23,6 +25,13 @@ class TestRecreateUpstreamLinks(ModuleStoreTestCase):
 
     ENABLED_SIGNALS = ['course_deleted', 'course_published']
 
+    def setUp(self):
+        super().setUp()
+        self.now = timezone.now()
+        freezer = freeze_time(self.now)
+        freezer.start()
+        self.addCleanup(freezer.stop)
+
     def call_command(self, *args, **kwargs):
         """
         call command with pass args.
@@ -49,10 +58,10 @@ def test_call_for_single_course(self, mock_task):
         Test command with single course argument
         """
         self.call_command('--course', 'some-course')
-        mock_task.delay.assert_called_with('some-course', False)
+        mock_task.delay.assert_called_with('some-course', False, created=self.now)
         # call with --force
         self.call_command('--course', 'some-course', '--force')
-        mock_task.delay.assert_called_with('some-course', True)
+        mock_task.delay.assert_called_with('some-course', True, created=self.now)
 
     @patch(
         'openedx.core.djangoapps.content_libraries.management.commands.recreate_upstream_links.create_or_update_upstream_links'  # pylint: disable=line-too-long
@@ -62,8 +71,8 @@ def test_call_for_multiple_course(self, mock_task):
         Test command with multiple course arguments
         """
         self.call_command('--course', 'some-course', '--course', 'one-more-course')
-        mock_task.delay.assert_any_call('some-course', False)
-        mock_task.delay.assert_any_call('one-more-course', False)
+        mock_task.delay.assert_any_call('some-course', False, created=self.now)
+        mock_task.delay.assert_any_call('one-more-course', False, created=self.now)
 
     @patch(
         'openedx.core.djangoapps.content_libraries.management.commands.recreate_upstream_links.create_or_update_upstream_links'  # pylint: disable=line-too-long
@@ -75,10 +84,11 @@ def test_call_for_all_courses(self, mock_task):
         course_key_1 = CourseFactory.create(emit_signals=True).id
         course_key_2 = CourseFactory.create(emit_signals=True).id
         self.call_command('--all')
-        mock_task.delay.assert_any_call(str(course_key_1), False)
-        mock_task.delay.assert_any_call(str(course_key_2), False)
+        mock_task.delay.assert_any_call(str(course_key_1), False, created=self.now)
+        mock_task.delay.assert_any_call(str(course_key_2), False, created=self.now)
 
 
+@skip_unless_cms
 class TestUpstreamLinksTasks(ModuleStoreTestCase):
     """
     Test tasks related to managing upstream->downstream links.
@@ -105,12 +115,14 @@ def setUp(self):
                 category="html",
                 display_name="An HTML Block",
                 upstream=self.upstream_1,
+                upstream_version=1,
             )
             self.component_2 = BlockFactory.create(
                 parent=self.unit,
                 category="html",
                 display_name="Another HTML Block",
                 upstream=self.upstream_2,
+                upstream_version=1,
             )
             self.component_3 = BlockFactory.create(
                 parent=self.unit,
diff --git a/xmodule/modulestore/tests/test_mixed_modulestore.py b/xmodule/modulestore/tests/test_mixed_modulestore.py
index 0928ab253b9c..4d335ceaa554 100644
--- a/xmodule/modulestore/tests/test_mixed_modulestore.py
+++ b/xmodule/modulestore/tests/test_mixed_modulestore.py
@@ -164,6 +164,13 @@ def setUp(self):
         self.course_locations = {}
 
         self.user_id = ModuleStoreEnum.UserID.test
+        # mock and ignore create_or_update_xblock_upstream_link task to avoid unnecessary
+        # errors as it is tested separately
+        create_or_update_xblock_upstream_link_patch = patch(
+            'openedx.core.djangoapps.content_libraries.signal_handlers.create_or_update_xblock_upstream_link'
+        )
+        create_or_update_xblock_upstream_link_patch.start()
+        self.addCleanup(create_or_update_xblock_upstream_link_patch.stop)
 
     def _check_connection(self):
         """
@@ -1099,7 +1106,7 @@ def test_has_changes_missing_child(self, default_ms, default_branch):
     #          check CONTENT_TAGGING_AUTO CourseWaffleFlag
     #   Find: active_versions, 2 structures (published & draft), definition (unnecessary)
     #   Sends: updated draft and published structures and active_versions
-    @ddt.data((ModuleStoreEnum.Type.split, 5, 2, 3))
+    @ddt.data((ModuleStoreEnum.Type.split, 6, 2, 3))
     @ddt.unpack
     def test_delete_item(self, default_ms, num_mysql, max_find, max_send):
         """
@@ -1122,7 +1129,7 @@ def test_delete_item(self, default_ms, num_mysql, max_find, max_send):
     #           check CONTENT_TAGGING_AUTO CourseWaffleFlag
     #    find: draft and published structures, definition (unnecessary)
     #    sends: update published (why?), draft, and active_versions
-    @ddt.data((ModuleStoreEnum.Type.split, 5, 3, 3))
+    @ddt.data((ModuleStoreEnum.Type.split, 6, 3, 3))
     @ddt.unpack
     def test_delete_private_vertical(self, default_ms, num_mysql, max_find, max_send):
         """
@@ -1172,7 +1179,7 @@ def test_delete_private_vertical(self, default_ms, num_mysql, max_find, max_send
     #          check CONTENT_TAGGING_AUTO CourseWaffleFlag
     #   find: structure (cached)
     #   send: update structure and active_versions
-    @ddt.data((ModuleStoreEnum.Type.split, 5, 1, 2))
+    @ddt.data((ModuleStoreEnum.Type.split, 6, 1, 2))
     @ddt.unpack
     def test_delete_draft_vertical(self, default_ms, num_mysql, max_find, max_send):
         """