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

Test validators on each levels of schema #85

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

kloud-byun
Copy link
Contributor

  • test_inputfield_validation.py

    • test_valid
    • test_invalid
    • test_list_validate_item
    • test_list_mixed_valid
      • actually kept this since the operated input will be different than the one for argument level
    • test_nested_invalid
      • tested input field of input field (nested)
  • test_inputobject_validation.py

    • tested validation on a simple relationship between "profession" and "hobbies"
    • test_valid_user
    • test_no_profession_provided
    • test_invalid_profession_given_hobbies
    • test_invalid_profession_name
    • test_invalid_multiple_errors

    Added in static type check assertions for test cases along with # type: ignore[list-item] for the list validator.

@kloud-byun
Copy link
Contributor Author

Kept both test_inputobject_validation.py and test_inputfield_validation.py as simple as possible; to simply test the validity of the validators at each levels of the schema.
InputField validations will test for each single InputField individually, while InputObject validations will test for validity of collection of InputFields.

@kloud-byun
Copy link
Contributor Author

kloud-byun commented Jul 26, 2023

  • test_field_validation.py
    • test_valid_user
    • test_valid_no_profession
    • test_invalid_profession_given_hobbies
    • test_invalid_profession_starts_with_username
    • test_invalid_multiple_errors

Finished the test_field_validation.py as well. Currently mirrors the same tests from test_inputobject_validation.py, but it just applies the validator at the Field level rather than at the InputObject level.

That finishes the validation testings at all 4 different levels of the schema. Test scripts for Field and InputObject are pretty much equivalent, except the targeted level; and test scripts for Argument and InputField are very similar as well, except Argument test file is the only test file that consists of 4 extra GraphQL validations.

If required, I can also include the generic GraphQL validation test cases for the rest 3 of the test files.
I tried to mirror the test cases to keep the consistency between the files, since most of the complex and unique validators + nested validators will be tested within test_complex_validation.py. But I can add/modify the test cases so that none of the test files will be redundant or similar to each other - if required.

Working on test_validators.py that will simply test to cover all the branches of validators.py, then I'll move on to test_complex_validation.py.

@kloud-byun kloud-byun changed the title Test validators on InputField and InputObject Test validators on Field, InputObject, InputField Jul 26, 2023
@kloud-byun
Copy link
Contributor Author

When raising assertions for the validators at Field and InputObject level, the errors are being stored in result.errors[0].extensions[''] for Field and result.errors[0].extensions['input'][0][''] for InputObject. I can modify the path to be something else by adding an additional layer within the validator function, but wasn't sure if that was desired.
Also, test_validators.py now utilizes fixture & parametrize to keep the file simple and clean.

@kloud-byun kloud-byun changed the title Test validators on Field, InputObject, InputField Test validators on each levels of schema Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant