Skip to content

Commit a7deb60

Browse files
committed
Added quiz generation function. Added __future__ imports for py2 compatability
1 parent 5e792aa commit a7deb60

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

canvas_mock_data.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import print_function, unicode_literals
2+
13
from faker import Faker
24
from canvasapi import Canvas
35

@@ -93,3 +95,22 @@ def generate_enrollments(account_id, min_students=1, max_students=5):
9395
already_enrolled.append(enroll_user.id)
9496

9597
# TODO: Add support for enrolling Teachers/ TAs
98+
99+
100+
def generate_quizzes(course_id, min_quizzes=1, max_quizzes=5):
101+
course = canvas.get_course(course_id)
102+
num_quizzes = fake.random_int(min_quizzes, max_quizzes)
103+
104+
QUIZ_TYPES = ['practice_quiz', 'assignment', 'graded_survey', 'survey']
105+
106+
for i in range(num_quizzes):
107+
course.create_quiz(quiz={
108+
'title': fake.bs().title(),
109+
'description': fake.text(max_nb_chars=fake.random_int(100, 500)),
110+
'quiz_type': fake.random_element(QUIZ_TYPES),
111+
'time_limit': fake.random_int(1, 30) * 5 if fake.boolean(50) else None,
112+
'published': fake.boolean(75),
113+
'allowed_attempts': fake.random_int(1, 3) if fake.boolean(75) else -1
114+
})
115+
116+
# TODO: add quiz questions

0 commit comments

Comments
 (0)