diff --git a/tests/fields/fields.py b/tests/fields/fields.py index b77ba753..49e9508c 100644 --- a/tests/fields/fields.py +++ b/tests/fields/fields.py @@ -1026,21 +1026,16 @@ class FieldTest(MongoDBTestCase): foo.save() self.assertIn("List is too long", str(cm.exception)) - def test_list_field_max_length(self): - """Ensure ListField's max_length is respected.""" + def test_list_field_max_length_set_operator(self): + """Ensure ListField's max_length is respected for a "set" operator.""" class Foo(Document): - items = ListField(IntField(), max_length=5) + items = ListField(IntField(), max_length=3) - foo = Foo() - for i in range(1, 7): - foo.items.append(i) - if i < 6: - foo.save() - else: - with self.assertRaises(ValidationError) as cm: - foo.save() - self.assertIn("List is too long", str(cm.exception)) + foo = Foo.objects.create(items=[1, 2, 3]) + with self.assertRaises(ValidationError) as cm: + foo.modify(set__items=[1, 2, 3, 4]) + self.assertIn("List is too long", str(cm.exception)) def test_list_field_rejects_strings(self): """Strings aren't valid list field data types."""