Patch CMS app code in tests using fully qualified names

This commit is contained in:
Kyle McCormick
2020-10-01 14:23:00 -04:00
committed by Kyle McCormick
parent 437526b4bb
commit 7538691484
24 changed files with 113 additions and 81 deletions

View File

@@ -221,16 +221,16 @@ class TestUserTaskStopped(APITestCase):
with mock.patch('django.core.mail.send_mail') as mock_exception:
mock_exception.side_effect = NoAuthHandlerFound()
with mock.patch('cms_user_tasks.tasks.send_task_complete_email.retry') as mock_retry:
with mock.patch('cms.djangoapps.cms_user_tasks.tasks.send_task_complete_email.retry') as mock_retry:
user_task_stopped.send(sender=UserTaskStatus, status=self.status)
self.assertTrue(mock_retry.called)
def test_queue_email_failure(self):
logger = logging.getLogger("cms_user_tasks.signals")
logger = logging.getLogger("cms.djangoapps.cms_user_tasks.signals")
hdlr = MockLoggingHandler(level="DEBUG")
logger.addHandler(hdlr)
with mock.patch('cms_user_tasks.tasks.send_task_complete_email.delay') as mock_delay:
with mock.patch('cms.djangoapps.cms_user_tasks.tasks.send_task_complete_email.delay') as mock_delay:
mock_delay.side_effect = NoAuthHandlerFound()
user_task_stopped.send(sender=UserTaskStatus, status=self.status)
self.assertTrue(mock_delay.called)

View File

@@ -20,7 +20,7 @@ class DeleteCourseTests(ModuleStoreTestCase):
Test for course deleting functionality of the 'delete_course' command
"""
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
YESNO_PATCH_LOCATION = 'contentstore.management.commands.delete_course.query_yes_no'
YESNO_PATCH_LOCATION = 'cms.djangoapps.contentstore.management.commands.delete_course.query_yes_no'
def test_invalid_course_key(self):
course_run_key = 'foo/TestX/TS01/2015_Q7'

View File

@@ -107,7 +107,7 @@ class TestForcePublishModifications(ModuleStoreTestCase):
# verify that draft and publish point to different versions
self.assertNotEqual(draft_version, published_version)
with mock.patch('contentstore.management.commands.force_publish.query_yes_no') as patched_yes_no:
with mock.patch('cms.djangoapps.contentstore.management.commands.force_publish.query_yes_no') as patched_yes_no:
patched_yes_no.return_value = True
# force publish course

View File

@@ -19,7 +19,7 @@ class TestGenerateCourses(ModuleStoreTestCase):
Unit tests for creating a course in split store via command line
"""
@mock.patch('contentstore.management.commands.generate_courses.logger')
@mock.patch('cms.djangoapps.contentstore.management.commands.generate_courses.logger')
def test_generate_course_in_stores(self, mock_logger):
"""
Test that a course is created successfully
@@ -56,7 +56,7 @@ class TestGenerateCourses(ModuleStoreTestCase):
arg = json.dumps(settings)
call_command("generate_courses", arg)
@mock.patch('contentstore.management.commands.generate_courses.logger')
@mock.patch('cms.djangoapps.contentstore.management.commands.generate_courses.logger')
@ddt.data("organization", "number", "run", "fields")
def test_missing_course_settings(self, setting, mock_logger):
"""
@@ -74,7 +74,7 @@ class TestGenerateCourses(ModuleStoreTestCase):
call_command("generate_courses", arg)
mock_logger.warning.assert_any_call("Course json is missing " + setting)
@mock.patch('contentstore.management.commands.generate_courses.logger')
@mock.patch('cms.djangoapps.contentstore.management.commands.generate_courses.logger')
def test_invalid_user(self, mock_logger):
"""
Test that providing an invalid user in the course JSON will result in the appropriate error message
@@ -90,7 +90,7 @@ class TestGenerateCourses(ModuleStoreTestCase):
call_command("generate_courses", arg)
mock_logger.warning.assert_any_call("invalid_user user does not exist")
@mock.patch('contentstore.management.commands.generate_courses.logger')
@mock.patch('cms.djangoapps.contentstore.management.commands.generate_courses.logger')
def test_missing_display_name(self, mock_logger):
"""
Test that missing required display_name in JSON object will result in the appropriate error message
@@ -106,7 +106,7 @@ class TestGenerateCourses(ModuleStoreTestCase):
call_command("generate_courses", arg)
mock_logger.warning.assert_any_call("Fields json is missing display_name")
@mock.patch('contentstore.management.commands.generate_courses.logger')
@mock.patch('cms.djangoapps.contentstore.management.commands.generate_courses.logger')
def test_invalid_course_field(self, mock_logger):
"""
Test that an invalid course field will result in the appropriate message
@@ -122,7 +122,7 @@ class TestGenerateCourses(ModuleStoreTestCase):
call_command("generate_courses", arg)
mock_logger.info.assert_any_call((u'invalid_field') + "is not a valid CourseField")
@mock.patch('contentstore.management.commands.generate_courses.logger')
@mock.patch('cms.djangoapps.contentstore.management.commands.generate_courses.logger')
def test_invalid_date_setting(self, mock_logger):
"""
Test that an invalid date json will result in the appropriate message
@@ -138,7 +138,7 @@ class TestGenerateCourses(ModuleStoreTestCase):
call_command("generate_courses", arg)
mock_logger.info.assert_any_call("The date string could not be parsed for announcement")
@mock.patch('contentstore.management.commands.generate_courses.logger')
@mock.patch('cms.djangoapps.contentstore.management.commands.generate_courses.logger')
def test_invalid_course_tab_list_setting(self, mock_logger):
"""
Test that an invalid course tab list json will result in the appropriate message
@@ -154,7 +154,7 @@ class TestGenerateCourses(ModuleStoreTestCase):
call_command("generate_courses", arg)
mock_logger.info.assert_any_call("The course tab list string could not be parsed for tabs")
@mock.patch('contentstore.management.commands.generate_courses.logger')
@mock.patch('cms.djangoapps.contentstore.management.commands.generate_courses.logger')
@ddt.data("mobile_available", "enable_proctored_exams")
def test_missing_course_fields(self, field, mock_logger):
"""

View File

@@ -36,9 +36,11 @@ class TestReindexCourse(ModuleStoreTestCase):
org="test", course="course2", display_name="run1"
)
REINDEX_PATH_LOCATION = 'contentstore.management.commands.reindex_course.CoursewareSearchIndexer.do_course_reindex'
MODULESTORE_PATCH_LOCATION = 'contentstore.management.commands.reindex_course.modulestore'
YESNO_PATCH_LOCATION = 'contentstore.management.commands.reindex_course.query_yes_no'
REINDEX_PATH_LOCATION = (
'cms.djangoapps.contentstore.management.commands.reindex_course.CoursewareSearchIndexer.do_course_reindex'
)
MODULESTORE_PATCH_LOCATION = 'cms.djangoapps.contentstore.management.commands.reindex_course.modulestore'
YESNO_PATCH_LOCATION = 'cms.djangoapps.contentstore.management.commands.reindex_course.query_yes_no'
def _get_lib_key(self, library):
""" Get's library key as it is passed to indexer """

View File

@@ -36,9 +36,11 @@ class TestReindexLibrary(ModuleStoreTestCase):
org="test", course="course2", display_name="run1", default_store=ModuleStoreEnum.Type.split
)
REINDEX_PATH_LOCATION = 'contentstore.management.commands.reindex_library.LibrarySearchIndexer.do_library_reindex'
MODULESTORE_PATCH_LOCATION = 'contentstore.management.commands.reindex_library.modulestore'
YESNO_PATCH_LOCATION = 'contentstore.management.commands.reindex_library.query_yes_no'
REINDEX_PATH_LOCATION = (
'cms.djangoapps.contentstore.management.commands.reindex_library.LibrarySearchIndexer.do_library_reindex'
)
MODULESTORE_PATCH_LOCATION = 'cms.djangoapps.contentstore.management.commands.reindex_library.modulestore'
YESNO_PATCH_LOCATION = 'cms.djangoapps.contentstore.management.commands.reindex_library.query_yes_no'
def _get_lib_key(self, library):
""" Get's library key as it is passed to indexer """

View File

@@ -14,7 +14,7 @@ from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
COMMAND_MODULE = 'contentstore.management.commands.sync_courses'
COMMAND_MODULE = 'cms.djangoapps.contentstore.management.commands.sync_courses'
@mock.patch(COMMAND_MODULE + '.get_course_runs')

View File

