Merge pull request #5655 from edx/ammar/unit-improvements

Unit Test Improvements
This commit is contained in:
Muhammad Ammar
2014-11-05 19:55:39 +05:00
38 changed files with 194 additions and 159 deletions

View File

@@ -11,6 +11,9 @@ from xmodule.modulestore.django import modulestore
from xmodule.modulestore.mongo.base import location_to_query
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.xml_importer import import_from_xml
from django.conf import settings
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
class ExportAllCourses(ModuleStoreTestCase):
@@ -30,7 +33,7 @@ class ExportAllCourses(ModuleStoreTestCase):
import_from_xml(
self.module_store,
'**replace_user**',
'common/test/data/',
TEST_DATA_DIR,
['dot-underscore'],
static_content_store=self.content_store,
do_import_static=True,

View File

@@ -56,6 +56,8 @@ from xmodule.contentstore.content import StaticContent
TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE)
class ContentStoreTestCase(CourseTestCase):
@@ -69,7 +71,7 @@ class ImportRequiredTestCases(ContentStoreTestCase):
Tests which legitimately need to import a course
"""
def test_no_static_link_rewrites_on_import(self):
course_items = import_from_xml(self.store, self.user.id, 'common/test/data/', ['toy'])
course_items = import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'])
course = course_items[0]
handouts_usage_key = course.id.make_usage_key('course_info', 'handouts')
@@ -81,7 +83,7 @@ class ImportRequiredTestCases(ContentStoreTestCase):
self.assertIn('/static/', handouts.data)
def test_xlint_fails(self):
err_cnt = perform_xlint('common/test/data', ['toy'])
err_cnt = perform_xlint(TEST_DATA_DIR, ['toy'])
self.assertGreater(err_cnt, 0)
def test_about_overrides(self):
@@ -90,7 +92,7 @@ class ImportRequiredTestCases(ContentStoreTestCase):
e.g. /about/Fall_2012/effort.html
while there is a base definition in /about/effort.html
'''
course_items = import_from_xml(self.store, self.user.id, 'common/test/data/', ['toy'])
course_items = import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'])
course_key = course_items[0].id
effort = self.store.get_item(course_key.make_usage_key('about', 'effort'))
self.assertEqual(effort.data, '6 hours')
@@ -105,7 +107,7 @@ class ImportRequiredTestCases(ContentStoreTestCase):
'''
content_store = contentstore()
import_from_xml(self.store, self.user.id, 'common/test/data/', ['toy'], static_content_store=content_store, verbose=True)
import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'], static_content_store=content_store, verbose=True)
course = self.store.get_course(SlashSeparatedCourseKey('edX', 'toy', '2012_Fall'))
@@ -153,7 +155,7 @@ class ImportRequiredTestCases(ContentStoreTestCase):
Test that course info updates are imported and exported with all content fields ('data', 'items')
"""
content_store = contentstore()
data_dir = "common/test/data/"
data_dir = TEST_DATA_DIR
courses = import_from_xml(
self.store, self.user.id, data_dir, ['course_info_updates'],
static_content_store=content_store, verbose=True,
@@ -166,7 +168,7 @@ class ImportRequiredTestCases(ContentStoreTestCase):
self.assertIsNotNone(course_updates)
# check that course which is imported has files 'updates.html' and 'updates.items.json'
filesystem = OSFS(data_dir + 'course_info_updates/info')
filesystem = OSFS(data_dir + '/course_info_updates/info')
self.assertTrue(filesystem.exists('updates.html'))
self.assertTrue(filesystem.exists('updates.items.json'))
@@ -204,7 +206,7 @@ class ImportRequiredTestCases(ContentStoreTestCase):
def test_rewrite_nonportable_links_on_import(self):
content_store = contentstore()
import_from_xml(self.store, self.user.id, 'common/test/data/', ['toy'], static_content_store=content_store)
import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'], static_content_store=content_store)
# first check a static asset link
course_key = SlashSeparatedCourseKey('edX', 'toy', 'run')
@@ -323,7 +325,7 @@ class ImportRequiredTestCases(ContentStoreTestCase):
def test_export_course_with_metadata_only_video(self):
content_store = contentstore()
import_from_xml(self.store, self.user.id, 'common/test/data/', ['toy'])
import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'])
course_id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
# create a new video module and add it as a child to a vertical
@@ -352,7 +354,7 @@ class ImportRequiredTestCases(ContentStoreTestCase):
"""
content_store = contentstore()
import_from_xml(self.store, self.user.id, 'common/test/data/', ['word_cloud'])
import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['word_cloud'])
course_id = SlashSeparatedCourseKey('HarvardX', 'ER22x', '2013_Spring')
verticals = self.store.get_items(course_id, qualifiers={'category': 'vertical'})
@@ -379,7 +381,7 @@ class ImportRequiredTestCases(ContentStoreTestCase):
"""
content_store = contentstore()
import_from_xml(self.store, self.user.id, 'common/test/data/', ['toy'])
import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'])
course_id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
verticals = self.store.get_items(course_id, qualifiers={'category': 'vertical'})
@@ -410,7 +412,7 @@ class ImportRequiredTestCases(ContentStoreTestCase):
"""
content_store = contentstore()
import_from_xml(self.store, self.user.id, 'common/test/data/', ['toy'])
import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'])
course_id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
@@ -432,7 +434,7 @@ class ImportRequiredTestCases(ContentStoreTestCase):
def test_export_course_without_content_store(self):
# Create toy course
course_items = import_from_xml(self.store, self.user.id, 'common/test/data/', ['toy'])
course_items = import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'])
course_id = course_items[0].id
root_dir = path(mkdtemp_clean())
@@ -1221,7 +1223,7 @@ class ContentStoreTest(ContentStoreTestCase):
)
self.assertEqual(resp.status_code, 200)
course_items = import_from_xml(self.store, self.user.id, 'common/test/data/', ['simple'])
course_items = import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['simple'])
course_key = course_items[0].id
resp = self._show_course_overview(course_key)
@@ -1268,7 +1270,7 @@ class ContentStoreTest(ContentStoreTestCase):
target_course_id = _get_course_id(self.course_data)
_create_course(self, target_course_id, self.course_data)
import_from_xml(self.store, self.user.id, 'common/test/data/', ['toy'], target_course_id=target_course_id)
import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'], target_course_id=target_course_id)
modules = self.store.get_items(target_course_id)
@@ -1303,7 +1305,7 @@ class ContentStoreTest(ContentStoreTestCase):
course_module.save()
# Import a course with wiki_slug == location.course
import_from_xml(self.store, self.user.id, 'common/test/data/', ['toy'], target_course_id=target_course_id)
import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'], target_course_id=target_course_id)
course_module = self.store.get_course(target_course_id)
self.assertEquals(course_module.wiki_slug, 'toy')
@@ -1318,17 +1320,17 @@ class ContentStoreTest(ContentStoreTestCase):
_create_course(self, target_course_id, course_data)
# Import a course with wiki_slug == location.course
import_from_xml(self.store, self.user.id, 'common/test/data/', ['toy'], target_course_id=target_course_id)
import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'], target_course_id=target_course_id)
course_module = self.store.get_course(target_course_id)
self.assertEquals(course_module.wiki_slug, 'MITx.111.2013_Spring')
# Now try importing a course with wiki_slug == '{0}.{1}.{2}'.format(location.org, location.course, location.run)
import_from_xml(self.store, self.user.id, 'common/test/data/', ['two_toys'], target_course_id=target_course_id)
import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['two_toys'], target_course_id=target_course_id)
course_module = self.store.get_course(target_course_id)
self.assertEquals(course_module.wiki_slug, 'MITx.111.2013_Spring')
def test_import_metadata_with_attempts_empty_string(self):
import_from_xml(self.store, self.user.id, 'common/test/data/', ['simple'])
import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['simple'])
did_load_item = False
try:
course_key = SlashSeparatedCourseKey('edX', 'simple', 'problem')
@@ -1350,7 +1352,7 @@ class ContentStoreTest(ContentStoreTestCase):
self.assertNotEquals(new_discussion_item.discussion_id, '$$GUID$$')
def test_metadata_inheritance(self):
course_items = import_from_xml(self.store, self.user.id, 'common/test/data/', ['toy'])
course_items = import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'])
course = course_items[0]
verticals = self.store.get_items(course.id, qualifiers={'category': 'vertical'})
@@ -1419,7 +1421,7 @@ class ContentStoreTest(ContentStoreTestCase):
courses = import_from_xml(
self.store,
self.user.id,
'common/test/data/',
TEST_DATA_DIR,
['conditional_and_poll'],
static_content_store=content_store
)

View File

@@ -24,6 +24,8 @@ from uuid import uuid4
TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
@ddt.ddt
@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE)
@@ -48,7 +50,7 @@ class ContentStoreImportTest(ModuleStoreTestCase):
import_from_xml(
module_store,
self.user.id,
'common/test/data/',
TEST_DATA_DIR,
['test_import_course'],
static_content_store=content_store,
do_import_static=False,
@@ -70,7 +72,7 @@ class ContentStoreImportTest(ModuleStoreTestCase):
course_items = import_from_xml(
module_store,
self.user.id,
'common/test/data',
TEST_DATA_DIR,
['test_import_course_2'],
target_course_id=course.id,
verbose=True,
@@ -86,7 +88,7 @@ class ContentStoreImportTest(ModuleStoreTestCase):
import_from_xml(
module_store,
self.user.id,
'common/test/data/',
TEST_DATA_DIR,
['2014_Uni'],
target_course_id=course_id
)
@@ -131,7 +133,7 @@ class ContentStoreImportTest(ModuleStoreTestCase):
content_store = contentstore()
module_store = modulestore()
import_from_xml(module_store, self.user.id, 'common/test/data/', ['toy'], static_content_store=content_store, do_import_static=False, verbose=True)
import_from_xml(module_store, self.user.id, TEST_DATA_DIR, ['toy'], static_content_store=content_store, do_import_static=False, verbose=True)
course = module_store.get_course(SlashSeparatedCourseKey('edX', 'toy', '2012_Fall'))
@@ -142,7 +144,7 @@ class ContentStoreImportTest(ModuleStoreTestCase):
def test_no_static_link_rewrites_on_import(self):
module_store = modulestore()
courses = import_from_xml(module_store, self.user.id, 'common/test/data/', ['toy'], do_import_static=False, verbose=True)
courses = import_from_xml(module_store, self.user.id, TEST_DATA_DIR, ['toy'], do_import_static=False, verbose=True)
course_key = courses[0].id
handouts = module_store.get_item(course_key.make_usage_key('course_info', 'handouts'))
@@ -183,7 +185,7 @@ class ContentStoreImportTest(ModuleStoreTestCase):
import_from_xml(
module_store,
self.user.id,
'common/test/data/',
TEST_DATA_DIR,
['conditional'],
target_course_id=target_course_id
)
@@ -213,7 +215,7 @@ class ContentStoreImportTest(ModuleStoreTestCase):
import_from_xml(
module_store,
self.user.id,
'common/test/data/',
TEST_DATA_DIR,
['open_ended'],
target_course_id=target_course_id
)
@@ -254,7 +256,7 @@ class ContentStoreImportTest(ModuleStoreTestCase):
import_from_xml(
module_store,
self.user.id,
'common/test/data/',
TEST_DATA_DIR,
[source_course_name],
target_course_id=target_course_id
)

View File

@@ -2,6 +2,9 @@ from xmodule.modulestore.xml_importer import import_from_xml
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.django import modulestore
from django.conf import settings
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
# This test is in the CMS module because the test configuration to use a draft
@@ -10,7 +13,7 @@ class DraftReorderTestCase(ModuleStoreTestCase):
def test_order(self):
store = modulestore()
course_items = import_from_xml(store, self.user.id, 'common/test/data/', ['import_draft_order'])
course_items = import_from_xml(store, self.user.id, TEST_DATA_DIR, ['import_draft_order'])
course_key = course_items[0].id
sequential = store.get_item(course_key.make_usage_key('sequential', '0f4f7649b10141b0bdc9922dcf94515a'))
verticals = sequential.children

View File

@@ -8,6 +8,9 @@ from xblock.fields import String
from xmodule.modulestore.xml_importer import import_from_xml
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.mongo.draft import as_draft
from django.conf import settings
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
class StubXBlock(XBlock):
@@ -58,7 +61,7 @@ class XBlockImportTest(ModuleStoreTestCase):
"""
courses = import_from_xml(
self.store, self.user.id, 'common/test/data', [course_dir]
self.store, self.user.id, TEST_DATA_DIR, [course_dir]
)
xblock_location = courses[0].id.make_usage_key('stubxblock', 'xblock_test')

View File

@@ -18,6 +18,9 @@ from student.models import Registration
from opaque_keys.edx.locations import SlashSeparatedCourseKey, AssetLocation
from contentstore.utils import reverse_url
from xmodule.modulestore.split_mongo.split import SplitMongoModuleStore
from django.conf import settings
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
def parse_json(response):
@@ -137,7 +140,7 @@ class CourseTestCase(ModuleStoreTestCase):
Imports the test toy course and populates it with additional test data
"""
content_store = contentstore()
import_from_xml(self.store, self.user.id, 'common/test/data/', ['toy'], static_content_store=content_store)
import_from_xml(self.store, self.user.id, TEST_DATA_DIR, ['toy'], static_content_store=content_store)
course_id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')
# create an Orphan

View File

@@ -21,6 +21,9 @@ from xmodule.modulestore.django import modulestore
from xmodule.modulestore.xml_importer import import_from_xml
from django.test.utils import override_settings
from opaque_keys.edx.locations import SlashSeparatedCourseKey, AssetLocation
from django.conf import settings
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
class AssetsTestCase(CourseTestCase):
@@ -54,7 +57,7 @@ class BasicAssetsTestCase(AssetsTestCase):
course_items = import_from_xml(
module_store,
self.user.id,
'common/test/data/',
TEST_DATA_DIR,
['toy'],
static_content_store=contentstore(),
verbose=True
@@ -247,7 +250,7 @@ class LockAssetTestCase(AssetsTestCase):
course_items = import_from_xml(
module_store,
self.user.id,
'common/test/data/',
TEST_DATA_DIR,
['toy'],
static_content_store=contentstore(),
verbose=True