Skip to content

Commit

Permalink
issue #104 - fix BillingPeriod date calculation; WIP fixing acceptanc…
Browse files Browse the repository at this point in the history
…e tests for changes
  • Loading branch information
jantman committed Aug 19, 2017
1 parent 23d2162 commit ed0a04e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
22 changes: 15 additions & 7 deletions biweeklybudget/interest.py
Expand Up @@ -330,16 +330,24 @@ def __init__(self, end_date, start_date=None):
self._period_for_date = end_date
if start_date is None:
if end_date.day < 15:
self._start_date = end_date.replace(day=1)
# if end date is < 15, period is month before end_date
self._end_date = (end_date.replace(day=1) - timedelta(days=1))
self._start_date = self._end_date.replace(day=1)
else:
self._start_date = (end_date + relativedelta(
months=1
)).replace(day=1)
# if end date >= 15, period is month containing end_date
self._start_date = end_date.replace(day=1)
self._end_date = end_date.replace(
day=(monthrange(
end_date.year, end_date.month
)[1])
)
else:
self._start_date = start_date
self._end_date = self._start_date.replace(
day=(monthrange(self._start_date.year, self._start_date.month)[1])
)
self._end_date = self._start_date.replace(
day=(monthrange(
self._start_date.year, self._start_date.month
)[1])
)

@property
def start_date(self):
Expand Down
16 changes: 7 additions & 9 deletions biweeklybudget/tests/acceptance/test_interest.py
Expand Up @@ -41,7 +41,7 @@

from biweeklybudget.tests.acceptance_helpers import AcceptanceHelper
from biweeklybudget.interest import (
InterestHelper, CCStatement, BillingPeriodNumDays, AdbCompoundedDaily,
InterestHelper, CCStatement, _BillingPeriod, AdbCompoundedDaily,
MinPaymentAmEx, MinPaymentDiscover
)
from biweeklybudget.models import Account
Expand All @@ -66,10 +66,9 @@ def test_init_statements(self, testdb):
assert sorted(res.keys()) == [3, 4]
s3 = res[3]
assert isinstance(s3, CCStatement)
assert isinstance(s3._billing_period, BillingPeriodNumDays)
assert s3._billing_period.num_days == 30
assert s3._billing_period._end_date == date(2017, 7, 27)
assert s3._billing_period._start_date == date(2017, 6, 27)
assert isinstance(s3._billing_period, _BillingPeriod)
assert s3._billing_period._end_date == date(2017, 7, 31)
assert s3._billing_period._start_date == date(2017, 7, 1)
assert isinstance(s3._interest_cls, AdbCompoundedDaily)
assert s3._interest_cls.apr == Decimal('0.0100')
assert isinstance(s3._min_pay_cls, MinPaymentAmEx)
Expand All @@ -80,10 +79,9 @@ def test_init_statements(self, testdb):
assert s3._interest_amt == Decimal('16.25')
s4 = res[4]
assert isinstance(s4, CCStatement)
assert isinstance(s4._billing_period, BillingPeriodNumDays)
assert s4._billing_period.num_days == 30
assert s4._billing_period._end_date == date(2017, 7, 26)
assert s4._billing_period._start_date == date(2017, 6, 26)
assert isinstance(s4._billing_period, _BillingPeriod)
assert s4._billing_period._end_date == date(2017, 7, 31)
assert s4._billing_period._start_date == date(2017, 7, 1)
assert isinstance(s4._interest_cls, AdbCompoundedDaily)
assert s4._interest_cls.apr == Decimal('0.1000')
assert isinstance(s4._min_pay_cls, MinPaymentDiscover)
Expand Down
30 changes: 15 additions & 15 deletions biweeklybudget/tests/unit/test_interest.py
Expand Up @@ -425,11 +425,11 @@ class TestBillingPeriod(object):

def test_init(self):
cls = _BillingPeriod(date(2017, 1, 20))
assert cls._end_date == date(2017, 2, 28)
assert cls._start_date == date(2017, 2, 1)
cls = _BillingPeriod(date(2017, 1, 5))
assert cls._end_date == date(2017, 1, 31)
assert cls._start_date == date(2017, 1, 1)
cls = _BillingPeriod(date(2017, 1, 5))
assert cls._end_date == date(2016, 12, 31)
assert cls._start_date == date(2016, 12, 1)

def test_description(self):
cls = _BillingPeriod(date(2017, 1, 20))
Expand Down Expand Up @@ -1196,23 +1196,23 @@ def test_cc_one_pay_min(self):
MinPaymentMethod(),
[self.stmt_cc_one]
)
assert res == [(28, Decimal('962.9988625702411101133192793'))]
assert res == [(28, Decimal('963.0134129663259560304255428'))]

def test_cc_two_pay_min(self):
res = calculate_payoffs(
MinPaymentMethod(),
[self.stmt_cc_two]
)
assert res == [(162, Decimal('8664.861877369277471400473622'))]
assert res == [(162, Decimal('8666.307398441498144465534193'))]

def test_combined_pay_min(self):
res = calculate_payoffs(
MinPaymentMethod(),
[self.stmt_cc_one, self.stmt_cc_two]
)
assert res == [
(28, Decimal('962.9988625702411101133192793')),
(162, Decimal('8664.861877369277471400473622'))
(28, Decimal('963.0134129663259560304255428')),
(162, Decimal('8666.307398441498144465534193'))
]

def test_combined_pay_lowest_ir(self):
Expand All @@ -1221,8 +1221,8 @@ def test_combined_pay_lowest_ir(self):
[self.stmt_cc_one, self.stmt_cc_two]
)
assert res == [
(21, Decimal('960.9178327498502165965138131')),
(56, Decimal('6988.237124948955044765363412'))
(21, Decimal('960.9358774264952173529404070')),
(56, Decimal('6989.409862579702020000831215'))
]

def test_combined_pay_lowest_bal(self):
Expand All @@ -1231,8 +1231,8 @@ def test_combined_pay_lowest_bal(self):
[self.stmt_cc_one, self.stmt_cc_two]
)
assert res == [
(21, Decimal('960.9178327498502165965138131')),
(56, Decimal('6988.237124948955044765363412'))
(21, Decimal('960.9358774264952173529404070')),
(56, Decimal('6989.409862579702020000831215'))
]

def test_combined_pay_highest_ir(self):
Expand All @@ -1241,8 +1241,8 @@ def test_combined_pay_highest_ir(self):
[self.stmt_cc_one, self.stmt_cc_two]
)
assert res == [
(28, Decimal('962.9988625702411101133192793')),
(55, Decimal('6956.345228060182432444990377'))
(28, Decimal('963.0134129663259560304255428')),
(55, Decimal('6957.598431791986846666601930'))
]

def test_combined_pay_highest_bal(self):
Expand All @@ -1251,8 +1251,8 @@ def test_combined_pay_highest_bal(self):
[self.stmt_cc_one, self.stmt_cc_two]
)
assert res == [
(28, Decimal('962.9988625702411101133192793')),
(55, Decimal('6956.345228060182432444990377'))
(28, Decimal('963.0134129663259560304255428')),
(55, Decimal('6957.598431791986846666601930'))
]


Expand Down

0 comments on commit ed0a04e

Please sign in to comment.