From 484dabe4c28852c4b609f5c213203079cbc7627e Mon Sep 17 00:00:00 2001 From: Markus Bauer Date: Fri, 16 Jun 2023 15:47:33 +0200 Subject: [PATCH] API for exam correction --- cakecms/cakecms.py | 36 ++++++++++++++++++++++++++++++++++ examples/get-exam-solutions.py | 35 ++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/cakecms/cakecms.py b/cakecms/cakecms.py index e55b909..96ed7be 100644 --- a/cakecms/cakecms.py +++ b/cakecms/cakecms.py @@ -61,6 +61,18 @@ class CakeCMS: print('[', r.status_code, ']') return r + def post_exams_api(self, uri, data, course=None, **kwargs): + if self.token: + self.session.headers['X-CMS-API-TOKEN'] = self.token + url = self.url + '/examination_backend/' + (self.course if course is None else course) + '/' + uri + headers = {'X-Exams-Tenant': self.course if course is None else course, 'X-CSRF-CHECK': '1'} + if self.debug: + print('> POST', url, ' ', end='') + r = self.session.post(url, json=data, headers=headers, **kwargs) + if self.debug: + print('[', r.status_code, ']') + return r + def assert_success(self, result): if 'error' in result and result['error'] == 'exception': if self.debug: print('