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
e61f24c2
Verified
Commit
e61f24c2
authored
Apr 09, 2019
by
Peter Stanko
Browse files
Tests updated
parent
9a32bcd4
Changes
4
Hide whitespace changes
Inline
Side-by-side
CHANGELOG
View file @
e61f24c2
= Portal Changelog
[2019-03-07] - Get versions - commit id and message `/management/versions`
[2019-03-07] - Ability to extract `gitlab_token` from `cookies` and `headers`
[2019-03-07] - Ability to show Gitlab Projects and enable Gitlab projects
[2019-03-04] - Ability to tag submission
[2019-03-07] - Added CHANGELOG
[2019-04-08] - Project config parameters as YAML
[2019-04-07] - Get versions - commit id and message `/management/versions`
[2019-04-07] - Ability to extract `gitlab_token` from `cookies` and `headers`
[2019-04-07] - Ability to show Gitlab Projects and enable Gitlab projects
[2019-04-04] - Ability to tag submission
[2019-04-07] - Added CHANGELOG
portal/facade/projects_facade.py
View file @
e61f24c2
...
...
@@ -16,6 +16,12 @@ def _check_gl_repo_size(gl_project, project):
if
repo_size
>
max_repo_size
:
raise
errors
.
SubmissionRefusedError
(
f
"Your repository is bigger than the limit:"
f
"
{
repo_size
}
>
{
max_repo_size
}
"
)
else
:
log
.
debug
(
f
"[CHECK] Your repository size is within the limit: "
f
"
{
repo_size
}
>
{
max_repo_size
}
"
)
else
:
log
.
debug
(
"[CHECK] Max repo size has not been set - skip"
)
return
True
def
_check_gl_repo_visibility
(
gl_project
,
project
):
...
...
@@ -26,6 +32,12 @@ def _check_gl_repo_visibility(gl_project, project):
raise
errors
.
SubmissionRefusedError
(
f
"Your repository visibility "
f
"is not
{
required_repo_visibility
}
."
f
" Actual:
{
repo_visibility
}
"
)
else
:
log
.
debug
(
f
"[CHECK] Your repository visibility is correct - "
f
"
{
repo_visibility
}
"
)
else
:
log
.
debug
(
"[CHECK] Required repo visibility has not been set - skip"
)
return
True
class
ProjectsFacade
(
GeneralCRUDFacade
):
...
...
@@ -87,6 +99,7 @@ class ProjectsFacade(GeneralCRUDFacade):
client
=
client
or
self
.
client
result
=
self
.
_service
(
project
).
check_submission_create
(
client
)
if
self
.
_services
.
kontr_gitlab
.
is_authorized
and
not
project
.
submit_configurable
:
log
.
debug
(
"[CHECK] Checking gitlab params"
)
result
=
self
.
_check_gitlab_params
(
client
,
project
)
return
result
...
...
portal/rest/projects.py
View file @
e61f24c2
...
...
@@ -232,7 +232,7 @@ class ProjectSubmissionsCheck(CustomResource):
self
.
_check_user_can_create_submission
(
project
,
user
)
log
.
info
(
f
"[REST] Check Create submission in
{
project
.
log_name
}
"
f
"by
{
self
.
client
.
log_name
}
for user
{
user
.
log_name
}
"
)
return
flask
.
jsonify
(
{
'message'
:
'User is able to create submission'
}
)
,
200
return
{
'message'
:
'User is able to create submission'
},
200
def
_check_user_can_create_submission
(
self
,
project
,
user
):
if
self
.
client
.
type
==
ClientType
.
USER
:
...
...
tests/rest/test_project.py
View file @
e61f24c2
...
...
@@ -187,8 +187,7 @@ def test_create_submission(client, request_dict):
path
=
f
"/courses/
{
cpp
.
codename
}
/projects/
{
p
.
name
}
/submissions"
response
=
rest_tools
.
make_request
(
client
,
path
,
json
=
request_dict
,
method
=
'post'
)
assert
response
.
status_code
==
201
assert
response
.
mimetype
==
'application/json'
assert_response
(
response
,
code
=
201
)
new_submission
=
rest_tools
.
extract_data
(
response
)
p_updated
=
Project
.
query
.
filter
(
Project
.
course_id
==
cpp
.
id
)
\
...
...
@@ -200,6 +199,17 @@ def test_create_submission(client, request_dict):
rest_tools
.
assert_submission_in
(
user_updated
.
submissions
,
new_submission
)
@
pytest
.
mark
.
celery
(
result_backend
=
'redis://'
)
def
test_check_create_submission_as_admin
(
client
,
request_dict
):
cpp
=
Course
.
query
.
filter_by
(
codename
=
"testcourse1"
).
first
()
p
=
cpp
.
projects
[
0
]
path
=
f
"/courses/
{
cpp
.
codename
}
/projects/
{
p
.
name
}
/submissions/check"
response
=
rest_tools
.
make_request
(
client
,
path
)
assert_response
(
response
,
code
=
200
)
@
pytest
.
mark
.
celery
(
result_backend
=
'redis://'
)
def
test_create_submission_as_different_user
(
client
,
portal_services
,
request_dict
):
cpp
=
portal_services
.
find
.
course
(
"testcourse1"
)
...
...
@@ -235,6 +245,16 @@ def test_create_submission_as_student(client, ent_mocker, portal_services, reque
assert
new_submission
[
'id'
]
@
pytest
.
mark
.
celery
(
result_backend
=
'redis://'
)
def
test_check_create_submission_as_student
(
client
,
ent_mocker
,
portal_services
,
request_dict
):
user
,
course
,
project
=
ent_mocker
.
create_user_in_course
(
'testuser'
,
role_type
=
'student'
)
path
=
f
"/courses/
{
course
.
codename
}
/projects/
{
project
.
name
}
/submissions/check"
project
user_credentials
=
get_user_credentials
(
user
.
username
)
response
=
rest_tools
.
make_request
(
client
,
path
,
credentials
=
user_credentials
)
assert_response
(
response
,
code
=
200
)
@
pytest
.
mark
.
celery
(
result_backend
=
'redis://'
)
def
test_create_submission_second_should_fail
(
client
,
ent_mocker
,
portal_services
,
request_dict
):
user
,
course
,
project
=
ent_mocker
.
create_user_in_course
(
'testuser'
,
role_type
=
'student'
)
...
...
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