Commit 29038325 by David Ormsbee

Convert course_structure_api tests to SharedModuleStoreTestCase.

parent 830a695f
...@@ -16,7 +16,7 @@ from opaque_keys.edx.locator import CourseLocator ...@@ -16,7 +16,7 @@ from opaque_keys.edx.locator import CourseLocator
from xmodule.error_module import ErrorDescriptor from xmodule.error_module import ErrorDescriptor
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls
from xmodule.modulestore.xml import CourseLocationManager from xmodule.modulestore.xml import CourseLocationManager
from xmodule.tests import get_test_system from xmodule.tests import get_test_system
...@@ -38,7 +38,6 @@ class CourseViewTestsMixin(object): ...@@ -38,7 +38,6 @@ class CourseViewTestsMixin(object):
def setUp(self): def setUp(self):
super(CourseViewTestsMixin, self).setUp() super(CourseViewTestsMixin, self).setUp()
self.create_test_data()
self.create_user_and_access_token() self.create_user_and_access_token()
def create_user(self): def create_user(self):
...@@ -49,9 +48,10 @@ class CourseViewTestsMixin(object): ...@@ -49,9 +48,10 @@ class CourseViewTestsMixin(object):
self.oauth_client = ClientFactory.create() self.oauth_client = ClientFactory.create()
self.access_token = AccessTokenFactory.create(user=self.user, client=self.oauth_client).token self.access_token = AccessTokenFactory.create(user=self.user, client=self.oauth_client).token
def create_test_data(self): @classmethod
self.invalid_course_id = 'foo/bar/baz' def create_course_data(cls):
self.course = CourseFactory.create(display_name='An Introduction to API Testing', raw_grader=[ cls.invalid_course_id = 'foo/bar/baz'
cls.course = CourseFactory.create(display_name='An Introduction to API Testing', raw_grader=[
{ {
"min_count": 24, "min_count": 24,
"weight": 0.2, "weight": 0.2,
...@@ -67,40 +67,40 @@ class CourseViewTestsMixin(object): ...@@ -67,40 +67,40 @@ class CourseViewTestsMixin(object):
"short_label": "Exam" "short_label": "Exam"
} }
]) ])
self.course_id = unicode(self.course.id) cls.course_id = unicode(cls.course.id)
with cls.store.bulk_operations(cls.course.id, emit_signals=False):
self.sequential = ItemFactory.create( cls.sequential = ItemFactory.create(
category="sequential", category="sequential",
parent_location=self.course.location, parent_location=cls.course.location,
display_name="Lesson 1", display_name="Lesson 1",
format="Homework", format="Homework",
graded=True graded=True
) )
factory = MultipleChoiceResponseXMLFactory() factory = MultipleChoiceResponseXMLFactory()
args = {'choices': [False, True, False]} args = {'choices': [False, True, False]}
problem_xml = factory.build_xml(**args) problem_xml = factory.build_xml(**args)
self.problem = ItemFactory.create( cls.problem = ItemFactory.create(
category="problem", category="problem",
parent_location=self.sequential.location, parent_location=cls.sequential.location,
display_name="Problem 1", display_name="Problem 1",
format="Homework", format="Homework",
data=problem_xml, data=problem_xml,
) )
self.video = ItemFactory.create( cls.video = ItemFactory.create(
category="video", category="video",
parent_location=self.sequential.location, parent_location=cls.sequential.location,
display_name="Video 1", display_name="Video 1",
) )
self.html = ItemFactory.create( cls.html = ItemFactory.create(
category="html", category="html",
parent_location=self.sequential.location, parent_location=cls.sequential.location,
display_name="HTML 1", display_name="HTML 1",
) )
self.empty_course = CourseFactory.create( cls.empty_course = CourseFactory.create(
start=datetime(2014, 6, 16, 14, 30), start=datetime(2014, 6, 16, 14, 30),
end=datetime(2015, 1, 16), end=datetime(2015, 1, 16),
org="MTD", org="MTD",
...@@ -208,9 +208,14 @@ class CourseDetailTestMixin(object): ...@@ -208,9 +208,14 @@ class CourseDetailTestMixin(object):
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
class CourseListTests(CourseViewTestsMixin, ModuleStoreTestCase): class CourseListTests(CourseViewTestsMixin, SharedModuleStoreTestCase):
view = 'course_structure_api:v0:list' view = 'course_structure_api:v0:list'
@classmethod
def setUpClass(cls):
super(CourseListTests, cls).setUpClass()
cls.create_course_data()
def test_get(self): def test_get(self):
""" """
The view should return a list of all courses. The view should return a list of all courses.
...@@ -219,7 +224,6 @@ class CourseListTests(CourseViewTestsMixin, ModuleStoreTestCase): ...@@ -219,7 +224,6 @@ class CourseListTests(CourseViewTestsMixin, ModuleStoreTestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
data = response.data data = response.data
courses = data['results'] courses = data['results']
self.assertEqual(len(courses), 2) self.assertEqual(len(courses), 2)
self.assertEqual(data['count'], 2) self.assertEqual(data['count'], 2)
self.assertEqual(data['num_pages'], 1) self.assertEqual(data['num_pages'], 1)
...@@ -299,17 +303,27 @@ class CourseListTests(CourseViewTestsMixin, ModuleStoreTestCase): ...@@ -299,17 +303,27 @@ class CourseListTests(CourseViewTestsMixin, ModuleStoreTestCase):
self.test_get() self.test_get()
class CourseDetailTests(CourseDetailTestMixin, CourseViewTestsMixin, ModuleStoreTestCase): class CourseDetailTests(CourseDetailTestMixin, CourseViewTestsMixin, SharedModuleStoreTestCase):
view = 'course_structure_api:v0:detail' view = 'course_structure_api:v0:detail'
@classmethod
def setUpClass(cls):
super(CourseDetailTests, cls).setUpClass()
cls.create_course_data()
def test_get(self): def test_get(self):
response = super(CourseDetailTests, self).test_get() response = super(CourseDetailTests, self).test_get()
self.assertValidResponseCourse(response.data, self.course) self.assertValidResponseCourse(response.data, self.course)
class CourseStructureTests(CourseDetailTestMixin, CourseViewTestsMixin, ModuleStoreTestCase): class CourseStructureTests(CourseDetailTestMixin, CourseViewTestsMixin, SharedModuleStoreTestCase):
view = 'course_structure_api:v0:structure' view = 'course_structure_api:v0:structure'
@classmethod
def setUpClass(cls):
super(CourseStructureTests, cls).setUpClass()
cls.create_course_data()
def setUp(self): def setUp(self):
super(CourseStructureTests, self).setUp() super(CourseStructureTests, self).setUp()
...@@ -363,9 +377,14 @@ class CourseStructureTests(CourseDetailTestMixin, CourseViewTestsMixin, ModuleSt ...@@ -363,9 +377,14 @@ class CourseStructureTests(CourseDetailTestMixin, CourseViewTestsMixin, ModuleSt
self.assertDictEqual(response.data, expected) self.assertDictEqual(response.data, expected)
class CourseGradingPolicyTests(CourseDetailTestMixin, CourseViewTestsMixin, ModuleStoreTestCase): class CourseGradingPolicyTests(CourseDetailTestMixin, CourseViewTestsMixin, SharedModuleStoreTestCase):
view = 'course_structure_api:v0:grading_policy' view = 'course_structure_api:v0:grading_policy'
@classmethod
def setUpClass(cls):
super(CourseGradingPolicyTests, cls).setUpClass()
cls.create_course_data()
def test_get(self): def test_get(self):
""" """
The view should return grading policy for a course. The view should return grading policy for a course.
...@@ -480,6 +499,7 @@ class CourseBlocksOrNavigationTestMixin(CourseDetailTestMixin, CourseViewTestsMi ...@@ -480,6 +499,7 @@ class CourseBlocksOrNavigationTestMixin(CourseDetailTestMixin, CourseViewTestsMi
response = self.http_get_for_course(data={'block_json': 'incorrect'}) response = self.http_get_for_course(data={'block_json': 'incorrect'})
self.assertEqual(response.status_code, 400) self.assertEqual(response.status_code, 400)
@SharedModuleStoreTestCase.modifies_courseware
def test_no_access_to_block(self): def test_no_access_to_block(self):
""" """
Verifies the view returns only the top-level course block, excluding the sequential block Verifies the view returns only the top-level course block, excluding the sequential block
...@@ -576,15 +596,20 @@ class CourseNavigationTestMixin(object): ...@@ -576,15 +596,20 @@ class CourseNavigationTestMixin(object):
self.assertEquals(len(block['descendants']), expected_num_descendants) self.assertEquals(len(block['descendants']), expected_num_descendants)
class CourseBlocksTests(CourseBlocksOrNavigationTestMixin, CourseBlocksTestMixin, ModuleStoreTestCase): class CourseBlocksTests(CourseBlocksOrNavigationTestMixin, CourseBlocksTestMixin, SharedModuleStoreTestCase):
""" """
A Test class for testing the Course 'blocks' view. A Test class for testing the Course 'blocks' view.
""" """
block_navigation_view_type = 'blocks' block_navigation_view_type = 'blocks'
container_fields = ['children'] container_fields = ['children']
@classmethod
def setUpClass(cls):
super(CourseBlocksTests, cls).setUpClass()
cls.create_course_data()
class CourseNavigationTests(CourseBlocksOrNavigationTestMixin, CourseNavigationTestMixin, ModuleStoreTestCase): class CourseNavigationTests(CourseBlocksOrNavigationTestMixin, CourseNavigationTestMixin, SharedModuleStoreTestCase):
""" """
A Test class for testing the Course 'navigation' view. A Test class for testing the Course 'navigation' view.
""" """
...@@ -592,11 +617,21 @@ class CourseNavigationTests(CourseBlocksOrNavigationTestMixin, CourseNavigationT ...@@ -592,11 +617,21 @@ class CourseNavigationTests(CourseBlocksOrNavigationTestMixin, CourseNavigationT
container_fields = ['descendants'] container_fields = ['descendants']
block_fields = [] block_fields = []
@classmethod
def setUpClass(cls):
super(CourseNavigationTests, cls).setUpClass()
cls.create_course_data()
class CourseBlocksAndNavigationTests(CourseBlocksOrNavigationTestMixin, CourseBlocksTestMixin, class CourseBlocksAndNavigationTests(CourseBlocksOrNavigationTestMixin, CourseBlocksTestMixin,
CourseNavigationTestMixin, ModuleStoreTestCase): CourseNavigationTestMixin, SharedModuleStoreTestCase):
""" """
A Test class for testing the Course 'blocks+navigation' view. A Test class for testing the Course 'blocks+navigation' view.
""" """
block_navigation_view_type = 'blocks+navigation' block_navigation_view_type = 'blocks+navigation'
container_fields = ['children', 'descendants'] container_fields = ['children', 'descendants']
@classmethod
def setUpClass(cls):
super(CourseBlocksAndNavigationTests, cls).setUpClass()
cls.create_course_data()
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