Example #1
0
    def test_update_children(self):
        """
        test updating an item's children ensuring the definition doesn't version but the course does if it should
        """
        locator = BlockUsageLocator(course_id="GreekHero", usage_id="chapter3", branch='draft')
        block = modulestore().get_item(locator)
        pre_def_id = block.definition_locator.definition_id
        pre_version_guid = block.location.version_guid

        # reorder children
        self.assertGreater(len(block.children), 0, "meaningless test")
        moved_child = block.children.pop()
        block.save()  # decache model changes
        updated_problem = modulestore().update_item(block, 'childchanger')
        # check that course version changed and course's previous is the other one
        self.assertEqual(updated_problem.definition_locator.definition_id, pre_def_id)
        self.assertNotEqual(updated_problem.location.version_guid, pre_version_guid)
        self.assertEqual(updated_problem.children, block.children)
        self.assertNotIn(moved_child, updated_problem.children)
        locator.usage_id = "chapter1"
        other_block = modulestore().get_item(locator)
        other_block.children.append(moved_child)
        other_block.save()  # decache model changes
        other_updated = modulestore().update_item(other_block, 'childchanger')
        self.assertIn(moved_child, other_updated.children)
Example #2
0
 def test_get_parents(self):
     '''
     get_parent_locations(locator, [usage_id], [branch]): [BlockUsageLocator]
     '''
     locator = BlockUsageLocator(course_id="GreekHero", branch='draft', usage_id='chapter1')
     parents = modulestore().get_parent_locations(locator)
     self.assertEqual(len(parents), 1)
     self.assertEqual(parents[0].usage_id, 'head12345')
     self.assertEqual(parents[0].course_id, "GreekHero")
     locator.usage_id = 'chapter2'
     parents = modulestore().get_parent_locations(locator)
     self.assertEqual(len(parents), 1)
     self.assertEqual(parents[0].usage_id, 'head12345')
     locator.usage_id = 'nosuchblock'
     parents = modulestore().get_parent_locations(locator)
     self.assertEqual(len(parents), 0)