Skip to content

Commit

Permalink
test: fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Jan 16, 2025
1 parent b4539a4 commit 49837d4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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.
Expand All @@ -49,10 +56,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
Expand All @@ -62,8 +69,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
Expand All @@ -75,8 +82,8 @@ 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)


class TestUpstreamLinksTasks(ModuleStoreTestCase):
Expand Down Expand Up @@ -105,12 +112,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,
Expand Down
18 changes: 12 additions & 6 deletions xmodule/modulestore/tests/test_mixed_modulestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ def _create_course(self, course_key, asides=None):
block_id='Overview', asides=asides)
self.writable_chapter_location = chapter.location

def _create_block_hierarchy(self):
# mock and ignore create_or_update_xblock_upstream_link task to avoid unnecessary errors as it is tested separately
@patch('openedx.core.djangoapps.content_libraries.signal_handlers.create_or_update_xblock_upstream_link')
def _create_block_hierarchy(self, _):
"""
Creates a hierarchy of blocks for testing
Each block's (version_agnostic) location is assigned as a field of the class and can be easily accessed
Expand Down Expand Up @@ -307,7 +309,9 @@ def _initialize_mixed(self, mappings=None, contentstore=None):
)
self.addCleanup(self.store.close_all_connections)

def initdb(self, default):
# mock and ignore create_or_update_xblock_upstream_link task to avoid unnecessary errors as it is tested separately
@patch('openedx.core.djangoapps.content_libraries.signal_handlers.create_or_update_xblock_upstream_link')
def initdb(self, default, _):
"""
Initialize the database and create one test course in it
"""
Expand Down Expand Up @@ -570,9 +574,11 @@ def test_get_items_include_orphans(self, default_ms, expected_items_in_tree, orp
# check CONTENT_TAGGING_AUTO CourseWaffleFlag
# find: definitions (calculator field), structures
# sends: 2 sends to update index & structure (note, it would also be definition if a content field changed)
# mock and ignore create_or_update_xblock_upstream_link task to avoid unnecessary errors as it is tested separately
@patch('openedx.core.djangoapps.content_libraries.signal_handlers.create_or_update_xblock_upstream_link')
@ddt.data((ModuleStoreEnum.Type.split, 4, 2, 2))
@ddt.unpack
def test_update_item(self, default_ms, num_mysql, max_find, max_send):
def test_update_item(self, default_ms, num_mysql, max_find, max_send, _):
"""
Update should succeed for r/w dbs
"""
Expand Down Expand Up @@ -1099,7 +1105,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):
"""
Expand All @@ -1122,7 +1128,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):
"""
Expand Down Expand Up @@ -1172,7 +1178,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):
"""
Expand Down

0 comments on commit 49837d4

Please sign in to comment.