Skip to content

Commit d7dba5a

Browse files
committed
Added assignment generation. Added docstring to quiz generation function
1 parent a7deb60 commit d7dba5a

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

canvas_mock_data.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ def generate_enrollments(account_id, min_students=1, max_students=5):
9898

9999

100100
def generate_quizzes(course_id, min_quizzes=1, max_quizzes=5):
101+
"""
102+
Create randomized quizzes in a course.
103+
104+
:param course_id: The Canvas Course to create quizzes in.
105+
:type course_id: int
106+
:param min_quizzes: The minimum number of quizzes to create.
107+
:type min_quizzes: int
108+
:param max_quizzes: The maximum number of quizzes to create.
109+
:type max_quizzes: int
110+
"""
101111
course = canvas.get_course(course_id)
102112
num_quizzes = fake.random_int(min_quizzes, max_quizzes)
103113

@@ -114,3 +124,48 @@ def generate_quizzes(course_id, min_quizzes=1, max_quizzes=5):
114124
})
115125

116126
# TODO: add quiz questions
127+
128+
129+
def generate_assignments(course_id, min_assignments=5, max_assignments=10):
130+
"""
131+
Create randomized assignments in a course.
132+
133+
:param course_id: The Canvas Course to create assignments in.
134+
:type course_id: int
135+
:param min_assignments: The minimum number of assignments to create.
136+
:type min_assignments: int
137+
:param max_assignments: The maximum number of assignments to create.
138+
:type max_assignments: int
139+
"""
140+
def get_sub_types():
141+
"""
142+
Return a list of valid sub types.
143+
144+
:rtype: list
145+
"""
146+
ASSIGN_SUB_TYPES = {
147+
'online': ['online_upload', 'online_text_entry', 'online_url'],
148+
'offline': ['online_quiz', 'none', 'on_paper', 'discussion_topic', 'external_tool']
149+
}
150+
151+
if fake.boolean(25): # 25% chance of being offline only
152+
# if not online, allow only one type of submission from the offline group
153+
return [fake.random_element(ASSIGN_SUB_TYPES['offline'])]
154+
155+
# if online, pick at least one online (and possibly some offline) sub types
156+
online = fake.random_sample(ASSIGN_SUB_TYPES['online'], fake.random_int(1, 3))
157+
offline = fake.random_sample(ASSIGN_SUB_TYPES['offline'], fake.random_int(0, 3))
158+
return list(online | offline)
159+
160+
course = canvas.get_course(course_id)
161+
162+
num_assignments = fake.random_int(min_assignments, max_assignments)
163+
164+
for i in range(num_assignments):
165+
submission_types = get_sub_types()
166+
course.create_assignment(assignment={
167+
'name': fake.bs().title(),
168+
'submission_types': submission_types,
169+
'description': fake.text(max_nb_chars=fake.random_int(100, 500)),
170+
'published': fake.boolean(75)
171+
})

0 commit comments

Comments
 (0)