Skip to content

Commit

Permalink
fix: suggestion comments applied
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanDavidBuitrago committed Nov 27, 2023
1 parent e498e5f commit 76802bf
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 60 deletions.
26 changes: 13 additions & 13 deletions openedx/core/djangoapps/content_libraries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def create_library(
raise LibraryAlreadyExists(slug) # lint-amnesty, pylint: disable=raise-missing-from
CONTENT_LIBRARY_CREATED.send_event(
content_library=ContentLibraryData(
library_key=ref.library_key
library_key=ref.library_key,
)
)
return ContentLibraryMetadata(
Expand Down Expand Up @@ -608,7 +608,7 @@ def update_library(
update_bundle(ref.bundle_uuid, **fields)
CONTENT_LIBRARY_UPDATED.send_event(
content_library=ContentLibraryData(
library_key=ref.library_key
library_key=ref.library_key,
)
)

Expand All @@ -627,7 +627,7 @@ def delete_library(library_key):
ref.delete()
CONTENT_LIBRARY_DELETED.send_event(
content_library=ContentLibraryData(
library_key=ref.library_key
library_key=ref.library_key,
)
)
try:
Expand Down Expand Up @@ -769,7 +769,7 @@ def set_library_block_olx(usage_key, new_olx_str):
LIBRARY_BLOCK_UPDATED.send_event(
library_block=LibraryBlockData(
library_key=usage_key.context_key,
usage_key=usage_key
usage_key=usage_key,
)
)

Expand Down Expand Up @@ -823,7 +823,7 @@ def create_library_block(library_key, block_type, definition_id):
LIBRARY_BLOCK_CREATED.send_event(
library_block=LibraryBlockData(
library_key=ref.library_key,
usage_key=usage_key
usage_key=usage_key,
)
)
return get_library_block(usage_key)
Expand Down Expand Up @@ -881,7 +881,7 @@ def delete_library_block(usage_key, remove_from_parent=True):
LIBRARY_BLOCK_DELETED.send_event(
library_block=LibraryBlockData(
library_key=lib_bundle.library_key,
usage_key=usage_key
usage_key=usage_key,
)
)

Expand Down Expand Up @@ -910,7 +910,7 @@ def create_library_block_child(parent_usage_key, block_type, definition_id):
LIBRARY_BLOCK_UPDATED.send_event(
library_block=LibraryBlockData(
library_key=ref.library_key,
usage_key=metadata.usage_key
usage_key=metadata.usage_key,
)
)
return metadata
Expand Down Expand Up @@ -965,7 +965,7 @@ def add_library_block_static_asset_file(usage_key, file_name, file_content):
LIBRARY_BLOCK_UPDATED.send_event(
library_block=LibraryBlockData(
library_key=lib_bundle.library_key,
usage_key=usage_key
usage_key=usage_key,
)
)
return LibraryXBlockStaticFile(path=file_metadata.path, url=file_metadata.url, size=file_metadata.size)
Expand All @@ -991,7 +991,7 @@ def delete_library_block_static_asset_file(usage_key, file_name):
LIBRARY_BLOCK_UPDATED.send_event(
library_block=LibraryBlockData(
library_key=lib_bundle.library_key,
usage_key=usage_key
usage_key=usage_key,
)
)

Expand Down Expand Up @@ -1088,7 +1088,7 @@ def create_bundle_link(library_key, link_id, target_opaque_key, version=None):
LibraryBundle(library_key, ref.bundle_uuid, draft_name=DRAFT_NAME).cache.clear()
CONTENT_LIBRARY_UPDATED.send_event(
content_library=ContentLibraryData(
library_key=library_key
library_key=library_key,
)
)

Expand Down Expand Up @@ -1116,7 +1116,7 @@ def update_bundle_link(library_key, link_id, version=None, delete=False):
LibraryBundle(library_key, ref.bundle_uuid, draft_name=DRAFT_NAME).cache.clear()
CONTENT_LIBRARY_UPDATED.send_event(
content_library=ContentLibraryData(
library_key=library_key
library_key=library_key,
)
)

Expand All @@ -1136,7 +1136,7 @@ def publish_changes(library_key):
LibraryBundle(library_key, ref.bundle_uuid, draft_name=DRAFT_NAME).cache.clear()
CONTENT_LIBRARY_UPDATED.send_event(
content_library=ContentLibraryData(
library_key=library_key
library_key=library_key,
)
)

Expand All @@ -1157,7 +1157,7 @@ def revert_changes(library_key):
CONTENT_LIBRARY_UPDATED.send_event(
content_library=ContentLibraryData(
library_key=library_key,
update_blocks=True
update_blocks=True,
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,9 @@ def test_library_blocks_filters(self, is_indexing_enabled):
assert len(self._get_library_blocks(lib['id'], {'text_search': 'Video'})) == 1
assert len(self._get_library_blocks(lib['id'], {'text_search': 'Foo', 'block_type': 'video'})) == 0
assert len(self._get_library_blocks(lib['id'], {'text_search': 'Baz', 'block_type': 'video'})) == 1
assert len(self._get_library_blocks(lib['id'], {'text_search': 'Baz', 'block_type': ['video', 'html']})) ==\
2
assert len(
self._get_library_blocks(lib['id'],{'text_search': 'Baz', 'block_type': ['video', 'html']})
) == 2
assert len(self._get_library_blocks(lib['id'], {'block_type': 'video'})) == 1
assert len(self._get_library_blocks(lib['id'], {'block_type': 'problem'})) == 3
assert len(self._get_library_blocks(lib['id'], {'block_type': 'squirrel'})) == 0
Expand Down Expand Up @@ -955,7 +956,12 @@ def test_content_library_create_event(self):
"""
event_receiver = Mock()
CONTENT_LIBRARY_CREATED.connect(event_receiver)
lib = self._create_library(slug="test_lib_event_create", title="Event Test Library", description="Testing event in library") # lint-amnesty, pylint: disable=line-too-long

lib = self._create_library(
slug="test_lib_event_create",
title="Event Test Library",
description="Testing event in library"
)
library_key = LibraryLocatorV2.from_string(lib['id'])

event_receiver.assert_called_once()
Expand All @@ -977,8 +983,12 @@ def test_content_library_update_event(self):
"""
event_receiver = Mock()
CONTENT_LIBRARY_UPDATED.connect(event_receiver)
lib = self._create_library(slug="test_lib_event_update", title="Event Test Library", description="Testing event in library") # lint-amnesty, pylint: disable=line-too-long

lib = self._create_library(
slug="test_lib_event_update",
title="Event Test Library",
description="Testing event in library"
)
lib2 = self._update_library(lib["id"], title="New Title")
library_key = LibraryLocatorV2.from_string(lib2['id'])

Expand All @@ -1001,7 +1011,12 @@ def test_content_library_delete_event(self):
"""
event_receiver = Mock()
CONTENT_LIBRARY_DELETED.connect(event_receiver)
lib = self._create_library(slug="test_lib_event_delete", title="Event Test Library", description="Testing event in library") # lint-amnesty, pylint: disable=line-too-long

lib = self._create_library(
slug="test_lib_event_delete",
title="Event Test Library",
description="Testing event in library"
)
library_key = LibraryLocatorV2.from_string(lib['id'])

self._delete_library(lib["id"])
Expand All @@ -1025,10 +1040,14 @@ def test_library_block_create_event(self):
"""
event_receiver = Mock()
LIBRARY_BLOCK_CREATED.connect(event_receiver)
lib = self._create_library(slug="test_lib_block_event_create", title="Event Test Library", description="Testing event in library") # lint-amnesty, pylint: disable=line-too-long

lib = self._create_library(
slug="test_lib_block_event_create",
title="Event Test Library",
description="Testing event in library"
)
lib_id = lib["id"]
self._add_block_to_library(lib_id, "problem", "problem1")

library_key = LibraryLocatorV2.from_string(lib_id)
usage_key = LibraryUsageLocatorV2(
lib_key=library_key,
Expand All @@ -1055,19 +1074,21 @@ def test_library_block_olx_update_event(self):
"""
event_receiver = Mock()
LIBRARY_BLOCK_UPDATED.connect(event_receiver)
lib = self._create_library(slug="test_lib_block_event_olx_update", title="Event Test Library", description="Testing event in library") # lint-amnesty, pylint: disable=line-too-long
lib_id = lib["id"]

lib = self._create_library(
slug="test_lib_block_event_olx_update",
title="Event Test Library",
description="Testing event in library"
)
lib_id = lib["id"]
library_key = LibraryLocatorV2.from_string(lib_id)

block = self._add_block_to_library(lib_id, "problem", "problem1")
block_id = block["id"]
usage_key = LibraryUsageLocatorV2(
lib_key=library_key,
block_type="problem",
usage_id="problem1"
)

new_olx = """
<problem display_name="New Multi Choice Question" max_attempts="5">
<multiplechoiceresponse>
Expand All @@ -1082,7 +1103,6 @@ def test_library_block_olx_update_event(self):
</multiplechoiceresponse>
</problem>
""".strip()

self._set_library_block_olx(block_id, new_olx)

event_receiver.assert_called_once()
Expand All @@ -1104,16 +1124,17 @@ def test_library_block_child_update_event(self):
"""
event_receiver = Mock()
LIBRARY_BLOCK_UPDATED.connect(event_receiver)
lib = self._create_library(slug="test_lib_block_event_child_update", title="Event Test Library", description="Testing event in library") # lint-amnesty, pylint: disable=line-too-long
lib_id = lib["id"]

lib = self._create_library(
slug="test_lib_block_event_child_update",
title="Event Test Library",
description="Testing event in library"
)
lib_id = lib["id"]
library_key = LibraryLocatorV2.from_string(lib_id)

parent_block = self._add_block_to_library(lib_id, "unit", "u1")
parent_block_id = parent_block["id"]

self._add_block_to_library(lib["id"], "problem", "problem1", parent_block=parent_block_id)

usage_key = LibraryUsageLocatorV2(
lib_key=library_key,
block_type="problem",
Expand All @@ -1139,15 +1160,17 @@ def test_library_block_add_asset_update_event(self):
"""
event_receiver = Mock()
LIBRARY_BLOCK_UPDATED.connect(event_receiver)
lib = self._create_library(slug="test_lib_block_event_add_asset_update", title="Event Test Library", description="Testing event in library") # lint-amnesty, pylint: disable=line-too-long
lib_id = lib["id"]

lib = self._create_library(
slug="test_lib_block_event_add_asset_update",
title="Event Test Library",
description="Testing event in library"
)
lib_id = lib["id"]
library_key = LibraryLocatorV2.from_string(lib_id)

block = self._add_block_to_library(lib_id, "unit", "u1")
block_id = block["id"]
self._set_library_block_asset(block_id, "test.txt", b"data")

usage_key = LibraryUsageLocatorV2(
lib_key=library_key,
block_type="unit",
Expand All @@ -1173,17 +1196,18 @@ def test_library_block_del_asset_update_event(self):
"""
event_receiver = Mock()
LIBRARY_BLOCK_UPDATED.connect(event_receiver)
lib = self._create_library(slug="test_lib_block_event_del_asset_update", title="Event Test Library", description="Testing event in library") # lint-amnesty, pylint: disable=line-too-long
lib_id = lib["id"]

lib = self._create_library(
slug="test_lib_block_event_del_asset_update",
title="Event Test Library",
description="Testing event in library"
)
lib_id = lib["id"]
library_key = LibraryLocatorV2.from_string(lib_id)

block = self._add_block_to_library(lib_id, "unit", "u1")
block_id = block["id"]
self._set_library_block_asset(block_id, "test.txt", b"data")

self._delete_library_block_asset(block_id, 'text.txt')

usage_key = LibraryUsageLocatorV2(
lib_key=library_key,
block_type="unit",
Expand All @@ -1209,20 +1233,21 @@ def test_library_block_delete_event(self):
"""
event_receiver = Mock()
LIBRARY_BLOCK_DELETED.connect(event_receiver)
lib = self._create_library(slug="test_lib_block_event_delete", title="Event Test Library", description="Testing event in library") # lint-amnesty, pylint: disable=line-too-long

lib = self._create_library(
slug="test_lib_block_event_delete",
title="Event Test Library",
description="Testing event in library"
)
lib_id = lib["id"]
library_key = LibraryLocatorV2.from_string(lib_id)

block = self._add_block_to_library(lib_id, "problem", "problem1")
block_id = block['id']

usage_key = LibraryUsageLocatorV2(
lib_key=library_key,
block_type="problem",
usage_id="problem1"
)

self._delete_library_block(block_id)

event_receiver.assert_called()
Expand Down
2 changes: 1 addition & 1 deletion xmodule/modulestore/mixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
XBLOCK_CREATED,
XBLOCK_DELETED,
XBLOCK_PUBLISHED,
XBLOCK_UPDATED
XBLOCK_UPDATED,
)

from django.utils.timezone import datetime, timezone
Expand Down
Loading

0 comments on commit 76802bf

Please sign in to comment.