Newer
Older
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from datetime import timedelta
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from management.data.shared import DataFactory
from portal.database.models import Review, Submission, SubmissionState
from portal.tools import time
def init_dev_data(app: Flask, db: SQLAlchemy):
with app.app_context():
factory = DataFactory(db)
# users
student1 = factory.create_user(username='student1', uco=111)
student2 = factory.create_user(username='student2', uco=222)
teacher1 = factory.create_user(username='teacher1', password='123123',
name='Teacher And Student', uco=1001)
teacher2 = factory.create_user(username='teacher2', password='123123',
name='Teacher Only', uco=1002)
lecturer1 = factory.create_user(
username='lecturer1',
name='Courses Owner',
password='654321',
uco=1010
)
# courses
test_course1 = factory.create_course(codename='TestCourse1', name='Test Course One')
test_course2 = factory.create_course(codename='TestCourse2', name='test Course Two')
# groups
tc1_students = factory.create_group(course=test_course1, name="seminar01")
tc1_teachers = factory.create_group(course=test_course1, name="teachers")
tc2_students = factory.create_group(course=test_course2, name="seminar01")
tc2_teachers = factory.create_group(course=test_course2, name="teachers")
tc1_hw01 = factory.create_project(
course=test_course1, name="HW01", config=dict(
file_whitelist="main.cpp",
pre_submit_script="python for kontr pre",
post_submit_script="python for kontr post",
submission_scheduler_config="python for sub Q",
submission_parameters="{\"type\":\"text\"}",
submissions_allowed_from=time.NOW(),
submissions_allowed_to=time.NOW() + timedelta(days=2),
archive_from=time.NOW() + timedelta(days=30)
)
)
tc1_hw02 = factory.create_project(
course=test_course1, name="HW02", config=dict(
file_whitelist="main.cpp\nfunc.hpp\nfunc.cpp",
pre_submit_script="python for kontr pre",
post_submit_script="python for kontr post",
submission_scheduler_config="python for sub Q",
submission_parameters="{\"type\":\"text\"}",
submissions_allowed_from=time.NOW() - timedelta(days=1),
submissions_allowed_to=time.NOW() + timedelta(days=10),
archive_from=time.NOW() + timedelta(days=30)
)
)
tc2_hw01 = factory.create_project(
course=test_course2, name="HW01", config=dict(
file_whitelist="main.c", pre_submit_script="python for kontr pre",
post_submit_script="python for kontr post",
submission_scheduler_config="python for sub Q",
submission_parameters="{\"type\":\"text\"}",
submissions_allowed_from=time.NOW() - timedelta(days=1),
submissions_allowed_to=time.NOW() - timedelta(minutes=1),
archive_from=time.NOW() + timedelta(days=30)
)
)
# roles
tc1_student = factory.scaffold_role(role_type='student', course=test_course1)
tc1_teacher = factory.scaffold_role(role_type='teacher', course=test_course1)
tc1_owner = factory.scaffold_role(role_type='owner', course=test_course1)
tc2_student = factory.scaffold_role(role_type='student', course=test_course2)
tc2_teacher = factory.scaffold_role(role_type='teacher', course=test_course2)
tc2_owner = factory.scaffold_role(role_type='owner', course=test_course2)
# relationships
teacher_student = teacher1
teacher_both = teacher2
student_tc1 = student1
student_both = student2
# roles
lecturer1.roles.append(tc1_owner)
lecturer1.roles.append(tc2_owner)
teacher_student.roles.append(tc1_teacher)
teacher_student.roles.append(tc2_student)
teacher_both.roles.append(tc1_teacher)
teacher_both.roles.append(tc2_teacher)
student_tc1.roles.append(tc1_student)
student_both.roles.append(tc1_student)
student_both.roles.append(tc2_student)
# groups
teacher_student.groups.append(tc1_teachers)
teacher_student.groups.append(tc2_students)
teacher_both.groups.append(tc1_teachers)
teacher_both.groups.append(tc2_teachers)
student_tc1.groups.append(tc1_students)
student_both.groups.append(tc1_students)
student_both.groups.append(tc2_students)
# submissions
tc2_sub1 = Submission(user=teacher_student, project=tc2_hw01, parameters="")
tc2_sub1.state = SubmissionState.FINISHED
tc2_sub2 = Submission(user=student_both, project=tc2_hw01, parameters="")
tc2_sub2.state = SubmissionState.ABORTED
tc1_sub_p1_cancel = Submission(user=student_both, project=tc1_hw01, parameters="")
tc1_sub_p1_cancel.state = SubmissionState.CANCELLED
tc1_sub_p1_abort = Submission(user=student_tc1, project=tc1_hw01, parameters="")
tc1_sub_p1_abort.state = SubmissionState.ABORTED
tc1_sub_p1_finished = Submission(user=student_both, project=tc1_hw01, parameters="")
tc1_sub_p1_finished.state = SubmissionState.FINISHED
tc1_sub_p1_in_progress = Submission(user=student_tc1, project=tc1_hw01, parameters="")
tc1_sub_p1_in_progress.state = SubmissionState.IN_PROGRESS
# Projects in groups
tc1_students.projects.append(tc1_hw01)
tc2_students.projects.append(tc2_hw01)
db.session.add_all(
[tc2_sub1, tc2_sub2, tc1_sub_p1_cancel, tc1_sub_p1_abort, tc1_sub_p1_finished,
tc1_sub_p1_in_progress])
# reviews
review = Review(tc2_sub1)
factory.create_review_item(author=teacher_both, review=review, line=1,
content="problem here")
factory.create_review_item(author=teacher_both, review=review, line=5,
content="good stuff")
factory.create_review_item(author=teacher_student, review=review,
line=1, content="oops")
db.session.add_all([review])
# components
factory.create_component(name='executor')
factory.create_component(name='processing', component_type='processing')
# Commit to the DB
db.session.commit()