Skip to content

Commit

Permalink
test: Tests for studio_submit of conditional and word cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Feb 1, 2025
1 parent 8fd986b commit 0d3f523
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
2 changes: 1 addition & 1 deletion common/templates/xblock_v2/xblock_iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
blockJS.element = element;

if (['MetadataOnlyEditingDescriptor', 'SequenceDescriptor'].includes(data['xmodule-type'])) {
// The xmodule type `MetadataOnlyEditingDescriptor` renders a `<div>` with
// The xmodule type `MetadataOnlyEditingDescriptor` and `SequenceDescriptor` renders a `<div>` with
// the block metadata in the `data-metadata` attribute. But is necessary
// to call `XBlockEditorView.xblockReady()` to run the scripts to build the
// editor using the metadata.
Expand Down
9 changes: 2 additions & 7 deletions xmodule/conditional_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class ConditionalBlock(
default=_('You must complete {link} before you can access this unit.')
)

has_children = True

_tag_name = 'conditional'

resources_dir = None
Expand Down Expand Up @@ -410,10 +412,3 @@ def non_editable_metadata_fields(self):
ConditionalBlock.show_tag_list,
])
return non_editable_fields

@property
def has_children(self):
"""
Determines whether this block has children
"""
return bool(self.sources_list)
27 changes: 27 additions & 0 deletions xmodule/tests/test_conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest.mock import Mock, patch

from django.conf import settings
from webob import Request
from fs.memoryfs import MemoryFS
from lxml import etree
from opaque_keys.edx.keys import CourseKey
Expand Down Expand Up @@ -402,3 +403,29 @@ def test_validation_messages(self):
assert validation.summary.type == StudioValidationMessage.NOT_CONFIGURED
assert validation.summary.action_class == 'edit-button'
assert validation.summary.action_label == 'Configure list of sources'

def test_studio_submit_handler(self):
"""
Test studio_submint handler
"""
TEST_SUBMIT_DATA = {
'display_name': "New Conditional",
'show_tag_list': ["1", "2"],
'sources_list': ["1", "2"],
'conditional_attr': "test",
'conditional_value': 'value',
'conditional_message': 'message',
}
body = json.dumps(TEST_SUBMIT_DATA)
request = Request.blank('/')
request.method = 'POST'
request.body = body.encode('utf-8')
res = self.conditional.handle('studio_submit', request)
assert json.loads(res.body.decode('utf8')) == {'result': 'success'}

assert self.conditional.display_name == TEST_SUBMIT_DATA['display_name']
assert self.conditional.show_tag_list == TEST_SUBMIT_DATA['show_tag_list']
assert self.conditional.sources_list == TEST_SUBMIT_DATA['sources_list']
assert self.conditional.conditional_attr == TEST_SUBMIT_DATA['conditional_attr']
assert self.conditional.conditional_value == TEST_SUBMIT_DATA['conditional_value']
assert self.conditional.conditional_message == TEST_SUBMIT_DATA['conditional_message']
27 changes: 27 additions & 0 deletions xmodule/tests/test_word_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.test import TestCase
from fs.memoryfs import MemoryFS
from lxml import etree
from webob import Request
from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
from webob.multidict import MultiDict
from xblock.field_data import DictFieldData
Expand Down Expand Up @@ -115,3 +116,29 @@ def test_indexibility(self):
{'content_type': 'Word Cloud',
'content': {'display_name': 'Word Cloud Block',
'instructions': 'Enter some random words that comes to your mind'}}

def test_studio_submit_handler(self):
"""
Test studio_submint handler
"""
TEST_SUBMIT_DATA = {
'display_name': "New Word Cloud",
'instructions': "This is a Test",
'num_inputs': 5,
'num_top_words': 10,
'display_student_percents': 'False',
}
module_system = get_test_system()
block = WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock())
body = json.dumps(TEST_SUBMIT_DATA)
request = Request.blank('/')
request.method = 'POST'
request.body = body.encode('utf-8')
res = block.handle('studio_submit', request)
assert json.loads(res.body.decode('utf8')) == {'result': 'success'}

assert block.display_name == TEST_SUBMIT_DATA['display_name']
assert block.instructions == TEST_SUBMIT_DATA['instructions']
assert block.num_inputs == TEST_SUBMIT_DATA['num_inputs']
assert block.num_top_words == TEST_SUBMIT_DATA['num_top_words']
assert block.display_student_percents == (TEST_SUBMIT_DATA['display_student_percents'] == "True")

0 comments on commit 0d3f523

Please sign in to comment.