Commit 1f17538d by Calen Pennington

Clean up tests in preparation for switching Vertical from an XModule to an XBlock

parent 33361a05
......@@ -61,7 +61,7 @@ def see_a_multi_step_component(step, category):
'Raw HTML': '<p>This template is similar to the Text template. The only difference is',
}
actual_html = world.css_html(selector, index=idx)
assert_in(html_matcher[step_hash['Component']], actual_html)
assert_in(html_matcher[step_hash['Component']].strip(), actual_html.strip())
else:
actual_text = world.css_text(selector, index=idx)
assert_in(step_hash['Component'].upper(), actual_text)
......
......@@ -27,7 +27,7 @@ def add_page(step):
def see_a_static_page_named_foo(step, name):
pages_css = 'div.xmodule_StaticTabModule'
page_name_html = world.css_html(pages_css)
assert_equal(page_name_html, '\n {name}\n'.format(name=name))
assert_equal(page_name_html.strip(), name)
@step(u'I should not see any static pages$')
......
......@@ -5,6 +5,7 @@ import ddt
from mock import patch, Mock, PropertyMock
from pytz import UTC
from pyquery import PyQuery
from webob import Response
from django.http import Http404
......@@ -1026,7 +1027,8 @@ class TestEditItemSplitMongo(TestEditItemSetup):
for __ in xrange(3):
resp = self.client.get(view_url, HTTP_ACCEPT='application/json')
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.content.count('xblock-{}'.format(STUDIO_VIEW)), 1)
content = json.loads(resp.content)
self.assertEqual(len(PyQuery(content['html'])('.xblock-{}'.format(STUDIO_VIEW))), 1)
class TestEditSplitModule(ItemTest):
......
......@@ -9,6 +9,7 @@ For processing xml always prefer this over using lxml.etree directly.
from lxml.etree import * # pylint: disable=wildcard-import, unused-wildcard-import
from lxml.etree import XMLParser as _XMLParser
from lxml.etree import _ElementTree # pylint: disable=unused-import
# This should be imported after lxml.etree so that it overrides the following attributes.
from defusedxml.lxml import parse, fromstring, XML
......
......@@ -20,6 +20,7 @@ from nose.plugins.attrib import attr
import pymongo
from pytz import UTC
from xmodule.x_module import XModuleMixin
from xmodule.modulestore.edit_info import EditInfoMixin
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.tests.test_cross_modulestore_import_export import MongoContentstoreBuilder
......@@ -73,7 +74,7 @@ class TestMixedModuleStore(CourseComparisonTest):
'default_class': DEFAULT_CLASS,
'fs_root': DATA_DIR,
'render_template': RENDER_TEMPLATE,
'xblock_mixins': (EditInfoMixin, InheritanceMixin, LocationMixin),
'xblock_mixins': (EditInfoMixin, InheritanceMixin, LocationMixin, XModuleMixin),
}
DOC_STORE_CONFIG = {
'host': HOST,
......
......@@ -41,8 +41,10 @@ from git.test.lib.asserts import assert_not_none
from xmodule.x_module import XModuleMixin
from xmodule.modulestore.mongo.base import as_draft
from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST
from xmodule.modulestore.tests.utils import LocationMixin
from xmodule.modulestore.edit_info import EditInfoMixin
from xmodule.modulestore.exceptions import ItemNotFoundError
from xmodule.modulestore.inheritance import InheritanceMixin
log = logging.getLogger(__name__)
......@@ -124,7 +126,7 @@ class TestMongoModuleStoreBase(unittest.TestCase):
doc_store_config, FS_ROOT, RENDER_TEMPLATE,
default_class=DEFAULT_CLASS,
branch_setting_func=lambda: ModuleStoreEnum.Branch.draft_preferred,
xblock_mixins=(EditInfoMixin,)
xblock_mixins=(EditInfoMixin, InheritanceMixin, LocationMixin, XModuleMixin)
)
import_course_from_xml(
......
......@@ -8,6 +8,7 @@ import mock
from opaque_keys.edx.locator import CourseLocator, BlockUsageLocator
from xmodule.modulestore import ModuleStoreEnum
from xmodule.x_module import XModuleMixin
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.mongo import DraftMongoModuleStore
from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore
......@@ -41,7 +42,7 @@ class SplitWMongoCourseBoostrapper(unittest.TestCase):
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': '',
'render_template': mock.Mock(return_value=""),
'xblock_mixins': (InheritanceMixin,)
'xblock_mixins': (InheritanceMixin, XModuleMixin)
}
split_course_key = CourseLocator('test_org', 'test_course', 'runid', branch=ModuleStoreEnum.BranchName.draft)
......
......@@ -9,6 +9,7 @@ from mock import patch
from xmodule.modulestore.xml import XMLModuleStore
from xmodule.modulestore import ModuleStoreEnum
from xmodule.x_module import XModuleMixin
from xmodule.tests import DATA_DIR
from opaque_keys.edx.locations import SlashSeparatedCourseKey
......@@ -46,7 +47,11 @@ class TestXMLModuleStore(unittest.TestCase):
# Load the course, but don't make error modules. This will succeed,
# but will record the errors.
modulestore = XMLModuleStore(DATA_DIR, source_dirs=['toy'], load_error_modules=False)
modulestore = XMLModuleStore(
DATA_DIR,
source_dirs=['toy'],
xblock_mixins=(XModuleMixin,),
load_error_modules=False)
# Look up the errors during load. There should be none.
errors = modulestore.get_course_errors(SlashSeparatedCourseKey("edX", "toy", "2012_Fall"))
......@@ -119,7 +124,11 @@ class TestXMLModuleStore(unittest.TestCase):
"""
Test a course whose structure is not a tree.
"""
store = XMLModuleStore(DATA_DIR, source_dirs=['xml_dag'])
store = XMLModuleStore(
DATA_DIR,
source_dirs=['xml_dag'],
xblock_mixins=(XModuleMixin,),
)
course_key = store.get_courses()[0].id
mock_logging.warning.assert_called_with(
......
......@@ -5,6 +5,7 @@ from importlib import import_module
from opaque_keys.edx.keys import UsageKey
from unittest import TestCase
from xblock.fields import XBlockMixin
from xmodule.x_module import XModuleMixin
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.draft_and_published import ModuleStoreDraftAndPublished
from xmodule.modulestore.edit_info import EditInfoMixin
......@@ -84,7 +85,7 @@ class MixedSplitTestCase(TestCase):
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': DATA_DIR,
'render_template': RENDER_TEMPLATE,
'xblock_mixins': (EditInfoMixin, InheritanceMixin, LocationMixin),
'xblock_mixins': (EditInfoMixin, InheritanceMixin, LocationMixin, XModuleMixin),
}
DOC_STORE_CONFIG = {
'host': MONGO_HOST,
......
......@@ -32,7 +32,7 @@ from lxml import etree
from xmodule.modulestore.xml import XMLModuleStore, LibraryXMLModuleStore, ImportSystem
from xblock.runtime import KvsFieldData, DictKeyValueStore
from xmodule.x_module import XModuleDescriptor
from xmodule.x_module import XModuleDescriptor, XModuleMixin
from opaque_keys.edx.keys import UsageKey
from xblock.fields import Scope, Reference, ReferenceList, ReferenceValueDict
from xmodule.contentstore.content import StaticContent
......@@ -47,6 +47,7 @@ from xmodule.modulestore.exceptions import DuplicateCourseError
from xmodule.modulestore.mongo.base import MongoRevisionKey
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.store_utilities import draft_node_constructor, get_draft_subtree_roots
from xmodule.modulestore.tests.utils import LocationMixin
log = logging.getLogger(__name__)
......@@ -1031,7 +1032,8 @@ def validate_course_policy(module_store, course_id):
def perform_xlint(
data_dir, source_dirs,
default_class='xmodule.raw_module.RawDescriptor',
load_error_modules=True):
load_error_modules=True,
xblock_mixins=(LocationMixin, XModuleMixin)):
err_cnt = 0
warn_cnt = 0
......@@ -1039,7 +1041,8 @@ def perform_xlint(
data_dir,
default_class=default_class,
source_dirs=source_dirs,
load_error_modules=load_error_modules
load_error_modules=load_error_modules,
xblock_mixins=xblock_mixins
)
# check all data source path information
......
......@@ -86,6 +86,21 @@ class TestModuleSystem(ModuleSystem): # pylint: disable=abstract-method
def get_asides(self, block):
return []
def __repr__(self):
"""
Custom hacky repr.
XBlock.Runtime.render() replaces the _view_name attribute while rendering, which
causes rendered comparisons of blocks to fail as unequal. So make the _view_name
attribute None during the base repr - and set it back to original value afterward.
"""
orig_view_name = None
if hasattr(self, '_view_name'):
orig_view_name = self._view_name
self._view_name = None
rt_repr = super(TestModuleSystem, self).__repr__()
self._view_name = orig_view_name
return rt_repr
def get_test_system(course_id=SlashSeparatedCourseKey('org', 'course', 'run')):
"""
......
......@@ -9,6 +9,7 @@ from factory import Factory, lazy_attribute, post_generation, Sequence
from lxml import etree
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.x_module import XModuleMixin
from xmodule.modulestore import only_xmodules
......@@ -66,7 +67,7 @@ class XmlImportFactory(Factory):
FACTORY_FOR = XmlImportData
filesystem = MemoryFS()
xblock_mixins = (InheritanceMixin,)
xblock_mixins = (InheritanceMixin, XModuleMixin)
xblock_select = only_xmodules
url_name = Sequence(str)
attribs = {}
......
......@@ -126,9 +126,12 @@ class CommandsTestBase(ModuleStoreTestCase):
self.assertEqual(dump[child_id]['category'], 'videosequence')
self.assertEqual(len(dump[child_id]['children']), 2)
video_id = test_course_key.make_usage_key('video', 'Welcome').to_deprecated_string()
video_id = unicode(test_course_key.make_usage_key('video', 'Welcome'))
self.assertEqual(dump[video_id]['category'], 'video')
self.assertEqual(len(dump[video_id]['metadata']), 5)
self.assertItemsEqual(
dump[video_id]['metadata'].keys(),
['download_video', 'youtube_id_0_75', 'youtube_id_1_0', 'youtube_id_1_25', 'youtube_id_1_5']
)
self.assertIn('youtube_id_1_0', dump[video_id]['metadata'])
# Check if there are the right number of elements
......
......@@ -16,6 +16,7 @@ from django.contrib.auth.models import AnonymousUser
from mock import MagicMock, patch, Mock
from opaque_keys.edx.keys import UsageKey, CourseKey
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from pyquery import PyQuery
from courseware.module_render import hash_resource
from xblock.field_data import FieldData
from xblock.runtime import Runtime
......@@ -430,7 +431,8 @@ class TestHandleXBlockCallback(ModuleStoreTestCase, LoginEnrollmentTestCase):
content = json.loads(response.content)
for section in expected:
self.assertIn(section, content)
self.assertIn('<div class="xblock xblock-student_view xmodule_display', content['html'])
doc = PyQuery(content['html'])
self.assertEquals(len(doc('div.xblock.xblock-student_view')), 1)
@ddt.ddt
......@@ -567,7 +569,7 @@ class TestHtmlModifiers(ModuleStoreTestCase):
)
result_fragment = module.render(STUDENT_VIEW)
self.assertIn('div class="xblock xblock-student_view xmodule_display xmodule_HtmlModule"', result_fragment.content)
self.assertEquals(len(PyQuery(result_fragment.content)('div.xblock.xblock-student_view.xmodule_HtmlModule')), 1)
def test_xmodule_display_wrapper_disabled(self):
module = render.get_module(
......
......@@ -144,6 +144,7 @@ pep8==1.5.7
PyContracts==1.7.1
pylint==1.4.2
python-subunit==0.0.16
pyquery==1.2.9
radon==1.2
rednose==0.3
selenium==2.42.1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment