Skip to content

Commit

Permalink
Test max_size validator
Browse files Browse the repository at this point in the history
  • Loading branch information
gotcha committed Jan 16, 2025
1 parent f4e1161 commit 2a98f07
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Changelog
- Some tuning of migration from PFG
[ThibautBorn]

- Test max_size validator
[gotcha]


4.3.0 (2024-12-13)
------------------
Expand Down
24 changes: 24 additions & 0 deletions src/collective/easyform/tests/fixtures/fieldset_file_maxsize.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<model xmlns="http://namespaces.plone.org/supermodel/schema"
xmlns:easyform="http://namespaces.plone.org/supermodel/easyform"
xmlns:form="http://namespaces.plone.org/supermodel/form"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
xmlns:indexer="http://namespaces.plone.org/supermodel/indexer"
xmlns:lingua="http://namespaces.plone.org/supermodel/lingua"
xmlns:marshal="http://namespaces.plone.org/supermodel/marshal"
xmlns:security="http://namespaces.plone.org/supermodel/security"
xmlns:users="http://namespaces.plone.org/supermodel/users"
>
<schema>
<fieldset label="Fieldset 1"
name="fs1"
>
<field name="file1"
type="plone.namedfile.field.NamedFile"
>
<description />
<required>False</required>
<title>Upload</title>
</field>
</fieldset>
</schema>
</model>
16 changes: 16 additions & 0 deletions src/collective/easyform/tests/testValidators.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,3 +542,19 @@ def test_too_big(self):
form = EasyFormForm(self.ff1, request)()
self.assertNotIn("Thanks for your input.", form)
self.assertIn("File is bigger than allowed size of 300 bytes!", form)


class TestFieldsetFileMaxSizeValidator(LoadFixtureBase):
"""ensure file validators works"""

schema_fixture = "fieldset_file_maxsize.xml"

def test_too_big(self):
registry = getUtility(IRegistry)
registry.records["easyform.max_filesize"].value = 300
data = {"file1": DummyUpload(2000, "blah.pdf")}
request = self.LoadRequestForm(**data)
request.method = "POST"
form = EasyFormForm(self.ff1, request)()
self.assertNotIn("Thanks for your input.", form)
self.assertIn("File is bigger than allowed size of 300 bytes!", form)

0 comments on commit 2a98f07

Please sign in to comment.