Basic API support for the upcoming examination feature
parent
547a1042b3
commit
f7404bb6e1
|
@ -49,6 +49,18 @@ class CakeCMS:
|
|||
print('[', r.status_code, ']')
|
||||
return r
|
||||
|
||||
def get_exams_api(self, uri, 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}
|
||||
if self.debug:
|
||||
print('> GET', url, ' ', end='')
|
||||
r = self.session.get(url, 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('<!', result['type'], ':', result['message'])
|
||||
|
@ -297,3 +309,12 @@ class CakeCMS:
|
|||
|
||||
def tokens_index(self, course=None):
|
||||
return self.get('tokens/index', course=course).json()['tokens']
|
||||
|
||||
def exams_index(self, course=None):
|
||||
return self.get_exams_api('exams', course=course).json()
|
||||
|
||||
def exam_solutions_index(self, exam_id, course=None):
|
||||
return self.get_exams_api('solutions/'+str(exam_id), course=course).json()
|
||||
|
||||
def exam_solutions_get(self, solution_id, course=None):
|
||||
return self.get_exams_api('solution/get/' + str(solution_id), course=course).json()
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
import json
|
||||
|
||||
import cakecms
|
||||
|
||||
HOST = 'http://localhost/cakecms'
|
||||
TOKEN = '2q4q3dsLrnFsXf8AMFSKEZj3'
|
||||
COURSE = '...'
|
||||
|
||||
# create an instance
|
||||
cms = cakecms.CakeCMS(HOST, TOKEN)
|
||||
cms.debug = True
|
||||
cms.course = COURSE
|
||||
|
||||
# list exams
|
||||
exams = cms.exams_index()
|
||||
|
||||
# list solutions for an exam
|
||||
exam_id = exams[0]['id']
|
||||
solutions = cms.exam_solutions_index(exam_id)
|
||||
print(solutions)
|
||||
|
||||
# list the responses of a solution
|
||||
for solution in solutions['solutionList']:
|
||||
content = cms.exam_solutions_get(solution['id'])
|
||||
print('-'*80)
|
||||
print('#'+str(solution['id'])+': ', json.dumps(content['data'], indent=4))
|
||||
|
Loading…
Reference in New Issue