Skip to content

Commit 93bb2bd

Browse files
committed
add utils tests
1 parent 591ae38 commit 93bb2bd

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Tests for ol-openedx-course-sync utils.
3+
"""
4+
5+
from unittest import mock
6+
7+
from ddt import data, ddt
8+
from ol_openedx_course_sync.utils import copy_course_content
9+
from openedx.core.djangolib.testing.utils import skip_unless_cms
10+
from tests.utils import OLOpenedXCourseSyncTestCase
11+
from xmodule.modulestore import ModuleStoreEnum
12+
from xmodule.modulestore.django import modulestore
13+
14+
15+
@ddt
16+
class TestUtils(OLOpenedXCourseSyncTestCase):
17+
"""
18+
Test the ol_openedx_course_sync utils.
19+
"""
20+
21+
@skip_unless_cms
22+
@data(ModuleStoreEnum.BranchName.draft, ModuleStoreEnum.BranchName.published)
23+
def test_copy_course_content(self, branch):
24+
"""
25+
Test the copy_course_content function.
26+
"""
27+
with mock.patch(
28+
"ol_openedx_course_sync.utils.modulestore"
29+
) as mixed_modulestore_mock:
30+
split_modulestore_mock = mock.Mock()
31+
split_modulestore_mock.copy = mock.Mock()
32+
mixed_modulestore_mock.return_value = mock.Mock(
33+
make_course_usage_key=mock.Mock(
34+
return_value=modulestore().make_course_usage_key(
35+
self.source_course.usage_key.course_key
36+
)
37+
),
38+
_get_modulestore_for_courselike=mock.Mock(
39+
side_effect=[split_modulestore_mock, split_modulestore_mock]
40+
),
41+
)
42+
copy_course_content(
43+
None,
44+
self.source_course.usage_key.course_key,
45+
self.target_course.usage_key.course_key,
46+
branch,
47+
)
48+
split_modulestore_mock.copy.assert_called_once()
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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

Comments
 (0)