Skip to content
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
122 changes: 35 additions & 87 deletions lms/djangoapps/courseware/tests/test_word_cloud.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
"""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 @@ -25,17 +20,10 @@


@pytest.mark.usefixtures("override_descriptor_system")
class _TestWordCloudBase(BaseTestXmodule):
class TestWordCloud(BaseTestXmodule):
"""Integration test for Word Cloud Block."""
__test__ = False
CATEGORY = "word_cloud"

@classmethod
def setUpClass(cls):
super().setUpClass()
plugin.PLUGIN_CACHE = {}
importlib.reload(word_cloud_block)

def setUp(self):
super().setUp()
self.request_factory = RequestFactoryNoCsrf()
Expand All @@ -49,18 +37,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 +58,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 +222,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 +242,14 @@ 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


@override_settings(USE_EXTRACTED_WORD_CLOUD_BLOCK=False)
class TestWordCloudBuiltIn(_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)
51 changes: 0 additions & 51 deletions lms/templates/word_cloud.html

This file was deleted.

9 changes: 0 additions & 9 deletions openedx/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2105,15 +2105,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 Author

Choose a reason for hiding this comment

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

Opened one entry for all 8 blocks: openedx/docs.openedx.org#1554. It's a draft until the platform PRs land, so the list matches what actually ships in Willow.

Generated using Claude Code


# .. toggle_name: USE_EXTRACTED_ANNOTATABLE_BLOCK
# .. toggle_default: True
# .. toggle_implementation: DjangoSetting
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. openedx/public-engineering#534 now says "Re-point the entrypoint" (xblock_word_cloud:WordCloudBlock), and the description has a Changed heading for it.

Generated using Claude Code

wrapper = "xmodule.wrapper_block:WrapperBlock"

[project.entry-points."xblock_asides.v1"]
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ xblock==6.3.5
xblock-drag-and-drop-v2==5.1.2
xblock-google-drive==0.8.2
xblock-poll==1.16.1
xblocks-core==4.0.1
xblocks-core==4.0.3
xmlsec==1.3.14
# via python3-saml
xss-utils==1.1.0
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,7 @@ xblock==6.3.5
xblock-drag-and-drop-v2==5.1.2
xblock-google-drive==0.8.2
xblock-poll==1.16.1
xblocks-core==4.0.1
xblocks-core==4.0.3
xmlsec==1.3.14
# via python3-saml
xss-utils==1.1.0
Expand Down
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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'
]
}
};
22 changes: 0 additions & 22 deletions webpack.common.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,6 @@ 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
{

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6ab3d7d.

Generated using Claude Code

test: /xmodule\/js\/common_static\/js\/vendor\/draggabilly.js/,
use: [
Expand Down Expand Up @@ -545,18 +536,6 @@ module.exports = Merge.merge({
}
]
},
{
test: /d3.min/,
use: [
'babel-loader',
{
loader: 'exports-loader',
options: {
d3: true
}
}
]
},
{
test: /logger/,
use: [
Expand Down Expand Up @@ -629,7 +608,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