Commit c0ee1940 by Nimisha Asthagiri

Pylint issues in test_mixed_modulestore.py.

parent 9c942d7e
# pylint: disable=no-member
"""
Unit tests for the Mixed Modulestore, with DDT for the various stores (Split, Draft, XML)
"""
import datetime import datetime
import ddt import ddt
import itertools import itertools
...@@ -92,7 +96,7 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -92,7 +96,7 @@ class TestMixedModuleStore(unittest.TestCase):
] ]
} }
def _compareIgnoreVersion(self, loc1, loc2, msg=None): def _compare_ignore_version(self, loc1, loc2, msg=None):
""" """
AssertEqual replacement for CourseLocator AssertEqual replacement for CourseLocator
""" """
...@@ -114,8 +118,8 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -114,8 +118,8 @@ class TestMixedModuleStore(unittest.TestCase):
self.addCleanup(self.connection.close) self.addCleanup(self.connection.close)
super(TestMixedModuleStore, self).setUp() super(TestMixedModuleStore, self).setUp()
self.addTypeEqualityFunc(BlockUsageLocator, '_compareIgnoreVersion') self.addTypeEqualityFunc(BlockUsageLocator, '_compare_ignore_version')
self.addTypeEqualityFunc(CourseLocator, '_compareIgnoreVersion') self.addTypeEqualityFunc(CourseLocator, '_compare_ignore_version')
# define attrs which get set in initdb to quell pylint # define attrs which get set in initdb to quell pylint
self.writable_chapter_location = self.store = self.fake_location = self.xml_chapter_location = None self.writable_chapter_location = self.store = self.fake_location = self.xml_chapter_location = None
self.course_locations = [] self.course_locations = []
...@@ -123,7 +127,7 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -123,7 +127,7 @@ class TestMixedModuleStore(unittest.TestCase):
self.user_id = ModuleStoreEnum.UserID.test self.user_id = ModuleStoreEnum.UserID.test
# pylint: disable=invalid-name # pylint: disable=invalid-name
def _create_course(self, default, course_key): def _create_course(self, course_key):
""" """
Create a course w/ one item in the persistence store using the given course & item location. Create a course w/ one item in the persistence store using the given course & item location.
""" """
...@@ -187,6 +191,9 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -187,6 +191,9 @@ class TestMixedModuleStore(unittest.TestCase):
] ]
def create_sub_tree(parent, block_info): def create_sub_tree(parent, block_info):
"""
recursive function that creates the given block and its descendants
"""
block = self.store.create_child( block = self.store.create_child(
self.user_id, parent.location, self.user_id, parent.location,
block_info.category, block_id=block_info.display_name, block_info.category, block_id=block_info.display_name,
...@@ -207,6 +214,9 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -207,6 +214,9 @@ class TestMixedModuleStore(unittest.TestCase):
return self.course_locations[string].course_key return self.course_locations[string].course_key
def _initialize_mixed(self): def _initialize_mixed(self):
"""
initializes the mixed modulestore
"""
self.store = MixedModuleStore(None, create_modulestore_instance=create_modulestore_instance, **self.options) self.store = MixedModuleStore(None, create_modulestore_instance=create_modulestore_instance, **self.options)
self.addCleanup(self.store.close_all_connections) self.addCleanup(self.store.close_all_connections)
...@@ -239,7 +249,7 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -239,7 +249,7 @@ class TestMixedModuleStore(unittest.TestCase):
self.xml_chapter_location = self.course_locations[self.XML_COURSEID1].replace( self.xml_chapter_location = self.course_locations[self.XML_COURSEID1].replace(
category='chapter', name='Overview' category='chapter', name='Overview'
) )
self._create_course(default, self.course_locations[self.MONGO_COURSEID].course_key) self._create_course(self.course_locations[self.MONGO_COURSEID].course_key)
@ddt.data('draft', 'split') @ddt.data('draft', 'split')
def test_get_modulestore_type(self, default_ms): def test_get_modulestore_type(self, default_ms):
...@@ -448,6 +458,9 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -448,6 +458,9 @@ class TestMixedModuleStore(unittest.TestCase):
self.assertFalse(self.store.has_changes(component)) self.assertFalse(self.store.has_changes(component))
def _has_changes(self, location): def _has_changes(self, location):
"""
Helper function that loads the item before calling has_changes
"""
return self.store.has_changes(self.store.get_item(location)) return self.store.has_changes(self.store.get_item(location))
def setup_has_changes(self, default_ms): def setup_has_changes(self, default_ms):
...@@ -706,7 +719,7 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -706,7 +719,7 @@ class TestMixedModuleStore(unittest.TestCase):
# create and delete a private vertical with private children # create and delete a private vertical with private children
private_vert = self.store.create_child( private_vert = self.store.create_child(
# don't use course_location as it may not be the repr # don't use course_location as it may not be the repr
self.user_id, self.course_locations[self.MONGO_COURSEID], 'vertical', block_id='publish' self.user_id, self.course_locations[self.MONGO_COURSEID], 'vertical', block_id='publish'
) )
private_leaf = self.store.create_child( private_leaf = self.store.create_child(
self.user_id, private_vert.location, 'html', block_id='bug_leaf' self.user_id, private_vert.location, 'html', block_id='bug_leaf'
...@@ -748,13 +761,12 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -748,13 +761,12 @@ class TestMixedModuleStore(unittest.TestCase):
published_courses = self.store.get_courses(remove_branch=True) published_courses = self.store.get_courses(remove_branch=True)
self.assertEquals([c.id for c in draft_courses], [c.id for c in published_courses]) self.assertEquals([c.id for c in draft_courses], [c.id for c in published_courses])
def test_xml_get_courses(self): def test_xml_get_courses(self):
""" """
Test that the xml modulestore only loaded the courses from the maps. Test that the xml modulestore only loaded the courses from the maps.
""" """
self.initdb('draft') self.initdb('draft')
xml_store = self.store._get_modulestore_by_type(ModuleStoreEnum.Type.xml) xml_store = self.store._get_modulestore_by_type(ModuleStoreEnum.Type.xml) # pylint: disable=protected-access
courses = xml_store.get_courses() courses = xml_store.get_courses()
self.assertEqual(len(courses), 2) self.assertEqual(len(courses), 2)
course_ids = [course.id for course in courses] course_ids = [course.id for course in courses]
...@@ -768,7 +780,7 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -768,7 +780,7 @@ class TestMixedModuleStore(unittest.TestCase):
Test that the xml modulestore doesn't allow write ops. Test that the xml modulestore doesn't allow write ops.
""" """
self.initdb('draft') self.initdb('draft')
xml_store = self.store._get_modulestore_by_type(ModuleStoreEnum.Type.xml) xml_store = self.store._get_modulestore_by_type(ModuleStoreEnum.Type.xml) # pylint: disable=protected-access
# the important thing is not which exception it raises but that it raises an exception # the important thing is not which exception it raises but that it raises an exception
with self.assertRaises(AttributeError): with self.assertRaises(AttributeError):
xml_store.create_course("org", "course", "run", self.user_id) xml_store.create_course("org", "course", "run", self.user_id)
...@@ -811,6 +823,9 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -811,6 +823,9 @@ class TestMixedModuleStore(unittest.TestCase):
self.assertEqual(parent, self.course_locations[self.XML_COURSEID1]) self.assertEqual(parent, self.course_locations[self.XML_COURSEID1])
def verify_get_parent_locations_results(self, expected_results): def verify_get_parent_locations_results(self, expected_results):
"""
Verifies the results of calling get_parent_locations matches expected_results.
"""
for child_location, parent_location, revision in expected_results: for child_location, parent_location, revision in expected_results:
self.assertEqual( self.assertEqual(
parent_location, parent_location,
...@@ -1107,7 +1122,7 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -1107,7 +1122,7 @@ class TestMixedModuleStore(unittest.TestCase):
self.store.publish(self.course.location, self.user_id) self.store.publish(self.course.location, self.user_id)
# test that problem "problem_x1a_1" has only one published parent # test that problem "problem_x1a_1" has only one published parent
mongo_store = self.store._get_modulestore_for_courseid(course_id) mongo_store = self.store._get_modulestore_for_courseid(course_id) # pylint: disable=protected-access
with self.store.branch_setting(ModuleStoreEnum.Branch.published_only, course_id): with self.store.branch_setting(ModuleStoreEnum.Branch.published_only, course_id):
parent = mongo_store.get_parent_location(self.problem_x1a_1) parent = mongo_store.get_parent_location(self.problem_x1a_1)
self.assertEqual(parent, self.vertical_x1a) self.assertEqual(parent, self.vertical_x1a)
...@@ -1353,10 +1368,8 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -1353,10 +1368,8 @@ class TestMixedModuleStore(unittest.TestCase):
after_create = datetime.datetime.now(UTC) after_create = datetime.datetime.now(UTC)
# Verify that all nodes were last edited in the past by create_user # Verify that all nodes were last edited in the past by create_user
[ for block in [component, child, sibling]:
check_node(block.location, None, after_create, self.user_id, None, after_create, self.user_id) check_node(block.location, None, after_create, self.user_id, None, after_create, self.user_id)
for block in [component, child, sibling]
]
# Change the component, then check that there now are changes # Change the component, then check that there now are changes
component.display_name = 'Changed Display Name' component.display_name = 'Changed Display Name'
...@@ -1368,7 +1381,6 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -1368,7 +1381,6 @@ class TestMixedModuleStore(unittest.TestCase):
# but child didn't change # but child didn't change
check_node(child.location, None, after_create, self.user_id, None, after_create, self.user_id) check_node(child.location, None, after_create, self.user_id, None, after_create, self.user_id)
# Change the child # Change the child
child = self.store.get_item(child.location) child = self.store.get_item(child.location)
child.display_name = 'Changed Display Name' child.display_name = 'Changed Display Name'
...@@ -1642,11 +1654,13 @@ class TestMixedModuleStore(unittest.TestCase): ...@@ -1642,11 +1654,13 @@ class TestMixedModuleStore(unittest.TestCase):
assertNumProblems(problem_original_name, 0) assertNumProblems(problem_original_name, 0)
def verify_default_store(self, store_type): def verify_default_store(self, store_type):
# verify default_store property """
Verifies the default_store property
"""
self.assertEquals(self.store.default_modulestore.get_modulestore_type(), store_type) self.assertEquals(self.store.default_modulestore.get_modulestore_type(), store_type)
# verify internal helper method # verify internal helper method
store = self.store._get_modulestore_for_courseid() store = self.store._get_modulestore_for_courseid() # pylint: disable=protected-access
self.assertEquals(store.get_modulestore_type(), store_type) self.assertEquals(store.get_modulestore_type(), store_type)
# verify store used for creating a course # verify store used for creating a course
......
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