Ensure ListField's max_length is respected.
(self)
| 1026 | e.save() |
| 1027 | |
| 1028 | def test_list_field_max_length(self): |
| 1029 | """Ensure ListField's max_length is respected.""" |
| 1030 | |
| 1031 | class Foo(Document): |
| 1032 | items = ListField(IntField(), max_length=5) |
| 1033 | |
| 1034 | foo = Foo() |
| 1035 | for i in range(1, 7): |
| 1036 | foo.items.append(i) |
| 1037 | if i < 6: |
| 1038 | foo.save() |
| 1039 | else: |
| 1040 | with pytest.raises(ValidationError) as exc_info: |
| 1041 | foo.save() |
| 1042 | assert "List is too long" in str(exc_info.value) |
| 1043 | |
| 1044 | def test_list_field_max_length_set_operator(self): |
| 1045 | """Ensure ListField's max_length is respected for a "set" operator.""" |