Skip to content

Conversation

@ZeelSatasiya
Copy link
Collaborator

@ZeelSatasiya ZeelSatasiya commented Apr 3, 2025

Fixes: #2392

Refactored tests for set policy service.

  1. new policy
  2. existing policy
  3. database insert failure
  4. invalid country id
  5. empty label
    Modified fixtures file
    Modified set_policy() function to check get(country_id) returning null

@codecov
Copy link

codecov bot commented Apr 3, 2025

Codecov Report

Attention: Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 76.51%. Comparing base (c113e87) to head (f52d4f5).
Report is 99 commits behind head on master.

Files with missing lines Patch % Lines
policyengine_api/services/policy_service.py 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2339      +/-   ##
==========================================
- Coverage   77.16%   76.51%   -0.66%     
==========================================
  Files          88       91       +3     
  Lines        3377     3628     +251     
  Branches      366      407      +41     
==========================================
+ Hits         2606     2776     +170     
- Misses        703      782      +79     
- Partials       68       70       +2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ZeelSatasiya ZeelSatasiya requested a review from anth-volk April 4, 2025 18:21
@anth-volk
Copy link
Collaborator

To proceed, would you mind creating an issue to add tests to set_policy within the policy service, then add Fixes #NUMBER to the description here?

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 this work @ZeelSatasiya! I've requested a few changes, but hoping to move forward after those.

.DS_Store Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue, blocking: Please delete this artifact

Do you know where this comes from? Could be useful to add to .gitignore, but I'm unfamiliar with it myself

Copy link
Collaborator

Choose a reason for hiding this comment

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

issue, blocking: Same as above



@pytest.fixture
def mock_database():
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: You shouldn't need this

We already provide test_db as a fixture to all tests within the tests/unit folder, so you shouldn't need this separate mocking feature

test_policy = {"param": "value"}
test_label = "new_policy"
test_country_id = "US"
test_country_id = "us"
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: Why is this change necessary?

If it's to prevent some sort of test failure, then I wonder if there's a more fundamental bug of some sort?


current_api_version = COUNTRY_PACKAGE_VERSIONS.get(test_country_id)

# Setup mocks
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment: Were you to use the test_db fixture exposed here, you should be able to just fetch the created record back out here, rather than having to set up all these mocks

json.loads(existing_policy["policy_json"]),
)

# THEN the result should indicate the policy already exists
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment: Using the test_db fixture here, you should be able to:

  1. Create a fixture that just adds your expected record to the database before you start testing
  2. Attempt to add the record
  3. (Depending on function behavior) Either expect an error throw or check the output record to make sure that it employed some sort of behavior specific to this situation

@ZeelSatasiya ZeelSatasiya changed the title Refactored tests for set policy service Refactored tests for set policy service (Fixes: #2392) Apr 21, 2025
@anth-volk anth-volk self-requested a review May 6, 2025 23:35
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.

Pursuant to conversation with @ZeelSatasiya, I think my comments around using the test_db fixture do not make sense for this test file. LGTM!

@anth-volk anth-volk merged commit 58631cb into master May 6, 2025
6 of 7 checks passed
@anth-volk anth-volk deleted the test_set_policy_service branch May 6, 2025 23:37
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.

Added additional tests for set_policy for policy service

3 participants