Skip to content

Commit

Permalink
test: add fixtures for special exams
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Sep 8, 2023
1 parent d782649 commit d6c6570
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 24 deletions.
6 changes: 4 additions & 2 deletions docs/event-mapping/Supported_events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ Forum events
Exam events
------------------

* `edx.special_exam.practice.attempt.started`_ | edX `sample <../../event_routing_backends/processors/tests/fixtures/current/edx.special_exam.practice.attempt.started.json>` | xAPI `map <./xAPI_mapping.rst#edx-special-exam-practire-attempt-started>` , `sample <../../event_routing_backends/processors/xapi/tests/fixtures/expected/edx.special_exam.practice.attempt.started.json>`__
* `edx.special_exam.practice.attempt.submitted`_ | edX `sample <../../event_routing_backends/processors/tests/fixtures/current/edx.special_exam.practice.attempt.submitted.json>` | xAPI `map <./xAPI_mapping.rst#edx-special-exam-practire-attempt-submitted>` , `sample <../../event_routing_backends/processors/xapi/tests/fixtures/expected/edx.special_exam.practice.attempt.submitted.json>`__
* `edx.special_exam.timed.attempt.started`_ | edX `sample <../../event_routing_backends/processors/tests/fixtures/current/edx.special_exam.timed.attempt.started.json>`__ | xAPI `map <./xAPI_mapping.rst#edx-special-exam-timed-attempt-started>`__ , `sample <../../event_routing_backends/processors/xapi/tests/fixtures/expected/edx.special_exam.timed.attempt.started.json>`__
* `edx.special_exam.timed.attempt.submitted`_ | edX `sample <../../event_routing_backends/processors/tests/fixtures/current/edx.special_exam.timed.attempt.submitted.json>`__ | xAPI `map <./xAPI_mapping.rst#edx-special-exam-timed-attempt-submitted>`__ , `sample <../../event_routing_backends/processors/xapi/tests/fixtures/expected/edx.special_exam.timed.attempt.submitted.json>`__


.. _edx.course.enrollment.activated: http://edx.readthedocs.io/projects/devdata/en/latest/internal_data_formats/tracking_logs/student_event_types.html#edx-course-enrollment-activated-and-edx-course-enrollment-deactivated
Expand Down Expand Up @@ -121,3 +121,5 @@ Exam events
.. _edx.forum.comment.deleted: https://docs.openedx.org/en/latest/developers/references/internal_data_formats/tracking_logs/student_event_types.html#edx-forum-comment-deleted
.. _edx.forum.comment.reported: https://docs.openedx.org/en/latest/developers/references/internal_data_formats/tracking_logs/student_event_types.html#edx-forum-comment-reported
.. _edx.forum.comment.unreported: https://docs.openedx.org/en/latest/developers/references/internal_data_formats/tracking_logs/student_event_types.html#edx-forum-comment-unreported
.. _edx.special_exam.timed.attempt.started: https://docs.openedx.org/en/latest/developers/references/internal_data_formats/tracking_logs/student_event_types.html#edx-special-exam-proctored-attempt-started-edx-special-exam-practice-attempt-started-and-edx-special-exam-timed-attempt-started
.. _edx.special_exam.timed.attempt.submitted: https://docs.openedx.org/en/latest/developers/references/internal_data_formats/tracking_logs/student_event_types.html#edx-special-exam-proctored-attempt-submitted-edx-special-exam-practice-attempt-submitted-and-edx-special-exam-timed-attempt-submitted
12 changes: 10 additions & 2 deletions event_routing_backends/processors/tests/transformers_test_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ def test_event_transformer(self, event_filename, mocked_uuid):
with open(expected_event_file_path, encoding='utf-8') as expected:
expected_event = json.loads(expected.read())

actual_transformed_event = self.registry.get_transformer(original_event).transform()
try:
actual_transformed_event = self.registry.get_transformer(original_event).transform()
self.compare_events(actual_transformed_event, expected_event)
except Exception as e:
with open("actual_transformed_event.json", "w") as actual_transformed_event_file:
actual_transformed_event_file.write(actual_transformed_event.to_json())

Check warning on line 116 in event_routing_backends/processors/tests/transformers_test_mixin.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/tests/transformers_test_mixin.py#L114-L116

Added lines #L114 - L116 were not covered by tests

self.compare_events(actual_transformed_event, expected_event)
with open("expected_event.json", "w") as expected_event_file:
json.dump(expected_event, expected_event_file, indent=4)

Check warning on line 119 in event_routing_backends/processors/tests/transformers_test_mixin.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/tests/transformers_test_mixin.py#L118-L119

Added lines #L118 - L119 were not covered by tests

raise e

Check warning on line 121 in event_routing_backends/processors/tests/transformers_test_mixin.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/tests/transformers_test_mixin.py#L121

