From 863a70c6fad6c46d597e30c91edd89e7b44ec3d0 Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Mon, 15 Mar 2021 14:33:47 +0500 Subject: [PATCH 1/2] BOM-2453 tests are failings and complaining related objects doest not exists in User table. Create object in test setup to fix it. In another fix article id was giving integrity error. Fixing task test. --- .../contentstore/tests/test_proctoring.py | 5 +++++ .../contentstore/tests/test_tasks.py | 19 ++++++------------- .../accounts/tests/test_retirement_views.py | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_proctoring.py b/cms/djangoapps/contentstore/tests/test_proctoring.py index 76437f7b5c..37f2e3072b 100644 --- a/cms/djangoapps/contentstore/tests/test_proctoring.py +++ b/cms/djangoapps/contentstore/tests/test_proctoring.py @@ -12,6 +12,8 @@ from edx_proctoring.api import get_all_exams_for_course, get_review_policy_by_ex from pytz import UTC from cms.djangoapps.contentstore.signals.handlers import listen_for_course_publish +from common.djangoapps.student.tests.factories import UserFactory +from common.lib.xmodule.xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory @@ -37,6 +39,9 @@ class TestProctoredExams(ModuleStoreTestCase): proctoring_provider=settings.PROCTORING_BACKENDS['DEFAULT'], ) + # create object to avoid tests failures in proctoring. + UserFactory(id=ModuleStoreEnum.UserID.test) + def _verify_exam_data(self, sequence, expected_active): """ Helper method to compare the sequence with the stored exam, diff --git a/cms/djangoapps/contentstore/tests/test_tasks.py b/cms/djangoapps/contentstore/tests/test_tasks.py index cb4d604e69..dace746429 100644 --- a/cms/djangoapps/contentstore/tests/test_tasks.py +++ b/cms/djangoapps/contentstore/tests/test_tasks.py @@ -20,6 +20,7 @@ from cms.djangoapps.contentstore.tasks import export_olx, rerun_course from cms.djangoapps.contentstore.tests.test_libraries import LibraryTestCase from cms.djangoapps.contentstore.tests.utils import CourseTestCase from common.djangoapps.course_action_state.models import CourseRerunState +from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.embargo.models import Country, CountryAccessRule, RestrictedCourse from xmodule.modulestore.django import modulestore @@ -62,23 +63,15 @@ class ExportCourseTestCase(CourseTestCase): result = export_olx.delay(self.user.id, key, 'en') self._assert_failed(result, json.dumps({'raw_error_msg': 'Boom!'})) - def test_invalid_user_id(self): + @mock.patch('cms.djangoapps.contentstore.tasks.User.objects.get', side_effect=User.DoesNotExist) + def test_invalid_user_id(self, mock_raise_exc): # pylint: disable=unused-argument """ Verify that attempts to export a course as an invalid user fail """ - user_id = User.objects.order_by('-id').first().pk + 100 + user = UserFactory(id=User.objects.order_by('-id').first().pk + 100) key = str(self.course.location.course_key) - result = export_olx.delay(user_id, key, 'en') - self._assert_failed(result, f'Unknown User ID: {user_id}') - - def test_non_course_author(self): - """ - Verify that users who aren't authors of the course are unable to export it - """ - _, nonstaff_user = self.create_non_staff_authed_user_client() - key = str(self.course.location.course_key) - result = export_olx.delay(nonstaff_user.id, key, 'en') - self._assert_failed(result, 'Permission denied') + result = export_olx.delay(user.id, key, 'en') + self._assert_failed(result, f'Unknown User ID: {user.id}') def _assert_failed(self, task_result, error_message): """ diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_retirement_views.py b/openedx/core/djangoapps/user_api/accounts/tests/test_retirement_views.py index d2b22ce362..7cecac8cbd 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_retirement_views.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_retirement_views.py @@ -1594,7 +1594,7 @@ class TestLMSAccountRetirementPost(RetirementTestCase, ModuleStoreTestCase): plugin=rp, user=self.test_user, ) - article = Article.objects.create() + article = Article.objects.create(id=rp.article_id) ArticleRevision.objects.create(ip_address="ipaddresss", user=self.test_user, article=article) # ManualEnrollmentAudit setup From 9de74b1b13e6c5c910bf0c4d93a48f6adac4210b Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Tue, 16 Mar 2021 01:15:48 +0500 Subject: [PATCH 2/2] BOM-2453 tests are failings and complaining related objects doest not exists in User table. Create object in test setup to fix it. In another fix article id was giving integrity error. Fixing task test. --- cms/djangoapps/contentstore/tests/test_tasks.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cms/djangoapps/contentstore/tests/test_tasks.py b/cms/djangoapps/contentstore/tests/test_tasks.py index dace746429..73497824d5 100644 --- a/cms/djangoapps/contentstore/tests/test_tasks.py +++ b/cms/djangoapps/contentstore/tests/test_tasks.py @@ -73,6 +73,15 @@ class ExportCourseTestCase(CourseTestCase): result = export_olx.delay(user.id, key, 'en') self._assert_failed(result, f'Unknown User ID: {user.id}') + def test_non_course_author(self): + """ + Verify that users who aren't authors of the course are unable to export it + """ + _, nonstaff_user = self.create_non_staff_authed_user_client() + key = str(self.course.location.course_key) + result = export_olx.delay(nonstaff_user.id, key, 'en') + self._assert_failed(result, 'Permission denied') + def _assert_failed(self, task_result, error_message): """ Verify that a task failed with the specified error message