Skip to content

Create validation for document types with error handling#1846

Merged
freakboy3742 merged 17 commits intobeeware:mainfrom
oakal510:configuration-error-document-types
Jul 27, 2024
Merged

Create validation for document types with error handling#1846
freakboy3742 merged 17 commits intobeeware:mainfrom
oakal510:configuration-error-document-types

Conversation

@oakal510
Copy link
Contributor

@oakal510 oakal510 commented May 28, 2024

  • This PR is for added validation checks for document types with error handling for failing to provide requisite document type details relating to icon, description, extension, and URL for a given document type in an app. Existing tests were updated to account for the validation and new tests were created to ensure proper validation.
  • This PR will ensure that if a user does not provide valid document type details, the user will receive clear error messages.

Fixes #1770

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

This looks really good! I've left some comments inline, but they're mostly cosmetic wording changes for error messages, or suggestions about ways to simplify tests and/or code - the core of this is really solid.

validate_document_icon("ext", invalid_document)


def test_validate_document_invalid_icon():
Copy link
Member

Choose a reason for hiding this comment

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

It's generally a good idea to parameterize "invalid" tests so that you can try out a range of things that you know should be invalid. Even if there's only 2 initially, having a parameterised test makes it easier to add other examples later if the need arises.

The same is true of "valid" tests as well - there's less need for tests of valid examples, but it can be helpful sometimes to explicitly validate some cases (e.g., that strings with and without spaces are valid). That's not an issue here explicitly, but as protection against future possible validations, it's helpful to have the testing infrastructure in place.

"extension": "ext",
}
# Failure raises an exception
with pytest.raises(BriefcaseConfigError):
Copy link
Member

Choose a reason for hiding this comment

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

As before - adding a match clause is helpful here (and in other raises tests in this file)

"extension": "ext",
}
# Failure raises an exception
with pytest.raises(BriefcaseConfigError):
Copy link
Member

Choose a reason for hiding this comment

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

As before - adding a match clause is helpful here.

],
)
def test_validations(validation):
valid_document = {
Copy link
Member

Choose a reason for hiding this comment

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

The "valid" document type declaration could be used as a template for all other uses. Rather than defining a 4 line dictionary in every test, you can define a single fixture for valid_document, and then each test can either modify or delete the one field that needs to be modified to generate an invalid document type for a specific test.

oakal510 and others added 7 commits May 28, 2024 11:02
Co-authored-by: Russell Keith-Magee <[email protected]>
Co-authored-by: Russell Keith-Magee <[email protected]>
Co-authored-by: Russell Keith-Magee <[email protected]>
Co-authored-by: Russell Keith-Magee <[email protected]>
Co-authored-by: Russell Keith-Magee <[email protected]>
Co-authored-by: Russell Keith-Magee <[email protected]>
Co-authored-by: Russell Keith-Magee <[email protected]>
@oakal510 oakal510 marked this pull request as draft May 28, 2024 18:07
@oakal510 oakal510 marked this pull request as ready for review July 26, 2024 21:35
@oakal510
Copy link
Contributor Author

Thanks for all the feedback! Please take a look at the latest version, which incorporates your feedback. Thank you!

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

Thanks for those changes! I've made a couple of minor tweaks - merging the four validation methods into one (since there's never going to be a reason to independently validate each field), and some minor stylistic tweaks to the test cases (adding test descriptions, and some formatting changes to the test parameterization)- but otherwise, this looks great! Thanks for the contribution!

@freakboy3742
Copy link
Member

The CI failure is something we've seen before, but historically it's been a transient thing. However, in this case, it looks like it's repeatable. AFAICT, it's not something you've caused with these changes (other than producing a test case that can reproduce it reliably), so unless you're particularly enthused to go hunting an obscure Ubuntu bug, you don't need to dig into it.

@freakboy3742 freakboy3742 merged commit 23d1ed3 into beeware:main Jul 27, 2024
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.

Validate app document types before passing to cookiecutter

2 participants