@@ -511,8 +511,8 @@ class CourseGradingTest(CourseTestCase):
self.assertDictEqual(grader, subgrader, str(i) + "th graders not equal")
@mock.patch('track.event_transaction_utils.uuid4')
@mock.patch('models.settings.course_grading.tracker')
@mock.patch('contentstore.signals.signals.GRADING_POLICY_CHANGED.send')
@mock.patch('cms.djangoapps.models.settings.course_grading.tracker')
@mock.patch('cms.djangoapps.contentstore.signals.signals.GRADING_POLICY_CHANGED.send')
@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_update_from_json(self, store, send_signal, tracker, uuid):
uuid.return_value = "mockUUID"
@@ -648,8 +648,8 @@ class CourseGradingTest(CourseTestCase):
self.assertTrue(result)
@mock.patch('track.event_transaction_utils.uuid4')
@mock.patch('models.settings.course_grading.tracker')
@mock.patch('contentstore.signals.signals.GRADING_POLICY_CHANGED.send')
@mock.patch('cms.djangoapps.models.settings.course_grading.tracker')
@mock.patch('cms.djangoapps.contentstore.signals.signals.GRADING_POLICY_CHANGED.send')
def test_update_grader_from_json(self, send_signal, tracker, uuid):
uuid.return_value = 'mockUUID'
test_grader = CourseGradingModel.fetch(self.course.id)
@@ -693,7 +693,7 @@ class CourseGradingTest(CourseTestCase):
], any_order=True)
@mock.patch('track.event_transaction_utils.uuid4')
@mock.patch('models.settings.course_grading.tracker')
@mock.patch('cms.djangoapps.models.settings.course_grading.tracker')
def test_update_cutoffs_from_json(self, tracker, uuid):
uuid.return_value = 'mockUUID'
test_grader = CourseGradingModel.fetch(self.course.id)
@@ -754,8 +754,8 @@ class CourseGradingTest(CourseTestCase):
self.assertEqual(None, altered_grader.grace_period, "Delete grace period")
@mock.patch('track.event_transaction_utils.uuid4')
@mock.patch('models.settings.course_grading.tracker')
@mock.patch('contentstore.signals.signals.GRADING_POLICY_CHANGED.send')
@mock.patch('cms.djangoapps.models.settings.course_grading.tracker')
@mock.patch('cms.djangoapps.contentstore.signals.signals.GRADING_POLICY_CHANGED.send')
def test_update_section_grader_type(self, send_signal, tracker, uuid):
uuid.return_value = 'mockUUID'
# Get the descriptor and the section_grader_type and assert they are the default values
@@ -834,7 +834,7 @@ class CourseGradingTest(CourseTestCase):
grader_sample = self._model_from_url(grader_type_url_base + '/1')
self.assertEqual(grader_sample, whole_model['graders'][1])
@mock.patch('contentstore.signals.signals.GRADING_POLICY_CHANGED.send')
@mock.patch('cms.djangoapps.contentstore.signals.signals.GRADING_POLICY_CHANGED.send')
def test_add_delete_grader(self, send_signal):
grader_type_url_base = get_url(self.course.id, 'grading_handler')
original_model = self._model_from_url(grader_type_url_base)

View File

