Skip to content
Open
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
111 changes: 35 additions & 76 deletions lms/djangoapps/courseware/tests/test_word_cloud.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
"""Word cloud integration tests using mongo modulestore."""
import importlib
import json
import re
from operator import itemgetter
from unittest.mock import patch
from uuid import UUID

import pytest
from django.conf import settings
from django.test import override_settings
from xblock import plugin

from common.djangoapps.student.tests.factories import RequestFactoryNoCsrf
from xmodule import word_cloud_block

# noinspection PyUnresolvedReferences
from xmodule.tests.helpers import ( # pylint: disable=unused-import # noqa: F401
Expand All @@ -34,7 +30,6 @@ class _TestWordCloudBase(BaseTestXmodule):
def setUpClass(cls):
super().setUpClass()
plugin.PLUGIN_CACHE = {}
importlib.reload(word_cloud_block)

def setUp(self):
super().setUp()
Expand All @@ -49,18 +44,15 @@ def _get_users_state(self):
users_state = {}

for user in self.users:
if settings.USE_EXTRACTED_WORD_CLOUD_BLOCK:
# The extracted Word Cloud XBlock uses @XBlock.json_handler, which expects a different
# request format and url pattern
handler_url = self.get_url('', handler_name='handle_get_state')
response = self.clients[user.username].post(
handler_url,
data=json.dumps({}),
content_type='application/json',
HTTP_X_REQUESTED_WITH='XMLHttpRequest',
)
else:
response = self.clients[user.username].post(self.get_url('get_state'))
# The extracted Word Cloud XBlock uses @XBlock.json_handler, which expects a different
# request format and url pattern
handler_url = self.get_url('', handler_name='handle_get_state')
response = self.clients[user.username].post(
handler_url,
data=json.dumps({}),
content_type='application/json',
HTTP_X_REQUESTED_WITH='XMLHttpRequest',
)
users_state[user.username] = json.loads(response.content.decode('utf-8'))

return users_state
Expand All @@ -73,22 +65,15 @@ def _post_words(self, words):
users_state = {}

for user in self.users:
if settings.USE_EXTRACTED_WORD_CLOUD_BLOCK:
# The extracted Word Cloud XBlock uses @XBlock.json_handler, which expects a different
# request format and url pattern
handler_url = self.get_url('', handler_name='handle_submit_state')
response = self.clients[user.username].post(
handler_url,
data=json.dumps({'student_words': words}),
content_type='application/json',
HTTP_X_REQUESTED_WITH='XMLHttpRequest',
)
else:
response = self.clients[user.username].post(
self.get_url('submit'),
{'student_words[]': words},
HTTP_X_REQUESTED_WITH='XMLHttpRequest'
)
# The extracted Word Cloud XBlock uses @XBlock.json_handler, which expects a different
# request format and url pattern
handler_url = self.get_url('', handler_name='handle_submit_state')
response = self.clients[user.username].post(
handler_url,
data=json.dumps({'student_words': words}),
content_type='application/json',
HTTP_X_REQUESTED_WITH='XMLHttpRequest',
)
users_state[user.username] = json.loads(response.content.decode('utf-8'))

return users_state
Expand Down Expand Up @@ -244,25 +229,11 @@ def test_handle_ajax_incorrect_dispatch(self):
for user in self.users
}

if settings.USE_EXTRACTED_WORD_CLOUD_BLOCK:
# The extracted Word Cloud XBlock uses @XBlock.json_handler to handle AJAX requests,
# which automatically returns a 404 for unknown requests, so there's no need to test
# the incorrect dispatch case in this scenario.
for username, response in responses.items(): # noqa: B007
self.assertEqual(response.status_code, 404) # noqa: PT009
return

status_codes = {response.status_code for response in responses.values()}
assert status_codes.pop() == 200

for user in self.users:
self.assertDictEqual( # noqa: PT009
json.loads(responses[user.username].content.decode('utf-8')),
{
'status': 'fail',
'error': 'Unknown Command!'
}
)
# The extracted Word Cloud XBlock uses @XBlock.json_handler to handle AJAX requests,
# which automatically returns a 404 for unknown requests, so there's no need to test
# the incorrect dispatch case in this scenario.
for username, response in responses.items(): # noqa: B007
self.assertEqual(response.status_code, 404) # noqa: PT009

@patch('xblock.utils.resources.ResourceLoader.render_django_template', side_effect=mock_render_template)
def test_word_cloud_constructor(self, mock_render_django_template):
Expand All @@ -278,30 +249,18 @@ def test_word_cloud_constructor(self, mock_render_django_template):
'submitted': False, # default value,
}

if settings.USE_EXTRACTED_WORD_CLOUD_BLOCK:
# If `USE_EXTRACTED_WORD_CLOUD_BLOCK` is enabled, the `expected_context` will be different
# because in the extracted Word Cloud XBlock, the expected context:
# - contains `range_num_inputs`
# - uses `UUID` for `element_id` instead of `html_id()`
# - does not include `ajax_url` since it uses the `@XBlock.json_handler` decorator for AJAX requests
expected_context['range_num_inputs'] = range(5)
uuid_str = re.search(r"UUID\('([a-f0-9\-]+)'\)", fragment.content).group(1)
expected_context['element_id'] = UUID(uuid_str)
mock_render_django_template.assert_called_once()
# Remove i18n service
fragment_content_clean = re.sub(r"\{.*?}", "{}", fragment.content)
assert fragment_content_clean == self.runtime.render_template('templates/word_cloud.html', expected_context)
else:
expected_context['ajax_url'] = self.block.ajax_url
expected_context['element_id'] = self.block.location.html_id()
assert fragment.content == self.runtime.render_template('word_cloud.html', expected_context)


