Skip to content

Commit 852a243

Browse files
test: fix tests after refactoring
1 parent 5f6a1e5 commit 852a243

File tree

3 files changed

+66
-34
lines changed

3 files changed

+66
-34
lines changed

cms/djangoapps/import_from_modulestore/tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_import_staged_content_to_library(self):
7373

7474
import_staged_content_to_library_task_mock.apply_async.assert_called_once_with(
7575
kwargs={
76-
"usage_keys_string": usage_ids,
76+
"usage_key_strings": usage_ids,
7777
"import_uuid": import_event.uuid,
7878
"learning_package_id": self.library.learning_package.id,
7979
"user_id": import_event.user.id,

cms/djangoapps/import_from_modulestore/tests/test_helpers.py

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ def setUp(self):
5656

5757
def test_import_from_staged_content(self):
5858
expected_imported_xblocks = [self.video, self.problem]
59-
staged_content = self.import_event.get_staged_content_by_source_usage_key(self.chapter.location)
59+
staged_content_for_import = self.import_event.staged_content_for_import.get(
60+
source_usage_key=self.chapter.location
61+
)
62+
staged_content = staged_content_for_import.staged_content
6063
import_client = ImportClient(
6164
import_event=self.import_event,
6265
staged_content=staged_content,
@@ -72,7 +75,10 @@ def test_import_from_staged_content(self):
7275

7376
@patch('cms.djangoapps.import_from_modulestore.helpers.ImportClient._process_import')
7477
def test_import_from_staged_content_block_not_found(self, mocked_process_import):
75-
staged_content = self.import_event.get_staged_content_by_source_usage_key(self.chapter.location)
78+
staged_content_for_import = self.import_event.staged_content_for_import.get(
79+
source_usage_key=self.chapter.location
80+
)
81+
staged_content = staged_content_for_import.staged_content
7682
import_client = ImportClient(
7783
import_event=self.import_event,
7884
staged_content=staged_content,
@@ -88,19 +94,19 @@ def test_import_from_staged_content_block_not_found(self, mocked_process_import)
8894
mocked_process_import.assert_not_called()
8995

9096
@ddt.data(
91-
# TODO: Chapter and sequential will be uncommented in the future
92-
# after adding it to the Learning Core.
93-
# 'chapter',
94-
# 'sequential',
97+
'chapter',
98+
'sequential',
9599
'vertical'
96100
)
97101
def test_create_container(self, block_lvl):
98102
container_to_import = getattr(self, block_lvl)
99103
block_usage_key_to_import = str(container_to_import.location)
100-
staged_content = self.import_event.get_staged_content_by_source_usage_key(block_usage_key_to_import)
104+
staged_content_for_import = self.import_event.staged_content_for_import.get(
105+
source_usage_key=self.chapter.location
106+
)
101107
import_client = ImportClient(
102108
import_event=self.import_event,
103-
staged_content=staged_content,
109+
staged_content=staged_content_for_import.staged_content,
104110
target_learning_package=self.learning_package,
105111
block_usage_key_to_import=block_usage_key_to_import,
106112
composition_level='xblock',
@@ -117,10 +123,12 @@ def test_create_container(self, block_lvl):
117123

118124
def test_create_container_with_xblock(self):
119125
block_usage_key_to_import = str(self.problem.location)
120-
staged_content = self.import_event.get_staged_content_by_source_usage_key(block_usage_key_to_import)
126+
staged_content_for_import = self.import_event.staged_content_for_import.get(
127+
source_usage_key=self.chapter.location
128+
)
121129
import_client = ImportClient(
122130
import_event=self.import_event,
123-
staged_content=staged_content,
131+
staged_content=staged_content_for_import.staged_content,
124132
target_learning_package=self.learning_package,
125133
block_usage_key_to_import=block_usage_key_to_import,
126134
composition_level='xblock',
@@ -138,7 +146,10 @@ def test_create_container_with_xblock(self):
138146
def test_process_import_with_complicated_blocks(self, block_lvl):
139147
container_to_import = getattr(self, block_lvl)
140148
block_usage_key_to_import = str(container_to_import.location)
141-
staged_content = self.import_event.get_staged_content_by_source_usage_key(self.chapter.location)
149+
staged_content_for_import = self.import_event.staged_content_for_import.get(
150+
source_usage_key=self.chapter.location
151+
)
152+
staged_content = staged_content_for_import.staged_content
142153
expected_imported_xblocks = [self.problem, self.video]
143154

144155
import_client = ImportClient(
@@ -160,11 +171,13 @@ def test_process_import_with_complicated_blocks(self, block_lvl):
160171
def test_process_import_with_simple_blocks(self, block_type_to_import):
161172
block_to_import = getattr(self, block_type_to_import)
162173
block_usage_key_to_import = str(block_to_import.location)
163-
staged_content = self.import_event.get_staged_content_by_source_usage_key(self.chapter.location)
174+
staged_content_for_import = self.import_event.staged_content_for_import.get(
175+
source_usage_key=self.chapter.location
176+
)
164177
expected_imported_xblocks = [block_to_import]
165178
import_client = ImportClient(
166179
import_event=self.import_event,
167-
staged_content=staged_content,
180+
staged_content=staged_content_for_import.staged_content,
168181
target_learning_package=self.learning_package,
169182
block_usage_key_to_import=block_usage_key_to_import,
170183
composition_level='xblock',
@@ -182,11 +195,13 @@ def test_process_import_with_simple_blocks(self, block_type_to_import):
182195
def test_process_import_with_override(self, override):
183196
block_to_import = self.problem
184197
block_usage_key_to_import = str(block_to_import.location)
185-
staged_content = self.import_event.get_staged_content_by_source_usage_key(self.chapter.location)
198+
staged_content_for_import = self.import_event.staged_content_for_import.get(
199+
source_usage_key=self.chapter.location
200+
)
186201

187202
import_client = ImportClient(
188203
import_event=self.import_event,
189-
staged_content=staged_content,
204+
staged_content=staged_content_for_import.staged_content,
190205
target_learning_package=self.learning_package,
191206
block_usage_key_to_import=block_usage_key_to_import,
192207
composition_level='xblock',
@@ -200,7 +215,11 @@ def test_process_import_with_override(self, override):
200215

201216
with self.captureOnCommitCallbacks(execute=True):
202217
new_import_event = api.stage_content_for_import(source_key=self.course.id, user_id=self.user.id)
203-
new_staged_content = new_import_event.get_staged_content_by_source_usage_key(self.chapter.location)
218+
219+
staged_content_for_import = new_import_event.staged_content_for_import.get(
220+
source_usage_key=self.chapter.location
221+
)
222+
new_staged_content = staged_content_for_import.staged_content
204223
import_client = ImportClient(
205224
import_event=new_import_event,
206225
staged_content=new_staged_content,
@@ -234,7 +253,10 @@ def test_process_import_with_override(self, override):
234253
def test_container_override(self, mock_authoring_api):
235254
container_to_import = self.vertical
236255
block_usage_key_to_import = str(container_to_import.location)
237-
staged_content = self.import_event.get_staged_content_by_source_usage_key(self.chapter.location)
256+
staged_content_for_import = self.import_event.staged_content_for_import.get(
257+
source_usage_key=self.chapter.location
258+
)
259+
staged_content = staged_content_for_import.staged_content
238260

239261
import_client = ImportClient(
240262
import_event=self.import_event,
@@ -283,7 +305,10 @@ def test_composition_levels(self, composition_level):
283305

284306
container_to_import = self.vertical
285307
block_usage_key_to_import = str(container_to_import.location)
286-
staged_content = self.import_event.get_staged_content_by_source_usage_key(self.chapter.location)
308+
staged_content_for_import = self.import_event.staged_content_for_import.get(
309+
source_usage_key=self.chapter.location
310+
)
311+
staged_content = staged_content_for_import.staged_content
287312

288313
import_client = ImportClient(
289314
import_event=self.import_event,
@@ -304,7 +329,10 @@ def test_composition_levels(self, composition_level):
304329
def test_process_staged_content_files(self, mock_content_staging_api):
305330
block_to_import = self.problem
306331
block_usage_key_to_import = str(block_to_import.location)
307-
staged_content = self.import_event.get_staged_content_by_source_usage_key(self.chapter.location)
332+
staged_content_for_import = self.import_event.staged_content_for_import.get(
333+
source_usage_key=self.chapter.location
334+
)
335+
staged_content = staged_content_for_import.staged_content
308336

309337
import_client = ImportClient(
310338
import_event=self.import_event,
@@ -339,11 +367,13 @@ def test_process_staged_content_files(self, mock_content_staging_api):
339367
def test_update_container_components(self):
340368
container_to_import = self.vertical
341369
block_usage_key_to_import = str(container_to_import.location)
342-
staged_content = self.import_event.get_staged_content_by_source_usage_key(self.chapter.location)
370+
staged_content_for_import = self.import_event.staged_content_for_import.get(
371+
source_usage_key=self.chapter.location
372+
)
343373

344374
import_client = ImportClient(
345375
import_event=self.import_event,
346-
staged_content=staged_content,
376+
staged_content=staged_content_for_import.staged_content,
347377
target_learning_package=self.learning_package,
348378
block_usage_key_to_import=block_usage_key_to_import,
349379
composition_level='container',

cms/djangoapps/import_from_modulestore/tests/test_tasks.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Tests for tasks in import_from_modulestore app.
33
"""
4+
from django.core.exceptions import ObjectDoesNotExist
45
from organizations.models import Organization
56
from openedx_learning.api.authoring_models import LearningPackage
67
from unittest.mock import patch
@@ -117,21 +118,22 @@ def test_import_staged_content_to_library_task(self):
117118
self.assertEqual(library_learning_package.content_set.count(), len(expected_imported_xblocks))
118119
self.assertEqual(self.import_event.publishableentityimport_set.count(), len(expected_imported_xblocks))
119120

120-
@patch('cms.djangoapps.import_from_modulestore.tasks.ImportClient')
121-
def test_import_library_block_not_found(self, mock_import_client):
121+
@patch('cms.djangoapps.import_from_modulestore.tasks.import_from_staged_content')
122+
def test_import_library_block_not_found(self, mock_import_from_staged_content):
122123
""" Test that if a block is not found in the staged content, it is not imported. """
123124
non_existent_usage_ids = ['block-v1:edX+Demo+2023+type@vertical+block@12345']
124125
save_legacy_content_to_staged_content_task(self.import_event.uuid)
125-
126-
import_staged_content_to_library_task(
127-
non_existent_usage_ids,
128-
str(self.import_event.uuid),
129-
self.content_library.learning_package.id,
130-
self.user.id,
131-
'xblock',
132-
override=True,
133-
)
134-
mock_import_client.assert_not_called()
126+
with self.allow_transaction_exception():
127+
with self.assertRaises(ObjectDoesNotExist):
128+
import_staged_content_to_library_task(
129+
non_existent_usage_ids,
130+
str(self.import_event.uuid),
131+
self.content_library.learning_package.id,
132+
self.user.id,
133+
'xblock',
134+
override=True,
135+
)
136+
mock_import_from_staged_content.assert_not_called()
135137

136138
def test_cannot_import_staged_content_twice(self):
137139
"""

0 commit comments

Comments
 (0)