Skip to content

Commit

Permalink
chore: fix pylint errors in test files for string formatting
Browse files Browse the repository at this point in the history
JIRA:MST-1061
  • Loading branch information
Matt Hughes authored and matthugs committed Sep 27, 2021
1 parent 24af502 commit 19af988
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 97 deletions.
6 changes: 3 additions & 3 deletions edx_proctoring/backends/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ def on_exam_saved(self, exam):
# pylint: disable=unused-argument
def get_instructor_url(self, course_id, user, exam_id=None, attempt_id=None, show_configuration_dashboard=False):
"Return a fake instructor url"
url = '/instructor/%s/' % course_id
url = f'/instructor/{course_id}/'
if exam_id:
url += '?exam=%s' % exam_id
url += f'?exam={exam_id}'
if attempt_id:
url += '&attempt=%s' % attempt_id
url += f'&attempt={attempt_id}'

if show_configuration_dashboard:
url += '&config=true'
Expand Down
9 changes: 3 additions & 6 deletions edx_proctoring/backends/tests/test_software_secure.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,7 @@ def assert_get_payload_mock(self, exam, context):
# assert that this is in the 'reviewerNotes' field that is passed to SoftwareSecure
expected = context['review_policy']
if review_policy_exception:
expected = '{base}; {exception}'.format(
base=expected,
exception=review_policy_exception
)
expected = f'{expected}; {review_policy_exception}'

test_self.assertEqual(result['reviewerNotes'], expected)
return result
Expand Down Expand Up @@ -331,8 +328,8 @@ def assert_get_payload_mock_no_policy(self, exam, context):
for illegal_char in SOFTWARE_SECURE_INVALID_CHARS:
exam_id = create_exam(
course_id='foo/bar/baz',
content_id='content with {}'.format(illegal_char),
exam_name='Sample Exam with {} character'.format(illegal_char),
content_id=f'content with {illegal_char}',
exam_name=f'Sample Exam with {illegal_char} character',
time_limit_mins=10,
is_proctored=True,
backend='software_secure',
Expand Down
10 changes: 5 additions & 5 deletions edx_proctoring/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2932,7 +2932,7 @@ def test_exam_configuration_dashboard_url(self):
)
self.assertEqual(
get_exam_configuration_dashboard_url(self.course_id, 'test_content_2'),
'/edx_proctoring/v1/instructor/a/b/c/{}?config=true'.format(exam_id)
f'/edx_proctoring/v1/instructor/a/b/c/{exam_id}?config=true'
)

def test_clear_onboarding_errors(self):
Expand Down Expand Up @@ -3482,9 +3482,9 @@ def test_get_exam_attempt_data(self, is_proctored_exam, is_learning_mfe):
exam_id = self.timed_exam_id if not is_proctored_exam else self.proctored_exam_id
attempt_data = get_exam_attempt_data(exam_id, attempt.id, is_learning_mfe)
content_id = self.content_id if is_proctored_exam else self.content_id_timed
expected_exam_url = '{}/course/{}/{}'.format(
settings.LEARNING_MICROFRONTEND_URL, self.course_id, content_id
) if is_learning_mfe else reverse('jump_to', args=[self.course_id, content_id])
expected_exam_url = (f'{settings.LEARNING_MICROFRONTEND_URL}/course/{self.course_id}/{content_id}'
if is_learning_mfe
else reverse('jump_to', args=[self.course_id, content_id]))

