Commit 42af561a by ichuang

pep8 and pylint for tests of nostatic import

parent 9b26e5bc
......@@ -18,7 +18,7 @@ class Command(BaseCommand):
make_option('--nostatic',
action='store_true',
help='Skip import of static content'),
)
)
def handle(self, *args, **options):
"Execute the command"
......
#pylint: disable=E1101
'''
Tests for importing with no static
'''
import json
import shutil
import sys
import mock
from django.test.client import Client
from django.test.utils import override_settings
from django.conf import settings
from django.core.urlresolvers import reverse
from path import path
import copy
from json import loads
from django.contrib.auth.models import User
from auth.authz import add_user_to_creator_group
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore import Location, mongo
from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore
from xmodule.contentstore.django import contentstore, _CONTENTSTORE
from xmodule.contentstore.django import contentstore
from xmodule.modulestore.xml_importer import import_from_xml
from xmodule.contentstore.content import StaticContent
......@@ -36,11 +30,20 @@ TEST_DATA_CONTENTSTORE['OPTIONS']['db'] = 'test_xcontent_%s' % uuid4().hex
class MongoCollectionFindWrapper(object):
'''
MongoCollectionFindWrapper for testing.
'''
def __init__(self, original):
"""
intit func
"""
self.original = original
self.counter = 0
def find(self, query, *args, **kwargs):
"""
find func
"""
self.counter = self.counter + 1
return self.original(query, *args, **kwargs)
......@@ -76,7 +79,7 @@ class ContentStoreImportNoStaticTest(ModuleStoreTestCase):
def load_test_import_course(self):
'''
Load the standard course used to test imports (for do_import_static=False behavior).
Load the standard course used to test imports (for do_import_static=False behavior).
'''
content_store = contentstore()
module_store = modulestore('direct')
......@@ -87,12 +90,11 @@ class ContentStoreImportNoStaticTest(ModuleStoreTestCase):
return module_store, content_store, course, course_location
def test_static_import(self):
'''
Stuff in static_import should always be imported into contentstore
'''
module_store, content_store, course, course_location = self.load_test_import_course()
_, content_store, course, course_location = self.load_test_import_course()
# make sure we have ONE asset in our contentstore ("should_be_imported.html")
all_assets = content_store.get_all_content_for_course(course_location)
......@@ -107,12 +109,11 @@ class ContentStoreImportNoStaticTest(ModuleStoreTestCase):
pass
self.assertIsNotNone(content)
# make sure course.lms.static_asset_path is correct
print "static_asset_path = {0}".format(course.lms.static_asset_path)
self.assertEqual(course.lms.static_asset_path, 'test_import_course')
def test_asset_import_nostatic(self):
'''
This test validates that an image asset is NOT imported when do_import_static=False
......@@ -123,14 +124,13 @@ class ContentStoreImportNoStaticTest(ModuleStoreTestCase):
import_from_xml(module_store, 'common/test/data/', ['toy'], static_content_store=content_store, do_import_static=False, verbose=True)
course_location = CourseDescriptor.id_to_location('edX/toy/2012_Fall')
course = module_store.get_item(course_location)
module_store.get_item(course_location)
# make sure we have NO assets in our contentstore
all_assets = content_store.get_all_content_for_course(course_location)
print "len(all_assets)=%d" % len(all_assets)
self.assertEqual(len(all_assets), 0)
def test_no_static_link_rewrites_on_import(self):
module_store = modulestore('direct')
import_from_xml(module_store, 'common/test/data/', ['toy'], do_import_static=False, verbose=True)
......@@ -140,4 +140,3 @@ class ContentStoreImportNoStaticTest(ModuleStoreTestCase):
handouts = module_store.get_item(Location(['i4x', 'edX', 'toy', 'html', 'toyhtml', None]))
self.assertIn('/static/', handouts.data)
......@@ -174,7 +174,6 @@ def import_from_xml(store, data_dir, course_dirs=None,
import_static_content(xml_module_store.modules[course_id], course_location, course_data_path, static_content_store,
_namespace_rename, subpath=simport, verbose=verbose)
# finally loop through all the modules
for module in xml_module_store.modules[course_id].itervalues():
......
......@@ -83,7 +83,7 @@ class ModuleRenderTestCase(LoginEnrollmentTestCase):
# See if the url got rewritten to the target link
# note if the URL mapping changes then this assertion will break
self.assertIn('/courses/'+self.course_id+'/jump_to_id/vertical_test', html)
self.assertIn('/courses/' + self.course_id + '/jump_to_id/vertical_test', html)
def test_modx_dispatch(self):
self.assertRaises(Http404, render.modx_dispatch, 'dummy', 'dummy',
......@@ -139,7 +139,6 @@ class ModuleRenderTestCase(LoginEnrollmentTestCase):
self.course_id
)
def test_xqueue_callback_success(self):
"""
Test for happy-path xqueue_callback
......@@ -356,10 +355,9 @@ class TestHtmlModifiers(ModuleStoreTestCase):
result_fragment.content
)
def test_static_asset_path_use(self):
'''
when a course is loaded with do_import_static=False (see xml_importer.py), then
when a course is loaded with do_import_static=False (see xml_importer.py), then
static_asset_path is set as an lms kv in course. That should make static paths
not be mangled (ie not changed to c4x://).
'''
......@@ -374,7 +372,6 @@ class TestHtmlModifiers(ModuleStoreTestCase):
result_fragment = module.runtime.render(module, None, 'student_view')
self.assertIn('href="/static/toy_course_dir', result_fragment.content)
def test_course_image(self):
url = course_image_url(self.course)
self.assertTrue(url.startswith('/c4x/'))
......@@ -384,14 +381,12 @@ class TestHtmlModifiers(ModuleStoreTestCase):
self.assertTrue(url.startswith('/static/toy_course_dir/'))
self.course.lms.static_asset_path = ""
def test_get_course_info_section(self):
self.course.lms.static_asset_path = "toy_course_dir"
handouts = get_course_info_section(self.request, self.course, "handouts")
get_course_info_section(self.request, self.course, "handouts")
# TODO: check handouts output...right now test course seems to have no such content
# at least this makes sure get_course_info_section returns without exception
def test_course_link_rewrite(self):
module = render.get_module(
self.user,
......
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