Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#72] Add backend validation of form rules #4029

Merged
merged 10 commits into from
Apr 2, 2024

Conversation

vaszig
Copy link
Contributor

@vaszig vaszig commented Mar 20, 2024

Partly closes #72

This PR handles the following components, the rest of them will be handled in an another PR:

  • textarea
  • time
  • postcode
  • bsn (11-check)
  • select
  • checkbox
  • currency
  • signature
  • map

@vaszig vaszig marked this pull request as draft March 20, 2024 15:45
@vaszig vaszig force-pushed the task/72-backend-validation-of-form-rules branch from 52ee39e to 69cdcc9 Compare March 21, 2024 12:59
Copy link

codecov bot commented Mar 21, 2024

Codecov Report

Attention: Patch coverage is 98.55072% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 96.10%. Comparing base (2b7b6b6) to head (2db8fd0).
Report is 4 commits behind head on master.

Files Patch % Lines
src/openforms/formio/components/custom.py 92.59% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4029      +/-   ##
==========================================
+ Coverage   96.07%   96.10%   +0.02%     
==========================================
  Files         729      730       +1     
  Lines       22980    23094     +114     
  Branches     2674     2698      +24     
==========================================
+ Hits        22078    22194     +116     
+ Misses        639      638       -1     
+ Partials      263      262       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vaszig vaszig marked this pull request as ready for review March 21, 2024 13:53
@SilviaAmAm SilviaAmAm self-requested a review March 21, 2024 14:55
src/openforms/formio/components/vanilla.py Outdated Show resolved Hide resolved
src/openforms/formio/components/vanilla.py Outdated Show resolved Hide resolved
src/openforms/formio/components/vanilla.py Outdated Show resolved Hide resolved
src/openforms/formio/typing/vanilla.py Outdated Show resolved Hide resolved
Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing the matching e2e tests yet? These are important to ensure that the frontend and backend behaviour are aligned:

https://github.com/open-formulieren/open-forms/blob/master/src/openforms/tests/e2e/test_input_validation.py

src/openforms/formio/components/vanilla.py Outdated Show resolved Hide resolved
src/openforms/formio/tests/validation/test_time.py Outdated Show resolved Hide resolved
src/openforms/formio/components/vanilla.py Outdated Show resolved Hide resolved
src/openforms/formio/components/vanilla.py Show resolved Hide resolved
src/openforms/tests/e2e/input_validation_base.py Outdated Show resolved Hide resolved
src/openforms/tests/e2e/input_validation_base.py Outdated Show resolved Hide resolved
src/openforms/tests/e2e/test_input_validation.py Outdated Show resolved Hide resolved
src/openforms/tests/e2e/test_input_validation.py Outdated Show resolved Hide resolved
src/openforms/tests/e2e/test_input_validation.py Outdated Show resolved Hide resolved
src/openforms/tests/e2e/test_input_validation.py Outdated Show resolved Hide resolved
src/openforms/tests/e2e/test_input_validation.py Outdated Show resolved Hide resolved
src/openforms/tests/e2e/test_input_validation.py Outdated Show resolved Hide resolved
src/openforms/formio/api/validators.py Outdated Show resolved Hide resolved
vaszig added 5 commits March 29, 2024 16:26
This commit handles the backend validation for the following components:
- textarea
- time
- postcode
- bsn (11-check)
- select
- checkbox
- currency
- signature
- map
@sergei-maertens sergei-maertens force-pushed the task/72-backend-validation-of-form-rules branch from 842d756 to a68c8fd Compare March 29, 2024 15:27
* Refactored and moved validator
* Added more tests
* Fixed warning in playwright test
@sergei-maertens
Copy link
Member

I tested some more complex forms that revealed some validation issues before, and as far as I can tell this doesn't introduce new problems yet, but not all component types were used in there 😬

Use accurate keys/labels for the components being tested.
* Especially text-based fields with multiple: true are problematic
* Fixed textarea
@sergei-maertens sergei-maertens force-pushed the task/72-backend-validation-of-form-rules branch from 4f27452 to bc7fcfe Compare April 2, 2024 07:23
* Ensure multiple false|true is handled appropriately
* Model current behaviour of frontend data in tests
* Ensure that empty options are treated correctly
  depending on required/optional config
Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vaszig do you mind sanity checking my changes?

Copy link
Contributor Author

@vaszig vaszig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would approve this but github doesn't let me to do so..

The only thing, as mentioned in slack as well, is something like splitting some things like the TimeBetweenValidator and the custom field, but I guess this can be done in the next-relative PR which is open.


is_valid, _ = validate_formio_data(component, {"time": "15:36"})

self.assertTrue(is_valid)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am missing something here. Could you please explain why we have this behaviour here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coverage reporting complained about missing branch coverage on the match statement, so this is what it addresses - it happens that invalid configuration ends up in the JSON and this ensures it is logged/covered by tests :)

@sergei-maertens sergei-maertens merged commit 31380fa into master Apr 2, 2024
27 checks passed
@sergei-maertens sergei-maertens deleted the task/72-backend-validation-of-form-rules branch April 2, 2024 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

As developer I want to implement frontend and backend validation of form fields
3 participants