Skip to content

Commit

Permalink
chore: python package upgrades (incl. pylint) and style changes
Browse files Browse the repository at this point in the history
JIRA:MST-1061
  • Loading branch information
Matt Hughes authored and matthugs committed Sep 30, 2021
1 parent 82a9846 commit 895c738
Show file tree
Hide file tree
Showing 18 changed files with 457 additions and 425 deletions.
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.2'
__version__ = '4.0.3'

default_app_config = 'edx_proctoring.apps.EdxProctoringConfig' # pylint: disable=invalid-name
5 changes: 1 addition & 4 deletions edx_proctoring/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,7 @@ def lookups(self, request, model_admin):
# prepend the exam_name with a parsed out course_id
lookups += ((
exam.id,
'{course_id}: {exam_name}'.format(
course_id=prettify_course_id(course_id),
exam_name=exam.exam_name
)
f'{prettify_course_id(course_id)}: {exam.exam_name}'
),)

return lookups
Expand Down
695 changes: 359 additions & 336 deletions edx_proctoring/api.py

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions edx_proctoring/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ def make_worker_config(backends, out='/tmp/workers.json'):
# no npm module defined
continue
except IOError:
warnings.warn('Proctoring backend %s defined an npm module,'
'but it is not installed at %r' % (backend.__class__, package_file))
warnings.warn(f'Proctoring backend {backend.__class__} defined an npm module,'
f'but it is not installed at {package_file!r}')
except KeyError:
warnings.warn('%r does not contain a `main` entry' % package_file)
warnings.warn(f'{package_file!r} does not contain a `main` entry')
if config:
try:
with open(out, 'wb+') as outfp:
outfp.write(json.dumps(config).encode('utf-8'))
except IOError:
warnings.warn("Could not write worker config to %s" % out)
warnings.warn(f"Could not write worker config to {out}")
else:
# make sure that this file is group writable, because it may be written by different users
os.chmod(out, 0o664)
Expand Down Expand Up @@ -134,8 +134,8 @@ def get_backend(self, name=None):
try:
return self.backends[name]
except KeyError as error:
raise NotImplementedError("No proctoring backend configured for '{}'. "
"Available: {}".format(name, list(self.backends))) from error
raise NotImplementedError(f"No proctoring backend configured for '{name}'. "
f"Available: {list(self.backends)}") from error

