Verified Commit f457bd64 authored by Peter Stanko's avatar Peter Stanko
Browse files

Tests for submission is notes read

parent 71cdbf79
Pipeline #31642 failed with stage
in 7 minutes and 51 seconds
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
user(User): User instance
......@@ -106,9 +108,9 @@ class IsApiService(GeneralService):
shortcut = shortcut or project.codename"[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):
......@@ -57,7 +57,7 @@ class IsApiWrapper:
def write_notepad(self, user: 'User', content=None, shortcut: str = None):"[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)
......@@ -69,6 +69,7 @@ def make_request(client: FlaskClient, url: str, method: str = 'get',
params['data'] = json_parser.dumps(json)
params['data'] = data
log.debug(f"[REQ] {full_url}: {params}")
return, **params)
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 import IsApiWrapper
from 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)
def test_read_is_muni_notepad_for_submission(created_submission, client, portal_services):
<OBSAH>25 bodu</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};" \
operation = f";operace=blok-dej-obsah;zkratka={created_submission.project.codename};" \
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/{}/review/is_muni/notepad'
response = rest_tools.make_request(client, surl, json=dict(content=content), method='post')
response = rest_tools.make_request(client, surl, json=dict(content=content), method='get')
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'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment