From 58828da55bed78dd9ca6915919e157e727d42010 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 5 Sep 2019 12:35:39 -0400 Subject: [PATCH] Fix patches to use proper courseware imports --- common/djangoapps/student/tests/tests.py | 2 +- lms/djangoapps/branding/tests/test_page.py | 10 ++++---- lms/djangoapps/ccx/api/v0/tests/test_views.py | 2 +- lms/djangoapps/ccx/tests/test_views.py | 6 ++--- .../courseware/tests/test_access.py | 23 +++++++++++-------- .../courseware/tests/test_courses.py | 4 ++-- .../courseware/tests/test_entrance_exam.py | 2 +- .../courseware/tests/test_module_render.py | 18 +++++++-------- .../tests/test_self_paced_overrides.py | 6 ++--- .../tests/test_submitting_problems.py | 2 +- lms/djangoapps/courseware/tests/test_tabs.py | 2 +- .../tests/test_view_authentication.py | 12 +++++----- lms/djangoapps/courseware/tests/test_views.py | 21 +++++++++-------- .../instructor_task/tests/test_integration.py | 4 ++-- 14 files changed, 59 insertions(+), 55 deletions(-) diff --git a/common/djangoapps/student/tests/tests.py b/common/djangoapps/student/tests/tests.py index ad451ae689..244a8d1d90 100644 --- a/common/djangoapps/student/tests/tests.py +++ b/common/djangoapps/student/tests/tests.py @@ -395,7 +395,7 @@ class DashboardTest(ModuleStoreTestCase): self.assertIsNone(course_mode_info['days_for_upsell']) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') - @patch('courseware.views.index.log.warning') + @patch('lms.djangoapps.courseware.views.index.log.warning') @patch.dict('django.conf.settings.FEATURES', {'ENABLE_PAID_COURSE_REGISTRATION': True}) def test_blocked_course_scenario(self, log_warning): diff --git a/lms/djangoapps/branding/tests/test_page.py b/lms/djangoapps/branding/tests/test_page.py index 7cbda47029..3b8bed715c 100644 --- a/lms/djangoapps/branding/tests/test_page.py +++ b/lms/djangoapps/branding/tests/test_page.py @@ -192,7 +192,7 @@ class IndexPageCourseCardsSortingTests(ModuleStoreTestCase): self.factory = RequestFactory() @patch('student.views.management.render_to_response', RENDER_MOCK) - @patch('courseware.views.views.render_to_response', RENDER_MOCK) + @patch('lms.djangoapps.courseware.views.views.render_to_response', RENDER_MOCK) @patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSE_DISCOVERY': False}) def test_course_discovery_off(self): """ @@ -216,7 +216,7 @@ class IndexPageCourseCardsSortingTests(ModuleStoreTestCase): self.assertIn('
Sample") # Test when render raises an exception - with mock.patch('courseware.courses.get_module') as mock_module_render: + with mock.patch('lms.djangoapps.courseware.courses.get_module') as mock_module_render: mock_module_render.return_value = mock.MagicMock( render=mock.Mock(side_effect=Exception('Render failed!')) ) @@ -329,7 +329,7 @@ class CoursesRenderTest(ModuleStoreTestCase): self.assertEqual(course_about, "A course about toys.") # Test when render raises an exception - with mock.patch('courseware.courses.get_module') as mock_module_render: + with mock.patch('lms.djangoapps.courseware.courses.get_module') as mock_module_render: mock_module_render.return_value = mock.MagicMock( render=mock.Mock(side_effect=Exception('Render failed!')) ) diff --git a/lms/djangoapps/courseware/tests/test_entrance_exam.py b/lms/djangoapps/courseware/tests/test_entrance_exam.py index 3d688d6bbf..1aad2624af 100644 --- a/lms/djangoapps/courseware/tests/test_entrance_exam.py +++ b/lms/djangoapps/courseware/tests/test_entrance_exam.py @@ -471,7 +471,7 @@ class EntranceExamTestCases(LoginEnrollmentTestCase, ModuleStoreTestCase, Milest exam_url = response.get('Location') self.assertRedirects(response, exam_url) - @patch('courseware.entrance_exams.get_entrance_exam_content', Mock(return_value=None)) + @patch('lms.djangoapps.courseware.entrance_exams.get_entrance_exam_content', Mock(return_value=None)) def test_courseware_page_access_after_passing_entrance_exam(self): """ Test courseware access page after passing entrance exam diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py index dad40d99f8..a9d37a8569 100644 --- a/lms/djangoapps/courseware/tests/test_module_render.py +++ b/lms/djangoapps/courseware/tests/test_module_render.py @@ -266,7 +266,7 @@ class ModuleRenderTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase): } # Patch getmodule to return our mock module - with patch('courseware.module_render.load_single_xblock', return_value=self.mock_module): + with patch('lms.djangoapps.courseware.module_render.load_single_xblock', return_value=self.mock_module): # call xqueue_callback with our mocked information request = self.request_factory.post(self.callback_url, data) render.xqueue_callback( @@ -288,7 +288,7 @@ class ModuleRenderTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase): 'xqueue_body': 'hello world', } - with patch('courseware.module_render.load_single_xblock', return_value=self.mock_module): + with patch('lms.djangoapps.courseware.module_render.load_single_xblock', return_value=self.mock_module): # Test with missing xqueue data with self.assertRaises(Http404): request = self.request_factory.post(self.callback_url, {}) @@ -818,12 +818,12 @@ class TestHandleXBlockCallback(SharedModuleStoreTestCase, LoginEnrollmentTestCas ) with patch( - 'courseware.module_render.is_xblock_aside', + 'lms.djangoapps.courseware.module_render.is_xblock_aside', return_value=is_xblock_aside ), patch( - 'courseware.module_render.get_aside_from_xblock' + 'lms.djangoapps.courseware.module_render.get_aside_from_xblock' ) as mocked_get_aside_from_xblock, patch( - "courseware.module_render.webob_to_django_response" + 'lms.djangoapps.courseware.module_render.webob_to_django_response' ) as mocked_webob_to_django_response: render.handle_xblock_callback( request, @@ -900,7 +900,7 @@ class TestHandleXBlockCallback(SharedModuleStoreTestCase, LoginEnrollmentTestCas request.session = {} request.user.real_user = GlobalStaffFactory.create() request.user.real_user.masquerade_settings = CourseMasquerade(course.id, user_name="jem") - with patch('courseware.module_render.is_masquerading_as_specific_student') as mock_masq: + with patch('lms.djangoapps.courseware.module_render.is_masquerading_as_specific_student') as mock_masq: mock_masq.return_value = True response = render.handle_xblock_callback( request, @@ -1823,7 +1823,7 @@ class DetachedXBlock(XBlock): @patch.dict('django.conf.settings.FEATURES', {'DISPLAY_DEBUG_INFO_TO_STAFF': True, 'DISPLAY_HISTOGRAMS_TO_STAFF': True}) -@patch('courseware.module_render.has_access', Mock(return_value=True, autospec=True)) +@patch('lms.djangoapps.courseware.module_render.has_access', Mock(return_value=True, autospec=True)) class TestStaffDebugInfo(SharedModuleStoreTestCase): """Tests to verify that Staff Debug Info panel and histograms are displayed to staff.""" @@ -1992,7 +1992,7 @@ class TestAnonymousStudentId(SharedModuleStoreTestCase, LoginEnrollmentTestCase) super(TestAnonymousStudentId, self).setUp() self.user = UserFactory() - @patch('courseware.module_render.has_access', Mock(return_value=True, autospec=True)) + @patch('lms.djangoapps.courseware.module_render.has_access', Mock(return_value=True, autospec=True)) def _get_anonymous_id(self, course_id, xblock_class): location = course_id.make_usage_key('dummy_category', 'dummy_name') descriptor = Mock( @@ -2467,7 +2467,7 @@ class TestFilteredChildren(SharedModuleStoreTestCase): self.users = {number: UserFactory() for number in USER_NUMBERS} self._old_has_access = render.has_access - patcher = patch('courseware.module_render.has_access', self._has_access) + patcher = patch('lms.djangoapps.courseware.module_render.has_access', self._has_access) patcher.start() self.addCleanup(patcher.stop) diff --git a/lms/djangoapps/courseware/tests/test_self_paced_overrides.py b/lms/djangoapps/courseware/tests/test_self_paced_overrides.py index 4769fd7278..dcd4d52984 100644 --- a/lms/djangoapps/courseware/tests/test_self_paced_overrides.py +++ b/lms/djangoapps/courseware/tests/test_self_paced_overrides.py @@ -85,7 +85,7 @@ class SelfPacedDateOverrideTest(ModuleStoreTestCase): __, sp_section = self.setup_course(display_name="Self-Paced Course", self_paced=True) self.assertIsNone(sp_section.due) - @patch.dict('courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) + @patch.dict('lms.djangoapps.courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) def test_course_access_to_beta_users(self): """ Test that beta testers can access `self_paced` course prior to start date. @@ -113,7 +113,7 @@ class SelfPacedDateOverrideTest(ModuleStoreTestCase): self.assertTrue(has_access(beta_tester, 'load', self_paced_course)) self.assertTrue(has_access(beta_tester, 'load', self_paced_section, self_paced_course.id)) - @patch.dict('courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) + @patch.dict('lms.djangoapps.courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) def test_instructor_paced_discussion_xblock_visibility(self): """ Verify that discussion xblocks scheduled for release in the future are @@ -128,7 +128,7 @@ class SelfPacedDateOverrideTest(ModuleStoreTestCase): all(xblock.display_name == 'released' for xblock in xblocks) ) - @patch.dict('courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) + @patch.dict('lms.djangoapps.courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) def test_self_paced_discussion_xblock_visibility(self): """ Regression test. Verify that discussion xblocks scheduled for release diff --git a/lms/djangoapps/courseware/tests/test_submitting_problems.py b/lms/djangoapps/courseware/tests/test_submitting_problems.py index 243d1bb51e..d36a6442f3 100644 --- a/lms/djangoapps/courseware/tests/test_submitting_problems.py +++ b/lms/djangoapps/courseware/tests/test_submitting_problems.py @@ -791,7 +791,7 @@ class ProblemWithUploadedFilesTest(TestSubmittingProblems): self.addCleanup(fileobj.close) self.problem_setup("the_problem", filenames) - with patch('courseware.module_render.XQUEUE_INTERFACE.session') as mock_session: + with patch('lms.djangoapps.courseware.module_render.XQUEUE_INTERFACE.session') as mock_session: resp = self.submit_question_answer("the_problem", {'2_1': fileobjs}) self.assertEqual(resp.status_code, 200) diff --git a/lms/djangoapps/courseware/tests/test_tabs.py b/lms/djangoapps/courseware/tests/test_tabs.py index a26aebfd9e..f984ffa386 100644 --- a/lms/djangoapps/courseware/tests/test_tabs.py +++ b/lms/djangoapps/courseware/tests/test_tabs.py @@ -282,7 +282,7 @@ class StaticTabDateTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase): self.assertIn('static_tab', tab_content) # Test when render raises an exception - with patch('courseware.views.views.get_module') as mock_module_render: + with patch('lms.djangoapps.courseware.views.views.get_module') as mock_module_render: mock_module_render.return_value = MagicMock( render=Mock(side_effect=Exception('Render failed!')) ) diff --git a/lms/djangoapps/courseware/tests/test_view_authentication.py b/lms/djangoapps/courseware/tests/test_view_authentication.py index 21bbe53f24..73635ac938 100644 --- a/lms/djangoapps/courseware/tests/test_view_authentication.py +++ b/lms/djangoapps/courseware/tests/test_view_authentication.py @@ -307,7 +307,7 @@ class TestViewAuth(EnterpriseTestConsentRequired, ModuleStoreTestCase, LoginEnro for url in urls: self.assert_request_status_code(200, url) - @patch.dict('courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) + @patch.dict('lms.djangoapps.courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) def test_dark_launch_enrolled_student(self): """ Make sure that before course start, students can't access course @@ -334,7 +334,7 @@ class TestViewAuth(EnterpriseTestConsentRequired, ModuleStoreTestCase, LoginEnro self._check_non_staff_light(self.test_course) self._check_non_staff_dark(self.test_course) - @patch.dict('courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) + @patch.dict('lms.djangoapps.courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) def test_dark_launch_instructor(self): """ Make sure that before course start instructors can access the @@ -357,7 +357,7 @@ class TestViewAuth(EnterpriseTestConsentRequired, ModuleStoreTestCase, LoginEnro self._check_non_staff_light(self.test_course) self._check_non_staff_dark(self.test_course) - @patch.dict('courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) + @patch.dict('lms.djangoapps.courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) def test_dark_launch_global_staff(self): """ Make sure that before course start staff can access @@ -379,7 +379,7 @@ class TestViewAuth(EnterpriseTestConsentRequired, ModuleStoreTestCase, LoginEnro self._check_staff(self.course) self._check_staff(self.test_course) - @patch.dict('courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) + @patch.dict('lms.djangoapps.courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) def test_enrollment_period(self): """ Check that enrollment periods work. @@ -432,7 +432,7 @@ class TestBetatesterAccess(ModuleStoreTestCase, CourseAccessTestMixin): self.normal_student = UserFactory() self.beta_tester = BetaTesterFactory(course_key=self.course.id) - @patch.dict('courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) + @patch.dict('lms.djangoapps.courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) def test_course_beta_period(self): """ Check that beta-test access works for courses. @@ -441,7 +441,7 @@ class TestBetatesterAccess(ModuleStoreTestCase, CourseAccessTestMixin): self.assertCannotAccessCourse(self.normal_student, 'load', self.course) self.assertCanAccessCourse(self.beta_tester, 'load', self.course) - @patch.dict('courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) + @patch.dict('lms.djangoapps.courseware.access.settings.FEATURES', {'DISABLE_START_DATES': False}) def test_content_beta_period(self): """ Check that beta-test access works for content. diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 7cb2876f4f..d12c217c79 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -347,7 +347,7 @@ class ViewsTestCase(ModuleStoreTestCase): self._verify_index_response(expected_response_code=404, chapter_name='non-existent') def test_index_nonexistent_chapter_masquerade(self): - with patch('courseware.views.index.setup_masquerade') as patch_masquerade: + with patch('lms.djangoapps.courseware.views.index.setup_masquerade') as patch_masquerade: masquerade = MagicMock(role='student') patch_masquerade.return_value = (masquerade, self.user) self._verify_index_response(expected_response_code=302, chapter_name='non-existent') @@ -356,7 +356,7 @@ class ViewsTestCase(ModuleStoreTestCase): self._verify_index_response(expected_response_code=404, section_name='non-existent') def test_index_nonexistent_section_masquerade(self): - with patch('courseware.views.index.setup_masquerade') as patch_masquerade: + with patch('lms.djangoapps.courseware.views.index.setup_masquerade') as patch_masquerade: masquerade = MagicMock(role='student') patch_masquerade.return_value = (masquerade, self.user) self._verify_index_response(expected_response_code=302, section_name='non-existent') @@ -1700,7 +1700,7 @@ class ProgressPageTests(ProgressPageBaseTests): bannerText = get_expiration_banner_text(user, self.course) self.assertNotContains(response, bannerText, html=True) - @patch('courseware.views.views.is_course_passed', PropertyMock(return_value=True)) + @patch('lms.djangoapps.courseware.views.views.is_course_passed', PropertyMock(return_value=True)) @patch('lms.djangoapps.certificates.api.get_active_web_certificate', PropertyMock(return_value=True)) @override_settings(FEATURES=FEATURES_WITH_DISABLE_HONOR_CERTIFICATE) @ddt.data(CourseMode.AUDIT, CourseMode.HONOR) @@ -2184,14 +2184,14 @@ class GenerateUserCertTests(ModuleStoreTestCase): self.assertEqual(resp.status_code, HttpResponseBadRequest.status_code) self.assertIn("Your certificate will be available when you pass the course.", resp.content) - @patch('courseware.views.views.is_course_passed', return_value=True) + @patch('lms.djangoapps.courseware.views.views.is_course_passed', return_value=True) @override_settings(CERT_QUEUE='certificates', LMS_SEGMENT_KEY="foobar") def test_user_with_passing_grade(self, mock_is_course_passed): # If user has above passing grading then json will return cert generating message and # status valid code # mocking xqueue and Segment analytics - analytics_patcher = patch('courseware.views.views.segment') + analytics_patcher = patch('lms.djangoapps.courseware.views.views.segment') mock_tracker = analytics_patcher.start() self.addCleanup(analytics_patcher.stop) @@ -2465,7 +2465,7 @@ class TestIndexView(ModuleStoreTestCase): self.assertIn('xblock-student_view-html', unicode_content) self.assertIn('xblock-student_view-video', unicode_content) - @patch('courseware.views.views.CourseTabView.course_open_for_learner_enrollment') + @patch('lms.djangoapps.courseware.views.views.CourseTabView.course_open_for_learner_enrollment') @patch('openedx.core.djangoapps.util.user_messages.PageLevelMessages.register_warning_message') def test_courseware_messages_differentiate_for_anonymous_users( self, patch_register_warning_message, patch_course_open_for_learner_enrollment @@ -2496,7 +2496,7 @@ class TestIndexView(ModuleStoreTestCase): @patch('openedx.core.djangoapps.util.user_messages.PageLevelMessages.register_warning_message') def test_courseware_messages_masters_only(self, patch_register_warning_message): with patch( - 'courseware.views.views.CourseTabView.course_open_for_learner_enrollment' + 'lms.djangoapps.courseware.views.views.CourseTabView.course_open_for_learner_enrollment' ) as patch_course_open_for_learner_enrollment: course = CourseFactory() @@ -2535,7 +2535,8 @@ class TestIndexView(ModuleStoreTestCase): @ddt.unpack def test_should_show_enroll_button(self, course_open_for_self_enrollment, invitation_only, is_masters_only, expected_should_show_enroll_button): - with patch('courseware.views.views.course_open_for_self_enrollment') as patch_course_open_for_self_enrollment, \ + with patch('lms.djangoapps.courseware.views.views.course_open_for_self_enrollment') \ + as patch_course_open_for_self_enrollment, \ patch('course_modes.models.CourseMode.is_masters_only') as patch_is_masters_only: course = CourseFactory() @@ -2994,7 +2995,7 @@ class TestIndexViewCrawlerStudentStateWrites(SharedModuleStoreTestCase): def test_write_by_default(self): """By default, always write student state, regardless of user agent.""" - with patch('courseware.model_data.UserStateCache.set_many') as patched_state_client_set_many: + with patch('lms.djangoapps.courseware.model_data.UserStateCache.set_many') as patched_state_client_set_many: # Simulate someone using Chrome self._load_courseware('Mozilla/5.0 AppleWebKit/537.36') self.assertTrue(patched_state_client_set_many.called) @@ -3007,7 +3008,7 @@ class TestIndexViewCrawlerStudentStateWrites(SharedModuleStoreTestCase): def test_writes_with_config(self): """Test state writes (or lack thereof) based on config values.""" CrawlersConfig.objects.create(known_user_agents='edX-downloader,crawler_foo', enabled=True) - with patch('courseware.model_data.UserStateCache.set_many') as patched_state_client_set_many: + with patch('lms.djangoapps.courseware.model_data.UserStateCache.set_many') as patched_state_client_set_many: # Exact matching of crawler user agent self._load_courseware('crawler_foo') self.assertFalse(patched_state_client_set_many.called) diff --git a/lms/djangoapps/instructor_task/tests/test_integration.py b/lms/djangoapps/instructor_task/tests/test_integration.py index d77532f3fe..7c09eea095 100644 --- a/lms/djangoapps/instructor_task/tests/test_integration.py +++ b/lms/djangoapps/instructor_task/tests/test_integration.py @@ -488,7 +488,7 @@ class TestResetAttemptsTask(TestIntegrationTask): self.submit_student_answer('u1', problem_url_name, [OPTION_1, OPTION_1]) expected_message = "bad things happened" - with patch('courseware.models.StudentModule.save') as mock_save: + with patch('lms.djangoapps.courseware.models.StudentModule.save') as mock_save: mock_save.side_effect = ZeroDivisionError(expected_message) instructor_task = self.reset_problem_attempts('instructor', location) self._assert_task_failure(instructor_task.id, 'reset_problem_attempts', problem_url_name, expected_message) @@ -550,7 +550,7 @@ class TestDeleteProblemTask(TestIntegrationTask): self.submit_student_answer('u1', problem_url_name, [OPTION_1, OPTION_1]) expected_message = "bad things happened" - with patch('courseware.models.StudentModule.delete') as mock_delete: + with patch('lms.djangoapps.courseware.models.StudentModule.delete') as mock_delete: mock_delete.side_effect = ZeroDivisionError(expected_message) instructor_task = self.delete_problem_state('instructor', location) self._assert_task_failure(instructor_task.id, 'delete_problem_state', problem_url_name, expected_message)