forked from apluslms/a-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sis_test.py
82 lines (73 loc) · 2.65 KB
/
sis_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import json
import logging
from typing import List, Tuple
from django.conf import settings
from course.sis import StudentInfoSystem
logger = logging.getLogger('aplus.course')
origdata = [
{
"code": "TEST-A1111",
"id": "1",
"instance": "spring-2022",
"starting_time": "2022-01-13",
"ending_time": "2022-05-04",
"teachers": [ "teacher-A", "teacher-C" ],
"participants": [ "222222", "333333", "555555" ],
},
{
"code": "TEST-A1111",
"id": "2",
"instance": "summer-2022",
"starting_time": "2022-06-04",
"ending_time": "2022-07-30",
"teachers": [ "teacher-B" ],
"participants": [ "444444", "555555", "333333" ],
},
{
"code": "123456",
"id": "123",
"instance": "summer-2022",
"starting_time": "2022-06-01T00:00:00+03:00",
"ending_time": "2022-08-20T00:00:00+03:00",
"teachers": [ "teacher-A", "testTeacher" ],
"participants": [ "123TEST", "333333", "555555" ],
},
{
"code": "123456",
"id": "456",
"instance": "fall-2022",
"starting_time": "2022-09-01",
"ending_time": "2022-12-20",
"teachers": [ "teacher-A", "testTeacher" ],
"participants": [ "123TEST" ],
},
]
class SisTest(StudentInfoSystem):
'''
This SIS class can be used for testing the SIS functions. It can be taken into use
by adding the following to settings.py:
SIS_PLUGIN_MODULE = 'course.sis_test'
SIS_PLUGIN_CLASS = 'SisTest'
By using optional SIS_TEST_FILE setting, one can specify a file from which the SIS
configuration is read, overriding the default setup above.
'''
def __init__(self):
self.data = origdata
if hasattr(settings, 'SIS_TEST_FILE'):
try:
with open(settings.SIS_TEST_FILE, "r", encoding="utf-8") as f:
self.data = json.load(f)
except Exception:
logger.exception("File read error.")
def get_instances(self, course: str) -> List[Tuple[str, str]]:
selected = list(filter(lambda d: d['code'] == course, self.data))
ret = list(map(lambda k: (k['id'], k['instance']), selected))
return ret
def get_course_data(self, id: str) -> dict: # pylint: disable=redefined-builtin
selected = next(filter(lambda d: d['id'] == id, self.data), None)
return selected
def get_participants(self, id: str) -> List[str]: # pylint: disable=redefined-builtin
selected = next(filter(lambda d: d['id'] == id, self.data), None)
if selected:
return selected['participants']
return []