|
| 1 | +""" |
| 2 | +Utils for ol-openedx-course-sync tests. |
| 3 | +""" |
| 4 | + |
| 5 | +from datetime import datetime |
| 6 | + |
| 7 | +from pytz import UTC |
| 8 | +from xblock.runtime import DictKeyValueStore, KvsFieldData |
| 9 | +from xblock.test.tools import TestRuntime |
| 10 | +from xmodule.modulestore import ModuleStoreEnum |
| 11 | +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase |
| 12 | +from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory |
| 13 | + |
| 14 | + |
| 15 | +class OLOpenedXCourseSyncTestCase(ModuleStoreTestCase): |
| 16 | + """ |
| 17 | + Base test case for ol-openedx-course-sync tests. |
| 18 | + """ |
| 19 | + |
| 20 | + def setUp(self): |
| 21 | + super().setUp() |
| 22 | + |
| 23 | + key_store = DictKeyValueStore() |
| 24 | + field_data = KvsFieldData(key_store) |
| 25 | + self.runtime = TestRuntime(services={"field-data": field_data}) |
| 26 | + |
| 27 | + self.source_course = CourseFactory.create( |
| 28 | + default_store=ModuleStoreEnum.Type.split |
| 29 | + ) |
| 30 | + self.source_course_block = BlockFactory.create( |
| 31 | + parent_location=self.source_course.location, |
| 32 | + category="course", |
| 33 | + display_name="Source course", |
| 34 | + ) |
| 35 | + self.create_course_blocks(self.source_course_block) |
| 36 | + |
| 37 | + self.target_course = CourseFactory.create( |
| 38 | + default_store=ModuleStoreEnum.Type.split |
| 39 | + ) |
| 40 | + self.target_course_block = BlockFactory.create( |
| 41 | + parent_location=self.target_course.location, |
| 42 | + category="course", |
| 43 | + display_name="Target course", |
| 44 | + ) |
| 45 | + |
| 46 | + def create_course_blocks(self, course_block): |
| 47 | + """ |
| 48 | + Create a set of blocks for the course. |
| 49 | + """ |
| 50 | + chapter = BlockFactory.create( |
| 51 | + parent_location=course_block.location, |
| 52 | + category="chapter", |
| 53 | + display_name="Week 1", |
| 54 | + publish_item=True, |
| 55 | + start=datetime(2015, 3, 1, tzinfo=UTC), |
| 56 | + ) |
| 57 | + sequential = BlockFactory.create( |
| 58 | + parent_location=chapter.location, |
| 59 | + category="sequential", |
| 60 | + display_name="Lesson 1", |
| 61 | + publish_item=True, |
| 62 | + start=datetime(2015, 3, 1, tzinfo=UTC), |
| 63 | + ) |
| 64 | + vertical = BlockFactory.create( |
| 65 | + parent_location=sequential.location, |
| 66 | + category="vertical", |
| 67 | + display_name="Subsection 1", |
| 68 | + publish_item=True, |
| 69 | + start=datetime(2015, 4, 1, tzinfo=UTC), |
| 70 | + ) |
| 71 | + |
| 72 | + BlockFactory.create( |
| 73 | + category="problem", |
| 74 | + parent_location=vertical.location, |
| 75 | + display_name="A Problem Block", |
| 76 | + weight=1, |
| 77 | + user_id=self.user.id, |
| 78 | + publish_item=False, |
| 79 | + ) |
| 80 | + BlockFactory.create( |
| 81 | + parent_location=vertical.location, |
| 82 | + category="video", |
| 83 | + display_name="My Video", |
| 84 | + user_id=self.user.id, |
| 85 | + ) |
| 86 | + BlockFactory.create( |
| 87 | + category="html", |
| 88 | + parent_location=vertical.location, |
| 89 | + display_name="An HTML Block", |
| 90 | + user_id=self.user.id, |
| 91 | + ) |
0 commit comments