def setUp(self): self.ts = TransactionStore() origsd1 = date.today() origsd2 = date.today()+timedelta(days=2) self.t1 = Transaction( start=origsd1, description="Once, today", amount=1.00, frequency=Transaction.ONCE) self.t2 = Transaction( start=origsd2, description="Once, in two days", amount=1.01, frequency=Transaction.ONCE) self.t3 = Transaction( start=origsd1, description="Weekly", amount=1.02, frequency=Transaction.WEEKLY, skip=set([date.today()+timedelta(days=7)]), scheduled=True, cleared=True) self.t4 = Transaction( start=origsd2, description="Monthly", amount=1.03, frequency=Transaction.MONTHLY) self.ts.addTransactions(self.t1, self.t2, self.t3, self.t4)
def setUp(self): self.sd = date.today() self.t1 = Transaction(start=self.sd, description="Once, today", amount=1.00, frequency=Transaction.ONCE) self.t2 = Transaction(start=self.sd, description="Weekly", amount=1.02, frequency=Transaction.WEEKLY)
def setUp(self): sd = date.today() self.t1 = Transaction(start=sd, original_start=sd - timedelta(days=1), end=sd + timedelta(days=56), description="Weekly", amount=1.02, frequency=Transaction.WEEKLY, skip=set([sd + timedelta(days=7)]), scheduled=True, cleared=True)
def setUp(self): self.sd = date.today() self.sdp1 = self.sd + timedelta(days=1) self.sdp2 = self.sd + timedelta(days=2) self.sdp3 = self.sd + timedelta(days=3) self.t1 = Transaction(start=self.sd, description="Once, today", amount=1.00, frequency=Transaction.ONCE) self.t2 = Transaction(start=self.sdp2, description="Once, in two days", amount=1.01, frequency=Transaction.ONCE)
def test_add_multiple_transactions(self): d = date.today() ts = TransactionStore() t1 = Transaction( start=d, description="Once, today", amount=1.00, frequency=Transaction.ONCE) t2 = Transaction( start=d+timedelta(days=2), description="Once, in two days", amount=1.01, frequency=Transaction.ONCE) t3 = Transaction( start=d, end=d+timedelta(days=56), description="Weekly", amount=1.02, frequency=Transaction.WEEKLY, skip=set([d+timedelta(days=7)]), scheduled=True, cleared=True) self.assertEqual(len(ts.store), 0) ts.addTransactions(t1, t2, t3) t = next((t for t in ts.store if t.amount == 1.00), None) self.assertIsNotNone(t) self.assertEqual(t.start, d) self.assertEqual(t.description, "Once, today") self.assertEqual(t.amount, 1.00) self.assertEqual(t.frequency, Transaction.ONCE) t = next((t for t in ts.store if t.amount == 1.01), None) self.assertIsNotNone(t) self.assertEqual(t.start, d+timedelta(days=2)) self.assertEqual(t.description, "Once, in two days") self.assertEqual(t.amount, 1.01) self.assertEqual(t.frequency, Transaction.ONCE) t = next((t for t in ts.store if t.amount == 1.02), None) self.assertIsNotNone(t) self.assertEqual(t.start, d) self.assertEqual(t.description, "Weekly") self.assertEqual(t.amount, 1.02) self.assertEqual(t.frequency, Transaction.WEEKLY)
def setUp(self): self.ts = TransactionStore() t1 = Transaction( start=date.today(), description="Once, today", amount=1.00, frequency=Transaction.ONCE) t2 = Transaction( start=date.today()+timedelta(days=2), description="Once, in two days", amount=1.01, frequency=Transaction.ONCE) self.ts.addTransactions(t1, t2)
def test_remove_non_existent_single_transaction(self): t_missing = Transaction( start=date.today(), description="Missing", amount=1.00, frequency=Transaction.ONCE) self.assertEqual(len(self.ts.store), 3) self.ts.removeTransactions(t_missing) self.assertEqual(len(self.ts.store), 3)
def setUp(self): self.ts = TransactionStore() sd = date.today() skipd = date.today() + timedelta(days=14) t1 = Transaction( start=sd, description="Weekly", amount=1.00, frequency=Transaction.WEEKLY, skip=set([skipd])) t2 = Transaction( start=sd+timedelta(days=2), description="Monthly", amount=1.01, frequency=Transaction.MONTHLY) self.ts.addTransactions(t1, t2)
def setUp(self): self.ts = TransactionStore() t1 = Transaction( start=date.today(), description="Once", amount=1.00, frequency=Transaction.ONCE) self.ts.addTransactions(t1)
def setUp(self): self.t = Transaction(start=date.today(), description="Biweekly", amount=1.03, frequency=Transaction.BIWEEKLY) self.sd = self.t.start self.nbw = self.sd + timedelta(days=14) self.nbw_days = (self.nbw - self.sd).days self.nbwp1_days = self.nbw_days + 1 self.bwan = self.sd + timedelta(days=28) self.bwan_days = (self.bwan - self.sd).days
def setUp(self): self.t = Transaction(start=date.today(), description="Quarterly", amount=1.05, frequency=Transaction.QUARTERLY) self.sd = self.t.start self.nq = self.sd + relativedelta(months=3) self.nq_days = (self.nq - self.sd).days self.nqp1_days = self.nq_days + 1 self.qan = self.sd + relativedelta(months=6) self.qan_days = (self.qan - self.sd).days
def setUp(self): self.t = Transaction(start=date.today(), description="Weekly", amount=1.02, frequency=Transaction.WEEKLY) self.sd = self.t.start self.nw = self.sd + timedelta(days=7) self.nw_days = (self.nw - self.sd).days self.nwp1_days = self.nw_days + 1 self.wan = self.sd + timedelta(days=14) self.wan_days = (self.wan - self.sd).days
def setUp(self): self.t = Transaction(start=date.today(), description="Monthly", amount=1.04, frequency=Transaction.MONTHLY) self.sd = self.t.start self.nm = self.sd + relativedelta(months=1) self.nm_days = (self.nm - self.sd).days self.nmp1_days = self.nm_days + 1 self.man = self.sd + relativedelta(months=2) self.man_days = (self.man - self.sd).days
def setUp(self): self.t = Transaction(start=date.today(), description="Annually", amount=1.06, frequency=Transaction.ANNUALLY) self.sd = self.t.start self.ny = self.sd + relativedelta(years=1) self.ny_days = (self.ny - self.sd).days self.nyp1_days = self.ny_days + 1 self.yan = self.sd + relativedelta(years=2) self.yan_days = (self.yan - self.sd).days
def setUp(self): self.file = f'./test-{time.time()}' t1 = Transaction( start=date.today(), description="Once, today", amount=1.00, frequency=Transaction.ONCE) t2 = Transaction( start=date.today(), original_start=date.today()-timedelta(days=1), end=date.today()+timedelta(days=56), description="Weekly", amount=1.02, frequency=Transaction.WEEKLY, skip=set([date.today()+timedelta(days=7)]), scheduled=True, cleared=True) self.ts = TransactionStore() self.ts.store.append(t1) self.ts.store.append(t2)
def setUp(self): self.ts = TransactionStore() t1 = Transaction( start=date.today(), description="Once", amount=1.00, frequency=Transaction.ONCE) t2 = Transaction( start=date.today()+timedelta(days=2), description="Once, in two days", amount=1.01, frequency=Transaction.ONCE) t3 = Transaction( start=date.today(), end=date.today()+timedelta(days=56), description="Weekly", amount=1.02, frequency=Transaction.WEEKLY, skip=set([date.today()+timedelta(days=7)]), scheduled=True, cleared=True) self.ts.addTransactions(t1, t2, t3)
class TestStartDateChange(unittest.TestCase): def setUp(self): self.sd = date.today() self.t1 = Transaction(start=self.sd, description="Once, today", amount=1.00, frequency=Transaction.ONCE) self.t2 = Transaction(start=self.sd, description="Weekly", amount=1.02, frequency=Transaction.WEEKLY) def test_start_date_change_non_recurring(self): new_base = self.sd + timedelta(days=16) self.assertEqual(self.t1.frequency, Transaction.ONCE) self.assertEqual(self.t1.start, self.sd) self.assertEqual(self.t1.original_start, self.sd) self.t1.updateStartDate(new_base) self.assertEqual(self.t1.start, new_base) self.assertEqual(self.t1.original_start, self.sd) def test_start_date_change_recurring(self): new_base = self.sd + timedelta(days=16) new_start = self.sd + timedelta(days=21) self.assertEqual(self.t2.frequency, Transaction.WEEKLY) self.assertEqual(self.t2.start, self.sd) self.assertEqual(self.t2.original_start, self.sd) self.t2.updateStartDate(new_base) self.assertEqual(self.t2.start, new_start) self.assertEqual(self.t2.original_start, self.sd)
class TestOneTimeTransactionHits(unittest.TestCase): def setUp(self): self.sd = date.today() self.sdp1 = self.sd + timedelta(days=1) self.sdp2 = self.sd + timedelta(days=2) self.sdp3 = self.sd + timedelta(days=3) self.t1 = Transaction(start=self.sd, description="Once, today", amount=1.00, frequency=Transaction.ONCE) self.t2 = Transaction(start=self.sdp2, description="Once, in two days", amount=1.01, frequency=Transaction.ONCE) def test_start_date_hits(self): self.assertEqual(self.t1.amtOn(self.sd), self.t1.amount) self.assertEqual(self.t1.amtOn(self.sdp1), Money(0)) def test_date_after_start_date_hits(self): self.assertEqual(self.t2.amtOn(self.sd), Money(0)) self.assertEqual(self.t2.amtOn(self.sdp1), Money(0)) self.assertEqual(self.t2.amtOn(self.sdp2), self.t2.amount) self.assertEqual(self.t2.amtOn(self.sdp3), Money(0))
def test_add_single_transaction(self): d = date.today() ts = TransactionStore() self.assertEqual(len(ts.store), 0) t = Transaction( start=d, description="Once, today", amount=1.00, frequency=Transaction.ONCE) ts.addTransactions(t) self.assertEqual(len(ts.store), 1) t = next((t for t in ts.store if t.amount == 1.00), None) self.assertIsNotNone(t) self.assertEqual(t.start, d) self.assertEqual(t.description, "Once, today") self.assertEqual(t.amount, 1.00) self.assertEqual(t.frequency, Transaction.ONCE)
def test_constructor_empty(self): t = Transaction() self.assertIsInstance(t, Transaction) self.assertIsInstance(t.start, date) self.assertEqual(t.start, date.today()) self.assertIsInstance(t.original_start, date) self.assertEqual(t.original_start, t.start) self.assertIsNone(t.end, f"end not None: {t.end}") self.assertIsInstance(t.description, str) self.assertEqual(t.description, "<Description>") self.assertIsInstance(t.amount, Money) self.assertEqual(Decimal(repr(t.amount)), Decimal(0.0)) self.assertIsInstance(t.frequency, str) self.assertEqual(t.frequency, Transaction.ONCE) self.assertIsInstance(t.skip, set) self.assertEqual(len(t.skip), 0, f"non-empty skip : {t.skip}") self.assertIsInstance(t.scheduled, bool) self.assertFalse(t.scheduled) self.assertIsInstance(t.cleared, bool) self.assertFalse(t.cleared)
def test_remove_multiple_transactions_with_some_missing(self): t_missing = Transaction( start=date.today(), description="Missing", amount=1.00, frequency=Transaction.ONCE) self.assertEqual(len(self.ts.store), 3) t_list = self.ts.getTransaction("Once") self.assertEqual(len(t_list), 1) t1 = t_list[0] t_list = self.ts.getTransaction("Weekly") self.assertEqual(len(t_list), 1) t2 = t_list[0] self.ts.removeTransactions(t1, t2, t_missing) self.assertEqual(len(self.ts.store), 1) t_list = self.ts.getTransaction("Once") self.assertEqual(len(t_list), 0) t_list = self.ts.getTransaction("Weekly") self.assertEqual(len(t_list), 0)
class TestUpdateAmount(unittest.TestCase): def setUp(self): self.t = Transaction(start=date.today, description="Test", amount=1.02) def test_update_with_money(self): self.t.updateAmount(Money(3.50)) self.assertEqual(Decimal(repr(self.t.amount)), Decimal(3.50)) def test_update_with_float(self): self.t.updateAmount(3.50) self.assertEqual(Decimal(repr(self.t.amount)), Decimal(3.50)) def test_update_with_string(self): self.t.updateAmount('3.50') self.assertEqual(Decimal(repr(self.t.amount)), Decimal(3.50))
def test_generate_from_nonrecurring_today(self): st = Transaction( start=date.today(), description="Once, today", amount=1.00, frequency=Transaction.ONCE) self.cf.transaction_store.addTransactions(st) day = self.cf.getTodaysTransactions() (d, bal, t_list) = next(day) self.assertEqual(d, self.cf.start_date) self.assertEqual(d, self.cf.current_date) self.assertEqual(bal, self.cf.current_balance) self.assertEqual(len(t_list), 1) t = t_list[0] self.assertTransactionsEqual(t, st) self.assertEqual(bal, self.cf.start_balance + st.amount) for i in range(1, 100): (d, bal, t_list) = next(day) self.assertEqual(d, self.cf.current_date) self.assertEqual(d, self.cf.start_date + timedelta(days=i)) self.assertEqual(bal, self.cf.current_balance) self.assertEqual(len(t_list), 0) self.assertEqual(bal, self.cf.start_balance + st.amount)
def test_constructor_full(self): start = date.today() original_start = date.today() - timedelta(days=7) skip = start + timedelta(days=14) end = start + relativedelta(months=1) descr = "Test transaction" amt = 1.00 freq = Transaction.WEEKLY t = Transaction(start=start, original_start=original_start, end=end, description=descr, amount=amt, frequency=freq, skip=set([skip]), scheduled=True, cleared=True) self.assertIsInstance(t, Transaction) self.assertIsInstance(t.start, date) self.assertEqual(t.start, start) self.assertIsInstance(t.original_start, date) self.assertEqual(t.original_start, original_start) self.assertIsInstance(t.end, date) self.assertEqual(t.end, end) self.assertIsInstance(t.description, str) self.assertEqual(t.description, descr) self.assertIsInstance(t.amount, Money) self.assertEqual(Decimal(repr(t.amount)), Decimal(amt)) self.assertIsInstance(t.frequency, str) self.assertEqual(t.frequency, freq) self.assertIsInstance(t.skip, set) self.assertEqual(len(t.skip), 1) self.assertIn(skip, t.skip) self.assertIsInstance(t.scheduled, bool) self.assertTrue(t.scheduled) self.assertIsInstance(t.cleared, bool) self.assertTrue(t.cleared)
class TestDuplicateTransaction(unittest.TestCase): def setUp(self): sd = date.today() self.t1 = Transaction(start=sd, original_start=sd - timedelta(days=1), end=sd + timedelta(days=56), description="Weekly", amount=1.02, frequency=Transaction.WEEKLY, skip=set([sd + timedelta(days=7)]), scheduled=True, cleared=True) def test_duplicate_transaction(self): t2 = self.t1.duplicate() self.assertEqual(self.t1.start, t2.start) self.assertEqual(self.t1.original_start, t2.original_start) self.assertEqual(self.t1.end, t2.end) self.assertEqual(self.t1.description, t2.description) self.assertEqual(repr(self.t1.amount), repr(t2.amount)) self.assertEqual(self.t1.frequency, t2.frequency) self.assertEqual(self.t1.skip.symmetric_difference(t2.skip), set()) self.assertEqual(self.t1.scheduled, t2.scheduled) self.assertEqual(self.t1.cleared, t2.cleared)
def setUp(self): sd = date.today() sd2 = date.today()+timedelta(days=2) self.o1 = Transaction( start=sd, description="Once 1", amount=1.00, frequency=Transaction.ONCE) self.o2 = Transaction( start=sd2, description="Once 2", amount=1.01, frequency=Transaction.ONCE) self.w1 = Transaction( start=sd, description="Weekly 1", amount=1.03, frequency=Transaction.WEEKLY) self.w2 = Transaction( start=sd2, description="Weekly 2", amount=1.04, frequency=Transaction.WEEKLY) self.bw1 = Transaction( start=sd, description="BiWeekly 1", amount=1.05, frequency=Transaction.BIWEEKLY) self.bw2 = Transaction( start=sd2, description="BiWeekly 2", amount=1.06, frequency=Transaction.BIWEEKLY) self.m1 = Transaction( start=sd, description="Monthly 1", amount=1.07, frequency=Transaction.MONTHLY) self.m2 = Transaction( start=sd2, description="Monthly 2", amount=1.08, frequency=Transaction.MONTHLY) self.q1 = Transaction( start=sd, description="Quarterly 1", amount=1.09, frequency=Transaction.QUARTERLY) self.q2 = Transaction( start=sd2, description="Quarterly 2", amount=1.10, frequency=Transaction.QUARTERLY) self.a1 = Transaction( start=sd, description="Annually 1", amount=1.11, frequency=Transaction.ANNUALLY) self.a2 = Transaction( start=sd2, description="Annually 2", amount=1.12, frequency=Transaction.ANNUALLY) self.ts = TransactionStore() self.ts.addTransactions(self.o1, self.o2, self.w1, self.w2, self.bw1, self.bw2, self.m1, self.m2, self.q1, self.q2, self.a1, self.a2) random.shuffle(self.ts.store)
def newTransaction(self, event): t = Transaction() self.editTransaction(event, t)
def setUp(self): self.t = Transaction(start=date.today, description="Test", amount=1.02)