Skip to content

Commit

Permalink
fix: fix the test case
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan committed Jan 16, 2025
1 parent a9e8fae commit c84be1f
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions xmodule/tests/test_word_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import json
import os
from io import BytesIO
from unittest.mock import Mock
from lxml.etree import ElementTree

from django.test import TestCase
from fs.memoryfs import MemoryFS
Expand Down Expand Up @@ -40,7 +38,7 @@ def test_xml_import_export_cycle(self):
runtime.export_fs = MemoryFS()

original_xml = (
'<word_cloud display_name="Favorite Fruits" display_student_percents="false" '
'<word_cloud xblock-family="xblock.v1" display_name="Favorite Fruits" display_student_percents="false" '
'instructions="What are your favorite fruits?" num_inputs="3" num_top_words="100"/>\n'
)

Expand All @@ -61,17 +59,17 @@ def test_xml_import_export_cycle(self):

filepath = 'word_cloud/block_id.xml'
runtime.export_fs.makedirs(os.path.dirname(filepath), recreate=True)
# exported_xml_buffer = BytesIO()
with runtime.export_fs.open(filepath, 'wb') as fileobj:
# ElementTree(xml_object).write(fileobj, pretty_print=True, encoding='utf-8')
runtime.export_to_xml(block, fileobj)

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

# FIXME: Fix this case
# assert original_xml == exported_xml
# assert exported_xml_buffer.getvalue() == original_xml
exported_xml_tree = etree.fromstring(exported_xml.encode('utf-8'))
etree.cleanup_namespaces(etree.fromstring(exported_xml.encode('utf-8')))
exported_xml = etree.tostring(exported_xml_tree, encoding='unicode', pretty_print=True)

assert original_xml == exported_xml

def test_bad_ajax_request(self):
"""
Expand Down Expand Up @@ -123,7 +121,7 @@ def test_indexibility(self):

module_system = get_test_system()
block = WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock())
assert block.index_dictionary() ==\
assert block.index_dictionary() == \
{'content_type': 'Word Cloud',
'content': {'display_name': 'Word Cloud Block',
'instructions': 'Enter some random words that comes to your mind'}}

0 comments on commit c84be1f

Please sign in to comment.