8
8
fake = Faker ()
9
9
10
10
11
- def generate_users (num_users , account_id ):
11
+ def generate_users (account_id , num_users ):
12
+ """
13
+ Create realistic-looking mock users.
14
+
15
+ :param account_id: The Canvas Account to create users in.
16
+ :type account_id: int
17
+ :param num_users: The number of users to create.
18
+ :type num_users: int
19
+ """
12
20
account = canvas .get_account (account_id )
13
21
14
22
for i in range (1 , num_users + 1 ):
@@ -28,7 +36,15 @@ def generate_users(num_users, account_id):
28
36
account .create_user (pseudonym , user = user )
29
37
30
38
31
- def generate_courses (num_courses , account_id ):
39
+ def generate_courses (account_id , num_courses ):
40
+ """
41
+ Create realistic-looking mock courses.
42
+
43
+ :param account_id: The Canvas Account to create courses in.
44
+ :type account_id: int
45
+ :param num_courses: The number of courses to create.
46
+ :type num_courses: int
47
+ """
32
48
account = canvas .get_account (account_id )
33
49
34
50
for i in range (1 , num_courses + 1 ):
@@ -39,3 +55,41 @@ def generate_courses(num_courses, account_id):
39
55
}
40
56
41
57
account .create_course (course = course_dict )
58
+
59
+
60
+ def generate_enrollments (account_id , min_students = 1 , max_students = 5 ):
61
+ """
62
+ Enroll random users into each course.
63
+
64
+ :param account_id: The Canvas Account to create enrollments in.
65
+ :type account_id: int
66
+ :param min_students: The minimum number of student enrollments to add per course.
67
+ :type min_students: int
68
+ :param max_students: The maximum number of student enrollments to add per course.
69
+ :type max_students: int
70
+ """
71
+ account = canvas .get_account (account_id )
72
+
73
+ user_list = [user for user in account .get_users ()]
74
+ courses = account .get_courses ()
75
+
76
+ already_enrolled = []
77
+
78
+ for course in courses :
79
+ num_students = fake .random_int (min = min_students , max = max_students )
80
+ for i in range (0 , num_students ):
81
+ enroll_user = fake .random_element (user_list )
82
+
83
+ if enroll_user .id in already_enrolled :
84
+ continue
85
+
86
+ enroll_type = 'StudentEnrollment'
87
+ enrollment = {
88
+ 'notify' : False ,
89
+ 'enrollment_state' : 'active'
90
+ }
91
+
92
+ course .enroll_user (enroll_user , enroll_type , enrollment = enrollment )
93
+ already_enrolled .append (enroll_user .id )
94
+
95
+ # TODO: Add support for enrolling Teachers/ TAs
0 commit comments