Commit 36d321c4 by Waheed Ahmed

Merge pull request #8496 from edx/waheed/plat674-improve-test-with-ddt

Specified number of mongo and split calls in xblock outline handler test with ddt.
parents 04eff800 4323109c
...@@ -333,7 +333,7 @@ def xblock_outline_handler(request, usage_key_string): ...@@ -333,7 +333,7 @@ def xblock_outline_handler(request, usage_key_string):
if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'): if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'):
store = modulestore() store = modulestore()
with store.bulk_operations(usage_key.course_key): with store.bulk_operations(usage_key.course_key):
root_xblock = store.get_item(usage_key) root_xblock = store.get_item(usage_key, depth=None)
return JsonResponse(create_xblock_info( return JsonResponse(create_xblock_info(
root_xblock, root_xblock,
include_child_info=True, include_child_info=True,
......
...@@ -1384,6 +1384,7 @@ class TestComponentTemplates(CourseTestCase): ...@@ -1384,6 +1384,7 @@ class TestComponentTemplates(CourseTestCase):
self.assertEqual(template_display_names, ['Annotation', 'Open Response Assessment', 'Peer Grading Interface']) self.assertEqual(template_display_names, ['Annotation', 'Open Response Assessment', 'Peer Grading Interface'])
@ddt.ddt
class TestXBlockInfo(ItemTest): class TestXBlockInfo(ItemTest):
""" """
Unit tests for XBlock's outline handling. Unit tests for XBlock's outline handling.
...@@ -1410,15 +1411,19 @@ class TestXBlockInfo(ItemTest): ...@@ -1410,15 +1411,19 @@ class TestXBlockInfo(ItemTest):
json_response = json.loads(resp.content) json_response = json.loads(resp.content)
self.validate_course_xblock_info(json_response, course_outline=True) self.validate_course_xblock_info(json_response, course_outline=True)
def test_xblock_outline_handler_mongo_calls(self): @ddt.data(
expected_calls = 5 (ModuleStoreEnum.Type.split, 5, 5),
with self.store.default_store(ModuleStoreEnum.Type.split): (ModuleStoreEnum.Type.mongo, 4, 6),
)
@ddt.unpack
def test_xblock_outline_handler_mongo_calls(self, store_type, chapter_queries, chapter_queries_1):
with self.store.default_store(store_type):
course = CourseFactory.create() course = CourseFactory.create()
chapter = ItemFactory.create( chapter = ItemFactory.create(
parent_location=course.location, category='chapter', display_name='Week 1' parent_location=course.location, category='chapter', display_name='Week 1'
) )
outline_url = reverse_usage_url('xblock_outline_handler', chapter.location) outline_url = reverse_usage_url('xblock_outline_handler', chapter.location)
with check_mongo_calls(expected_calls): with check_mongo_calls(chapter_queries):
self.client.get(outline_url, HTTP_ACCEPT='application/json') self.client.get(outline_url, HTTP_ACCEPT='application/json')
sequential = ItemFactory.create( sequential = ItemFactory.create(
...@@ -1428,8 +1433,8 @@ class TestXBlockInfo(ItemTest): ...@@ -1428,8 +1433,8 @@ class TestXBlockInfo(ItemTest):
ItemFactory.create( ItemFactory.create(
parent_location=sequential.location, category='vertical', display_name='Vertical 1' parent_location=sequential.location, category='vertical', display_name='Vertical 1'
) )
# calls should be same after adding two new children. # calls should be same after adding two new children for split only.
with check_mongo_calls(expected_calls): with check_mongo_calls(chapter_queries_1):
self.client.get(outline_url, HTTP_ACCEPT='application/json') self.client.get(outline_url, HTTP_ACCEPT='application/json')
def test_entrance_exam_chapter_xblock_info(self): def test_entrance_exam_chapter_xblock_info(self):
......
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