@@ -762,7 +762,7 @@ class TestTaskExecution(SharedModuleStoreTestCase):
# as it encounters a CCX key. If that isn't working properly, it will
# fall through to the normal indexing and raise an exception because
# there is no data or backing course behind the course key.
with patch('contentstore.courseware_index.CoursewareSearchIndexer.index') as mock_index:
with patch('cms.djangoapps.contentstore.courseware_index.CoursewareSearchIndexer.index') as mock_index:
self.assertIsNone(
update_search_index(
"ccx-v1:OpenEdX+FAKECOURSE+FAKERUN+ccx@1", "2020-09-28T16:41:57.150796"

View File

@@ -45,8 +45,8 @@ class TestHandleItemDeleted(ModuleStoreTestCase, MilestonesTestCaseMixin):
gating_api.add_prerequisite(self.course.id, self.open_seq.location)
gating_api.set_required_content(self.course.id, self.gated_seq.location, self.open_seq.location, 100, 100)
@patch('contentstore.signals.handlers.gating_api.set_required_content')
@patch('contentstore.signals.handlers.gating_api.remove_prerequisite')
@patch('cms.djangoapps.contentstore.signals.handlers.gating_api.set_required_content')
@patch('cms.djangoapps.contentstore.signals.handlers.gating_api.remove_prerequisite')
def test_chapter_deleted(self, mock_remove_prereq, mock_set_required):
""" Test gating milestone data is cleanup up when course content item is deleted """
handle_item_deleted(usage_key=self.chapter.location, user_id=0)
@@ -55,8 +55,8 @@ class TestHandleItemDeleted(ModuleStoreTestCase, MilestonesTestCaseMixin):
self.open_seq.location.course_key, self.open_seq.location, None, None, None
)
@patch('contentstore.signals.handlers.gating_api.set_required_content')
@patch('contentstore.signals.handlers.gating_api.remove_prerequisite')
@patch('cms.djangoapps.contentstore.signals.handlers.gating_api.set_required_content')
@patch('cms.djangoapps.contentstore.signals.handlers.gating_api.remove_prerequisite')
def test_sequential_deleted(self, mock_remove_prereq, mock_set_required):
""" Test gating milestone data is cleanup up when course content item is deleted """
handle_item_deleted(usage_key=self.open_seq.location, user_id=0)

View File

@@ -53,7 +53,7 @@ class ExportCourseTestCase(CourseTestCase):
output = artifacts[0]
self.assertEqual(output.name, 'Output')
@mock.patch('contentstore.tasks.export_course_to_xml', side_effect=side_effect_exception)
@mock.patch('cms.djangoapps.contentstore.tasks.export_course_to_xml', side_effect=side_effect_exception)
def test_exception(self, mock_export): # pylint: disable=unused-argument
"""
The export task should fail gracefully if an exception is thrown

View File

@@ -272,7 +272,7 @@ class ScrapeVideoThumbnailsTestCase(CourseTestCase):
)
)
@override_settings(AWS_ACCESS_KEY_ID='test_key_id', AWS_SECRET_ACCESS_KEY='test_secret')
@patch('contentstore.video_utils.LOGGER')
@patch('cms.djangoapps.contentstore.video_utils.LOGGER')
@patch('requests.get')
@ddt.unpack
def test_scrape_youtube_thumbnail_logging(
@@ -332,8 +332,8 @@ class ScrapeVideoThumbnailsTestCase(CourseTestCase):
)
),
)
@patch('contentstore.video_utils.LOGGER')
@patch('contentstore.video_utils.download_youtube_video_thumbnail')
@patch('cms.djangoapps.contentstore.video_utils.LOGGER')
@patch('cms.djangoapps.contentstore.video_utils.download_youtube_video_thumbnail')
@ddt.unpack
def test_no_video_thumbnail_downloaded(
self,

View File

@@ -359,7 +359,7 @@ class UploadTestCase(AssetsTestCase):
(MAX_FILE_SIZE, "justequals.file.test", 200),
(MAX_FILE_SIZE + 90, "large.file.test", 413),
)
@mock.patch('contentstore.views.assets.get_file_size')
@mock.patch('cms.djangoapps.contentstore.views.assets.get_file_size')
def test_file_size(self, case, get_file_size):
max_file_size, name, status_code = case

View File

@@ -211,7 +211,7 @@ class CertificatesListHandlerTestCase(
"""
Set up CertificatesListHandlerTestCase.
"""
super(CertificatesListHandlerTestCase, self).setUp('contentstore.views.certificates.tracker')
super(CertificatesListHandlerTestCase, self).setUp('cms.djangoapps.contentstore.views.certificates.tracker')
self.reset_urls()
def _url(self):
@@ -436,7 +436,7 @@ class CertificatesDetailHandlerTestCase(
"""
Set up CertificatesDetailHandlerTestCase.
"""
super(CertificatesDetailHandlerTestCase, self).setUp('contentstore.views.certificates.tracker')
super(CertificatesDetailHandlerTestCase, self).setUp('cms.djangoapps.contentstore.views.certificates.tracker')
self.reset_urls()
def _url(self, cid=-1):

View File

@@ -205,7 +205,10 @@ class ContainerPageTestCase(StudioPageTestCase, LibraryTestCase):
empty_child_container = self._create_item(self.vertical.location, 'split_test', 'Split Test')
self.validate_preview_html(empty_child_container, self.reorderable_child_view, can_add=False)
@patch('contentstore.views.component.render_to_response', Mock(return_value=Mock(status_code=200, content='')))
@patch(
'cms.djangoapps.contentstore.views.component.render_to_response',
Mock(return_value=Mock(status_code=200, content=''))
)
def test_container_page_with_valid_and_invalid_usage_key_string(self):
"""
Check that invalid 'usage_key_string' raises Http404.

View File

@@ -57,7 +57,7 @@ class TestSubsectionGating(CourseTestCase):
)
self.seq2_url = reverse_usage_url('xblock_handler', self.seq2.location)
@patch('contentstore.views.item.gating_api.add_prerequisite')
@patch('cms.djangoapps.contentstore.views.item.gating_api.add_prerequisite')
def test_add_prerequisite(self, mock_add_prereq):
"""
Test adding a subsection as a prerequisite
@@ -69,7 +69,7 @@ class TestSubsectionGating(CourseTestCase):
)
mock_add_prereq.assert_called_with(self.course.id, self.seq1.location)
@patch('contentstore.views.item.gating_api.remove_prerequisite')
@patch('cms.djangoapps.contentstore.views.item.gating_api.remove_prerequisite')
def test_remove_prerequisite(self, mock_remove_prereq):
"""
Test removing a subsection as a prerequisite
@@ -81,7 +81,7 @@ class TestSubsectionGating(CourseTestCase):
)
mock_remove_prereq.assert_called_with(self.seq1.location)
@patch('contentstore.views.item.gating_api.set_required_content')
@patch('cms.djangoapps.contentstore.views.item.gating_api.set_required_content')
def test_add_gate(self, mock_set_required_content):
"""
Test adding a gated subsection
@@ -100,7 +100,7 @@ class TestSubsectionGating(CourseTestCase):
'100'
)
@patch('contentstore.views.item.gating_api.set_required_content')
@patch('cms.djangoapps.contentstore.views.item.gating_api.set_required_content')
def test_remove_gate(self, mock_set_required_content):
"""
Test removing a gated subsection
@@ -118,9 +118,9 @@ class TestSubsectionGating(CourseTestCase):
''
)
@patch('contentstore.views.item.gating_api.get_prerequisites')
@patch('contentstore.views.item.gating_api.get_required_content')
@patch('contentstore.views.item.gating_api.is_prerequisite')
@patch('cms.djangoapps.contentstore.views.item.gating_api.get_prerequisites')
@patch('cms.djangoapps.contentstore.views.item.gating_api.get_required_content')
@patch('cms.djangoapps.contentstore.views.item.gating_api.is_prerequisite')
@ddt.data(
(90, None),
(None, 90),
@@ -147,8 +147,8 @@ class TestSubsectionGating(CourseTestCase):
self.assertEqual(resp['prereq_min_completion'], min_completion)
self.assertEqual(resp['visibility_state'], VisibilityState.gated)
@patch('contentstore.signals.handlers.gating_api.set_required_content')
@patch('contentstore.signals.handlers.gating_api.remove_prerequisite')
@patch('cms.djangoapps.contentstore.signals.handlers.gating_api.set_required_content')
@patch('cms.djangoapps.contentstore.signals.handlers.gating_api.remove_prerequisite')
def test_delete_item_signal_handler_called(self, mock_remove_prereq, mock_set_required):
seq3 = ItemFactory.create(
parent_location=self.chapter.location,

View File

@@ -786,7 +786,7 @@ class ExportTestCase(CourseTestCase):
mock_artifact.file.storage.url.return_value = file_url
return mock_artifact
@patch('contentstore.views.import_export._latest_task_status')
@patch('cms.djangoapps.contentstore.views.import_export._latest_task_status')
@patch('user_tasks.models.UserTaskArtifact.objects.get')
def test_export_status_handler_other(
self,
@@ -806,7 +806,7 @@ class ExportTestCase(CourseTestCase):
result = json.loads(resp.content.decode('utf-8'))
self.assertEqual(result['ExportOutput'], '/path/to/testfile.tar.gz')
@patch('contentstore.views.import_export._latest_task_status')
@patch('cms.djangoapps.contentstore.views.import_export._latest_task_status')
@patch('user_tasks.models.UserTaskArtifact.objects.get')
def test_export_status_handler_s3(
self,
@@ -826,7 +826,7 @@ class ExportTestCase(CourseTestCase):
result = json.loads(resp.content.decode('utf-8'))
self.assertEqual(result['ExportOutput'], '/s3/file/path/testfile.tar.gz')
@patch('contentstore.views.import_export._latest_task_status')
@patch('cms.djangoapps.contentstore.views.import_export._latest_task_status')
@patch('user_tasks.models.UserTaskArtifact.objects.get')
def test_export_status_handler_filesystem(
self,

View File

@@ -332,7 +332,7 @@ class GetItemTest(ItemTest):
"""
Tests that valid paging is passed along to underlying block
"""
with patch('contentstore.views.item.get_preview_fragment') as patched_get_preview_fragment:
with patch('cms.djangoapps.contentstore.views.item.get_preview_fragment') as patched_get_preview_fragment:
retval = Mock()
type(retval).content = PropertyMock(return_value="Some content")
type(retval).resources = PropertyMock(return_value=[])
@@ -1235,7 +1235,7 @@ class TestMoveItem(ItemTest):
validation = html.validate()
self.assertEqual(len(validation.messages), 0)
@patch('contentstore.views.item.log')
@patch('cms.djangoapps.contentstore.views.item.log')
def test_move_logging(self, mock_logger):
"""
Test logging when an item is successfully moved.
@@ -2147,7 +2147,7 @@ class TestComponentHandler(TestCase):
self.request_factory = RequestFactory()
patcher = patch('contentstore.views.component.modulestore')
patcher = patch('cms.djangoapps.contentstore.views.component.modulestore')
self.modulestore = patcher.start()
self.addCleanup(patcher.stop)
@@ -2219,12 +2219,12 @@ class TestComponentHandler(TestCase):
self.descriptor.handle = create_response
with patch(
'contentstore.views.component.is_xblock_aside',
'cms.djangoapps.contentstore.views.component.is_xblock_aside',
return_value=is_xblock_aside
), patch(
'contentstore.views.component.get_aside_from_xblock'
'cms.djangoapps.contentstore.views.component.get_aside_from_xblock'
) as mocked_get_aside_from_xblock, patch(
"contentstore.views.component.webob_to_django_response"
"cms.djangoapps.contentstore.views.component.webob_to_django_response"
) as mocked_webob_to_django_response:
component_handler(
self.request,

View File

@@ -48,23 +48,23 @@ class UnitTestLibraries(CourseTestCase):
######################################################
# Tests for /library/ - list and create libraries:
@mock.patch("contentstore.views.library.LIBRARIES_ENABLED", False)
@mock.patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", False)
def test_library_creator_status_libraries_not_enabled(self):
_, nostaff_user = self.create_non_staff_authed_user_client()
self.assertEqual(get_library_creator_status(nostaff_user), False)
@mock.patch("contentstore.views.library.LIBRARIES_ENABLED", True)
@mock.patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", True)
def test_library_creator_status_with_is_staff_user(self):
self.assertEqual(get_library_creator_status(self.user), True)
@mock.patch("contentstore.views.library.LIBRARIES_ENABLED", True)
@mock.patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", True)
def test_library_creator_status_with_course_creator_role(self):
_, nostaff_user = self.create_non_staff_authed_user_client()
with mock.patch.dict('django.conf.settings.FEATURES', {"ENABLE_CREATOR_GROUP": True}):
grant_course_creator_status(self.user, nostaff_user)
self.assertEqual(get_library_creator_status(nostaff_user), True)
@mock.patch("contentstore.views.library.LIBRARIES_ENABLED", True)
@mock.patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", True)
def test_library_creator_status_with_no_course_creator_role(self):
_, nostaff_user = self.create_non_staff_authed_user_client()
self.assertEqual(get_library_creator_status(nostaff_user), True)
@@ -83,7 +83,7 @@ class UnitTestLibraries(CourseTestCase):
Ensure that the setting DISABLE_LIBRARY_CREATION overrides DISABLE_COURSE_CREATION as expected.
"""
_, nostaff_user = self.create_non_staff_authed_user_client()
with mock.patch("contentstore.views.library.LIBRARIES_ENABLED", True):
with mock.patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", True):
with mock.patch.dict(
"django.conf.settings.FEATURES",
{
@@ -94,7 +94,7 @@ class UnitTestLibraries(CourseTestCase):
self.assertEqual(get_library_creator_status(nostaff_user), expected_status)
@mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_COURSE_CREATION': True})
@mock.patch("contentstore.views.library.LIBRARIES_ENABLED", True)
@mock.patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", True)
def test_library_creator_status_with_no_course_creator_role_and_disabled_nonstaff_course_creation(self):
"""
Ensure that `DISABLE_COURSE_CREATION` feature works with libraries as well.
@@ -110,7 +110,7 @@ class UnitTestLibraries(CourseTestCase):
self.assertEqual(get_response.status_code, 200)
self.assertEqual(post_response.status_code, 403)
@patch("contentstore.views.library.LIBRARIES_ENABLED", False)
@patch("cms.djangoapps.contentstore.views.library.LIBRARIES_ENABLED", False)
def test_with_libraries_disabled(self):
"""
The library URLs should return 404 if libraries are disabled.

View File

@@ -92,7 +92,7 @@ class TranscriptCredentialsTest(CourseTestCase):
)
)
@ddt.unpack
@patch('contentstore.views.transcript_settings.update_3rd_party_transcription_service_credentials')
@patch('cms.djangoapps.contentstore.views.transcript_settings.update_3rd_party_transcription_service_credentials')
def test_transcript_credentials_handler(self, request_payload, update_credentials_response, expected_status_code,
expected_response, mock_update_credentials):
"""
@@ -209,7 +209,7 @@ class TranscriptDownloadTest(CourseTestCase):
response = self.client.post(self.view_url, content_type='application/json')
self.assertEqual(response.status_code, 405)
@patch('contentstore.views.transcript_settings.get_video_transcript_data')
@patch('cms.djangoapps.contentstore.views.transcript_settings.get_video_transcript_data')
def test_transcript_download_handler(self, mock_get_video_transcript_data):
"""
Tests that transcript download handler works as expected.
@@ -301,8 +301,11 @@ class TranscriptUploadTest(CourseTestCase):
response = self.client.get(self.view_url, content_type='application/json')
self.assertEqual(response.status_code, 405)
@patch('contentstore.views.transcript_settings.create_or_update_video_transcript')
@patch('contentstore.views.transcript_settings.get_available_transcript_languages', Mock(return_value=['en']))
@patch('cms.djangoapps.contentstore.views.transcript_settings.create_or_update_video_transcript')
@patch(
'cms.djangoapps.contentstore.views.transcript_settings.get_available_transcript_languages',
Mock(return_value=['en']),
)
def test_transcript_upload_handler(self, mock_create_or_update_video_transcript):
"""
Tests that transcript upload handler works as expected.
@@ -364,7 +367,10 @@ class TranscriptUploadTest(CourseTestCase):
)
)
@ddt.unpack
@patch('contentstore.views.transcript_settings.get_available_transcript_languages', Mock(return_value=['en']))
@patch(
'cms.djangoapps.contentstore.views.transcript_settings.get_available_transcript_languages',
Mock(return_value=['en']),
)
def test_transcript_upload_handler_missing_attrs(self, request_payload, expected_error_message):
"""
Tests the transcript upload handler when the required attributes are missing.
@@ -374,7 +380,10 @@ class TranscriptUploadTest(CourseTestCase):
self.assertEqual(response.status_code, 400)
self.assertEqual(json.loads(response.content.decode('utf-8'))['error'], expected_error_message)
@patch('contentstore.views.transcript_settings.get_available_transcript_languages', Mock(return_value=['en', 'es']))
@patch(
'cms.djangoapps.contentstore.views.transcript_settings.get_available_transcript_languages',
Mock(return_value=['en', 'es'])
)
def test_transcript_upload_handler_existing_transcript(self):
"""
Tests that upload handler do not update transcript's language if a transcript
@@ -393,7 +402,10 @@ class TranscriptUploadTest(CourseTestCase):
u'A transcript with the "es" language code already exists.'
)
@patch('contentstore.views.transcript_settings.get_available_transcript_languages', Mock(return_value=['en']))
@patch(
'cms.djangoapps.contentstore.views.transcript_settings.get_available_transcript_languages',
Mock(return_value=['en']),
)
def test_transcript_upload_handler_with_image(self):
"""
Tests the transcript upload handler with an image file.
@@ -417,7 +429,10 @@ class TranscriptUploadTest(CourseTestCase):
u'There is a problem with this transcript file. Try to upload a different file.'
)
@patch('contentstore.views.transcript_settings.get_available_transcript_languages', Mock(return_value=['en']))
@patch(
'cms.djangoapps.contentstore.views.transcript_settings.get_available_transcript_languages',
Mock(return_value=['en']),
)
def test_transcript_upload_handler_with_invalid_transcript(self):
"""
Tests the transcript upload handler with an invalid transcript file.

View File

@@ -624,7 +624,10 @@ class TestRenameTranscripts(BaseTranscripts):
@ddt.ddt
@patch('contentstore.views.transcripts_ajax.download_youtube_subs', Mock(return_value=SJSON_TRANSCRIPT_CONTENT))
@patch(
'cms.djangoapps.contentstore.views.transcripts_ajax.download_youtube_subs',
Mock(return_value=SJSON_TRANSCRIPT_CONTENT)
)
class TestReplaceTranscripts(BaseTranscripts):
"""
Tests for '/transcripts/replace' endpoint.
@@ -735,7 +738,8 @@ class TestReplaceTranscripts(BaseTranscripts):
Verify that replace transcript fails if YouTube does not have transcript for the given youtube id.
"""
error_message = u'YT ID not found.'
with patch('contentstore.views.transcripts_ajax.download_youtube_subs') as mock_download_youtube_subs:
patch_path = 'cms.djangoapps.contentstore.views.transcripts_ajax.download_youtube_subs'
with patch(patch_path) as mock_download_youtube_subs:
mock_download_youtube_subs.side_effect = GetTranscriptsFromYouTubeException(error_message)
response = self.replace_transcript(locator=self.video_usage_key, youtube_id='non-existent-yt-id')
self.assertContains(response, text=error_message, status_code=400)

View File

@@ -784,7 +784,7 @@ class VideosHandlerTestCase(VideoUploadTestMixin, CourseTestCase):
# Test should fail if video not found
self.assertEqual(True, False, 'Invalid edx_video_id')
@patch('contentstore.views.videos.LOGGER')
@patch('cms.djangoapps.contentstore.views.videos.LOGGER')
def test_video_status_update_request(self, mock_logger):
"""
Verifies that video status update request works as expected.
@@ -1432,7 +1432,7 @@ class TranscriptPreferencesTestCase(VideoUploadTestBase, CourseTestCase):
@override_settings(AWS_ACCESS_KEY_ID='test_key_id', AWS_SECRET_ACCESS_KEY='test_secret')
@patch('boto.s3.key.Key')
@patch('boto.s3.connection.S3Connection')
@patch('contentstore.views.videos.get_transcript_preferences')
@patch('cms.djangoapps.contentstore.views.videos.get_transcript_preferences')
def test_transcript_preferences_metadata(self, transcript_preferences, is_video_transcript_enabled,
mock_transcript_preferences, mock_conn, mock_key):
"""

View File

@@ -48,7 +48,10 @@ class CourseCreatorAdminTest(TestCase):
"STUDIO_REQUEST_EMAIL": self.studio_request_email
}
@mock.patch('course_creators.admin.render_to_string', mock.Mock(side_effect=mock_render_to_string, autospec=True))
@mock.patch(
'cms.djangoapps.course_creators.admin.render_to_string',
mock.Mock(side_effect=mock_render_to_string, autospec=True)
)
@mock.patch('django.contrib.auth.models.User.email_user')
def test_change_status(self, email_user):
"""
@@ -92,7 +95,10 @@ class CourseCreatorAdminTest(TestCase):
change_state_and_verify_email(CourseCreator.DENIED, False)
@mock.patch('course_creators.admin.render_to_string', mock.Mock(side_effect=mock_render_to_string, autospec=True))
@mock.patch(
'cms.djangoapps.course_creators.admin.render_to_string',
mock.Mock(side_effect=mock_render_to_string, autospec=True)
)
def test_mail_admin_on_pending(self):
"""
Tests that the admin account is notified when a user is in the 'pending' state.

View File

@@ -344,7 +344,7 @@ else:
COURSE_IMPORT_EXPORT_BUCKET = ENV_TOKENS.get('COURSE_IMPORT_EXPORT_BUCKET', '')
if COURSE_IMPORT_EXPORT_BUCKET:
COURSE_IMPORT_EXPORT_STORAGE = 'contentstore.storage.ImportExportS3Storage'
COURSE_IMPORT_EXPORT_STORAGE = 'cms.djangoapps.contentstore.storage.ImportExportS3Storage'
else:
COURSE_IMPORT_EXPORT_STORAGE = DEFAULT_FILE_STORAGE