Skip to content

Commit

Permalink
test: adds transformer tests
Browse files Browse the repository at this point in the history
Uses transforms fixture test utilities from ERB to ensure that raw
aggregator events are transformed to xAPI as expected.

* test_output/ -- used by ERB to write failed event transforms for debugging
* adds 'factory' as a test requirement because ERB tests needs it.
  • Loading branch information
pomegranited committed Jun 13, 2024
1 parent e82c49d commit 4542458
Show file tree
Hide file tree
Showing 26 changed files with 739 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pip-log.txt
.tox
coverage.xml
htmlcov/
test_output/*.json

# Translations
*.mo
Expand Down
2 changes: 1 addition & 1 deletion completion_aggregator/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def get_object(self) -> Activity:
Get object for xAPI transformed event.
"""
if not self.object_type:
raise NotImplementedError()
raise NotImplementedError() # pragma: no cover

return Activity(
id=self.get_object_iri("xblock", self.get_data("data.block_id")),
Expand Down
7 changes: 7 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ event-tracking==2.4.0
# -r requirements/quality.txt
# edx-completion
# edx-event-routing-backends
factory-boy==3.3.0
# via -r requirements/quality.txt
faker==25.8.0
# via
# -r requirements/quality.txt
# factory-boy
fastavro==1.9.4
# via
# -r requirements/quality.txt
Expand Down Expand Up @@ -468,6 +474,7 @@ python-dateutil==2.8.2
# botocore
# celery
# edx-event-routing-backends
# faker
# freezegun
# xblock
python-slugify==8.0.4
Expand Down
7 changes: 7 additions & 0 deletions requirements/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ event-tracking==2.4.0
# -r requirements/test.txt
# edx-completion
# edx-event-routing-backends
factory-boy==3.3.0
# via -r requirements/test.txt
faker==25.8.0
# via
# -r requirements/test.txt
# factory-boy
fastavro==1.9.4
# via
# -r requirements/base.txt
Expand Down Expand Up @@ -465,6 +471,7 @@ python-dateutil==2.8.2
# botocore
# celery
# edx-event-routing-backends
# faker
# freezegun
# xblock
python-slugify==8.0.4
Expand Down
7 changes: 7 additions & 0 deletions requirements/quality.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ event-tracking==2.4.0
# -r requirements/test.txt
# edx-completion
# edx-event-routing-backends
factory-boy==3.3.0
# via -r requirements/test.txt
faker==25.8.0
# via
# -r requirements/test.txt
# factory-boy
fastavro==1.9.4
# via
# -r requirements/test.txt
Expand Down Expand Up @@ -416,6 +422,7 @@ python-dateutil==2.8.2
# botocore
# celery
# edx-event-routing-backends
# faker
# freezegun
# xblock
python-slugify==8.0.4
Expand Down
1 change: 1 addition & 0 deletions requirements/test.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ django-oauth-toolkit

mysqlclient # For connecting to MySQL
edx-i18n-tools # For i18n_tool dummy
factory-boy # For event transformers
5 changes: 5 additions & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ event-tracking==2.4.0
# -r requirements/base.txt
# edx-completion
# edx-event-routing-backends
factory-boy==3.3.0
# via -r requirements/test.in
faker==25.8.0
# via factory-boy
fastavro==1.9.4
# via
# -r requirements/base.txt
Expand Down Expand Up @@ -362,6 +366,7 @@ python-dateutil==2.8.2
# botocore
# celery
# edx-event-routing-backends
# faker
# freezegun
# xblock
python-slugify==8.0.4
Expand Down
1 change: 1 addition & 0 deletions test_output/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Output dir for failed transformer tests
3 changes: 2 additions & 1 deletion test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def root(*args):
EVENT_TRACKING_BACKENDS = {}
EVENT_TRACKING_BACKENDS_ALLOWED_XAPI_EVENTS = []
EVENT_TRACKING_BACKENDS_ALLOWED_CALIPER_EVENTS = []
LMS_ROOT_URL = "http://lms.url"
LMS_ROOT_URL = "http://localhost:18000"
RUNNING_WITH_TEST_SETTINGS = True

# pylint: disable=unused-import,wrong-import-position
from test_utils.test_app import celery # isort:skip
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"actor": {
"objectType": "Agent",
"account": {
"name": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb",
"homePage": "http://localhost:18000"
}
},
"id":"484fe8d7-7a5b-52ff-a0ab-3d3d8c1a8b27",
"object":{
"id":"http://localhost:18000/xblock/block-v1:edX+DemoX+Demo_Course+type@chapter+block@b443e0d6bc4d43c1bed991dbd8a10d42",
"definition":{
"type":"http://adlnet.gov/expapi/activities/module"
},
"objectType":"Activity"
},
"verb":{
"id":"http://adlnet.gov/expapi/verbs/completed",
"display":{
"en":"completed"
}
},
"version":"1.0.3",
"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"
}
}
]
},
"extensions":{
"https://w3id.org/xapi/openedx/extension/transformer-version":"[email protected]",
"https://w3id.org/xapi/openedx/extensions/session-id":"056aca2a1c6b76742b283e73d3424453"
}
},
"timestamp":"2023-12-05T21:34:52.909063+00:00"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"actor": {
"objectType": "Agent",
"account": {
"name": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb",
"homePage": "http://localhost:18000"
}
},
"id":"484fe8d7-7a5b-52ff-a0ab-3d3d8c1a8b27",
"object":{
"id":"http://localhost:18000/xblock/block-v1:edX+DemoX+Demo_Course+type@course+block@course",
"definition":{
"type":"http://adlnet.gov/expapi/activities/course"
},
"objectType":"Activity"
},
"verb":{
"id":"http://adlnet.gov/expapi/verbs/completed",
"display":{
"en":"completed"
}
},
"version":"1.0.3",
"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"
}
}
]
},
"extensions":{
"https://w3id.org/xapi/openedx/extension/transformer-version":"[email protected]",
"https://w3id.org/xapi/openedx/extensions/session-id":"056aca2a1c6b76742b283e73d3424453"
}
},
"timestamp":"2023-12-05T21:34:52.909063+00:00"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"actor": {
"objectType": "Agent",
"account": {
"name": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb",
"homePage": "http://localhost:18000"
}
},
"id":"484fe8d7-7a5b-52ff-a0ab-3d3d8c1a8b27",
"object":{
"id":"http://localhost:18000/xblock/block-v1:edX+DemoX+Demo_Course+type@sequential+block@bf1eac10ebb649e3aaf9cc07325f8e04",
"definition":{
"type":"http://adlnet.gov/expapi/activities/module"
},
"objectType":"Activity"
},
"verb":{
"id":"http://adlnet.gov/expapi/verbs/completed",
"display":{
"en":"completed"
}
},
"version":"1.0.3",
"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"
}
}
]
},
"extensions":{
"https://w3id.org/xapi/openedx/extension/transformer-version":"[email protected]",
"https://w3id.org/xapi/openedx/extensions/session-id":"056aca2a1c6b76742b283e73d3424453"
}
},
"timestamp":"2023-12-05T21:34:52.909063+00:00"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"actor": {
"objectType": "Agent",
"account": {
"name": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb",
"homePage": "http://localhost:18000"
}
},
"id":"484fe8d7-7a5b-52ff-a0ab-3d3d8c1a8b27",
"object":{
"id":"http://localhost:18000/xblock/block-v1:edX+DemoX+Demo_Course+type@vertical+block@e1fabd9fa55f441caa75580f258ffbc3",
"definition":{
"type":"http://adlnet.gov/expapi/activities/module"
},
"objectType":"Activity"
},
"verb":{
"id":"http://adlnet.gov/expapi/verbs/completed",
"display":{
"en":"completed"
}
},
"version":"1.0.3",
"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"
}
}
]
},
"extensions":{
"https://w3id.org/xapi/openedx/extension/transformer-version":"[email protected]",
"https://w3id.org/xapi/openedx/extensions/session-id":"056aca2a1c6b76742b283e73d3424453"
}
},
"timestamp":"2023-12-05T21:34:52.909063+00:00"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"actor": {
"objectType": "Agent",
"account": {
"name": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb",
"homePage": "http://localhost:18000"
}
},
"id":"146d5372-1d64-54b1-8c60-b4acaad3c976",
"object":{
"id":"http://localhost:18000/xblock/block-v1:edX+DemoX+Demo_Course+type@chapter+block@b443e0d6bc4d43c1bed991dbd8a10d42",
"definition":{
"type":"http://adlnet.gov/expapi/activities/module"
},
"objectType":"Activity"
},
"verb":{
"id":"http://adlnet.gov/expapi/verbs/progressed",
"display":{
"en":"progressed"
}
},
"version":"1.0.3",
"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"
}
}
]
},
"extensions":{
"https://w3id.org/xapi/openedx/extension/transformer-version":"[email protected]",
"https://w3id.org/xapi/openedx/extensions/session-id":"056aca2a1c6b76742b283e73d3424453"
}
},
"result":{
"score":{
"scaled":0.5
},
"completion":false
},
"timestamp":"2023-12-05T21:34:52.909063+00:00"
}
Loading

0 comments on commit 4542458

Please sign in to comment.