Skip to content

Commit

Permalink
chore: fix pylint errors in some prod 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 28, 2021
1 parent 19af988 commit f4e4eb9
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 191 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Change Log
Unreleased
~~~~~~~~~~

[4.0.2] - 2021-09-28
~~~~~~~~~~~~~~~~~~~~~
* Batch of refactorings to use format strings/lazy string formatting for logging calls

[4.0.1] - 2021-09-21
~~~~~~~~~~~~~~~~~~~~~
* Bug fix for student onboarding statuses by course. If learner has multiple attempts, return non-reset attempt status if possible.
Expand Down
2 changes: 1 addition & 1 deletion edx_proctoring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"""

# Be sure to update the version number in edx_proctoring/package.json
__version__ = '4.0.1'
__version__ = '4.0.2'

default_app_config = 'edx_proctoring.apps.EdxProctoringConfig' # pylint: disable=invalid-name
37 changes: 16 additions & 21 deletions edx_proctoring/backends/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,16 @@ def get_javascript(self):

except WebpackBundleLookupError:
warnings.warn(
'Could not find webpack bundle for proctoring backend {package}.'
' Check whether webpack is configured to build such a bundle'.format(
package=package
)
f'Could not find webpack bundle for proctoring backend {package}.'
' Check whether webpack is configured to build such a bundle'
)
except BaseWebpackLoaderException:
warnings.warn(
'Could not find webpack bundle for proctoring backend {package}.'.format(
package=package
)
f'Could not find webpack bundle for proctoring backend {package}.'
)
except IOError as err:
warnings.warn(
'Webpack stats file corresponding to WebWorkers not found: {}'
.format(str(err))
f'Webpack stats file corresponding to WebWorkers not found: {str(err)}'
)

# if the Javascript URL is not an absolute URL (i.e. doesn't have a scheme), prepend
Expand Down Expand Up @@ -189,9 +184,8 @@ def register_exam_attempt(self, exam, context):
# attempt code isn't needed in this API
payload.pop('attempt_code', False)
log.debug(
'Creating exam attempt for exam_id={exam_id} (external_id={external_id}) at {url}'.format(
exam_id=exam['id'], external_id=exam['external_id'], url=url
)
'Creating exam attempt for exam_id=%(exam_id)i (external_id=%(external_id)s) at %(url)s',
{'exam_id': exam['id'], 'external_id': exam['external_id'], 'url': url}
)
response = self.session.post(url, json=payload)
if response.status_code != 200:
Expand Down Expand Up @@ -272,7 +266,10 @@ def on_exam_saved(self, exam):
url = self.exam_url.format(exam_id=external_id)
else:
url = self.create_exam_url
log.info('Saving exam_id={exam_id} to {url}'.format(exam_id=exam['id'], url=url))
log.info(
'Saving exam_id=%(exam_id)i to %(url)s',
{'exam_id': exam['id'], 'url': url}
)
response = None
try:
response = self.session.post(url, json=exam)
Expand All @@ -284,9 +281,8 @@ def on_exam_saved(self, exam):
else:
content = None
log.exception(
'Failed to save exam_id={exam_id} to {url}. Response: {content}'.format(
exam_id=exam['id'], url=url, content=content
)
'Failed to save exam_id=%(exam_id)i to %(url)s. Response: %(content)s',
{'exam_id': exam['id'], 'url': url, 'content': content}
)
data = {}
return data.get('id')
Expand Down Expand Up @@ -317,10 +313,9 @@ def get_instructor_url(self, course_id, user, exam_id=None, attempt_id=None, sho
url = self.instructor_url.format(client_id=self.client_id, jwt=encoded)

log.debug(
'Created instructor url for course_id={course_id} exam_id={exam_id} '
'attempt_id={attempt_id}'.format(
course_id=course_id, exam_id=exam_id, attempt_id=attempt_id
)
('Created instructor url for course_id=%(course_id)s exam_id=%(exam_id)i '
'attempt_id=%(attempt_id)s'),
{'course_id': course_id, 'exam_id': exam_id, 'attempt_id': attempt_id}
)
return url

Expand Down Expand Up @@ -362,7 +357,7 @@ def _get_language_headers(self):
default_lang = settings.LANGUAGE_CODE
lang_header = default_lang
if current_lang and current_lang != default_lang:
lang_header = '{};{}'.format(current_lang, default_lang)
lang_header = f'{current_lang};{default_lang}'
return {'Accept-Language': lang_header}

def _make_attempt_request(self, exam, attempt, method='POST', status=None, **payload):
Expand Down
42 changes: 13 additions & 29 deletions edx_proctoring/backends/software_secure.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,8 @@ def register_exam_attempt(self, exam, context):

if status not in [200, 201]:
err_msg = (
'Could not register attempt_code={attempt_code}. '
'HTTP Status code was {status_code} and response was {response}.'.format(
attempt_code=attempt_code,
status_code=status,
response=response
)
f'Could not register attempt_code={attempt_code}. '
f'HTTP Status code was {status} and response was {response}.'
)
log.error(err_msg)
raise BackendProviderCannotRegisterAttempt(err_msg, status)
Expand Down Expand Up @@ -141,13 +137,9 @@ def on_review_callback(self, attempt, payload):
)
if not match:
err_msg = (
'Found attempt_code {attempt_code}, but the recorded external_id did not '
'match the ssiRecordLocator that had been recorded previously. Has {existing} '
'but received {received}!'.format(
attempt_code=attempt['attempt_code'],
existing=attempt['external_id'],
received=received_id
)
f"Found attempt_code {attempt['attempt_code']}, but the recorded external_id did not "
f"match the ssiRecordLocator that had been recorded previously. Has {attempt['external_id']} "
f'but received {received_id}!'
)
raise ProctoredExamSuspiciousLookup(err_msg)

Expand All @@ -156,9 +148,7 @@ def on_review_callback(self, attempt, payload):
del payload['videoReviewLink']

log_msg = (
'Received callback from SoftwareSecure with review data: {payload}'.format(
payload=payload
)
f'Received callback from SoftwareSecure with review data: {payload}'
)
log.info(log_msg)
SoftwareSecureReviewStatus.validate(payload['reviewStatus'])
Expand Down Expand Up @@ -228,24 +218,18 @@ def _get_payload(self, exam, context):
review_policy = context.get('review_policy', constants.DEFAULT_SOFTWARE_SECURE_REVIEW_POLICY)
review_policy_exception = context.get('review_policy_exception')
scheme = 'https' if getattr(settings, 'HTTPS', 'on') == 'on' else 'http'
callback_url = '{scheme}://{hostname}{path}'.format(
scheme=scheme,
hostname=settings.SITE_NAME,
path=reverse(
'edx_proctoring:anonymous.proctoring_launch_callback.start_exam',
args=[attempt_code]
)
path = reverse(
'edx_proctoring:anonymous.proctoring_launch_callback.start_exam',
args=[attempt_code]
)
callback_url = f'{scheme}://{settings.SITE_NAME}{path}'

# compile the notes to the reviewer
# this is a combination of the Exam Policy which is for all students
# combined with any exceptions granted to the particular student
reviewer_notes = review_policy
if review_policy_exception:
reviewer_notes = '{notes}; {exception}'.format(
notes=reviewer_notes,
exception=review_policy_exception
)
reviewer_notes = f'{reviewer_notes}; {review_policy_exception}'

(first_name, last_name) = self._split_fullname(full_name)

Expand Down Expand Up @@ -353,8 +337,8 @@ def _sign_doc(self, body_json, method, headers, date):
message = method_string + headers_str + body_str

log_msg = (
'About to send payload to SoftwareSecure: examCode={examCode}, courseID={courseID}'.
format(examCode=body_json.get('examCode'), courseID=body_json.get('orgExtra').get('courseID'))
f"About to send payload to SoftwareSecure: examCode={body_json.get('examCode')}, "
f"courseID={body_json.get('orgExtra').get('courseID')}"
)
log.info(log_msg)

Expand Down
7 changes: 2 additions & 5 deletions edx_proctoring/management/commands/set_attempt_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,12 @@ def handle(self, *args, **options):

msg = (
'Running management command to update '
'attempt {attempt_id} status to {to_status}'.format(
attempt_id=attempt_id,
to_status=to_status
)
f'attempt {attempt_id} status to {to_status}'
)
self.stdout.write(msg)

if not ProctoredExamStudentAttemptStatus.is_valid_status(to_status):
raise CommandError('{to_status} is not a valid attempt status!'.format(to_status=to_status))
raise CommandError(f'{to_status} is not a valid attempt status!')

update_attempt_status(attempt_id, to_status)

Expand Down
6 changes: 3 additions & 3 deletions edx_proctoring/management/commands/set_is_attempt_active.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def handle(self, *args, **options):
self.check_and_update(archived_review, batch_size, sleep_time, only_update_archives=True)

if self.update_attempt_codes:
log.info('Updating {} reviews'.format(len(self.update_attempt_codes)))
log.info('Updating %i reviews', len(self.update_attempt_codes))
self.bulk_update(self.update_attempt_codes, False)

def check_and_update(self, review_object, size, sleep_time, only_update_archives=False):
Expand All @@ -72,10 +72,10 @@ def check_and_update(self, review_object, size, sleep_time, only_update_archives
self.distinct_attempt_codes.add(review_object.attempt_code)
self.update_attempt_codes.append(review_object.attempt_code)
self.update_field_count += 1
log.info('Adding review {} to be updated'.format(review_object.id))
log.info('Adding review %i to be updated', review_object.id)

if self.update_field_count == size:
log.info('Updating {} reviews'.format(size))
log.info('Updating %i reviews', size)
self.bulk_update(self.update_attempt_codes, only_update_archives)
self.update_field_count = 0
self.update_attempt_codes = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ def handle(self, *args, **options):
for review in reviews_in_date_range:
review_id = review.id
attempt_code = review.attempt_code
log.info('Saving review_id={review_id} for corresponding attempt_code={attempt_code}'.format(
review_id=review_id,
attempt_code=attempt_code
))
log.info(
'Saving review_id=%i for corresponding attempt_code=%s',
review_id,
attempt_code
)
review.save()
review_count += 1

Expand Down
Loading

0 comments on commit f4e4eb9

Please sign in to comment.