From e3851ab3d19c7fb30866de0e9e2f595983fe8ccd Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Mon, 16 Oct 2023 11:37:37 -0400 Subject: [PATCH] test: Update to reuse variables in more places. Some of the places where we had explicit copies of the password were not necessary so we referece the exsting TEST_PASSWORD variable where possible. --- cms/djangoapps/contentstore/tests/test_i18n.py | 2 +- lms/djangoapps/course_api/tests/mixins.py | 2 +- .../transformers/tests/helpers.py | 4 ++-- lms/djangoapps/course_wiki/tests/tests.py | 2 +- .../tests/test_submitting_problems.py | 2 +- .../grades/rest_api/v1/tests/test_views.py | 2 +- lms/djangoapps/mobile_api/testutils.py | 2 +- lms/djangoapps/survey/tests/test_utils.py | 2 +- lms/djangoapps/survey/tests/test_views.py | 2 +- .../verify_student/tests/test_views.py | 18 ++++++++++-------- .../test_crowdsource_hinter.py | 4 ++-- 11 files changed, 22 insertions(+), 20 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_i18n.py b/cms/djangoapps/contentstore/tests/test_i18n.py index afa4e03f0222..fdab4aef83f1 100644 --- a/cms/djangoapps/contentstore/tests/test_i18n.py +++ b/cms/djangoapps/contentstore/tests/test_i18n.py @@ -184,7 +184,7 @@ def setUp(self): self.uname = 'testuser' self.email = 'test+courses@edx.org' - self.password = 'Password1234' + self.password = self.TEST_PASSWORD # Create the use so we can log them in. self.user = UserFactory.create(username=self.uname, email=self.email, password=self.password) diff --git a/lms/djangoapps/course_api/tests/mixins.py b/lms/djangoapps/course_api/tests/mixins.py index 2940826c68c4..46671867b72c 100644 --- a/lms/djangoapps/course_api/tests/mixins.py +++ b/lms/djangoapps/course_api/tests/mixins.py @@ -8,7 +8,7 @@ from common.djangoapps.student.tests.factories import UserFactory, CourseEnrollmentFactory, CourseAccessRoleFactory from xmodule.modulestore.tests.factories import ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order -TEST_PASSWORD = 'edx' +TEST_PASSWORD = 'Password1234' class CourseApiFactoryMixin: diff --git a/lms/djangoapps/course_blocks/transformers/tests/helpers.py b/lms/djangoapps/course_blocks/transformers/tests/helpers.py index 4060052be84b..fb78946280fd 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/helpers.py +++ b/lms/djangoapps/course_blocks/transformers/tests/helpers.py @@ -50,7 +50,7 @@ def setUp(self): """ super().setUp() # Set up users. - self.password = 'Password1234' + self.password = self.TEST_PASSWORD self.user = UserFactory.create(password=self.password) self.staff = UserFactory.create(password=self.password, is_staff=True) @@ -253,7 +253,7 @@ def setUp(self): parent_block.children.append(self.xblock_keys[i]) update_block(parent_block) - self.password = 'Password1234' + self.password = self.TEST_PASSWORD self.student = UserFactory.create(is_staff=False, username='test_student', password=self.password) self.staff = UserFactory.create(is_staff=True, username='test_staff', password=self.password) CourseEnrollmentFactory.create( diff --git a/lms/djangoapps/course_wiki/tests/tests.py b/lms/djangoapps/course_wiki/tests/tests.py index f81b285afd35..7fc86947d4fa 100644 --- a/lms/djangoapps/course_wiki/tests/tests.py +++ b/lms/djangoapps/course_wiki/tests/tests.py @@ -24,7 +24,7 @@ def setUp(self): # Create two accounts self.student = 'view@test.com' self.instructor = 'view2@test.com' - self.password = 'Password1234' + self.password = self.TEST_PASSWORD for username, email in [('u1', self.student), ('u2', self.instructor)]: self.create_account(username, email, self.password) self.activate_user(email) diff --git a/lms/djangoapps/courseware/tests/test_submitting_problems.py b/lms/djangoapps/courseware/tests/test_submitting_problems.py index dee37a09c1d9..4d55645d7a5f 100644 --- a/lms/djangoapps/courseware/tests/test_submitting_problems.py +++ b/lms/djangoapps/courseware/tests/test_submitting_problems.py @@ -154,7 +154,7 @@ def setUp(self): # create a test student self.course = CourseFactory.create(display_name=self.COURSE_NAME, number=self.COURSE_SLUG) self.student = 'view@test.com' - self.password = 'Password1234' + self.password = self.TEST_PASSWORD self.create_account('u1', self.student, self.password) self.activate_user(self.student) self.enroll(self.course) diff --git a/lms/djangoapps/grades/rest_api/v1/tests/test_views.py b/lms/djangoapps/grades/rest_api/v1/tests/test_views.py index e5d82998b687..cd2107ec7c29 100644 --- a/lms/djangoapps/grades/rest_api/v1/tests/test_views.py +++ b/lms/djangoapps/grades/rest_api/v1/tests/test_views.py @@ -548,7 +548,7 @@ class CourseSubmissionHistoryWithDataTest(TestSubmittingProblems): def setUp(self): super().setUp() self.namespaced_url = 'grades_api:v1:submission_history' - self.password = 'Password1234' + self.password = self.TEST_PASSWORD self.basic_setup() self.global_staff = GlobalStaffFactory.create() diff --git a/lms/djangoapps/mobile_api/testutils.py b/lms/djangoapps/mobile_api/testutils.py index abd4e0a4e003..f74d4b45a5fd 100644 --- a/lms/djangoapps/mobile_api/testutils.py +++ b/lms/djangoapps/mobile_api/testutils.py @@ -50,7 +50,7 @@ def setUp(self): certificate_available_date=datetime.datetime.now(pytz.UTC) ) self.user = UserFactory.create() - self.password = 'Password1234' + self.password = self.TEST_PASSWORD self.username = self.user.username self.api_version = API_V1 IgnoreMobileAvailableFlagConfig(enabled=False).save() diff --git a/lms/djangoapps/survey/tests/test_utils.py b/lms/djangoapps/survey/tests/test_utils.py index 5a940a89011a..ce35474d6d28 100644 --- a/lms/djangoapps/survey/tests/test_utils.py +++ b/lms/djangoapps/survey/tests/test_utils.py @@ -28,7 +28,7 @@ def setUp(self): self.client = Client() # Create two accounts - self.password = 'Password1234' + self.password = self.TEST_PASSWORD self.student = UserFactory.create( username='student', email='student@test.com', password=self.password, ) diff --git a/lms/djangoapps/survey/tests/test_views.py b/lms/djangoapps/survey/tests/test_views.py index 9f537de46526..07ddd34e0576 100644 --- a/lms/djangoapps/survey/tests/test_views.py +++ b/lms/djangoapps/survey/tests/test_views.py @@ -29,7 +29,7 @@ def setUp(self): self.client = Client() # Create two accounts - self.password = 'Password1234' + self.password = self.TEST_PASSWORD self.student = UserFactory.create(username='student', email='student@test.com', password=self.password) self.test_survey_name = 'TestSurvey' diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index c537ff6fc251..77ee515d3757 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -93,6 +93,8 @@ def mock_render_to_response(*args, **kwargs): 3W+sdGFUK3GH1NAX71VxbAlFVLUetcMwai1+wXmGkRw6A7YezVFnhw== -----END RSA PRIVATE KEY-----""" +TEST_PASSWORD = 'Password1234' + def _mock_payment_processors(): """ @@ -122,8 +124,8 @@ def test_start_new_verification(self): Test the case where the user has no pending `PhotoVerificationAttempts`, but is just starting their first. """ - UserFactory.create(username="rusty", password='Password1234') - self.client.login(username="rusty", password='Password1234') + UserFactory.create(username="rusty", password=TEST_PASSWORD) + self.client.login(username="rusty", password=TEST_PASSWORD) def must_be_logged_in(self): self.assertHttpForbidden(self.client.get(self.start_url())) # lint-amnesty, pylint: disable=no-member @@ -1055,11 +1057,11 @@ def setUp(self): """ Create a user and course. """ super().setUp() - self.user = UserFactory.create(username="test", password='Password1234') + self.user = UserFactory.create(username="test", password=TEST_PASSWORD) self.course = CourseFactory.create() for mode, min_price in (('audit', 0), ('honor', 0), ('verified', 100)): CourseModeFactory.create(mode_slug=mode, course_id=self.course.id, min_price=min_price, sku=self.make_sku()) - self.client.login(username="test", password='Password1234') + self.client.login(username="test", password=TEST_PASSWORD) def _assert_checked_out( self, @@ -1868,7 +1870,7 @@ def setUp(self): super().setUp() self.user = AdminFactory() - login_success = self.client.login(username=self.user.username, password='Password1234') + login_success = self.client.login(username=self.user.username, password=TEST_PASSWORD) assert login_success self.attempt = SoftwareSecurePhotoVerification( status="submitted", @@ -1895,7 +1897,7 @@ def test_photo_url_view_returns_404_if_invalid_receipt_id(self): def test_403_for_non_staff(self): self.user = UserFactory() - login_success = self.client.login(username=self.user.username, password='Password1234') + login_success = self.client.login(username=self.user.username, password=TEST_PASSWORD) assert login_success url = reverse('verification_photo_urls', kwargs={'receipt_id': str(self.receipt_id)}) response = self.client.get(url) @@ -1934,7 +1936,7 @@ class TestDecodeImageViews(MockS3Boto3Mixin, TestVerificationBase): def setUp(self): super().setUp() self.user = AdminFactory() - login_success = self.client.login(username=self.user.username, password='Password1234') + login_success = self.client.login(username=self.user.username, password=TEST_PASSWORD) assert login_success def _mock_submit_images(self): @@ -1995,7 +1997,7 @@ def test_download_image_response(self, img_type, _mock_get_storage): @ddt.data("face", "photo_id") def test_403_for_non_staff(self, img_type): self.user = UserFactory() - login_success = self.client.login(username=self.user.username, password='Password1234') + login_success = self.client.login(username=self.user.username, password=TEST_PASSWORD) assert login_success self._mock_submit_images() diff --git a/openedx/tests/xblock_integration/test_crowdsource_hinter.py b/openedx/tests/xblock_integration/test_crowdsource_hinter.py index cf2cc368e6ba..61f1097481c7 100644 --- a/openedx/tests/xblock_integration/test_crowdsource_hinter.py +++ b/openedx/tests/xblock_integration/test_crowdsource_hinter.py @@ -21,8 +21,8 @@ class TestCrowdsourceHinter(SharedModuleStoreTestCase, LoginEnrollmentTestCase): Create the test environment with the crowdsourcehinter xblock. """ STUDENTS = [ - {'email': 'view@test.com', 'password': 'Password1234'}, - {'email': 'view2@test.com', 'password': 'Password1234'} + {'email': 'view@test.com', 'password': SharedModuleStoreTestCase.TEST_PASSWORD}, + {'email': 'view2@test.com', 'password': SharedModuleStoreTestCase.TEST_PASSWORD} ] XBLOCK_NAMES = ['crowdsourcehinter']