Skip to content
Snippets Groups Projects
Commit 4b7b467f authored by Lennard Strohmeyer's avatar Lennard Strohmeyer :penguin:
Browse files

Fix validation of xapi statements, update schema to correctly validate system...

Fix validation of xapi statements, update schema to correctly validate system messages (not included in original xapi standard)
parent 3f70b545
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,7 @@
},
"required": ["actor", "verb", "object"],
"$defs": {
"iri": { "type": "string", "pattern": "^[a-zA-Z0-9_]+:" },
"iri": { "type": "string", "pattern": "^[a-zA-Z0-9_]+" },
"languageMap": { "type": "object" },
"agent": {
"type": "object",
......@@ -111,7 +111,7 @@
},
"required": ["id"]
},
"mbox": { "type": "string", "pattern": "mailto:[a-z0-9._%+!$&*=^|~#%{}/-]+@([a-z0-9-]+.){1,}([a-z]{2,22})" },
"mbox": { "type": "string", "pattern": "(mailto:[a-z0-9._%+!$&*=^|~#%{}/-]+@([a-z0-9-]+.){1,}([a-z]{2,22}))|(system:[0-9]+)" },
"mbox_sha1sum": { "type": "string", "pattern": "^\b[0-9a-f]{5,40}$" },
"account": {
"type": "object",
......
......@@ -7,7 +7,7 @@ from jsonschema import ValidationError, validate
PROJECT_PATH = os.path.abspath(os.path.dirname(__name__))
class TestxAPIStatementeValidation(TestCase):
class TestxAPIStatementValidation(TestCase):
def setUp(self):
with open(os.path.join(PROJECT_PATH, "static/xapi_statement.schema.json")) as f:
self.schema = json.load(f)
......@@ -167,3 +167,24 @@ class TestxAPIStatementeValidation(TestCase):
validate(statement, self.schema)
except ValueError:
assert False
def test_validate_statement_with_tan(self):
statement = {
"actor": {
"objectType": "Agent",
"tan": "u4gueb983fnklerg",
},
"verb": {
"id": "http://adlnet.gov/expapi/verbs/failed",
"display": {"en-US": "failed"},
},
"object": {
"id": "https://example.adlnet.gov/AUidentifier",
"objectType": "Activity",
},
}
try:
validate(statement, self.schema)
except ValueError:
assert False
\ No newline at end of file
......@@ -197,9 +197,13 @@ class XAPITestCase(TestCase):
"actor": {"mbox": f"system:{provider.id}"},
"verb": {"id": "some_id"},
"object": {
"id": "some_other_id",
"id": "someOtherId",
"objectType": "Activity",
"definition": "object_definition",
"definition": {
"name": {
"de-DE": "Testobjekt"
}
},
},
"timestamp": datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
},
......@@ -506,7 +510,7 @@ class TestxAPIStatementActorAccount(BaseTestCase):
{
"valid": False,
"accepted": False,
"reason": "User missing in statement",
"reason": "'name' is a required property",
}
],
},
......
......@@ -52,7 +52,7 @@ def process_statement(x_api_statement, provider, latest_schema):
Process xAPI statement by checking for validation errors and user consent settings.
"""
try:
validate(x_api_statement, x_api_statement)
validate(x_api_statement, schema)
except ValidationError as e:
return {"valid": False, "accepted": False, "reason": e.message}
......@@ -164,7 +164,7 @@ def process_tan_statement(x_api_statement):
Process xAPI statement by checking for validation errors.
"""
try:
validate(x_api_statement, x_api_statement)
validate(x_api_statement, schema)
except ValidationError as e:
return {"valid": False, "reason": e.message}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment