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

Refactored test for get policy service #2189

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ZeelSatasiya
Copy link
Collaborator

No description provided.

@ZeelSatasiya ZeelSatasiya marked this pull request as draft February 20, 2025 02:43
@ZeelSatasiya
Copy link
Collaborator Author

Refactored the test for get_policy_service with below test cases:

  1. test with an existing record
  2. test with empty database
  3. test with invalid policy ID (id type: String)
  4. test with invalid policy ID (negative policy ID)

Created policy_fixtures.py file in /tests/fixtures folder
Created test_policy_service.py file in /tests/unit/services folder

@ZeelSatasiya ZeelSatasiya changed the title added files for the refactored test get policy service Refactored test for get policy service Feb 20, 2025
Copy link
Collaborator

@anth-volk anth-volk 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 all of this @ZeelSatasiya. Just had a few nitpicks and a few questions. Also: I'd actually rename your testing file to "tests/unit/services/test_policy_service.py", like you had, as we want every test file to be "test_" + filename.



# Sample policy data
sample_policy_data = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Rename this to something like "valid_policy_data" (assuming it is)

"label": None,
"api_version": "1.180.1",
"policy_json": json.dumps(
{"gov.irs.income.bracket.rates.2": {"2024-01-01.2024-12-31": 0.2433}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Define this policy object separately

Doing so is a bit cleaner, and when we move toward a better schematization standard, it will be a bit easier to manage that way

"policy_json": json.dumps(
{"gov.irs.income.bracket.rates.2": {"2024-01-01.2024-12-31": 0.2433}}
),
"policy_hash": "NgJhpeuRVnIAwgYWuJsd2fI/N88rIE6Kcj8q4TPD/i4=",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"policy_hash": "NgJhpeuRVnIAwgYWuJsd2fI/N88rIE6Kcj8q4TPD/i4=",
"policy_hash": valid_hash_value,

nit: This helps keep the data you're testing cleaner

Comment on lines 29 to 33
@pytest.fixture
def mock_database():
"""Mock the database module."""
with patch("policyengine_api.services.policy_service.database") as mock_db:
yield mock_db
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
@pytest.fixture
def mock_database():
"""Mock the database module."""
with patch("policyengine_api.services.policy_service.database") as mock_db:
yield mock_db

blocking: Remove this and use the test_db fixture in its place



@pytest.fixture
def existing_policy_record(test_db):
Copy link
Collaborator

Choose a reason for hiding this comment

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

accolade: Nice setup of this fixture

valid_policy_json = json.loads(existing_policy_record["policy_json"])

# THEN the result should contain the expected policy data
assert result["policy_json"] == valid_policy_json
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: This is only testing the JSON of the policy, but nothing else; compare the entire return output (whether that be a formatted dict, just the JSON, just an ID) to the part you're fetching out of the table

Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 92.50000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 74.84%. Comparing base (b201ce4) to head (f9db934).
Report is 21 commits behind head on master.

Files with missing lines Patch % Lines
tests/fixtures/policy_fixtures.py 81.25% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2189      +/-   ##
==========================================
- Coverage   75.48%   74.84%   -0.65%     
==========================================
  Files          78       81       +3     
  Lines        2921     3045     +124     
  Branches      309      328      +19     
==========================================
+ Hits         2205     2279      +74     
- Misses        651      701      +50     
  Partials       65       65              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

2 participants