Esempio n. 1
0
 def test_persist_dag(self):
     """
     try saving temporary xblocks
     """
     test_course = persistent_factories.PersistentCourseFactory.create(org='testx', prettyid='tempcourse',
         display_name='fun test course', user_id='testbot')
     test_chapter = XModuleDescriptor.load_from_json({'category': 'chapter',
         'metadata': {'display_name': 'chapter n'}},
         test_course.system, parent_xblock=test_course)
     test_def_content = '<problem>boo</problem>'
     test_problem = XModuleDescriptor.load_from_json({'category': 'problem',
         'definition': {'data': test_def_content}},
         test_course.system, parent_xblock=test_chapter)
     # better to pass in persisted parent over the subdag so
     # subdag gets the parent pointer (otherwise 2 ops, persist dag, update parent children,
     # persist parent
     persisted_course = modulestore('split').persist_xblock_dag(test_course, 'testbot')
     self.assertEqual(len(persisted_course.children), 1)
     persisted_chapter = persisted_course.get_children()[0]
     self.assertEqual(persisted_chapter.category, 'chapter')
     self.assertEqual(persisted_chapter.display_name, 'chapter n')
     self.assertEqual(len(persisted_chapter.children), 1)
     persisted_problem = persisted_chapter.get_children()[0]
     self.assertEqual(persisted_problem.category, 'problem')
     self.assertEqual(persisted_problem.data, test_def_content)
Esempio n. 2
0
 def test_persist_dag(self):
     """
     try saving temporary xblocks
     """
     test_course = persistent_factories.PersistentCourseFactory.create(
         org='testx',
         prettyid='tempcourse',
         display_name='fun test course',
         user_id='testbot')
     test_chapter = XModuleDescriptor.load_from_json(
         {
             'category': 'chapter',
             'metadata': {
                 'display_name': 'chapter n'
             }
         },
         test_course.system,
         parent_xblock=test_course)
     test_def_content = '<problem>boo</problem>'
     test_problem = XModuleDescriptor.load_from_json(
         {
             'category': 'problem',
             'definition': {
                 'data': test_def_content
             }
         },
         test_course.system,
         parent_xblock=test_chapter)
     # better to pass in persisted parent over the subdag so
     # subdag gets the parent pointer (otherwise 2 ops, persist dag, update parent children,
     # persist parent
     persisted_course = modulestore('split').persist_xblock_dag(
         test_course, 'testbot')
     self.assertEqual(len(persisted_course.children), 1)
     persisted_chapter = persisted_course.get_children()[0]
     self.assertEqual(persisted_chapter.category, 'chapter')
     self.assertEqual(persisted_chapter.display_name, 'chapter n')
     self.assertEqual(len(persisted_chapter.children), 1)
     persisted_problem = persisted_chapter.get_children()[0]
     self.assertEqual(persisted_problem.category, 'problem')
     self.assertEqual(persisted_problem.data, test_def_content)
Esempio n. 3
0
    def test_temporary_xblocks(self):
        """
        Test using load_from_json to create non persisted xblocks
        """
        test_course = persistent_factories.PersistentCourseFactory.create(
            org='testx',
            prettyid='tempcourse',
            display_name='fun test course',
            user_id='testbot')

        test_chapter = XModuleDescriptor.load_from_json(
            {
                'category': 'chapter',
                'metadata': {
                    'display_name': 'chapter n'
                }
            },
            test_course.system,
            parent_xblock=test_course)
        self.assertIsInstance(test_chapter, SequenceDescriptor)
        self.assertEqual(test_chapter.display_name, 'chapter n')
        self.assertIn(test_chapter, test_course.get_children())

        # test w/ a definition (e.g., a problem)
        test_def_content = '<problem>boo</problem>'
        test_problem = XModuleDescriptor.load_from_json(
            {
                'category': 'problem',
                'definition': {
                    'data': test_def_content
                }
            },
            test_course.system,
            parent_xblock=test_chapter)
        self.assertIsInstance(test_problem, CapaDescriptor)
        self.assertEqual(test_problem.data, test_def_content)
        self.assertIn(test_problem, test_chapter.get_children())
        test_problem.display_name = 'test problem'
        self.assertEqual(test_problem.display_name, 'test problem')
Esempio n. 4
0
    def test_temporary_xblocks(self):
        """
        Test using load_from_json to create non persisted xblocks
        """
        test_course = persistent_factories.PersistentCourseFactory.create(org='testx', prettyid='tempcourse',
            display_name='fun test course', user_id='testbot')

        test_chapter = XModuleDescriptor.load_from_json({'category': 'chapter',
            'metadata': {'display_name': 'chapter n'}},
            test_course.system, parent_xblock=test_course)
        self.assertIsInstance(test_chapter, SequenceDescriptor)
        self.assertEqual(test_chapter.display_name, 'chapter n')
        self.assertIn(test_chapter, test_course.get_children())

        # test w/ a definition (e.g., a problem)
        test_def_content = '<problem>boo</problem>'
        test_problem = XModuleDescriptor.load_from_json({'category': 'problem',
            'definition': {'data': test_def_content}},
            test_course.system, parent_xblock=test_chapter)
        self.assertIsInstance(test_problem, CapaDescriptor)
        self.assertEqual(test_problem.data, test_def_content)
        self.assertIn(test_problem, test_chapter.get_children())
        test_problem.display_name = 'test problem'
        self.assertEqual(test_problem.display_name, 'test problem')