Skip to content

Commit

Permalink
style: update pylint to enforce consistent quotation marks
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelroytman committed Apr 11, 2023
1 parent 936c04d commit 6c40bdf
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 163 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source=edx_exams
omit =
edx_exams/settings/*
edx_exams/conf*
edx_exams/docker_gunicorn_configuration.py
*wsgi.py
*migrations*
*admin.py
Expand Down
18 changes: 9 additions & 9 deletions edx_exams/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Meta:
model = User

fields = (
"id", "username", "email", "lms_user_id"
'id', 'username', 'email', 'lms_user_id'
)


Expand All @@ -36,7 +36,7 @@ class ProctoringProviderSerializer(serializers.ModelSerializer):

class Meta:
model = ProctoringProvider
fields = ["name", "verbose_name", "lti_configuration_id"]
fields = ['name', 'verbose_name', 'lti_configuration_id']


class ExamSerializer(serializers.ModelSerializer):
Expand All @@ -61,8 +61,8 @@ class Meta:
model = Exam

fields = (
"id", "exam_name", "course_id", "content_id", "time_limit_mins", "due_date", "exam_type",
"hide_after_due", "is_active"
'id', 'exam_name', 'course_id', 'content_id', 'time_limit_mins', 'due_date', 'exam_type',
'hide_after_due', 'is_active'
)

def validate_exam_type(self, value):
Expand All @@ -71,7 +71,7 @@ def validate_exam_type(self, value):
"""
valid_exam_types = [exam_type.name for exam_type in EXAM_TYPES]
if value not in valid_exam_types:
raise serializers.ValidationError("Must be a valid exam type.")
raise serializers.ValidationError('Must be a valid exam type.')
return value


Expand All @@ -92,8 +92,8 @@ class Meta:
model = ExamAttempt

fields = (
"id", "created", "modified", "user", "start_time", "end_time",
"status", "exam", "allowed_time_limit_mins", "attempt_number"
'id', 'created', 'modified', 'user', 'start_time', 'end_time',
'status', 'exam', 'allowed_time_limit_mins', 'attempt_number'
)


Expand Down Expand Up @@ -135,6 +135,6 @@ class Meta:
model = ExamAttempt

fields = (
"attempt_id", "attempt_status", "course_id", "exam_type",
"exam_display_name", "exam_url_path", "time_remaining_seconds"
'attempt_id', 'attempt_status', 'course_id', 'exam_type',
'exam_display_name', 'exam_url_path', 'time_remaining_seconds'
)
2 changes: 1 addition & 1 deletion edx_exams/apps/api/test_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ def build_jwt_headers(self, user):
"""
jwt_payload = self.default_payload(user)
jwt_token = self.generate_token(jwt_payload)
headers = {"HTTP_AUTHORIZATION": "JWT " + jwt_token}
headers = {'HTTP_AUTHORIZATION': 'JWT ' + jwt_token}
return headers
22 changes: 11 additions & 11 deletions edx_exams/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def patch_api(self, user, data):
data = json.dumps(data)
headers = self.build_jwt_headers(user)

return self.client.patch(self.url, data, **headers, content_type="application/json")
return self.client.patch(self.url, data, **headers, content_type='application/json')

def get_response(self, user, data, expected_response):
"""
Expand Down Expand Up @@ -117,8 +117,8 @@ def test_invalid_data(self):
}
]
response = self.get_response(self.user, data, 400)
self.assertIn("hide_after_due", response.data["errors"][0])
self.assertIn("is_active", response.data["errors"][0])
self.assertIn('hide_after_due', response.data['errors'][0])
self.assertIn('is_active', response.data['errors'][0])

def test_invalid_exam_type(self):
"""
Expand All @@ -136,7 +136,7 @@ def test_invalid_exam_type(self):
}
]
response = self.get_response(self.user, data, 400)
self.assertIn("exam_type", response.data["errors"][0])
self.assertIn('exam_type', response.data['errors'][0])

def test_existing_exam_update(self):
"""
Expand Down Expand Up @@ -287,7 +287,7 @@ def patch_api(self, user, data):
data = json.dumps(data)
headers = self.build_jwt_headers(user)

return self.client.patch(self.url, data, **headers, content_type="application/json")
return self.client.patch(self.url, data, **headers, content_type='application/json')

def test_patch_auth_failures(self):
"""
Expand Down Expand Up @@ -493,7 +493,7 @@ def get_response(self):
"""
Helper function to make a get request
"""
url = reverse("api:v1:proctoring-providers-list")
url = reverse('api:v1:proctoring-providers-list')
response = self.client.get(url)
return response

Expand Down Expand Up @@ -578,7 +578,7 @@ def get_exam_access(self, user, url):
return self.client.get(url, **headers)

def assert_valid_exam_access_token(self, response, user, exam):
token = response.data.get("exam_access_token")
token = response.data.get('exam_access_token')
self.assertEqual(unpack_token_for(token, user.lms_user_id).get('course_id'), exam.course_id)
self.assertEqual(unpack_token_for(token, user.lms_user_id).get('content_id'), exam.content_id)

Expand Down Expand Up @@ -818,7 +818,7 @@ def test_expiration_started_exam_attempt_various_times(self, start_delta, curren
self.assertEqual(response_status, response.status_code)

self.assert_valid_exam_access_token(response, self.user, self.exam)
expiration = response.data.get("exam_access_token_expiration")
expiration = response.data.get('exam_access_token_expiration')
default_secs = 60
if is_default:
self.assertEqual(expiration, default_secs)
Expand Down Expand Up @@ -866,7 +866,7 @@ def get_api(self, user):

headers = self.build_jwt_headers(user)
url = reverse('api:v1:exams-attempt-latest')
return self.client.get(url, **headers, content_type="application/json")
return self.client.get(url, **headers, content_type='application/json')

def create_mock_attempt(self, user, status, start_time, allowed_time_limit_mins):
"""
Expand Down Expand Up @@ -1045,7 +1045,7 @@ def put_api(self, user, attempt_id, data):
headers = self.build_jwt_headers(user)
url = reverse('api:v1:exams-attempt', args=[attempt_id])

return self.client.put(url, data, **headers, content_type="application/json")
return self.client.put(url, data, **headers, content_type='application/json')

def post_api(self, user, data):
"""
Expand All @@ -1055,7 +1055,7 @@ def post_api(self, user, data):
headers = self.build_jwt_headers(user)
url = reverse('api:v1:exams-attempt')

return self.client.post(url, data, **headers, content_type="application/json")
return self.client.post(url, data, **headers, content_type='application/json')

def test_put_user_update_permissions(self):
"""
Expand Down
6 changes: 3 additions & 3 deletions edx_exams/apps/api/v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
re_path(fr'configs/course_id/{COURSE_ID_PATTERN}',
CourseExamConfigurationsView.as_view(),
name='course-exam-config'),
re_path(r"^providers?$",
re_path(r'^providers?$',
ProctoringProvidersView.as_view(),
name="proctoring-providers-list",),
name='proctoring-providers-list',),
re_path(fr'access_tokens/exam_id/{EXAM_ID_PATTERN}',
ExamAccessTokensView.as_view(),
name="exam-access-tokens"),
name='exam-access-tokens'),
path('exams/attempt/<int:attempt_id>',
ExamAttemptView.as_view(),
name='exams-attempt',),
Expand Down
30 changes: 15 additions & 15 deletions edx_exams/apps/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def update_exam(cls, exam_object, fields):
exam_object.save()

log.info(
"Updated existing exam=%(exam_id)s",
'Updated existing exam=%(exam_id)s',
{
'exam_id': exam_object.id,
}
Expand All @@ -94,7 +94,7 @@ def create_exam(cls, fields):
exam = Exam.objects.create(resource_id=str(uuid.uuid4()), **fields)

log.info(
"Created new exam=%(exam_id)s",
'Created new exam=%(exam_id)s',
{
'exam_id': exam.id,
}
Expand Down Expand Up @@ -157,8 +157,8 @@ def handle_exams(cls, request_exams_list, course_exams_qs, course_id):
path_parameter('course_id', str, 'edX course run ID or external course key'),
],
responses={
200: "OK",
400: "Invalid request. See message."
200: 'OK',
400: 'Invalid request. See message.'
},
summary='Modify exams',
description='This endpoint should create new exams, update existing exams, '
Expand Down Expand Up @@ -186,7 +186,7 @@ def patch(self, request, course_id):
data = {}
else:
response_status = status.HTTP_400_BAD_REQUEST
data = {"detail": "Invalid data", "errors": serializer.errors}
data = {'detail': 'Invalid data', 'errors': serializer.errors}

return Response(status=response_status, data=data)

Expand Down Expand Up @@ -243,15 +243,15 @@ def patch(self, request, course_id):

# check that proctoring provider is in request
if 'provider' not in request.data:
error = {"detail": "No proctoring provider name in request."}
error = {'detail': 'No proctoring provider name in request.'}
elif request.data.get('provider') is None:
provider = None
else:
try:
provider = ProctoringProvider.objects.get(name=request.data['provider'])
# return 400 if proctoring provider does not exist
except ObjectDoesNotExist:
error = {"detail": "Proctoring provider does not exist."}
error = {'detail': 'Proctoring provider does not exist.'}

if not error:
CourseExamConfiguration.create_or_update(provider, course_id)
Expand Down Expand Up @@ -325,11 +325,11 @@ def get_response(cls, exam, user):
403 error if access is not granted.
"""
claims = {"course_id": exam.course_id, "content_id": exam.content_id}
claims = {'course_id': exam.course_id, 'content_id': exam.content_id}
expiration_window = 60
exam_attempt = ExamAttempt.get_current_exam_attempt(user.id, exam.id)

data = {"detail": "Exam access token not granted"}
data = {'detail': 'Exam access token not granted'}
grant_access = False
response_status = status.HTTP_403_FORBIDDEN

Expand All @@ -354,9 +354,9 @@ def get_response(cls, exam, user):
grant_access, response_status = True, status.HTTP_200_OK

if grant_access:
log.info("Creating exam access token")
log.info('Creating exam access token')
access_token = sign_token_for(user.lms_user_id, expiration_window, claims)
data = {"exam_access_token": access_token, "exam_access_token_expiration": expiration_window}
data = {'exam_access_token': access_token, 'exam_access_token_expiration': expiration_window}

response = Response(status=response_status,
data=data)
Expand All @@ -374,7 +374,7 @@ def get(self, request, exam_id):
except ObjectDoesNotExist:
response_status = status.HTTP_404_NOT_FOUND
return Response(status=response_status,
data={"detail": "Exam does not exist"})
data={'detail': 'Exam does not exist'})

response = self.get_response(exam, request.user)

Expand Down Expand Up @@ -512,8 +512,8 @@ def put(self, request, attempt_id):
# user should only be able to update their own attempt
if attempt.user.id != request.user.id:
error_msg = (
f"user_id={attempt.user.id} attempted to update attempt_id={attempt.id} in "
f"course_id={attempt.exam.course_id} but does not have access to it. (action={action})"
f'user_id={attempt.user.id} attempted to update attempt_id={attempt.id} in '
f'course_id={attempt.exam.course_id} but does not have access to it. (action={action})'
)
error = {'detail': error_msg}
return Response(status=status.HTTP_403_FORBIDDEN, data=error)
Expand All @@ -529,7 +529,7 @@ def put(self, request, attempt_id):
to_status = action_mapping.get(action)
if to_status:
attempt_id = update_attempt_status(attempt_id, to_status)
data = {"exam_attempt_id": attempt_id}
data = {'exam_attempt_id': attempt_id}
return Response(data)

return Response(
Expand Down
2 changes: 1 addition & 1 deletion edx_exams/apps/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _allow_status_transition(attempt_obj, to_status):
illegal_status_transition_msg = (
f'A status transition from "{attempt_obj.status}" to "{to_status}" was attempted '
f'on exam_id={attempt_obj.exam.id} for user_id={attempt_obj.user.id}. This is not '
f"allowed! (course_id={attempt_obj.exam.course_id})"
f'allowed! (course_id={attempt_obj.exam.course_id})'
)
return False, illegal_status_transition_msg
return True, ''
Expand Down
4 changes: 2 additions & 2 deletions edx_exams/apps/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

class Status:
"""Health statuses."""
OK = "OK"
UNAVAILABLE = "UNAVAILABLE"
OK = 'OK'
UNAVAILABLE = 'UNAVAILABLE'


# Pulled from edx-platform. Will correctly capture both old- and new-style
Expand Down
2 changes: 1 addition & 1 deletion edx_exams/apps/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def process_request(self, request): # pylint: disable=missing-function-docstrin
return

if request.COOKIES.get(jwt_cookie_header_payload_name(), None):
request.META[USE_JWT_COOKIE_HEADER] = "true"
request.META[USE_JWT_COOKIE_HEADER] = 'true'
8 changes: 4 additions & 4 deletions edx_exams/apps/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ def create_or_update(cls, provider, course_id):
if existing_config:
if existing_config.provider == provider:
# nothing to be done
log.info(f"Course exam configuration course_id={course_id} already has provider={provider_name}")
log.info(f'Course exam configuration course_id={course_id} already has provider={provider_name}')
return
count = cls.update_course_config_provider(existing_config, provider)
log.info(f"Updated course exam configuration course_id={course_id} "
+ f"to provider={provider_name} and recreated {count} exams")
log.info(f'Updated course exam configuration course_id={course_id} '
+ f'to provider={provider_name} and recreated {count} exams')
else:
CourseExamConfiguration.objects.create(course_id=course_id, provider=provider)
log.info(f"Created course exam configuration course_id={course_id}, provider={provider_name}")
log.info(f'Created course exam configuration course_id={course_id}, provider={provider_name}')

@classmethod
def update_course_config_provider(cls, existing_config, new_provider):
Expand Down
6 changes: 3 additions & 3 deletions edx_exams/apps/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class Health(APIView):
@schema(
parameters=[],
responses={
200: "OK",
503: "Service unavailable"
200: 'OK',
503: 'Service unavailable'
},
summary='Allows a load balancer to verify this service is up.',
description='Checks the status of the database connection on which this service relies.'
Expand All @@ -54,7 +54,7 @@ def get(self, request):

try:
cursor = connection.cursor()
cursor.execute("SELECT 1")
cursor.execute('SELECT 1')
cursor.fetchone()
cursor.close()
database_status = Status.OK
Expand Down
8 changes: 5 additions & 3 deletions edx_exams/docker_gunicorn_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

preload_app = True
timeout = 300
bind = "0.0.0.0:18740"
bind = '0.0.0.0:18740'

workers = 2


def pre_request(worker, req):
# pragma: no cover
"""Log requests before they are processed."""
worker.log.info("%s %s" % (req.method, req.path))
worker.log.info('%s %s' % (req.method, req.path))


def close_all_caches():
Expand Down Expand Up @@ -51,7 +52,8 @@ def post_fork(server, worker): # pylint: disable=unused-argument

def when_ready(server): # pylint: disable=unused-argument
"""When running in debug mode, run Django's `check` to better match what `manage.py runserver` does."""
# pragma: no cover
from django.conf import settings # lint-amnesty, pylint: disable=import-outside-toplevel
from django.core.management import call_command # lint-amnesty, pylint: disable=import-outside-toplevel
if settings.DEBUG:
call_command("check")
call_command('check')
6 changes: 3 additions & 3 deletions edx_exams/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
urlpatterns.append(path('__debug__/', include(debug_toolbar.urls)))

api_info = make_api_info(
title="edX Exams API",
version="v0",
description="A REST API for interacting with the edX exams service."
title='edX Exams API',
version='v0',
description='A REST API for interacting with the edX exams service.'
)

urlpatterns += make_docs_urls(
Expand Down
Loading

0 comments on commit 6c40bdf

Please sign in to comment.