Skip to content

Commit

Permalink
test: Update to reuse variables in more places.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
feanil committed Oct 16, 2023
1 parent 64e91d4 commit e3851ab
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/tests/test_i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def setUp(self):

self.uname = 'testuser'
self.email = '[email protected]'
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)
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/course_api/tests/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/course_blocks/transformers/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/course_wiki/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):
# Create two accounts
self.student = '[email protected]'
self.instructor = '[email protected]'
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]'
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)
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/grades/rest_api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/mobile_api/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/survey/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]', password=self.password,
)
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/survey/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]', password=self.password)

self.test_survey_name = 'TestSurvey'
Expand Down
18 changes: 10 additions & 8 deletions lms/djangoapps/verify_student/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions openedx/tests/xblock_integration/test_crowdsource_hinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class TestCrowdsourceHinter(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
Create the test environment with the crowdsourcehinter xblock.
"""
STUDENTS = [
{'email': '[email protected]', 'password': 'Password1234'},
{'email': '[email protected]', 'password': 'Password1234'}
{'email': '[email protected]', 'password': SharedModuleStoreTestCase.TEST_PASSWORD},
{'email': '[email protected]', 'password': SharedModuleStoreTestCase.TEST_PASSWORD}
]
XBLOCK_NAMES = ['crowdsourcehinter']

Expand Down

0 comments on commit e3851ab

Please sign in to comment.