def ready(self):
"""
Expand Down
19 changes: 13 additions & 6 deletions edx_proctoring/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ def start_exam_callback(request, attempt_code): # pylint: disable=unused-argume
"""
attempt = get_exam_attempt_by_code(attempt_code)
if not attempt:
log.warning('attempt_code={attempt_code} cannot be found.'.format(attempt_code=attempt_code))
log.warning(
'attempt_code=%(attempt_code)s cannot be found.',
{
'attempt_code': attempt_code,
}
)
return HttpResponse(
content='You have entered an exam code that is not valid.',
status=404
Expand All @@ -40,11 +45,13 @@ def start_exam_callback(request, attempt_code): # pylint: disable=unused-argume
if ProctoredExamStudentAttemptStatus.is_in_progress_status(attempt_status):
update_attempt_status(attempt['id'], ProctoredExamStudentAttemptStatus.submitted)
else:
log.warning('Attempted to enter proctored exam attempt_id={attempt_id} when status={attempt_status}'
.format(
attempt_id=attempt['id'],
attempt_status=attempt_status,
))
log.warning(
'Attempted to enter proctored exam attempt_id=%(attempt_id)s when status=%(attempt_status)s',
{
'attempt_id': attempt['id'],
'attempt_status': attempt_status,
}
)

course_id = attempt['proctored_exam']['course_id']
content_id = attempt['proctored_exam']['content_id']
Expand Down
2 changes: 1 addition & 1 deletion edx_proctoring/instructor_dashboard_exam_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

urlpatterns = [
url(
r'edx_proctoring/v1/instructor/{}/(?P<exam_id>\d+)$'.format(settings.COURSE_ID_PATTERN),
fr'edx_proctoring/v1/instructor/{settings.COURSE_ID_PATTERN}/(?P<exam_id>\d+)$',
views.InstructorDashboard.as_view(),
name='instructor_dashboard_exam'
),
Expand Down
24 changes: 9 additions & 15 deletions edx_proctoring/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,8 @@ class Meta:
def __str__(self):
""" String representation """
# pragma: no cover
return "{course_id}: {exam_name} ({active})".format(
course_id=self.course_id,
exam_name=self.exam_name,
active='active' if self.is_active else 'inactive',
)
active = 'active' if self.is_active else 'inactive'
return f'{self.course_id}: {self.exam_name} ({active})'

@classmethod
def get_exam_by_content_id(cls, course_id, content_id):
Expand Down Expand Up @@ -157,10 +154,7 @@ class ProctoredExamReviewPolicy(TimeStampedModel):
def __str__(self):
""" String representation """
# pragma: no cover
return "ProctoredExamReviewPolicy: {set_by_user} ({proctored_exam})".format(
set_by_user=self.set_by_user,
proctored_exam=self.proctored_exam,
)
return f'ProctoredExamReviewPolicy: {self.set_by_user} ({self.proctored_exam})'

class Meta:
""" Meta class for this Django model """
Expand Down Expand Up @@ -655,8 +649,8 @@ def add_allowance_for_user(cls, exam_id, user_info, key, value):

if not cls.is_allowance_value_valid(key, value):
err_msg = (
'allowance_value "{value}" should be non-negative integer value.'
).format(value=value)
f'allowance_value "{value}" should be non-negative integer value.'
)
raise AllowanceValueNotAllowedException(err_msg)
# were we passed a PK?
if isinstance(user_info, int):
Expand All @@ -669,17 +663,17 @@ def add_allowance_for_user(cls, exam_id, user_info, key, value):

if not users.exists():
err_msg = (
'Cannot find user against {user_info}'
).format(user_info=user_info)
f'Cannot find user against {user_info}'
)
raise UserNotFoundException(err_msg)

user_id = users[0].id

exam = ProctoredExam.get_exam_by_id(exam_id)
if exam and not exam.is_active:
err_msg = (
'Attempted to add an allowance for user_id={user_id} in exam_id={exam_id}, but '
'this exam is not active.'.format(user_id=user_id, exam_id=exam_id)
f'Attempted to add an allowance for user_id={user_id} in exam_id={exam_id}, but '
'this exam is not active.'
)
raise ProctoredExamNotActiveException(err_msg)

Expand Down
2 changes: 1 addition & 1 deletion edx_proctoring/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def is_in_reviewer_group(user, attempt):
"""
Returns whether user is in a group allowed to review this attempt
"""
backend_group = '%s_review' % attempt['proctored_exam']['backend']
backend_group = f"{attempt['proctored_exam']['backend']}_review"
return user.groups.filter(name=backend_group).exists()


