-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
base: master
Are you sure you want to change the base?
Changes from all commits
97d7043
2f86465
f09f28f
e49483d
59b3a14
aeb6eda
625f225
85a503f
d23a0a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
@@ -42,7 +45,11 @@ 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) | ||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per discussion in pair programming session (@kdmccormick , @ttqureshi ) we are creating scope ids here which shouldn't happen and is a potential bug |
||
|
||
block.location = BlockUsageLocator( | ||
CourseLocator('org', 'course', 'run', branch='revision'), 'word_cloud', 'block_id' | ||
) | ||
|
@@ -53,18 +60,34 @@ 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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use the same method as below to export the file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because add_xml_to_node is defined in XmlMixin class. In Extracted XBlocks we are preferring to use Xblock.core functionalities and using export_to_xml method which doesn't have |
||
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): | ||
""" | ||
Make sure that answer for incorrect request is error json. | ||
""" | ||
if settings.USE_EXTRACTED_WORD_CLOUD_BLOCK: | ||
return | ||
|
||
module_system = get_test_system() | ||
block = WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock()) | ||
|
@@ -83,8 +106,12 @@ def test_good_ajax_request(self): | |
module_system = get_test_system() | ||
block = WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock()) | ||
|
||
post_data = MultiDict(('student_words[]', word) for word in ['cat', 'cat', 'dog', 'sun']) | ||
response = json.loads(block.handle_ajax('submit', post_data)) | ||
if settings.USE_EXTRACTED_WORD_CLOUD_BLOCK: | ||
post_data = {'student_words': ['cat', 'cat', 'dog', 'sun']} | ||
response = block.submit_state(post_data) | ||
else: | ||
post_data = MultiDict(('student_words[]', word) for word in ['cat', 'cat', 'dog', 'sun']) | ||
response = json.loads(block.handle_ajax('submit', post_data)) | ||
assert response['status'] == 'success' | ||
assert response['submitted'] is True | ||
assert response['total_count'] == 22 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not check the block type in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, checking for both (Builtin & Extracted) XBlocks now.