-
Notifications
You must be signed in to change notification settings - Fork 0
π‘οΈ Shield: Expand JSON roundtrip tests for all fake data payloads #724
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
Merged
fderuiter
merged 1 commit into
main
from
shield-expand-json-roundtrip-coverage-6732592961790310232
Mar 2, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,63 @@ | ||
| import pytest | ||
|
|
||
| from imednet.models import Form, Job, Subject | ||
| from imednet.models import ( | ||
| Coding, | ||
| Form, | ||
| Interval, | ||
| Job, | ||
| Query, | ||
| Record, | ||
| RecordRevision, | ||
| Site, | ||
| Study, | ||
| Subject, | ||
| User, | ||
| Variable, | ||
| Visit, | ||
| ) | ||
| from imednet.testing import fake_data | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "cls,payload_func", | ||
| [ | ||
| (Subject, fake_data.fake_subject), | ||
| (Coding, fake_data.fake_coding), | ||
| (Form, fake_data.fake_form), | ||
| (Interval, fake_data.fake_interval), | ||
| (Job, fake_data.fake_job), | ||
| (Query, fake_data.fake_query), | ||
| (Record, fake_data.fake_record), | ||
| (RecordRevision, fake_data.fake_record_revision), | ||
| (Site, fake_data.fake_site), | ||
| (Study, fake_data.fake_study), | ||
| (Subject, fake_data.fake_subject), | ||
| (User, fake_data.fake_user), | ||
| (Variable, fake_data.fake_variable), | ||
| (Visit, fake_data.fake_visit), | ||
| ], | ||
| ) | ||
| def test_json_roundtrip(cls, payload_func): | ||
| payload = payload_func() | ||
| model = cls.from_json(payload) | ||
| dumped = model.model_dump(by_alias=True) | ||
| assert cls.from_json(dumped) == model | ||
|
|
||
|
|
||
| def test_fake_forms_for_cache(): | ||
| forms = fake_data.fake_forms_for_cache(num_forms=2, study_key="TEST-1") | ||
| assert len(forms) == 2 | ||
| for form in forms: | ||
| assert isinstance(form, Form) | ||
| assert form.study_key == "TEST-1" | ||
|
|
||
|
|
||
| def test_fake_variables_for_cache(): | ||
| forms = fake_data.fake_forms_for_cache(num_forms=1) | ||
| variables = fake_data.fake_variables_for_cache(forms, vars_per_form=2, study_key="TEST-1") | ||
| assert len(variables) == 2 | ||
| for variable in variables: | ||
| assert isinstance(variable, Variable) | ||
| assert variable.study_key == "TEST-1" | ||
| assert variable.form_id == forms[0].form_id | ||
| assert variable.form_key == forms[0].form_key | ||
| assert variable.form_name == forms[0].form_name | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
test_fake_forms_for_cachetest substantially duplicatestest_fake_forms_for_cache_returns_formsintests/utils/test_fake_data.py, which checks identical properties (list length,isinstance(f, Form), andstudy_key). Having the same functional coverage spread across two separate test files increases maintenance overhead without providing additional confidence.Since the purpose of
test_json_roundtrip.pyis JSON roundtrip testing, these standalone fixture-validation tests may be better placed (or consolidated) intests/utils/test_fake_data.py, or the new test should exercise something that the existing test does not (e.g., a full roundtrip assertion similar totest_fake_forms_for_cache_from_json).