fix: Fix function mocking.
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.
This commit is contained in:
@@ -920,15 +920,16 @@ class TestInstructorAPIBulkAccountCreationAndEnrollment(SharedModuleStoreTestCas
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user