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
f457bd64
Verified
Commit
f457bd64
authored
Apr 27, 2019
by
Peter Stanko
Browse files
Tests for submission is notes read
parent
71cdbf79
Pipeline
#31642
failed with stage
in 7 minutes and 51 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
portal/service/is_api_service.py
View file @
f457bd64
import
logging
from
typing
import
Collection
,
List
,
Set
from
typing
import
Collection
,
Dict
,
List
,
Set
from
is_api
import
entities
from
is_api.entities
import
NotepadContent
from
portal.database
import
Course
,
Group
,
Project
,
User
,
queries
from
portal.service
import
errors
...
...
@@ -93,7 +94,8 @@ class IsApiService(GeneralService):
f
"for
{
user
.
log_name
}
:
{
content
}
"
)
return
self
.
is_api
.
write_notepad
(
shortcut
=
shortcut
,
user
=
user
,
content
=
content
)
def
read_note
(
self
,
user
:
User
,
shortcut
:
str
=
None
,
project
:
Project
=
None
):
def
read_note
(
self
,
user
:
User
,
shortcut
:
str
=
None
,
project
:
Project
=
None
)
\
->
Dict
[
str
,
str
]:
"""Read the notepad token
Args:
user(User): User instance
...
...
@@ -106,9 +108,9 @@ class IsApiService(GeneralService):
shortcut
=
shortcut
or
project
.
codename
log
.
info
(
f
"[IS_API] Reading note for
{
self
.
course
.
log_name
}
- notepad:
{
shortcut
}
"
f
"for
{
user
.
log_name
}
"
)
result
=
self
.
is_api
.
read_notepad
(
shortcut
=
shortcut
,
users
=
[
user
])
result
:
NotepadContent
=
self
.
is_api
.
read_notepad
(
shortcut
=
shortcut
,
users
=
[
user
])
log
.
debug
(
f
"[IS_API] Content:
{
result
}
"
)
return
result
return
{
student
.
uco
:
student
.
content
for
student
in
result
.
students
}
def
create_notepad
(
self
,
shortcut
:
str
=
None
,
name
:
str
=
None
,
project
:
Project
=
None
,
**
kwargs
):
...
...
portal/tools/is_api_adapter.py
View file @
f457bd64
...
...
@@ -57,7 +57,7 @@ class IsApiWrapper:
def
write_notepad
(
self
,
user
:
'User'
,
content
=
None
,
shortcut
:
str
=
None
):
log
.
info
(
f
"[IS_API_ADAPT] Write notepad for
{
shortcut
}
to user
{
user
.
log_name
}
:
{
content
}
"
)
self
.
is_client
.
notepad_update
(
shortcut
=
shortcut
,
uco
=
user
.
uco
,
return
self
.
is_client
.
notepad_update
(
shortcut
=
shortcut
,
uco
=
user
.
uco
,
override
=
True
,
content
=
content
)
@
property
...
...
tests/rest/rest_tools.py
View file @
f457bd64
...
...
@@ -69,6 +69,7 @@ def make_request(client: FlaskClient, url: str, method: str = 'get',
params
[
'data'
]
=
json_parser
.
dumps
(
json
)
else
:
params
[
'data'
]
=
data
log
.
debug
(
f
"[REQ]
{
full_url
}
:
{
params
}
"
)
return
client
.
open
(
full_url
,
**
params
)
...
...
tests/rest/test_submission.py
View file @
f457bd64
import
pytest
import
responses
from
is_api
import
IsApiClient
from
portal
import
storage_wrapper
from
portal.database.models
import
Course
,
Review
,
ReviewItem
,
Submission
from
portal.database
import
SubmissionState
from
portal.database.models
import
Review
,
ReviewItem
,
Submission
from
portal.tools.is_api_adapter
import
IsApiWrapper
from
tests.rest.rest_tools
import
assert_response
from
.
import
rest_tools
...
...
@@ -301,15 +300,31 @@ def test_write_is_muni_notepad_for_submission(created_submission, client, portal
response
=
rest_tools
.
make_request
(
client
,
surl
,
json
=
dict
(
content
=
content
),
method
=
'post'
)
assert_response
(
response
=
response
,
code
=
200
)
@
responses
.
activate
def
test_read_is_muni_notepad_for_submission
(
created_submission
,
client
,
portal_services
):
BLOCKS_CONTENT
=
"""
<BLOKY_OBSAH>
<STUDENT>
<OBSAH>25 bodu</OBSAH>
<UCO>0</UCO>
<ZMENENO>20160111104208</ZMENENO>
<ZMENIL>444111222</ZMENIL>
</STUDENT>
</BLOKY_OBSAH>
"""
is_wrapper
:
IsApiWrapper
=
portal_services
.
is_api
(
created_submission
.
course
).
is_api
content
=
"Foo points *2"
operation
=
f
";operace=blok-
pis-student
-obsah;zkratka=
{
created_submission
.
project
.
codename
}
;"
\
f
"uco=
{
created_submission
.
user
.
uco
}
;obsah=
{
content
}
;prepis=a
"
operation
=
f
";operace=blok-
dej
-obsah;zkratka=
{
created_submission
.
project
.
codename
}
;"
\
f
"uco=
(
{
created_submission
.
user
.
uco
}
,);
"
url
=
gen_url
(
is_wrapper
=
is_wrapper
,
operation
=
operation
)
responses
.
add
(
responses
.
GET
,
url
,
body
=
"<ZAPIS>Úspěšně uloženo.</ZAPIS>"
,
status
=
200
)
responses
.
add
(
responses
.
GET
,
url
,
body
=
BLOCKS_CONTENT
,
status
=
200
)
surl
=
f
'/submissions/
{
created_submission
.
id
}
/review/is_muni/notepad'
response
=
rest_tools
.
make_request
(
client
,
surl
,
json
=
dict
(
content
=
content
),
method
=
'
pos
t'
)
response
=
rest_tools
.
make_request
(
client
,
surl
,
json
=
dict
(
content
=
content
),
method
=
'
ge
t'
)
assert_response
(
response
=
response
,
code
=
200
)
data
=
response
.
json
assert
isinstance
(
data
,
dict
)
content
=
data
.
get
(
str
(
created_submission
.
user
.
uco
))
assert
content
assert
content
==
'25 bodu'
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