Beispiel #1
0
 def arrange_df_students(students_list_path):
     file_ext = "." + students_list_path.split(".")[-1]
     df_students = create_students_df(file_ext, students_list_path)
     parser = ParseClassFile.from_object(ParseConfig)
     student_df = parser.parse_df(df_students)
     # add index manually because in the real function it parser the df from the database
     student_df["id"] = [i for i in range(1, student_df.shape[0] + 1)]
     return student_df
 def test_basic_file(self, parser, folders, file_name,
                     student_full_columns_columns, num_records):
     df_students = create_students_df(
         file_name,
         os.path.join(folders["student_list_folder"], file_name))
     result_df = parser.classic_file(df_students)
     assert result_df.shape[0] == num_records
     assert result_df.columns.isin(student_full_columns_columns).all()
Beispiel #3
0
def student_df(folders):
    file_name = "example_excel.xlsx"
    df_students = create_students_df(
        file_name, os.path.join(folders["student_list_folder"], file_name))
    parser = ParseClassFile.from_object(ParseConfig)
    student_df = parser.parse_df(df_students)
    # add index manually because in the real function it parser the df from the database
    student_df["id"] = [i for i in range(1, student_df.shape[0] + 1)]
    return student_df
 def test_mashov_file(self, parser, folders, file_name,
                      student_full_columns_columns, if_is_mashov_file,
                      num_records):
     df_students = create_students_df(
         file_name,
         os.path.join(folders["student_list_folder"], file_name))
     if parser.check_if_mashov_file(df_students):
         result_df = parser.mashov_file(df_students)
         assert result_df.shape[0] == num_records
         assert result_df.columns.isin(
             student_full_columns_columns).all()
     else:
         assert True
Beispiel #5
0
 def students_file(self, value):
     """
     The function will make sure the student file has the right extenstion
     :param value: the student file (FileStorage)
     :return: all the students from the file (Pandas DataFrame)
     """
     ext = Validators.check_ext(value.filename,
                                self._supported_student_files_ext)
     if not ext:
         raise ValueError(RestErrors.INVALID_STUDENTS_FILE)
     students_df = create_students_df(ext, value.stream)
     if students_df.shape[0] > self._max_students_in_class:
         raise ValueError(RestErrors.TO_MANY_RECORDS)
     if students_df.empty:
         raise ValueError(RestErrors.INVALID_STUDENTS_FILE)
     return parser.parse_df(students_df)
Beispiel #6
0
 def test_create_students_df_validation_problem(self, folders, file_name):
     with pytest.raises(ValueError):
         assert create_students_df(file_name, os.path.join(folders["student_list_folder"], file_name))
Beispiel #7
0
 def test_create_students_df_validation(self, folders, file_name, expected_output):
     df_students = create_students_df(file_name, os.path.join(folders["student_list_folder"], file_name))
     assert not df_students.empty == expected_output
Beispiel #8
0
 def arrange_df_students_before_parsing(students_list_path):
     file_ext = "." + students_list_path.split(".")[-1]
     df_students = create_students_df(file_ext, students_list_path)
     return df_students
 def test_check_if_mashov_file(self, parser, folders, file_name,
                               expected_output, num_records):
     df_students = create_students_df(
         file_name,
         os.path.join(folders["student_list_folder"], file_name))
     assert parser.check_if_mashov_file(df_students) == expected_output