def test_update_class(self, empty_json_database, test_full_class):
        test_json_database = empty_json_database
        test_class = Class(test_full_class.name, test_full_class.students)
        # create_class takes a NewClass object due to avatar moving machinery.
        test_class_new_class = NewClass(test_full_class.name,
                                        test_full_class.students)
        assert test_class.json_dict() == test_class_new_class.json_dict(
        )  # Ensure classes are the same.

        # Create class in database.
        test_json_database.create_class(
            NewClass(test_full_class.name, test_full_class.students))
        # Ensure test_class in database
        test_class.id = test_class.name

        # Loaded class will have ids:
        test_loaded_class = test_full_class.json_dict()
        for student in test_loaded_class['students']:
            student['id'] = student['name']
        assert test_json_database.load_class(
            test_class.name).json_dict() == test_loaded_class

        # Change class by adding student, update database:
        new_student = Student(name='new student')
        assert new_student not in test_class and new_student.name not in test_class  # Confirm student not in class.
        test_class.add_student(new_student)

        assert test_json_database.update_class(test_class) is None
        # Look up name because new_student object itself is not in the loaded class object.
        assert new_student.name in test_json_database.load_class(
            test_class.name)
def test_full_class() -> Class:
    test_full_class = Class(
        class_id=test_full_class_data_set['json_dict_rep']['id'],
        name=test_full_class_data_set['json_dict_rep']['name'])
    for student in test_full_class_data_set['json_dict_rep']['students']:
        test_full_class.add_student(Student(**student))

    test_full_class.json_str_rep = test_full_class_data_set['json_str_rep']
    test_full_class.json_dict_rep = test_full_class_data_set['json_dict_rep']

    return test_full_class
Exemple #3
0
def take_class_data_input(class_name: str):
    """
    Take student names, avatars, return Class object.

    :param class_name: str
    :return: Class
    """
    new_class = Class(name=class_name)
    while True:
        student_name = take_student_name_input(new_class)
        if student_name.upper() == 'END':
            break
        avatar_filename = take_student_avatar(class_name, student_name)
        new_class.add_student(name=student_name,
                              avatar_filename=avatar_filename)
    return new_class