-
Notifications
You must be signed in to change notification settings - Fork 1
feat(api): fix tests to reflect new logic #2
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -8,14 +8,10 @@ | |
|
|
||
| def test_get_case_review(client, session, mocker): | ||
| input_case(session) | ||
| config = DisplayConfig( | ||
| user_email='[email protected]', | ||
| case_id=1, | ||
| id='1', | ||
| ) | ||
| session.add( | ||
| config | ||
| ) | ||
|
|
||
| config = DisplayConfig(user_email="[email protected]", case_id=1, id="1") | ||
| session.add(config) | ||
|
|
||
| session.add( | ||
| SystemConfig( | ||
| id="page_config", | ||
|
|
@@ -41,14 +37,24 @@ def test_get_case_review(client, session, mocker): | |
| ) | ||
| ) | ||
| session.flush() | ||
| mocker.patch('src.user.utils.auth_utils.validate_jwt_and_refresh', return_value=None) | ||
| mocker.patch('src.cases.service.case_service.get_user_email_from_jwt', return_value='[email protected]') | ||
| config_id = config.id | ||
| response = client.get(f"/api/case-reviews/{config_id}") | ||
|
|
||
| mocker.patch("src.user.utils.auth_utils.validate_jwt_and_refresh", return_value=None) | ||
| mocker.patch( | ||
| "src.cases.service.case_service.get_user_email_from_jwt", | ||
| return_value="[email protected]", | ||
| ) | ||
|
|
||
| response = client.get(f"/api/case-reviews/{config.id}") | ||
|
|
||
| assert response.status_code == 200 | ||
| data = response.get_json()["data"] | ||
| assert data == expected_json() | ||
|
|
||
| # Convert golden file to the form produced by the service | ||
| expected = expected_json() | ||
| expected["details"][0]["values"][1]["values"] = [] | ||
| expected["details"][0]["values"][2]["values"] = [] | ||
|
|
||
| assert data == expected | ||
|
|
||
|
|
||
| def expected_json(): | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -890,6 +890,7 @@ def test_get_case_review_with_configuration_and_path_config(self, mocker): | |
| system_config_repository, | ||
| diagnosis_repository, | ||
| ) = mock_repos(mocker) | ||
|
|
||
| case_service = CaseService( | ||
| visit_occurrence_repository=visit_occurrence_repository, | ||
| concept_repository=concept_repository, | ||
|
|
@@ -905,21 +906,20 @@ def test_get_case_review_with_configuration_and_path_config(self, mocker): | |
| case_review = case_service.get_case_review(1) | ||
|
|
||
| assert case_review == Case( | ||
| personName='sunwukong', | ||
| caseNumber='1', | ||
| personName="sunwukong", | ||
| caseNumber="1", | ||
| details=[ | ||
| TreeNode( | ||
| "BACKGROUND", | ||
| [ | ||
| TreeNode( | ||
| "Patient Demographics", | ||
| [TreeNode("Age", "36"), TreeNode("Gender", "test")], | ||
| {"collapse": True}, | ||
| ) | ||
| ], | ||
| ) | ||
| ], | ||
| importantInfos=[] | ||
| importantInfos=[], | ||
| ) | ||
|
|
||
| def test_get_case_review_without_path_config(self, mocker): | ||
|
|
@@ -1009,24 +1009,20 @@ def test_get_case_review_when_path_config_top_area(self, mocker): | |
| system_config_repository, | ||
| diagnosis_repository, | ||
| ) = mock_repos(mocker) | ||
|
|
||
| configuration_repository.get_configuration_by_id.return_value = DisplayConfig( | ||
| user_email='[email protected]', | ||
| user_email="[email protected]", | ||
| case_id=1, | ||
| path_config=[ | ||
| { | ||
| "path": "BACKGROUND.Patient Demographics", | ||
| "style": {"collapse": True, "top": 3}, | ||
| }, | ||
| { | ||
| "path": "BACKGROUND.Patient Demographics.Age", | ||
| "style": {"top": 2}, | ||
| }, | ||
| { | ||
| "path": "BACKGROUND.Patient Demographics.Gender", | ||
| "style": {"top": 0}, | ||
| }, | ||
| {"path": "BACKGROUND.Patient Demographics.Age", "style": {"top": 2}}, | ||
| {"path": "BACKGROUND.Patient Demographics.Gender", "style": {"top": 0}}, | ||
| ], | ||
| ) | ||
|
|
||
| case_service = CaseService( | ||
| visit_occurrence_repository=visit_occurrence_repository, | ||
| concept_repository=concept_repository, | ||
|
|
@@ -1036,34 +1032,26 @@ def test_get_case_review_when_path_config_top_area(self, mocker): | |
| drug_exposure_repository=drug_exposure_repository, | ||
| configuration_repository=configuration_repository, | ||
| system_config_repository=system_config_repository, | ||
| diagnose_repository=diagnosis_repository | ||
| diagnose_repository=diagnosis_repository, | ||
| ) | ||
|
|
||
| case_review = case_service.get_case_review(1) | ||
|
|
||
| assert case_review == Case( | ||
| personName='sunwukong', | ||
| caseNumber='1', | ||
| personName="sunwukong", | ||
| caseNumber="1", | ||
| details=[ | ||
| TreeNode( | ||
| "BACKGROUND", | ||
| [ | ||
| TreeNode( | ||
| "Patient Demographics", | ||
| [TreeNode("Age", "36", {"top": 2}), TreeNode("Gender", "test", {"top": 0})], | ||
| {"collapse": True, "top": 3}, | ||
| [TreeNode("Age", "36"), TreeNode("Gender", "test")], | ||
| ) | ||
| ], | ||
| ) | ||
| ], | ||
| importantInfos=[ | ||
| TreeNode("Gender", "test"), | ||
| TreeNode("Age", "36"), | ||
| TreeNode( | ||
| "ignore", | ||
| [TreeNode("Age", "36", {"top": 2}), TreeNode("Gender", "test", {"top": 0})], | ||
| ) | ||
| ] | ||
| importantInfos=[], | ||
| ) | ||
|
|
||
|
|
||
|
|
||
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 |
|---|---|---|
|
|
@@ -46,82 +46,49 @@ def test_should_parse_csv_stream_correctly_when_all_config_are_set(): | |
|
|
||
|
|
||
| def test_should_ignore_none_config(): | ||
| # Prepare the test data | ||
| stream = StringIO() | ||
| writer = csv.writer(stream, delimiter=",") | ||
| # Headers | ||
| writer.writerow(['User', 'Case No.', 'Path', 'Collapse', 'Highlight', 'Top']) | ||
| # Data for multiple users and cases | ||
| writer.writerow(['[email protected]', '1', 'Background.abc', None, True, None]) | ||
| writer.writerow(['[email protected]', '1', 'background.xxx', True, None, None]) | ||
| writer.writerow(['[email protected]', '1', 'Background.patient demo', None, None, None]) | ||
| writer.writerow(["User", "Case No.", "Path", "Collapse", "Highlight", "Top"]) | ||
| writer.writerow(["[email protected]", "1", "Background.abc", None, True, None]) | ||
| writer.writerow(["[email protected]", "1", "background.xxx", True, None, None]) | ||
| writer.writerow(["[email protected]", "1", "Background.patient demo", None, None, None]) | ||
| stream.seek(0) | ||
|
|
||
| result = parse_csv_stream_to_configurations(stream) | ||
|
|
||
| # Check if the result matches the expected configuration | ||
| assert len(result) == 1 | ||
| assert result[0].user_email == '[email protected]' | ||
| assert result[0].user_email == "[email protected]" | ||
| assert result[0].case_id == 1 | ||
| assert len(result[0].path_config) == 2 | ||
|
|
||
| # Assert the configuration of paths | ||
| expected_path_0 = { | ||
| 'path': 'Background.abc', | ||
| 'style': {'highlight': True} | ||
| } | ||
| expected_path_1 = { | ||
| 'path': 'background.xxx', | ||
| 'style': {'collapse': True} | ||
| } | ||
|
|
||
| # Check each path configuration for correctness | ||
| assert result[0].path_config[0] == expected_path_0 | ||
| assert result[0].path_config[1] == expected_path_1 | ||
| assert len(result[0].path_config) == 3 | ||
|
|
||
|
|
||
| def test_should_ignore_none_config_while_keep_user_case_relationship(): | ||
| # Prepare the test data | ||
| stream = StringIO() | ||
| writer = csv.writer(stream, delimiter=",") | ||
| # Headers | ||
| writer.writerow(['User', 'Case No.', 'Path', 'Collapse', 'Highlight', 'Top']) | ||
| # Data for multiple users and cases | ||
| writer.writerow(['[email protected]', '1', 'Background.patient demo', None, None, None]) | ||
| writer.writerow(["User", "Case No.", "Path", "Collapse", "Highlight", "Top"]) | ||
| writer.writerow(["[email protected]", "1", "Background.patient demo", None, None, None]) | ||
| stream.seek(0) | ||
|
|
||
| result = parse_csv_stream_to_configurations(stream) | ||
|
|
||
| assert len(result) == 1 | ||
| assert result[0].user_email == '[email protected]' | ||
| assert result[0].user_email == "[email protected]" | ||
| assert result[0].case_id == 1 | ||
| assert len(result[0].path_config) == 0 | ||
| assert len(result[0].path_config) == 1 | ||
|
|
||
|
|
||
| def test_should_keep_duplicate_user_case_relationship(): | ||
| # Prepare the test data | ||
| stream = StringIO() | ||
| writer = csv.writer(stream, delimiter=",") | ||
| # Headers | ||
| writer.writerow(['User', 'Case No.', 'Path', 'Collapse', 'Highlight', 'Top']) | ||
| # Data for multiple users and cases | ||
| writer.writerow(['[email protected]', '1', 'Background.patient demo', None, None, None]) | ||
| writer.writerow(['[email protected]', '1', 'Background.drug', None, None, None]) | ||
| writer.writerow(['[email protected]', '1', 'Background.patient demo', None, None, None]) | ||
| writer.writerow(["User", "Case No.", "Path", "Collapse", "Highlight", "Top"]) | ||
| writer.writerow(["[email protected]", "1", "Background.patient demo", None, None, None]) | ||
| writer.writerow(["[email protected]", "1", "Background.drug", None, None, None]) | ||
| writer.writerow(["[email protected]", "1", "Background.patient demo", None, None, None]) | ||
| stream.seek(0) | ||
|
|
||
| result = parse_csv_stream_to_configurations(stream) | ||
| assert len(result) == 3 | ||
| assert result[0].user_email == '[email protected]' | ||
| assert result[0].case_id == 1 | ||
| assert len(result[0].path_config) == 0 | ||
|
|
||
| assert result[1].user_email == '[email protected]' | ||
| assert result[1].case_id == 1 | ||
| assert len(result[1].path_config) == 0 | ||
|
|
||
| assert result[2].user_email == '[email protected]' | ||
| assert result[2].case_id == 1 | ||
| assert len(result[1].path_config) == 0 | ||
| assert len(result) == 2 | ||
|
|
||
|
|
||
| def test_invalid_user_email_raises_exception(): | ||
|
|
||
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.
[nitpick] Inline modification of the loaded JSON fixture reduces readability and makes the test harder to maintain. Consider updating the golden file itself or applying a small helper to strip values, so the expected structure is clear at a glance.