-
Notifications
You must be signed in to change notification settings - Fork 14
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
Update sds schema validation #1538
base: main
Are you sure you want to change the base?
Conversation
…order for it to be validated
…o if a schema doesn't include it, no error is raised
…t schema version in sds payload
@@ -80,12 +71,19 @@ def validate_dataset_and_survey_id( # pylint: disable=unused-argument | |||
"Supplementary data did not return the specified Survey ID" | |||
) | |||
|
|||
if self.context["sds_schema_version"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can merge the nested if here. Also data["data"]
is a bit weird but not sure there is a way around it
"survey_id": "123", | ||
"title": "Test Supplementary Data", | ||
"theme": "default", | ||
"description": "A questionnaire to demo using Supplementary data for placeholders, validation and routing in both repeating and non repeating sections.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would update the description here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new schema is not actually being used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in an integration test 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add discussed we decided to remove the schema and the integration test
@@ -67,25 +58,33 @@ class SupplementaryDataMetadataSchema(Schema, StripWhitespaceMixin): | |||
|
|||
@validates_schema() | |||
def validate_dataset_and_survey_id( # pylint: disable=unused-argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function name should probably change since you also check "sds_schema_version" now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, I moved the sds_schema_version validation in it's own function underneath, just because it makes the name look smaller in addition to the method name making sense 😅 and validation still passes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good, that new function will require some unit testing (if it's not already tested).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
V minor - No worries if this has already been discussed, so feel free to ignore me 😆 but we now have 2 similar functions that validate things in the payload as follows:
- existing
validate_dataset_and_survey_id()
which validates 2 things in the payload - newly added
validate_sds_schema_version()
which validates 1 thing in the payload
would it be worth splitting validate_dataset_and_survey_id
into separate validation functions, if we're making the validation as individual functions?
Personal preference, but I feel like it might make the most sense to combine all validation logic for this into a single function so it checks all 3 things (like it was originally in the PR I think?) and just rename it to something like validate_payload()
?
@patch( | ||
"app.questionnaire.questionnaire_store_updater.QuestionnaireStoreUpdaterBase.set_supplementary_data", | ||
) | ||
def test_login_with_sds_schema_version_valid( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably need to move your testing to test_supplementary_data_parser.py
where the class and methods you changed are tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of this test was just to check if the schema opens, I initially did a functional test, but then we decided it would be better to add it as an integration test. So we chose to put it in test_login as these just check if schemas can open?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this is testing anything at the moment though cause if you change the sds_schema_version in your schema the suite still passes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed we agreed that the unit test did the same as the integration test and so I removed it
schemas/test/en/test_supplementary_data_with_sds_schema_version.json
Outdated
Show resolved
Hide resolved
dataset_id: str, | ||
identifier: str, | ||
survey_id: str, | ||
sds_schema_version: str | None = None, | ||
) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little detail here but for the return value type hint we recommend in our guide to at least give types of the dict keys and values. https://github.com/ONSdigital/eq-questionnaire-runner/blob/main/doc/python-type-hinting.md#generic-types
) | ||
|
||
|
||
def test_valid_supplementary_dataset_version(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create some more readable code by just writing a test where valid dataset version does not raise an error by using some @contextmanager decorator like this one:
from contextlib import contextmanager
@contextmanager
def not_raises(exception):
try:
yield
except exception:
raise pytest.fail("DID RAISE {0}".format(exception))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and then use it as with not_raises(ValidationError):
Then you can rename the test to align the wording with the first one.
What is the context of this PR?
To align with SDS & Author we need to update the validation rules for supplementary data schema versions within Runner in order to support future automation of the releases of new SDS schema versions.
supplementary_data_parser
previously used a list of known versions but this will become unmanageable with several versions. Instead, we compare thesds_schema_version
set in a questionnaire schema to theschema_version
found in the supplementary data payload. We passsds_schema_version
fromsession.py
tosupplementary_data_parser
for it to be validated. The old logic has been removed and tests have been updated/added to show this change.A new schema has been added called
test_supplementary_data_with_sds_schema_version.json
to include this new field.How to review
Checklist