def remove_enrollments(self,
                        enrollments,
                        allow_duplicates=False,
                        unique_attr=None):
     self.enrollments = remove_from_list(self.enrollments, enrollments,
                                         allow_duplicates, unique_attr)
예제 #2
0
 def remove_courses(self,
                    courses,
                    allow_duplicates=False,
                    unique_attr=None):
     self.courses = remove_from_list(self.courses, courses,
                                     allow_duplicates, unique_attr)
예제 #3
0
    def test_remove_from_list(self):
        # Simple case
        result1 = models.remove_from_list([1, 2, 3, 4, 5, 6], [4, 5, 6])
        expected1 = [1, 2, 3]
        self.assertEqual(result1, expected1)

        # Duplicate values
        result2 = models.remove_from_list([1, 1, 2, 3], [1])
        expected2 = [2, 3]
        self.assertEqual(result2, expected2)

        # Items to be removed don't exist in orig (want it to throw an exception)
        try:
            result3 = models.remove_from_list([1, 2, 3], [4, 5, 6])
            # Really just checking if it goes past the previous line without throwing an exception
            self.assertTrue(False)
        except AssertionError:
            # It's supposed to throw an error, so affirming that it did
            self.assertTrue(True)

        # Ignore warnings about item not existing in list
        result3 = models.remove_from_list([1, 2, 3], [4, 5, 6],
                                          ignore_warnings=True)
        # Really just checking if it goes past the previous line without throwing an exception
        expected3 = [1, 2, 3]
        self.assertEqual(result3, expected3)

        # Remove single item to list
        result4 = models.remove_from_list([1, 2, 3], 1)
        expected4 = [2, 3]
        self.assertEqual(result4, expected4)

        # Remove list from single item
        result5 = models.remove_from_list(1, [1, 2, 3], ignore_warnings=True)
        expected5 = []
        self.assertEqual(result5, expected5)

        # Remove single item from single item
        result6 = models.remove_from_list(1, 1)
        expected6 = []
        self.assertEqual(result6, expected6)

        # Empty remove list
        result7 = models.remove_from_list([1, 2, 3], [])
        expected7 = [1, 2, 3]
        self.assertEqual(result7, expected7)

        # Empty source list
        result8 = models.remove_from_list([], [1, 2, 3], ignore_warnings=True)
        expected8 = []
        self.assertEqual(result8, expected8)

        # None remove list
        result9 = models.remove_from_list([1, 2, 3],
                                          None,
                                          ignore_warnings=True)
        expected9 = [1, 2, 3]
        self.assertEqual(result9, expected9)

        # None source list
        result10 = models.remove_from_list(None, [1, 2, 3],
                                           ignore_warnings=True)
        expected10 = [None]
        self.assertEqual(result10, expected10)
예제 #4
0
 def remove_assignments(self,
                        assignments,
                        allow_duplicates=False,
                        unique_attr=None):
     self.assignments = remove_from_list(self.assignments, assignments,
                                         allow_duplicates, unique_attr)
예제 #5
0
 def remove_students(self,
                     students,
                     allow_duplicates=False,
                     unique_attr=None):
     self.students = remove_from_list(self.students, students,
                                      allow_duplicates, unique_attr)
예제 #6
0
 def remove_grades(self, grades, allow_duplicates=False, unique_attr=None):
     self.grades = remove_from_list(self.grades, grades, allow_duplicates,
                                    unique_attr)