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

140 validation metadata #165

Merged
merged 16 commits into from Apr 29, 2024
Merged

140 validation metadata #165

merged 16 commits into from Apr 29, 2024

Conversation

guffee23
Copy link
Contributor

Closes #140

Copy link

github-actions bot commented Apr 17, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/sbl_filing_api/entities/models
  dao.py
  dto.py
  src/sbl_filing_api/services
  submission_processor.py
Project Total  

This report was generated by python-coverage-comment-action

Comment on lines 119 to 121
val_res["logic_warnings"]["count"], val_res["logic_errors"]["count"] = len(
val_res["logic_warnings"]["details"]
), len(val_res["logic_errors"]["details"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

using tuple destructuring doesn't add much value here... you save 1 keystroke of not having to type out an additional =; but the formatting makes it a little more complicated to read.

Comment on lines 105 to 107
val_res["syntax_errors"] = {"count": 0, "details": []}
val_res["syntax_errors"]["details"] = val_json
val_res["syntax_errors"]["count"] = len(val_res["syntax_errors"]["details"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

these can just be assigned directly instead of having an inititializing step.

@lchen-2101
Copy link
Collaborator

let's also expand the test coverage on this PR, I don't think all the scenarios are covered in the existing tests; which is probably why the overall coverage decreased, and the PR coverage is only 26%; a few test scenarios would be to have the validation results return syntactical phase, logical phase; logical phase with both errors and warnings, logical with only errors, and logical with only warnings.

Comment on lines 49 to 143
@pytest.fixture(scope="function")
def df_to_json_mock(mocker: MockerFixture, validate_submission_mock: Mock):
mock_json_formatting = mocker.patch("sbl_filing_api.services.submission_processor.df_to_json")
mock_json_formatting.return_value = "[{}]"
def validation_success_mock(mocker: MockerFixture, validate_submission_mock: Mock):
mock_json_formatting = mocker.patch("sbl_filing_api.services.submission_processor.build_validation_results")
mock_json_formatting.return_value = """
{
"syntax_errors": {
"count": 0,
"details": []
},
"logic_errors": {
"count": 0,
"details": []
},
"logic_warnings": {
"count": 0,
"details": []
}
}"""
return mock_json_formatting


@pytest.fixture(scope="function")
def validation_syntax_errors_mock(mocker: MockerFixture, validate_submission_mock: Mock):
mock_json_formatting = mocker.patch("sbl_filing_api.services.submission_processor.build_validation_results")
mock_json_formatting.return_value = """
{
"syntax_errors": {
"count": 2,
"details": []
}
}"""
return mock_json_formatting


@pytest.fixture(scope="function")
def validation_logic_warnings_mock(mocker: MockerFixture, validate_submission_mock: Mock):
mock_json_formatting = mocker.patch("sbl_filing_api.services.submission_processor.build_validation_results")
mock_json_formatting.return_value = """
{
"syntax_errors": {
"count": 0,
"details": []
},
"logic_errors": {
"count": 0,
"details": []
},
"logic_warnings": {
"count": 1,
"details": []
}
}"""
return mock_json_formatting


@pytest.fixture(scope="function")
def validation_logic_errors_mock(mocker: MockerFixture, validate_submission_mock: Mock):
mock_json_formatting = mocker.patch("sbl_filing_api.services.submission_processor.build_validation_results")
mock_json_formatting.return_value = """
{
"syntax_errors": {
"count": 0,
"details": []
},
"logic_errors": {
"count": 4,
"details": []
},
"logic_warnings": {
"count": 0,
"details": []
}
}"""
return mock_json_formatting


@pytest.fixture(scope="function")
def validation_logic_warnings_and_errors_mock(mocker: MockerFixture, validate_submission_mock: Mock):
mock_json_formatting = mocker.patch("sbl_filing_api.services.submission_processor.build_validation_results")
mock_json_formatting.return_value = """
{
"syntax_errors": {
"count": 0,
"details": []
},
"logic_errors": {
"count": 3,
"details": []
},
"logic_warnings": {
"count": 2,
"details": []
}
}"""
return mock_json_formatting
Copy link
Collaborator

Choose a reason for hiding this comment

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

mocking out the return value for the method you are trying to test isn't productive; you are basically bypassing testing method, which is why the test coverage remains unchanged; if you click on the link with the lines in the test coverage comment, it shows the whole method is uncovered.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ideally, you would be constructing the dataframe to pass to the method for testing, but if that's too much of a lift, something you can mock for example could be df_to_json()

val_res["logic_warnings"]["count"] = len(val_res["logic_warnings"]["details"])
val_res["logic_errors"]["count"] = len(val_res["logic_errors"]["details"])

return val_res
Copy link
Contributor

Choose a reason for hiding this comment

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

This else block can be even further refined to:

        errors_list = [e for e in val_json if e["validation"]["severity"] == Severity.ERROR.value]
        warnings_list = [e for e in val_json if e["validation"]["severity"] == Severity.WARNING.value]
        val_res = {
            "syntax_errors": {"count": 0, "details": []},
            "logic_errors": {"count": len(errors_list), "details": errors_list},
            "logic_warnings": {"count": len(warnings_list), "details": warnings_list},
        }

to avoid looping and appending. List comprehension in python is faster on large data sets.

if result[2] == ValidationPhase.SYNTACTICAL.value:
val_res = {"syntax_errors": {"count": 0, "details": []}}
val_res["syntax_errors"]["details"] = val_json
val_res["syntax_errors"]["count"] = len(val_res["syntax_errors"]["details"])
Copy link
Contributor

@jcadam14 jcadam14 Apr 29, 2024

Choose a reason for hiding this comment

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

Just like below, this section can be shortened to just:
val_res = {"syntax_errors": {"count": len(val_json), "details": val_json}}

@jcadam14 jcadam14 merged commit 8f884ff into main Apr 29, 2024
3 checks passed
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.

Add validation error and warning counts and other useful submission metadata
3 participants