Expand Down
2 changes: 1 addition & 1 deletion edx_proctoring/statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def validate(cls, status):
if status not in cls.passing_statuses + cls.failing_statuses:
err_msg = (
'Received unexpected reviewStatus field value from payload. '
'Was {review_status}.'.format(review_status=status)
f'Was {status}.'
)
raise ProctoredExamBadReviewStatus(err_msg)
return True
Expand Down
15 changes: 10 additions & 5 deletions edx_proctoring/tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,24 @@ def test_send_email_failure(self, logger_mock):
If an email fails to send an error is logged and the attempt is updated
"""
exam_attempt = self._create_started_exam_attempt()
with patch.object(EmailMessage, 'send', side_effect=Exception('foo')):
exc_obj = Exception('foo')
with patch.object(EmailMessage, 'send', side_effect=exc_obj):
update_attempt_status(
exam_attempt.id,
'submitted',
)

exam_attempt.refresh_from_db()
self.assertEqual(exam_attempt.status, 'submitted')
log_format_string = (
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(
('Exception occurred while trying to send proctoring attempt '
'status email for user_id=%(user_id)s in course_id=%(course_id)s -- %(err)s'),
{
'user_id': self.user_id,
'course_id': self.course_id,
'err': exc_obj,
}
)
logger_mock.assert_any_call(log_format_string)

@ddt.data(
ProctoredExamStudentAttemptStatus.verified,
Expand Down
26 changes: 12 additions & 14 deletions edx_proctoring/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
name='proctored_exam.exam_by_id'
),
url(
r'edx_proctoring/v1/proctored_exam/exam/course_id/{}/content_id/(?P<content_id>[A-z0-9]+)$'.format(
settings.COURSE_ID_PATTERN),
(fr'edx_proctoring/v1/proctored_exam/exam/course_id/{settings.COURSE_ID_PATTERN}'
'/content_id/(?P<content_id>[A-z0-9]+)$'),
views.ProctoredExamView.as_view(),
name='proctored_exam.exam_by_content_id'
),
url(
r'edx_proctoring/v1/proctored_exam/exam/course_id/{}$'.format(
settings.COURSE_ID_PATTERN),
fr'edx_proctoring/v1/proctored_exam/exam/course_id/{settings.COURSE_ID_PATTERN}$',
views.ProctoredExamView.as_view(),
name='proctored_exam.exams_by_course_id'
),
Expand All @@ -40,13 +39,13 @@
name='proctored_exam.attempt'
),
url(
r'edx_proctoring/v1/proctored_exam/attempt/grouped/course_id/{}$'.format(settings.COURSE_ID_PATTERN),
fr'edx_proctoring/v1/proctored_exam/attempt/grouped/course_id/{settings.COURSE_ID_PATTERN}$',
views.StudentProctoredGroupedExamAttemptsByCourse.as_view(),
name='proctored_exam.attempts.grouped.course'
),
url(
r'edx_proctoring/v1/proctored_exam/attempt/grouped/course_id/{}/search/(?P<search_by>.+)$'.format(
settings.COURSE_ID_PATTERN),
'edx_proctoring/v1/proctored_exam/attempt/grouped/course_id/'
fr'{settings.COURSE_ID_PATTERN}/search/(?P<search_by>.+)$',
views.StudentProctoredGroupedExamAttemptsByCourse.as_view(),
name='proctored_exam.attempts.grouped.search'
),
Expand All @@ -71,7 +70,7 @@
name='proctored_exam.attempt.callback'
),
url(
r'edx_proctoring/v1/proctored_exam/{}/allowance$'.format(settings.COURSE_ID_PATTERN),
fr'edx_proctoring/v1/proctored_exam/{settings.COURSE_ID_PATTERN}/allowance$',
views.ExamAllowanceView.as_view(),
name='proctored_exam.allowance'
),
Expand All @@ -81,7 +80,7 @@
name='proctored_exam.allowance'
),
url(
r'edx_proctoring/v1/proctored_exam/{}/bulk_allowance$'.format(settings.COURSE_ID_PATTERN),
fr'edx_proctoring/v1/proctored_exam/{settings.COURSE_ID_PATTERN}/bulk_allowance$',
views.ExamBulkAllowanceView.as_view(),
name='proctored_exam.bulk_allowance'
),
Expand All @@ -91,7 +90,7 @@
name='proctored_exam.bulk_allowance'
),
url(
r'edx_proctoring/v1/proctored_exam/{}/grouped/allowance$'.format(settings.COURSE_ID_PATTERN),
fr'edx_proctoring/v1/proctored_exam/{settings.COURSE_ID_PATTERN}/grouped/allowance$',
views.GroupedExamAllowancesByStudent.as_view(),
name='proctored_exam.allowance.grouped.course'
),
Expand All @@ -106,12 +105,12 @@
name='user_onboarding.status'
),
url(
r'edx_proctoring/v1/user_onboarding/status/course_id/{}$'.format(settings.COURSE_ID_PATTERN),
fr'edx_proctoring/v1/user_onboarding/status/course_id/{settings.COURSE_ID_PATTERN}$',
views.StudentOnboardingStatusByCourseView.as_view(),
name='user_onboarding.status.course'
),
url(
r'edx_proctoring/v1/instructor/{}$'.format(settings.COURSE_ID_PATTERN),
fr'edx_proctoring/v1/instructor/{settings.COURSE_ID_PATTERN}$',
views.InstructorDashboard.as_view(),
name='instructor_dashboard_course'
),
Expand All @@ -126,8 +125,7 @@
name='user_retirement_api'
),
url(
r'edx_proctoring/v1/proctored_exam/attempt/course_id/{}$'.format(
settings.COURSE_ID_PATTERN),
fr'edx_proctoring/v1/proctored_exam/attempt/course_id/{settings.COURSE_ID_PATTERN}$',
views.ProctoredExamAttemptView.as_view(),
name='proctored_exam.exam_attempts'
),
Expand Down
10 changes: 6 additions & 4 deletions edx_proctoring/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ def locate_attempt_by_attempt_code(attempt_code):
return attempt_obj, True

# still can't find, error out
err_msg = (
'Could not locate attempt_code={attempt_code}'.format(attempt_code=attempt_code)
log.error(
'Could not locate attempt_code=%(attempt_code)s',
{
'attempt_code': attempt_code,
}
)
log.error(err_msg)
return None, None


Expand Down Expand Up @@ -328,7 +330,7 @@ def resolve_exam_url_for_learning_mfe(course_id, content_id):
""" Helper that builds the url to the exam for the MFE app learning. """
course_key = CourseKey.from_string(course_id)
usage_key = UsageKey.from_string(content_id)
url = '{}/course/{}/{}'.format(settings.LEARNING_MICROFRONTEND_URL, course_key, usage_key)
url = f'{settings.LEARNING_MICROFRONTEND_URL}/course/{course_key}/{usage_key}'
return url


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@edx/edx-proctoring",
"//": "Note that the version format is slightly different than that of the Python version when using prereleases.",
"version": "4.0.2",
"version": "4.0.3",
"main": "edx_proctoring/static/index.js",
"scripts": {
"test": "gulp test"
Expand Down
9 changes: 4 additions & 5 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ certifi==2021.5.30
# via requests
cffi==1.14.6
# via cryptography
charset-normalizer==2.0.4
charset-normalizer==2.0.6
# via requests
click==7.1.2
# via
Expand Down Expand Up @@ -87,7 +87,6 @@ edx-django-utils==4.4.0
# edx-when
edx-drf-extensions==7.0.1
# via
# -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
# -r requirements/base.in
# edx-when
edx-opaque-keys==2.2.2
Expand Down Expand Up @@ -117,7 +116,7 @@ lxml==4.6.3
# via xblock
markupsafe==2.0.1
# via xblock
newrelic==6.8.1.164
newrelic==7.0.0.166
# via edx-django-utils
pbr==5.6.0
# via stevedore
Expand Down Expand Up @@ -180,13 +179,13 @@ six==1.16.0
# python-dateutil
slumber==0.7.1
# via edx-rest-api-client
sqlparse==0.4.1
sqlparse==0.4.2
# via django
stevedore==3.4.0
# via
# edx-django-utils
# edx-opaque-keys
urllib3==1.26.6
urllib3==1.26.7
# via requests
vine==5.0.0
# via
Expand Down
10 changes: 5 additions & 5 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ backports.entry-points-selectable==1.1.0
# via virtualenv
certifi==2021.5.30
# via requests
charset-normalizer==2.0.4
charset-normalizer==2.0.6
# via requests
codecov==2.1.12
# via -r requirements/ci.in
coverage==5.5
# via codecov
distlib==0.3.2
distlib==0.3.3
# via virtualenv
filelock==3.0.12
# via
Expand All @@ -40,13 +40,13 @@ six==1.16.0
# virtualenv
toml==0.10.2
# via tox
tox==3.24.3
tox==3.24.4
# via
# -r requirements/ci.in
# tox-battery
tox-battery==0.6.1
# via -r requirements/ci.in
urllib3==1.26.6
urllib3==1.26.7
# via requests
virtualenv==20.7.2
virtualenv==20.8.0
# via tox
Loading

0 comments on commit 895c738

Please sign in to comment.