From 609f50d26191c1f2541c241de341985cc85427ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20W=C3=B3jcik?= Date: Thu, 27 Jun 2019 16:45:31 +0200 Subject: [PATCH] Fix the duplicate ListField max_length test (#2110) This is a follow-up after #2107. Not sure what happened here, but in https://github.com/MongoEngine/mongoengine/pull/2107/commits/87194856ecc5076bec2a186bae60c5d5b25c01ed I committed a copy-paste of the same test instead of a test validating the max_length behavior along with a "set" operator. --- tests/fields/fields.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) 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."""