Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rights Engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Polaris
Rights Engine
Commits
aec900d9
Commit
aec900d9
authored
9 months ago
by
Benjamin Ledel
Browse files
Options
Downloads
Patches
Plain Diff
* fix long json validation
parent
f070fd03
No related branches found
No related tags found
No related merge requests found
Pipeline
#1412750
failed
9 months ago
Stage: test
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/xapi/tests/test_xapi_statement_validation.py
+26
-0
26 additions, 0 deletions
src/xapi/tests/test_xapi_statement_validation.py
src/xapi/views.py
+7
-3
7 additions, 3 deletions
src/xapi/views.py
with
33 additions
and
3 deletions
src/xapi/tests/test_xapi_statement_validation.py
+
26
−
0
View file @
aec900d9
...
...
@@ -40,6 +40,32 @@ class TestxAPIStatementValidation(TestCase):
except
ValueError
:
assert
False
def
test_basic_valid_statement2000Times
(
self
):
statement
=
{
"
actor
"
:
{
"
objectType
"
:
"
Agent
"
,
"
name
"
:
"
Gert Frobe
"
,
"
account
"
:
{
"
homePage
"
:
"
http://example.adlnet.gov
"
,
"
name
"
:
"
1625378
"
},
},
"
verb
"
:
{
"
id
"
:
"
http://adlnet.gov/expapi/verbs/failed
"
,
"
display
"
:
{
"
en-US
"
:
"
failed
"
},
},
"
object
"
:
{
"
id
"
:
"
https://example.adlnet.gov/AUidentifier
"
,
"
objectType
"
:
"
Activity
"
,
},
}
try
:
cls
=
validator_for
(
self
.
schema
)
cls
.
check_schema
(
self
.
schema
)
instance
=
cls
(
self
.
schema
)
for
i
in
range
(
1
,
2000
):
instance
.
validate
(
statement
)
except
ValueError
:
assert
False
def
test_validate_statement_with_uuid
(
self
):
statement
=
{
"
id
"
:
"
e05aa883-acaf-40ad-bf54-02c8ce485fb0
"
,
...
...
This diff is collapsed.
Click to expand it.
src/xapi/views.py
+
7
−
3
View file @
aec900d9
...
...
@@ -9,6 +9,7 @@ from django.core.exceptions import ObjectDoesNotExist
from
django.http.response
import
JsonResponse
from
django.shortcuts
import
render
from
jsonschema
import
ValidationError
,
validate
from
jsonschema.validators
import
validator_for
from
rest_framework
import
status
from
rest_framework.views
import
APIView
...
...
@@ -23,7 +24,10 @@ from pathlib import Path
PROJECT_PATH
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__name__
))
with
open
(
os
.
path
.
join
(
PROJECT_PATH
,
"
static/xapi_statement.schema.json
"
))
as
f
:
schema
=
json
.
load
(
f
)
schema
=
json
.
loads
(
f
.
read
())
cls
=
validator_for
(
schema
)
cls
.
check_schema
(
schema
)
instance
=
cls
(
schema
)
def
store_in_db
(
x_api_statement
):
...
...
@@ -108,7 +112,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
,
schema
)
instance
.
validate
(
x_api_statement
)
except
ValidationError
as
e
:
return
{
"
valid
"
:
False
,
"
accepted
"
:
False
,
"
reason
"
:
e
.
message
}
...
...
@@ -232,7 +236,7 @@ def process_tan_statement(x_api_statement):
Process xAPI statement by checking for validation errors.
"""
try
:
validate
(
x_api_statement
,
schema
)
instance
.
validate
(
x_api_statement
)
except
ValidationError
as
e
:
return
{
"
valid
"
:
False
,
"
reason
"
:
e
.
message
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment