Loading portal/service/is_api_service.py +6 −4 Original line number Original line Diff line number Diff line import logging import logging from typing import Collection, List, Set from typing import Collection, Dict, List, Set from is_api import entities from is_api import entities from is_api.entities import NotepadContent from portal.database import Course, Group, Project, User, queries from portal.database import Course, Group, Project, User, queries from portal.service import errors from portal.service import errors Loading Loading @@ -93,7 +94,8 @@ class IsApiService(GeneralService): f"for {user.log_name}: {content}") f"for {user.log_name}: {content}") return self.is_api.write_notepad(shortcut=shortcut, user=user, content=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 """Read the notepad token Args: Args: user(User): User instance user(User): User instance Loading @@ -106,9 +108,9 @@ class IsApiService(GeneralService): shortcut = shortcut or project.codename shortcut = shortcut or project.codename log.info(f"[IS_API] Reading note for {self.course.log_name} - notepad: {shortcut} " log.info(f"[IS_API] Reading note for {self.course.log_name} - notepad: {shortcut} " f"for {user.log_name}") 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}") 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, def create_notepad(self, shortcut: str = None, name: str = None, project: Project = None, **kwargs): project: Project = None, **kwargs): Loading portal/tools/is_api_adapter.py +1 −1 Original line number Original line Diff line number Diff line Loading @@ -57,7 +57,7 @@ class IsApiWrapper: def write_notepad(self, user: 'User', content=None, shortcut: str = None): 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}") 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) override=True, content=content) @property @property Loading tests/rest/rest_tools.py +1 −0 Original line number Original line Diff line number Diff line Loading @@ -69,6 +69,7 @@ def make_request(client: FlaskClient, url: str, method: str = 'get', params['data'] = json_parser.dumps(json) params['data'] = json_parser.dumps(json) else: else: params['data'] = data params['data'] = data log.debug(f"[REQ] {full_url}: {params}") return client.open(full_url, **params) return client.open(full_url, **params) Loading tests/rest/test_submission.py +21 −6 Original line number Original line Diff line number Diff line import pytest import pytest import responses import responses from is_api import IsApiClient from portal import storage_wrapper from portal import storage_wrapper from portal.database.models import Course, Review, ReviewItem, Submission from portal.database import SubmissionState from portal.database import SubmissionState from portal.database.models import Review, ReviewItem, Submission from portal.tools.is_api_adapter import IsApiWrapper from portal.tools.is_api_adapter import IsApiWrapper from tests.rest.rest_tools import assert_response from tests.rest.rest_tools import assert_response from . import rest_tools from . import rest_tools Loading Loading @@ -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') response = rest_tools.make_request(client, surl, json=dict(content=content), method='post') assert_response(response=response, code=200) assert_response(response=response, code=200) @responses.activate @responses.activate def test_read_is_muni_notepad_for_submission(created_submission, client, portal_services): 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 is_wrapper: IsApiWrapper = portal_services.is_api(created_submission.course).is_api content = "Foo points *2" 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};" \ f"uco={created_submission.user.uco};obsah={content};prepis=a" f"uco=({created_submission.user.uco},);" url = gen_url(is_wrapper=is_wrapper, operation=operation) 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' surl = f'/submissions/{created_submission.id}/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) 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' Loading
portal/service/is_api_service.py +6 −4 Original line number Original line Diff line number Diff line import logging import logging from typing import Collection, List, Set from typing import Collection, Dict, List, Set from is_api import entities from is_api import entities from is_api.entities import NotepadContent from portal.database import Course, Group, Project, User, queries from portal.database import Course, Group, Project, User, queries from portal.service import errors from portal.service import errors Loading Loading @@ -93,7 +94,8 @@ class IsApiService(GeneralService): f"for {user.log_name}: {content}") f"for {user.log_name}: {content}") return self.is_api.write_notepad(shortcut=shortcut, user=user, content=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 """Read the notepad token Args: Args: user(User): User instance user(User): User instance Loading @@ -106,9 +108,9 @@ class IsApiService(GeneralService): shortcut = shortcut or project.codename shortcut = shortcut or project.codename log.info(f"[IS_API] Reading note for {self.course.log_name} - notepad: {shortcut} " log.info(f"[IS_API] Reading note for {self.course.log_name} - notepad: {shortcut} " f"for {user.log_name}") 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}") 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, def create_notepad(self, shortcut: str = None, name: str = None, project: Project = None, **kwargs): project: Project = None, **kwargs): Loading
portal/tools/is_api_adapter.py +1 −1 Original line number Original line Diff line number Diff line Loading @@ -57,7 +57,7 @@ class IsApiWrapper: def write_notepad(self, user: 'User', content=None, shortcut: str = None): 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}") 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) override=True, content=content) @property @property Loading
tests/rest/rest_tools.py +1 −0 Original line number Original line Diff line number Diff line Loading @@ -69,6 +69,7 @@ def make_request(client: FlaskClient, url: str, method: str = 'get', params['data'] = json_parser.dumps(json) params['data'] = json_parser.dumps(json) else: else: params['data'] = data params['data'] = data log.debug(f"[REQ] {full_url}: {params}") return client.open(full_url, **params) return client.open(full_url, **params) Loading
tests/rest/test_submission.py +21 −6 Original line number Original line Diff line number Diff line import pytest import pytest import responses import responses from is_api import IsApiClient from portal import storage_wrapper from portal import storage_wrapper from portal.database.models import Course, Review, ReviewItem, Submission from portal.database import SubmissionState from portal.database import SubmissionState from portal.database.models import Review, ReviewItem, Submission from portal.tools.is_api_adapter import IsApiWrapper from portal.tools.is_api_adapter import IsApiWrapper from tests.rest.rest_tools import assert_response from tests.rest.rest_tools import assert_response from . import rest_tools from . import rest_tools Loading Loading @@ -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') response = rest_tools.make_request(client, surl, json=dict(content=content), method='post') assert_response(response=response, code=200) assert_response(response=response, code=200) @responses.activate @responses.activate def test_read_is_muni_notepad_for_submission(created_submission, client, portal_services): 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 is_wrapper: IsApiWrapper = portal_services.is_api(created_submission.course).is_api content = "Foo points *2" 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};" \ f"uco={created_submission.user.uco};obsah={content};prepis=a" f"uco=({created_submission.user.uco},);" url = gen_url(is_wrapper=is_wrapper, operation=operation) 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' surl = f'/submissions/{created_submission.id}/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) 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'