assert attempt_data
assert 'attempt_id' in attempt_data
Expand Down Expand Up @@ -3644,7 +3644,7 @@ def test_check_prerequisites(self, status, are_satisfied, expected_prerequisites
result = check_prerequisites(self.exam, self.user_id)
self.assertEqual(result['prerequisite_status']['are_prerequisites_satisifed'], are_satisfied)
self.assertEqual(
len(result['prerequisite_status']['{}_prerequisites'.format(status)]),
len(result['prerequisite_status'][f'{status}_prerequisites']),
expected_prerequisites_len
)
if status == 'declined':
Expand Down
19 changes: 7 additions & 12 deletions edx_proctoring/tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,8 @@ def test_send_email_failure(self, logger_mock):
exam_attempt.refresh_from_db()
self.assertEqual(exam_attempt.status, 'submitted')
log_format_string = (
'Exception occurred while trying to send proctoring attempt '
'status email for user_id={user_id} in course_id={course_id} -- {err}'.format(
user_id=self.user_id,
course_id=self.course_id,
err='foo',
)
f'Exception occurred while trying to send proctoring attempt '
f'status email for user_id={self.user_id} in course_id={self.course_id} -- foo'
)
logger_mock.assert_any_call(log_format_string)

Expand Down Expand Up @@ -199,9 +195,8 @@ def test_email_template_select(self, status, template_name, select_template_mock
)

expected_args = [
'emails/proctoring/{backend}/{template_name}'.format(
backend=exam_attempt.proctored_exam.backend, template_name=template_name),
'emails/{template_name}'.format(template_name=template_name)
f'emails/proctoring/{exam_attempt.proctored_exam.backend}/{template_name}',
f'emails/{template_name}',
]
select_template_mock.assert_called_once_with(expected_args)

Expand Down Expand Up @@ -301,7 +296,7 @@ def test_correct_edx_support_url(self, status, override_email):
Test that the correct edX support URL is used in emails. The email should use either the backend specific
contact URL, if one is specified, or fall back to the edX contact us support page.
"""
contact_url = 'http://{site_name}/support/contact_us'.format(site_name=SITE_NAME)
contact_url = f'http://{SITE_NAME}/support/contact_us'
backend_settings = settings.PROCTORING_BACKENDS

if override_email:
Expand All @@ -322,6 +317,6 @@ def test_correct_edx_support_url(self, status, override_email):

# Verify the edX support URL
actual_body = self._normalize_whitespace(mail.outbox[0].body)
self.assertIn('<a href="{contact_url}"> '
'{contact_url} </a>'.format(contact_url=contact_url),
self.assertIn(f'<a href="{contact_url}"> '
f'{contact_url} </a>',
actual_body)
13 changes: 5 additions & 8 deletions edx_proctoring/tests/test_mfe_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ def setUp(self):
'content_id': self.content_id,
'is_learning_mfe': True,
})
self.expected_exam_url = '{}/course/{}/{}'.format(
settings.LEARNING_MICROFRONTEND_URL, self.course_id, self.content_id
)
self.expected_exam_url = f'{settings.LEARNING_MICROFRONTEND_URL}/course/{self.course_id}/{self.content_id}'
yesterday = timezone.now() - timezone.timedelta(days=1)
self.course_scheduled_sections = {
BlockUsageLocator.from_string(self.content_id_onboarding): MockScheduleItemData(yesterday),
Expand Down Expand Up @@ -167,9 +165,7 @@ def test_get_started_timed_exam_attempts_data(self):
self.assertEqual(response.status_code, 200)
response_data = json.loads(response.content.decode('utf-8'))
exam_data = response_data['exam']
expected_exam_url = '{}/course/{}/{}'.format(
settings.LEARNING_MICROFRONTEND_URL, self.course_id, self.content_id_timed
)
expected_exam_url = f'{settings.LEARNING_MICROFRONTEND_URL}/course/{self.course_id}/{self.content_id_timed}'
assert 'prerequisite_status' not in exam_data
assert 'active_attempt' in response_data and response_data['active_attempt']
self.assertHasExamData(response_data, has_attempt=True, content_id=self.content_id_timed)
Expand Down Expand Up @@ -305,8 +301,9 @@ def test_exam_data_contains_link_to_onboarding_exam_if_attempt_in_onboarding_err
onboarding_exam = ProctoredExam.objects.get(id=self.onboarding_exam_id)

if is_learning_mfe:
expected_exam_url = '{}/course/{}/{}'.format(
settings.LEARNING_MICROFRONTEND_URL, self.course_id, onboarding_exam.content_id
expected_exam_url = (
f'{settings.LEARNING_MICROFRONTEND_URL}/course/'
f'{self.course_id}/{onboarding_exam.content_id}'
)
else:
expected_exam_url = reverse('jump_to', args=[self.course_id, onboarding_exam.content_id])
Expand Down
8 changes: 4 additions & 4 deletions edx_proctoring/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@ def test_get_exam_attempts(self):

# create number of exam attempts
for i in range(90):
user = User.objects.create(username='tester{0}'.format(i), email='tester{0}@test.com'.format(i))
user = User.objects.create(username=f'tester{i}', email=f'tester{i}@test.com')
ProctoredExamStudentAttempt.create_exam_attempt(
proctored_exam.id, user.id,
'test_attempt_code{0}'.format(i), True, False, 'test_external_id{0}'.format(i)
f'test_attempt_code{i}', True, False, f'test_external_id{i}'
)

with self.assertNumQueries(1):
Expand Down Expand Up @@ -430,10 +430,10 @@ def test_exam_review_policy(self):
attempt = ProctoredExamStudentAttempt.create_exam_attempt(
proctored_exam.id,
self.user.id,
'test_attempt_code{0}'.format(self.user.id),
f'test_attempt_code{self.user.id}',
True,
False,
'test_external_id{0}'.format(self.user.id)
f'test_external_id{self.user.id}'
)
attempt.review_policy_id = policy.id
attempt.save()
Expand Down
2 changes: 1 addition & 1 deletion edx_proctoring/tests/test_reviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def test_post_review_auth(self):
)
assert response.status_code == 200
# user in the review group
group_name = '%s_review' % (self.attempt['proctored_exam']['backend'])
group_name = f"{self.attempt['proctored_exam']['backend']}_review"
self.user.groups.get_or_create(name=group_name)
self.user.is_staff = False
self.user.save()
Expand Down
19 changes: 10 additions & 9 deletions edx_proctoring/tests/test_student_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ def test_get_student_view(self):
"""
rendered_response = self.render_proctored_exam()
self.assertIn(
'data-exam-id="{proctored_exam_id}"'.format(proctored_exam_id=self.proctored_exam_id),
f'data-exam-id="{self.proctored_exam_id}"',
rendered_response
)
self.assertIn(self.start_an_exam_msg.format(exam_name=self.exam_name), rendered_response)
self.assertIn(self.start_an_exam_msg, rendered_response)

# try practice exam variant
rendered_response = self.render_practice_exam()
Expand Down Expand Up @@ -1301,12 +1301,12 @@ def test_get_studentview_unstarted_timed_exam(self):
}
)
self.assertNotIn(
'data-exam-id="{proctored_exam_id}"'.format(proctored_exam_id=self.proctored_exam_id),
f'data-exam-id="{self.proctored_exam_id}"',
rendered_response
)
self.assertIn(self.timed_exam_msg.format(exam_name=self.exam_name), rendered_response)
self.assertIn('1 hour and 30 minutes', rendered_response)
self.assertNotIn(self.start_an_exam_msg.format(exam_name=self.exam_name), rendered_response)
self.assertNotIn(self.start_an_exam_msg, rendered_response)

def test_get_studentview_unstarted_timed_exam_with_allowance(self):
"""
Expand All @@ -1329,12 +1329,12 @@ def test_get_studentview_unstarted_timed_exam_with_allowance(self):
context={}
)
self.assertNotIn(
'data-exam-id="{proctored_exam_id}"'.format(proctored_exam_id=self.proctored_exam_id),
f'data-exam-id="{self.proctored_exam_id}"',
rendered_response
)
self.assertIn(self.timed_exam_msg.format(exam_name=self.exam_name), rendered_response)
self.assertIn('31 minutes', rendered_response)
self.assertNotIn(self.start_an_exam_msg.format(exam_name=self.exam_name), rendered_response)
self.assertNotIn(self.start_an_exam_msg, rendered_response)

@ddt.data(
(ProctoredExamStudentAttemptStatus.ready_to_submit, 'Are you sure that you want to submit your timed exam?'),
Expand Down Expand Up @@ -1550,7 +1550,7 @@ def test_get_student_view_ready_to_resume_status(self, render_exam, exam_type):
self.assertIn(self.proctored_exam_ready_to_resume_msg, rendered_response)

time_remaining = humanized_time(int(get_exam_attempt_by_id(exam_attempt.id)['time_remaining_seconds'] / 60))
time_remaining_string = 'You will have {} to complete your exam.'.format(time_remaining)
time_remaining_string = f'You will have {time_remaining} to complete your exam.'
self.assertIn(time_remaining_string, rendered_response)

@ddt.data(
Expand Down Expand Up @@ -1578,7 +1578,8 @@ def test_get_student_view_ping_interval_for_view(self, render_exam, exam_type):

rendered_response = render_exam(self)

expected_javascript_string = 'edx.courseware.proctored_exam.ProctoringAppPingInterval = {}'.format(
DEFAULT_DESKTOP_APPLICATION_PING_INTERVAL_SECONDS
expected_javascript_string = (
'edx.courseware.proctored_exam.ProctoringAppPingInterval = '
f'{DEFAULT_DESKTOP_APPLICATION_PING_INTERVAL_SECONDS}'
)
self.assertIn(expected_javascript_string, rendered_response)
Loading

0 comments on commit 19af988

Please sign in to comment.