Skip to content

Commit

Permalink
Merge pull request #586 from edx/dcs/due-date-json
Browse files Browse the repository at this point in the history
Fixed saving exams to backend when there's a due date set
  • Loading branch information
Dave St.Germain authored Jul 8, 2019
2 parents c1269d4 + dacc29a commit 027bacf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion edx_proctoring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
from __future__ import absolute_import

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

default_app_config = 'edx_proctoring.apps.EdxProctoringConfig' # pylint: disable=invalid-name
7 changes: 5 additions & 2 deletions edx_proctoring/backends/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,11 @@ def on_exam_saved(self, exam):
response = self.session.post(url, json=exam)
data = response.json()
except Exception as exc: # pylint: disable=broad-except
# pylint: disable=no-member
content = exc.response.content if hasattr(exc, 'response') else response.content
if response:
# pylint: disable=no-member
content = exc.response.content if hasattr(exc, 'response') else response.content
else:
content = None
log.exception('failed to save exam. %r', content)
data = {}
return data.get('id')
Expand Down
6 changes: 6 additions & 0 deletions edx_proctoring/backends/tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ def test_failed_exam_save(self):
external_id = self.provider.on_exam_saved(self.backend_exam)
self.assertEqual(external_id, None)

@responses.activate
def test_bad_exam_save(self):
self.backend_exam['bad'] = object()
external_id = self.provider.on_exam_saved(self.backend_exam)
self.assertEqual(external_id, None)

@responses.activate
def test_register_exam_attempt(self):
context = {
Expand Down
7 changes: 7 additions & 0 deletions edx_proctoring/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ class Meta:
)


class ProctoredExamJSONSafeSerializer(ProctoredExamSerializer):
"""
ProctoredExam serializer which will return dates as strings.
"""
due_date = serializers.DateTimeField(required=False)


class UserSerializer(serializers.ModelSerializer):
"""
Serializer for the User Model.
Expand Down
8 changes: 4 additions & 4 deletions edx_proctoring/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def check_for_category_switch(sender, instance, **kwargs): # pylint: disable=un
if instance.id:
original = sender.objects.get(pk=instance.id)
if original.is_proctored and instance.is_proctored != original.is_proctored:
from edx_proctoring.serializers import ProctoredExamSerializer
exam = ProctoredExamSerializer(instance).data
from edx_proctoring.serializers import ProctoredExamJSONSafeSerializer
exam = ProctoredExamJSONSafeSerializer(instance).data
# from the perspective of the backend, the exam is now inactive.
exam['is_active'] = False
backend = get_backend_provider(name=exam['backend'])
Expand All @@ -44,8 +44,8 @@ def save_exam_on_backend(sender, instance, **kwargs): # pylint: disable=unused-
exam_obj = instance.proctored_exam
review_policy = instance
if exam_obj.is_proctored:
from edx_proctoring.serializers import ProctoredExamSerializer
exam = ProctoredExamSerializer(exam_obj).data
from edx_proctoring.serializers import ProctoredExamJSONSafeSerializer
exam = ProctoredExamJSONSafeSerializer(exam_obj).data
if review_policy:
exam['rule_summary'] = review_policy.review_policy
backend = get_backend_provider(exam)
Expand Down

0 comments on commit 027bacf

Please sign in to comment.