Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Kontr 2.0
Portal API Backend
Commits
103e565c
Unverified
Commit
103e565c
authored
Sep 25, 2018
by
Peter Stanko
Browse files
Rest errors to error_handlers and test for tree and not found files
parent
96d2ec16
Pipeline
#13539
passed with stage
in 15 minutes and 15 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
portal/rest/__init__.py
View file @
103e565c
...
...
@@ -56,6 +56,6 @@ def register_namespaces(app: Flask): # pylint: disable=cyclic-import
rest_api
.
init_app
(
app
)
from
.errors
import
load_errors
from
.error
_handler
s
import
load_errors
load_errors
(
app
)
return
app
portal/rest/errors.py
→
portal/rest/error
_handler
s.py
View file @
103e565c
...
...
@@ -60,6 +60,12 @@ def handle_not_implemented_error():
return
flask
.
jsonify
({
'message'
:
f
'Not implemented yet!'
}),
404
@
rest_api
.
errorhandler
(
storage
.
errors
.
NotFoundError
)
def
handle_storage_not_found_error
(
ex
:
storage
.
errors
.
NotFoundError
):
log
.
warning
(
f
"[STORAGE] Storage not found warning:
{
ex
}
"
)
return
flask
.
jsonify
({
'message'
:
str
(
ex
)}),
404
@
rest_api
.
errorhandler
(
storage
.
errors
.
KontrStorageError
)
def
handle_storage_error
(
ex
:
storage
.
errors
.
KontrStorageError
):
log
.
warning
(
f
"[STORAGE] Storage error:
{
ex
}
"
)
...
...
portal/rest/submissions.py
View file @
103e565c
import
flask
from
flask_jwt_extended
import
jwt_required
from
flask_restplus
import
Namespace
...
...
@@ -149,8 +148,7 @@ class SubmissionResultFilesTree(CustomResource):
self
.
permissions
(
course
=
course
).
require
.
read_submission_group
(
submission
)
storage_entity
=
storage
.
results
.
get
(
submission
.
id
)
service
=
self
.
rest
.
submissions
(
submission
)
tree
=
service
.
send_files_tree
(
storage_entity
)
return
flask
.
jsonify
(
tree
),
200
return
service
.
send_files_tree
(
storage_entity
)
@
submissions_namespace
.
route
(
'/<string:sid>/files/results'
)
...
...
tests/rest/test_submission_files.py
View file @
103e565c
from
pathlib
import
Path
import
pytest
from
portal.database
import
ProjectConfig
...
...
@@ -19,6 +21,15 @@ def expected(fpath):
return
f
'This is a test file:
{
fpath
}
'
def
assert_path
(
data
:
dict
,
path
:
str
):
current
=
data
path
=
Path
(
path
)
for
part
in
path
.
parts
:
current
=
current
.
get
(
part
)
assert
Path
(
current
)
==
path
def
test_submission_sources_are_available
(
client
,
mocked_submission
):
s
=
mocked_submission
response
=
utils
.
make_request
(
client
,
f
'/submissions/
{
s
.
id
}
/files/sources?path=src/main.c'
)
...
...
@@ -27,6 +38,26 @@ def test_submission_sources_are_available(client, mocked_submission):
assert
response
.
data
.
decode
(
'utf-8'
)
==
expected
(
'src/main.c'
)
def
test_submission_sources_are_not_available
(
client
,
mocked_submission
):
s
=
mocked_submission
response
=
utils
.
make_request
(
client
,
f
'/submissions/
{
s
.
id
}
/files/sources?path=nonexisting.c'
)
assert
response
.
status_code
==
404
def
test_submission_test_files_are_not_available
(
client
,
mocked_submission
):
s
=
mocked_submission
url
=
f
'/submissions/
{
s
.
id
}
/files/test_files?path=nonexisting.c'
response
=
utils
.
make_request
(
client
,
url
)
assert
response
.
status_code
==
404
def
test_submission_results_are_not_available
(
client
,
mocked_submission
):
s
=
mocked_submission
url
=
f
'/submissions/
{
s
.
id
}
/files/results?path=nonexisting.c'
response
=
utils
.
make_request
(
client
,
url
)
assert
response
.
status_code
==
404
def
test_submission_results_are_available
(
client
,
mocked_submission
):
s
=
mocked_submission
response
=
utils
.
make_request
(
client
,
f
'/submissions/
{
s
.
id
}
/files/results?path=student.json'
)
...
...
@@ -41,3 +72,33 @@ def test_submission_test_files_are_available(client, mocked_submission):
assert
response
.
status_code
==
200
assert
response
.
data
assert
response
.
data
.
decode
(
'utf-8'
)
==
expected
(
'test_main.c'
)
def
test_submission_sources_tree
(
client
,
mocked_submission
):
s
=
mocked_submission
response
=
utils
.
make_request
(
client
,
f
'/submissions/
{
s
.
id
}
/files/sources/tree'
)
assert
response
.
status_code
==
200
assert
response
.
data
data
=
utils
.
extract_data
(
response
=
response
)
assert_path
(
data
,
'src/main.c'
)
assert_path
(
data
,
'src/foo.c'
)
def
test_submission_test_files_tree
(
client
,
mocked_submission
):
s
=
mocked_submission
response
=
utils
.
make_request
(
client
,
f
'/submissions/
{
s
.
id
}
/files/test_files/tree'
)
assert
response
.
status_code
==
200
assert
response
.
data
data
=
utils
.
extract_data
(
response
=
response
)
assert_path
(
data
,
'test_main.c'
)
def
test_submission_results_tree
(
client
,
mocked_submission
):
s
=
mocked_submission
response
=
utils
.
make_request
(
client
,
f
'/submissions/
{
s
.
id
}
/files/results/tree'
)
assert
response
.
status_code
==
200
assert
response
.
data
data
=
utils
.
extract_data
(
response
)
assert_path
(
data
,
'results.json'
)
assert_path
(
data
,
'student.json'
)
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment