def test_update_grades_invalid_grade_low(self, mock_input): new_student = student.Student('Kylee', 'Purcell', 'A01088859', True, [60, 90, 40]) crud.file_write(new_student, 'testfile11.txt') crud.update_grades('A01088859', 'testfile11.txt') student_list = crud.file_read('testfile11.txt') crud.update_file([], 'testfile11.txt') self.assertEqual([60, 90, 40], student_list[0].get_grades_list())
def test_update_grades_valid_grade(self, mock_input): new_student = student.Student('Kylo', 'Purcell', 'A01088857', True, [80, 90, 70]) crud.file_write(new_student, 'testfile9.txt') crud.update_grades('A01088857', 'testfile9.txt') student_list = crud.file_read('testfile9.txt') crud.update_file([], 'testfile9.txt') self.assertEqual([80, 90, 70, 85], student_list[0].get_grades_list())
def test_file_delete_student_added_student_deleted(self): new_list = [] student1 = student.Student('Kylo', 'Ren', 'A01077789', False, [40, 50]) crud.file_write(student1, 'testfile3.txt') crud.file_delete_student('A01077789', 'testfile3.txt') for i in crud.file_read('testfile3.txt'): new_list.append(i.__repr__()) self.assertNotIn(student1.__repr__(), new_list)
def test_file_read_two_students_equal_list(self): reader = crud.file_read('testfile1.txt') new_list = [] student1 = student.Student('Kyla', 'Purcell', 'A01088856', True, [80, 90, 100]) student2 = student.Student('Kaylee', 'Hello', 'A01099967', False, []) for i in reader: new_list.append(i.__repr__()) self.assertEqual([student1.__repr__(), student2.__repr__()], new_list)
def test_print_class_list_one_student(self, mock_stdout): new_student = student.Student('Kylo', 'Purcell', 'A01088857', True, [80, 90, 70]) filename = 'testfile16.txt' crud.file_write(new_student, filename) student_list = crud.file_read(filename) crud.print_class_list('testfile16.txt') expected = 'Name: Kylo Purcell Student Number: A01088857 Status: True Grades: 80 90 70\n' \ 'There are 1 students currently enrolled in this school\n' crud.update_file([], filename) self.assertEqual(mock_stdout.getvalue(), expected)
def test_file_delete_student_in_file_with_multiple_students(self): new_list = [] student1 = student.Student('Kylo', 'Ren', 'A01077789', False, [40, 50]) student2 = student.Student('Delete', 'Me', 'A01099985', True, []) crud.file_write(student1, 'testfile4.txt') crud.file_write(student2, 'testfile4.txt') crud.file_delete_student('A01099985', 'testfile4.txt') for i in crud.file_read('testfile3.txt'): new_list.append(i.__repr__()) self.assertNotIn(student2.__repr__(), new_list)
def test_file_write_normal_case(self): new_student = student.Student('Kylo', 'Purcell', 'A01088857', True, [80, 90, 70]) filename = 'testfile1.txt' crud.file_write(new_student, filename) student_list = crud.file_read('testfile1.txt') self.assertEqual(new_student.__repr__(), student_list[len(student_list)-1].__repr__())
def test_update_file_normal_case(self): student1 = student.Student('Kylo', 'Ren', 'A01077789', False, [40, 50]) crud.update_file([student1], 'testfile2.txt') read = crud.file_read('testfile2.txt') self.assertEqual([student1][0].__repr__(), read[0].__repr__())
def test_file_read_return_type(self): self.student1 = student.Student("Yongju", "Kwon", "A01059332", True, [91, 93, 87]) crud.file_write(str(self.student1) + "\n") self.assertTrue(type(crud.file_read()) == list)
def test_file_read_length(self): self.student1 = student.Student("Yongju", "Kwon", "A01059332", True, [91, 93, 87]) crud.file_write(str(self.student1) + "\n") self.assertEqual(1, len(crud.file_read()))
def test_file_read_one_student(self): reader = crud.file_read('testfile1.txt') student1 = student.Student('Kyla', 'Purcell', 'A01088856', True, [80, 90, 100]) self.assertEqual(student1.__repr__(), reader[0].__repr__())
def test_file_read_is_list_of_objects(self): reader = crud.file_read('testfile1.txt') self.assertIsInstance(reader[0], object)
def test_file_read_is_type_list(self): reader = crud.file_read('testfile1.txt') self.assertEqual(list, type(reader))