def setUp(self): """ Add some transactions to a VirtualAcct. """ user = User(username = '******', email = '*****@*****.**') user.save() profile = UserProfile(user = user) profile.save() budget = Budget(owner = profile, period_budget_amount = '100.00') year = Year() year.save() budget.period_length = year budget.save() category = Category(owner = profile, name = 'test', budget = budget) category.save() self.acct = RealAcct(owner = profile) self.acct.save() self.vacct = VirtualAcct(owner = profile, real_acct = self.acct, parent_budget = budget) self.vacct.save() self.txn_1 = RealTxn(value = '110.00', category = category, real_acct = self.acct) self.txn_1.save() self.vtxn_1 = VirtualTxn(value = '90.00', real_txn = self.txn_1, virtual_acct = self.vacct) self.vtxn_1.save() self.vtxn_2 = VirtualTxn(value = '20.00', real_txn = self.txn_1, virtual_acct = self.vacct) self.vtxn_2.save()
def test_periodlength_inheritance(self): """ See if having PeriodLength as not abstract will call PeriodLength methods or subclass methods """ user = User(username = '******', email = '*****@*****.**') user.save() profile = UserProfile(user = user) profile.save() budget = Budget(owner = profile, period_budget_amount = '100.00') year = Year() year.save() budget.period_length = year budget.save() length = budget.period_length assert(length.__unicode__() == 'Year PeriodLength')
def setUp(self): self.period_length = PeriodLength() self.month = Month() self.year = Year() now = datetime.now() self.now = now self.month_beginning = datetime(now.year, now.month, 1) self.month_end = datetime(now.year, now.month, monthrange(now.year, now.month)[1]) self.next_month = datetime(now.year, now.month + 1, 1) self.previous_month = datetime(now.year, now.month - 1, 1) self.year_beginning = datetime(now.year, 1, 1) self.year_end = datetime(now.year, 12, 31) self.next_year = datetime(now.year + 1, now.month, 1) self.previous_year = datetime(now.year - 1, now.month, 1)
class PeriodLengthTests(TestCase): """ Test for all PeriodLength subclasses. """ def setUp(self): self.period_length = PeriodLength() self.month = Month() self.year = Year() now = datetime.now() self.now = now self.month_beginning = datetime(now.year, now.month, 1) self.month_end = datetime(now.year, now.month, monthrange(now.year, now.month)[1]) self.next_month = datetime(now.year, now.month + 1, 1) self.previous_month = datetime(now.year, now.month - 1, 1) self.year_beginning = datetime(now.year, 1, 1) self.year_end = datetime(now.year, 12, 31) self.next_year = datetime(now.year + 1, now.month, 1) self.previous_year = datetime(now.year - 1, now.month, 1) def test_period_length(self): now = datetime.now() try: self.period_length.current_period_start_date() assert(False) except NotImplementedError: assert(True) try: self.period_length.current_period_end_date() assert(False) except NotImplementedError: assert(True) try: self.period_length.in_current_period(now) assert(False) except NotImplementedError: assert(True) def test_month(self): assert(self.month.current_period_start_date == self.month_beginning) assert(self.month.current_period_end_date == self.month_end) assert(self.month.in_current_period(self.now)) assert(self.month.in_current_period(self.month_end)) assert(self.month.in_current_period(self.month_beginning)) assert(self.month.in_current_period(self.next_month) == False) assert(self.month.in_current_period(self.previous_month) == False) def test_year(self): assert(self.year.current_period_start_date == self.year_beginning) assert(self.year.current_period_end_date == self.year_end) assert(self.year.in_current_period(self.now)) assert(self.year.in_current_period(self.year_end)) assert(self.year.in_current_period(self.year_beginning)) assert(self.year.in_current_period(self.next_year) == False) assert(self.year.in_current_period(self.previous_year) == False)