Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test PR | Enable Extracted Word Cloud #35983

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
name: ${{ matrix.shard_name }}(py=${{ matrix.python-version }},dj=${{ matrix.django-version }},mongo=${{ matrix.mongo-version }})
runs-on: ${{ matrix.os-version }}
strategy:
fail-fast: false
matrix:
python-version:
- "3.11"
Expand Down
18 changes: 13 additions & 5 deletions lms/djangoapps/courseware/tests/test_word_cloud.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""Word cloud integration tests using mongo modulestore."""

from unittest.mock import patch

import pytest

import json
from operator import itemgetter

from django.conf import settings

# noinspection PyUnresolvedReferences
from xmodule.tests.helpers import override_descriptor_system # pylint: disable=unused-import
from xmodule.tests.helpers import override_descriptor_system, mock_render_template # pylint: disable=unused-import
from xmodule.x_module import STUDENT_VIEW

from .helpers import BaseTestXmodule
Expand Down Expand Up @@ -214,7 +216,8 @@ def test_handle_ajax_incorrect_dispatch(self):
}
)

def test_word_cloud_constructor(self):
@patch('xblock.utils.resources.ResourceLoader.render_django_template', side_effect=mock_render_template)
def test_word_cloud_constructor(self, mock_render_django_template):
"""
Make sure that all parameters extracted correctly from xml.
"""
Expand All @@ -223,10 +226,15 @@ def test_word_cloud_constructor(self):
'ajax_url': self.block.ajax_url,
'display_name': self.block.display_name,
'instructions': self.block.instructions,
'element_class': self.block.location.block_type,
'element_id': self.block.location.html_id(),
'num_inputs': 5, # default value
'submitted': False, # default value,
}

assert fragment.content == self.runtime.render_template('word_cloud.html', expected_context)
if settings.USE_EXTRACTED_WORD_CLOUD_BLOCK:
expected_context['range_num_inputs'] = range(5)
mock_render_django_template.assert_called_once()
assert fragment.content == self.runtime.render_template('templates/word_cloud.html', expected_context)
else:
expected_context['element_class'] = self.block.location.block_type
assert fragment.content == self.runtime.render_template('word_cloud.html', expected_context)
2 changes: 1 addition & 1 deletion lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5557,7 +5557,7 @@ def _should_send_learning_badge_events(settings):
# .. toggle_warning: Not production-ready until https://github.com/openedx/edx-platform/issues/34840 is done.
# .. toggle_creation_date: 2024-11-10
# .. toggle_target_removal_date: 2025-06-01
USE_EXTRACTED_WORD_CLOUD_BLOCK = False
USE_EXTRACTED_WORD_CLOUD_BLOCK = True

# .. toggle_name: USE_EXTRACTED_ANNOTATABLE_BLOCK
# .. toggle_default: False
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ xblock-utils==4.0.0
# via
# edx-sga
# xblock-poll
xblocks-contrib==0.1.0
git+https://github.com/openedx/xblocks-contrib.git@farhan/word-cloud-xblock
# via -r requirements/edx/bundled.in
xmlsec==1.3.14
# via python3-saml
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2284,7 +2284,7 @@ xblock-utils==4.0.0
# -r requirements/edx/testing.txt
# edx-sga
# xblock-poll
xblocks-contrib==0.1.0
git+https://github.com/openedx/xblocks-contrib.git@farhan/word-cloud-xblock
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ xblock-utils==4.0.0
# -r requirements/edx/base.txt
# edx-sga
# xblock-poll
xblocks-contrib==0.1.0
git+https://github.com/openedx/xblocks-contrib.git@farhan/word-cloud-xblock
# via -r requirements/edx/base.txt
xmlsec==1.3.14
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ xblock-utils==4.0.0
# -r requirements/edx/base.txt
# edx-sga
# xblock-poll
xblocks-contrib==0.1.0
git+https://github.com/openedx/xblocks-contrib.git@farhan/word-cloud-xblock
# via -r requirements/edx/base.txt
xmlsec==1.3.14
# via
Expand Down
32 changes: 28 additions & 4 deletions xmodule/tests/test_word_cloud.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
"""Test for Word Cloud Block functional logic."""

import json
import os
from unittest.mock import Mock

from django.conf import settings
from django.test import TestCase
from fs.memoryfs import MemoryFS
from lxml import etree
from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
from webob.multidict import MultiDict
from xblock.field_data import DictFieldData
from xblock.fields import ScopeIds

from xmodule.word_cloud_block import WordCloudBlock
from . import get_test_descriptor_system, get_test_system
Expand Down Expand Up @@ -42,7 +45,14 @@ def test_xml_import_export_cycle(self):

olx_element = etree.fromstring(original_xml)
runtime.id_generator = Mock()
block = WordCloudBlock.parse_xml(olx_element, runtime, None)

if settings.USE_EXTRACTED_WORD_CLOUD_BLOCK:
def_id = runtime.id_generator.create_definition(olx_element.tag, olx_element.get('url_name'))
keys = ScopeIds(None, olx_element.tag, def_id, runtime.id_generator.create_usage(def_id))
block = WordCloudBlock.parse_xml(olx_element, runtime, keys)
else:
block = WordCloudBlock.parse_xml(olx_element, runtime, None)

block.location = BlockUsageLocator(
CourseLocator('org', 'course', 'run', branch='revision'), 'word_cloud', 'block_id'
)
Expand All @@ -53,12 +63,26 @@ def test_xml_import_export_cycle(self):
assert block.num_inputs == 3
assert block.num_top_words == 100

node = etree.Element("unknown_root")
# This will export the olx to a separate file.
block.add_xml_to_node(node)
if settings.USE_EXTRACTED_WORD_CLOUD_BLOCK:
filepath = 'word_cloud/block_id.xml'
runtime.export_fs.makedirs(os.path.dirname(filepath), recreate=True)
with runtime.export_fs.open(filepath, 'wb') as fileObj:
runtime.export_to_xml(block, fileObj)
else:
node = etree.Element("unknown_root")
# This will export the olx to a separate file.
block.add_xml_to_node(node)

with runtime.export_fs.open('word_cloud/block_id.xml') as f:
exported_xml = f.read()

if settings.USE_EXTRACTED_WORD_CLOUD_BLOCK:
exported_xml_tree = etree.fromstring(exported_xml.encode('utf-8'))
etree.cleanup_namespaces(exported_xml_tree)
if 'xblock-family' in exported_xml_tree.attrib:
del exported_xml_tree.attrib['xblock-family']
exported_xml = etree.tostring(exported_xml_tree, encoding='unicode', pretty_print=True)

assert exported_xml == original_xml

def test_bad_ajax_request(self):
Expand Down
Loading