Skip to content

Commit

Permalink
fix: Fix function mocking.
Browse files Browse the repository at this point in the history
The way the patch decorator was being used is not supported in python
3.11.  Use the patch decorator to auto generate the correct mock and
make the test a bit more readabale.  The new change is both 3.8 and
3.11 compatible.
  • Loading branch information
feanil committed Apr 3, 2024
1 parent 9c2bf44 commit 70eed66
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lms/djangoapps/instructor/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,15 +920,16 @@ def test_users_created_and_enrolled_successfully_if_others_fail(self):
manual_enrollments = ManualEnrollmentAudit.objects.all()
assert manual_enrollments.count() == 2

@patch('lms.djangoapps.instructor.views.api', 'generate_random_string',
Mock(side_effect=['first', 'first', 'second']))
def test_generate_unique_password_no_reuse(self):
"""
generate_unique_password should generate a unique password string that hasn't been generated before.
"""
generated_password = ['first']
password = generate_unique_password(generated_password, 12)
assert password != 'first'
with patch('lms.djangoapps.instructor.views.api.generate_random_string') as mock:
mock.side_effect = ['first', 'first', 'second']

generated_password = ['first']
password = generate_unique_password(generated_password, 12)
assert password != 'first'

@patch.dict(settings.FEATURES, {'ALLOW_AUTOMATED_SIGNUPS': False})
def test_allow_automated_signups_flag_not_set(self):
Expand Down

0 comments on commit 70eed66

Please sign in to comment.