@override_settings(USE_EXTRACTED_WORD_CLOUD_BLOCK=True)
class TestWordCloudExtracted(_TestWordCloudBase):
__test__ = True
# In the extracted Word Cloud XBlock, the expected context:
# - contains `range_num_inputs`
# - uses `UUID` for `element_id` instead of `html_id()`
# - does not include `ajax_url` since it uses the `@XBlock.json_handler` decorator for AJAX requests
expected_context['range_num_inputs'] = range(5)
uuid_str = re.search(r"UUID\('([a-f0-9\-]+)'\)", fragment.content).group(1)
expected_context['element_id'] = UUID(uuid_str)
mock_render_django_template.assert_called_once()
# Remove i18n service
fragment_content_clean = re.sub(r"\{.*?}", "{}", fragment.content)
assert fragment_content_clean == self.runtime.render_template('templates/word_cloud.html', expected_context)


@override_settings(USE_EXTRACTED_WORD_CLOUD_BLOCK=False)
class TestWordCloudBuiltIn(_TestWordCloudBase):
class TestWordCloudExtracted(_TestWordCloudBase):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (optional): only one subclass is left, and the cache reset was only needed for the removed importlib.reload:

-class _TestWordCloudBase(BaseTestXmodule):
+class TestWordCloud(BaseTestXmodule):
     """Integration test for Word Cloud Block."""
-    __test__ = False
     ...
-        plugin.PLUGIN_CACHE = {}
 ...
-
-
-class TestWordCloudExtracted(_TestWordCloudBase):
-    __test__ = True

__test__ = True
51 changes: 0 additions & 51 deletions lms/templates/word_cloud.html

This file was deleted.

8 changes: 0 additions & 8 deletions openedx/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2112,14 +2112,6 @@ def add_optional_apps(optional_apps, installed_apps):
#
# Ticket: https://github.com/openedx/edx-platform/issues/35308

# .. toggle_name: USE_EXTRACTED_WORD_CLOUD_BLOCK
# .. toggle_default: True
# .. toggle_implementation: DjangoSetting
# .. toggle_description: Enables the use of the extracted Word Cloud XBlock, which has been shifted to the 'openedx/xblocks-core' repo.
# .. toggle_use_cases: temporary
# .. toggle_creation_date: 2024-11-10
# .. toggle_target_removal_date: 2026-04-10
USE_EXTRACTED_WORD_CLOUD_BLOCK = True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verawood dev/op notes announced this removal for Willow. Add it under Deprecations & Removals in Willow dev/op notes, or confirm one entry covers all 8 blocks:

* **Removed the built-in Word Cloud block.** ``xmodule.word_cloud_block`` and the
  ``USE_EXTRACTED_WORD_CLOUD_BLOCK`` setting are removed. The Word Cloud block from
  `xblocks-core <https://github.com/openedx/xblocks-core>`_ is always used.


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: double blank line.

Suggested change

# .. toggle_name: USE_EXTRACTED_ANNOTATABLE_BLOCK
# .. toggle_default: True
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ vertical = "xmodule.vertical_block:VerticalBlock"
video = "xmodule.video_block:VideoBlock"
videoalpha = "xmodule.video_block:VideoBlock"
videodev = "xmodule.template_block:TranslateCustomTagBlock"
word_cloud = "xmodule.word_cloud_block:WordCloudBlock"
word_cloud = "xblock_word_cloud:WordCloudBlock"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the "Remove the entrypoint" item in openedx/public-engineering#534 to say re-pointed, and list this under a "Changed" heading in the PR description.

wrapper = "xmodule.wrapper_block:WrapperBlock"

[project.entry-points."xblock_asides.v1"]
Expand Down
8 changes: 0 additions & 8 deletions webpack.builtinblocks.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,5 @@ module.exports = {
VideoBlockDisplay: [
'./xmodule/assets/video/public/js/10_main.js'
],
WordCloudBlockDisplay: [
'./xmodule/js/src/xmodule.js',
'./xmodule/assets/word_cloud/src/js/word_cloud.js'
],
WordCloudBlockEditor: [
'./xmodule/js/src/xmodule.js',
'./xmodule/js/src/raw/edit/metadata-only.js'
]
}
};
11 changes: 1 addition & 10 deletions webpack.common.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,7 @@ module.exports = Merge.merge({
* we know, the only modules that absolutely need to be added to the global namespace are those
* which define module types, for example "Problem" (in xmodule/js/src/capa/display.js).
*/
{
test: /xmodule\/assets\/word_cloud\/src\/js\/word_cloud.js/,
use: [
{
loader: 'imports-loader',
options: 'this=>window'
}
]
},

{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: leftover blank line.

Suggested change
{

test: /xmodule\/js\/common_static\/js\/vendor\/draggabilly.js/,
use: [
Expand Down Expand Up @@ -629,7 +621,6 @@ module.exports = Merge.merge({
'lms/static',
path.resolve(__dirname),
'xmodule/js/src',
'xmodule/assets/word_cloud/src/js',
'common/static',
'common/static/coffee/src',
'common/static/common/js',
Expand Down
1 change: 0 additions & 1 deletion xmodule/assets/word_cloud/.gitignore

This file was deleted.

Loading
Loading