Added line #L121 was not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -21,61 +21,56 @@ def get_object(self):
Returns:
`Activity`
"""
object_id = self.get_data("data.exam_content_id")
object_id = self.get_data("event.exam_content_id")

return Activity(
id=object_id,
definition=ActivityDefinition(
type=constants.XAPI_ACTIVITY_ASSESSMENT,
name=LanguageMap(**({constants.EN: self.get_data("data.exam_name")})),
name=LanguageMap(**({constants.EN: self.get_data("event.exam_name")})),
extensions=Extensions(
{
constants.XAPI_ACTIVITY_PRACTICE_EXAM: self.get_data(
"data.exam_is_practice_exam"
"event.exam_is_practice_exam"
),
constants.XAPI_ACTIVITY_PROCTORED_EXAM: self.get_data(
"data.exam_is_proctored"
"event.exam_is_proctored"
),
constants.XAPI_ACTIVITY_COURSE: self.get_data("data.course_id"),
constants.XAPI_ACTIVITY_COURSE: self.get_data("event.course_id"),
}
),
),
)

def get_context_extensions(self):
extensions = super().get_context_extensions()

return extensions.update({})

def get_context_activities(self):
context_activities = super().get_context_activities()

context_activities.grouping = [
Activity(
id=self.get_data("data.attempt_code"),
id=self.get_data("event.attempt_code"),
definition=ActivityDefinition(
type=constants.XAPI_ACTIVITY_EXAM_ATTEMPT,
name=LanguageMap(
**({constants.EN: self.get_data("data.course_name")})
),
name=LanguageMap({constants.EN: self.get_data("event.exam_name")}),
extensions=Extensions(
{
constants.XAPI_CONTEXT_ATTEMPT_STARTED: self.get_data(
"data.attempt_started_at"
"event.attempt_started_at"
),
constants.XAPI_CONTEXT_ATTEMPT_COMPLETED: self.get_data(
"data.attempt_completed_at"
"event.attempt_completed_at"
),
constants.XAPI_CONTEXT_ATTEMPT_TIME: self.get_data(
"data.attempt_event_elapsed_time_secs"
"event.attempt_event_elapsed_time_secs"
),
constants.XAPI_CONTEXT_ID: self.get_data("data.attempt_id"),
constants.XAPI_CONTEXT_ID: self.get_data("event.attempt_id"),
}
),
),
),
]

return context_activities


@XApiTransformersRegistry.register("edx.special_exam.timed.attempt.created")
class PracticeExamStartedTransformer(BaseExamTransformer):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"id": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb",
"version": "1.0.3",
"actor": {
"objectType": "Agent",
"account": { "name": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb", "homePage": "http://localhost:18000" }
},
"verb": { "id": "http://adlnet.gov/expapi/verbs/initialized", "display": { "en": "initialized" } },
"object": {
"id": "block-v1:edX+DemoX+Demo_Course+type@sequential+block@5b4bf8d7d41c4070b299abefed74155e",
"objectType": "Activity",
"definition": {
"name": { "en": "Subsection" },
"type": "http://adlnet.gov/expapi/activities/assessment",
"extensions": {
"https://w3id.org/xapi/openedx/extension/practice-exam": false,
"https://w3id.org/xapi/openedx/extension/proctored-exam": false
}
}
},
"timestamp": "2023-09-08T15:58:04.833393+00:00",
"context": {
"contextActivities": {
"parent": [
{
"id": "http://localhost:18000/course/course-v1:edX+DemoX+Demo_Course",
"objectType": "Activity",
"definition": {
"name": { "en-US": "Demonstration Course" },
"type": "http://adlnet.gov/expapi/activities/course"
}
}
],
"grouping": [
{
"id": "438AD672-DE2C-4F0B-8876-35444E7DD746",
"objectType": "Activity",
"definition": {
"name": { "en": "Subsection" },
"type": "http://adlnet.gov/expapi/activities/attempt",
"extensions": {
"https://w3id.org/xapi/openedx/extension/id": 1
}
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"id": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb",
"version": "1.0.3",
"actor": {
"objectType": "Agent",
"account": { "name": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb", "homePage": "http://localhost:18000" }
},
"verb": { "id": "http://adlnet.gov/expapi/verbs/terminated", "display": { "en": "terminated" } },
"object": {
"id": "block-v1:edX+DemoX+Demo_Course+type@sequential+block@5b4bf8d7d41c4070b299abefed74155e",
"objectType": "Activity",
"definition": {
"name": { "en": "Subsection" },
"type": "http://adlnet.gov/expapi/activities/assessment",
"extensions": {
"https://w3id.org/xapi/openedx/extension/practice-exam": false,
"https://w3id.org/xapi/openedx/extension/proctored-exam": false
}
}
},
"timestamp": "2023-09-08T16:20:53.604375+00:00",
"context": {
"contextActivities": {
"parent": [
{
"id": "http://localhost:18000/course/course-v1:edX+DemoX+Demo_Course",
"objectType": "Activity",
"definition": {
"name": { "en-US": "Demonstration Course" },
"type": "http://adlnet.gov/expapi/activities/course"
}
}
],
"grouping": [
{
"id": "438AD672-DE2C-4F0B-8876-35444E7DD746",
"objectType": "Activity",
"definition": {
"name": { "en": "Subsection" },
"type": "http://adlnet.gov/expapi/activities/attempt",
"extensions": {
"https://w3id.org/xapi/openedx/extension/attempt-started": "2023-09-08T15:58:04.838598+00:00",
"https://w3id.org/xapi/openedx/extension/attempt-completed": "2023-09-08T16:20:53.577698+00:00",
"https://w3id.org/xapi/openedx/extension/attempt-time": 1368.7657,
"https://w3id.org/xapi/openedx/extension/id": 1
}
}
}
]
}
}
}
4 changes: 2 additions & 2 deletions event_routing_backends/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def plugin_settings(settings):
'edx.course.enrollment.mode_changed',
'edx.grades.subsection.grade_calculated',
'edx.grades.course.grade_calculated',
'edx.special_exam.timed_attempt.created',
'edx.special_exam.timed_attempt.submitted',
'edx.special_exam.timed.attempt.created',
'edx.special_exam.timed.attempt.submitted',
'edx.forum.thread.created',
'edx.forum.thread.deleted',
'edx.forum.thread.edited',
Expand Down

0 comments on commit d6c6570

Please sign in to comment.