def remove_student(self, other): """ Removes the student from self.students and removes the edge for the graph connection :param other: Student to remove :type other: VisualUser :return: None """ User.remove_student(self, other) for edge in other.edges: if edge.node1 == self.node and edge.node2 == other.node: other.edges.remove(edge)
def test_user_double_remove_student(self): """ Tests that an error is raised when double removing a student """ u1 = User("u1", 1) u2 = User("u2", 1) u1.add_student(u2) u1.remove_student(u2) self.assertRaises(MissingStudentError, u1.remove_student, u2) self.assertEqual(len(u1.students), 0) self.assertFalse(u2 in u1.students) self.assertFalse(u1 in u2.coaches)
def test_user_remove_single_student(self): """ Tests removing a student from a user's students """ u1 = User("u1", 1) u2 = User("u2", 1) u1.add_student(u2) u1.remove_student(u2) self.assertEqual(len(u1.students), 0) self.assertFalse(u2 in u1.students) self.assertEqual(len(u2.coaches), 0) self.assertFalse(u1 in u2.coaches)
def test_user_remove_multiple_students_same_name(self): """ Tests removing students with the same name """ u1 = User("u1", 1) u2 = User("u2", 1) u3 = User("u2", 1) u1.add_student(u2) u1.add_student(u3) u1.remove_student(u2) self.assertEqual(len(u1.students), 1) self.assertTrue(u3 in u1.students) self.assertFalse(u2 in u1.students) self.assertTrue(u1 in u3.coaches) self.assertFalse(u1 in u2.coaches) u1.remove_student(u3) self.assertEqual(len(u1.students), 0) self.assertFalse(u3 in u1.students) self.assertFalse(u2 in u1.students) self.assertFalse(u1 in u3.coaches) self.assertFalse(u1 in u2.coaches)