Created
July 29, 2025 10:00
-
-
Save andlaf-ak/6e8d350d7084de68c4a81ea1c5766bbe to your computer and use it in GitHub Desktop.
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
from datetime import date, timedelta | |
def today(): | |
return date.today() | |
def given_policy(started_days_ago=0, premium=1000, grace_period_days=14): | |
start_date = today() - timedelta(days=started_days_ago) | |
return InsurancePolicy(start_date=start_date, premium=premium, grace_period_days=grace_period_days) | |
def when_policy_is_cancelled(policy, cancelled_days_after_start): | |
cancel_date = policy.start_date + timedelta(days=cancelled_days_after_start) | |
policy.cancel(on=cancel_date) | |
return policy | |
def when_claim_is_made(policy, amount=100): | |
policy.submit_claim(amount=amount) | |
return policy | |
def then_refund_should_be(policy, expected_amount): | |
assert policy.refund_amount() == expected_amount | |
def test_full_refund_when_cancelled_during_grace_period_and_no_claims(): | |
policy = given_policy(started_days_ago=0, premium=500) | |
policy = when_policy_is_cancelled(policy, cancelled_days_after_start=10) | |
then_refund_should_be(policy, expected_amount=500) | |
def test_partial_refund_when_cancelled_after_grace_period_and_no_claims(): | |
policy = given_policy(started_days_ago=0, premium=1200) | |
policy = when_policy_is_cancelled(policy, cancelled_days_after_start=30) | |
expected = policy.calculate_unused_premium(up_to=policy.cancelled_on) | |
then_refund_should_be(policy, expected_amount=expected) | |
def test_no_refund_when_cancelled_after_claims_made(): | |
policy = given_policy(started_days_ago=0, premium=500) | |
policy = when_claim_is_made(policy) | |
policy = when_policy_is_cancelled(policy, cancelled_days_after_start=5) | |
then_refund_should_be(policy, expected_amount=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
here, an interesting article (2019) but still interesting to read:
https://medium.com/javascript-scene/behavior-driven-development-bdd-and-functional-testing-62084ad7f1f2