src/canvas-extractor/tests/data_generation/enrollments.py
def generate_and_load_enrollments(
    users: List[User],
    sections_by_course: Dict[Course, List[Section]],
    users_per_section_count: int,
) -> Dict[Course, List[Enrollment]]:
    """
    Generate and load a number of enrollments into the Canvas API.

    Parameters
    ----------
    users: List[User]
        A list of User SDK objects
    users_per_section_count : int
        The number of users to be in each section
    sections_by_course: Dict[Course, List[Section]]
        A list of Canvas SDK Section objects, grouped by Course SDK object

    Returns
    -------
    Dict[Course, List[Enrollment]]
        A list of Canvas SDK Enrollment objects representing the created enrollments,
        grouped by Course SDK object
    """
    result: Dict[Course, List[Enrollment]] = {}

    for course, section_list in sections_by_course.items():
        for section in section_list:
            try:
                users_in_section = fake.random_sample(
                    elements=users, length=users_per_section_count
                )
                enrollments = list(
                    map(
                        lambda user: {
                            "user": user,
                            "enrollment_type": "StudentEnrollment",
                            "enrollment": {
                                "enrollment[course_section_id]": section.id,
                                "enrollment[enrollment_state]": "active",
                            },
                        },
                        users_in_section,
                    )
                )

                enrollments_list: List[Enrollment] = load_enrollments(course, enrollments)
                result[course] = enrollments_list
            except Exception as ex:
                logger.exception(ex)

    return result

    Generate and load a number of enrollments into the Canvas API.

    Parameters
    ----------
    users: List[User]
        A list of User SDK objects
    users_per_section_count : int
        The number of users to be in each section
    sections_by_course: Dict[Course, List[Section]]
        A list of Canvas SDK Section objects, grouped by Course SDK object

    Returns
    -------
    Dict[Course, List[Enrollment]]
        A list of Canvas SDK Enrollment objects representing the created enrollments,
        grouped by Course SDK object
    
Generate and load a number of enrollments into the Canvas API.
Parameters

List[User]
A list of User SDK objects
users_per_section_count : int
The number of users to be in each section
sections_by_course: Dict[Course, List[Section]]
A list of Canvas SDK Section objects, grouped by Course SDK object

Returns

Dict[Course, List[Enrollment]]
A list of Canvas SDK Enrollment objects representing the created enrollments,
grouped by Course SDK object
Generate and load a number of enrollments into the Canvas API . Parameters List [ User ] A list of User SDK objects users_per_section_count : int The number of users to be in each section sections_by_course : Dict [ Course List [ Section ]] A list of Canvas SDK Section objects grouped by Course SDK object Returns Dict [ Course List [ Enrollment ]] A list of Canvas SDK Enrollment objects representing the created enrollments grouped by Course SDK object
def generate_and_load_enrollments(
    users: List[User],
    sections_by_course: Dict[Course, List[Section]],
    users_per_section_count: int,
) -> Dict[Course, List[Enrollment]]:
    result: Dict[Course, List[Enrollment]] = {}
    for course, section_list in sections_by_course.items():
        for section in section_list:
            try:
                users_in_section = fake.random_sample(
                    elements=users, length=users_per_section_count
                )
                enrollments = list(
                    map(
                        lambda user: {
                            "user": user,
                            "enrollment_type": "StudentEnrollment",
                            "enrollment": {
                                "enrollment[course_section_id]": section.id,
                                "enrollment[enrollment_state]": "active",
                            },
                        },
                        users_in_section,
                    )
                )
                enrollments_list: List[Enrollment] = load_enrollments(course, enrollments)
                result[course] = enrollments_list
            except Exception as ex:
                logger.exception(ex)
    return result
def generate_and_load_enrollments ( users : List [ User ] , sections_by_course : Dict [ Course , List [ Section ] ] , users_per_section_count : int , ) -> Dict [ Course , List [ Enrollment ] ] : result : Dict [ Course , List [ Enrollment ] ] = { } for course , section_list in sections_by_course . items ( ) : for section in section_list : try : users_in_section = fake . random_sample ( elements = users , length = users_per_section_count ) enrollments = list ( map ( lambda user : { "user" : user , "enrollment_type" : "StudentEnrollment" , "enrollment" : { "enrollment[course_section_id]" : section . id , "enrollment[enrollment_state]" : "active" , } , } , users_in_section , ) ) enrollments_list : List [ Enrollment ] = load_enrollments ( course , enrollments ) result [ course ] = enrollments_list except Exception as ex : logger . exception ( ex ) return result
Generate and load a number of enrollments into the Canvas API.
Generate and load a number of enrollments into the Canvas API .
"""
    Generate and load a number of enrollments into the Canvas API.

    Parameters
    ----------
    users: List[User]
        A list of User SDK objects
    users_per_section_count : int
        The number of users to be in each section
    sections_by_course: Dict[Course, List[Section]]
        A list of Canvas SDK Section objects, grouped by Course SDK object

    Returns
    -------
    Dict[Course, List[Enrollment]]
        A list of Canvas SDK Enrollment objects representing the created enrollments,
        grouped by Course SDK object
    """
users
List[User]
sections_by_course
Dict[Course, List[Section]]
users_per_section_count
int