def test_budget_account(self): proto_budget = BudgetAccountFactory() assert (reverse("budget:budget_account", kwargs={"account_id": proto_budget.id }) == f"/budget/b/{proto_budget.id}") assert resolve(f"/budget/b/{proto_budget.id}" ).view_name == "budget:budget_account"
def test_money_accounts_in_form(self): proto_user = UserFactory.create() proto_moneys = MoneyAccountFactory.create_batch( randint(1, 10), user=proto_user, ) proto_budget = BudgetAccountFactory.create(user=proto_user) proto_transaction = TransactionFactory.build(user=proto_user) form = TransactionPaystubForm( { "amount_spent": proto_transaction.amount_spent, "budget_account": proto_budget.id, # "money_account": proto_money.id, "monthly_contribution": 40.2, "month_contribution": 30.2 }, user=proto_user) assert form.is_valid() # user, transaction_date, description still needed with self.assertRaises(IntegrityError): form.save() # show money_account list made self.assertEqual(len(proto_moneys), form.fields['money_account'].queryset.count()) self.assertQuerysetEqual(form.fields['money_account'].queryset, [repr(m) for m in proto_moneys], ordered=False)
def test_clean_budget_account(self): budget_account = BudgetAccountFactory() form = BudgetAccountForm({ "name": budget_account.name, "account_type": budget_account.account_type.id, "contribution_amount": budget_account.contribution_amount, "month_intervals": budget_account.month_intervals, "user": budget_account.user.id, "active": budget_account.active }) self.assertTrue(form.is_valid()) form.save()
def test_manager_find_all_shares_one_budget(self): proto_budget2 = BudgetAccountFactory() StockSharesFactory(stock=self.proto_stock, brokerage_account=self.proto_broker, budget_account=self.proto_budget) stock_shares2 = StockSharesFactory(stock=self.proto_stock, brokerage_account=self.proto_broker, budget_account=proto_budget2) all_shares = StockShares.objects.find_all_shares( self.proto_stock, budget_account=proto_budget2) self.assertQuerysetEqual(all_shares, [repr(stock_shares2)], ordered=False)
def test_add_paystub_forms(self): create_flex_account(self.user) money_accounts = MoneyAccountFactory.create_batch( randint(1, 10), user=self.user, ) budget_accounts = BudgetAccountFactory.create_batch( randint(1, 10), user=self.user, ) DeductionFactory.create_batch( randint(1, 5), user=self.user, paycheck=self.paycheck) # deductions for paystub take home user2 = create_another_user() MoneyAccountFactory.create_batch( randint(1, 10), user=user2, ) request_url = reverse('paychecks:paystub_add', kwargs={'paycheck_id': self.paycheck.id}) response = self.client.get(request_url) paystub_form = response.context['paystub_form'] self.assertQuerysetEqual(paystub_form.fields['paycheck'].queryset, [repr(self.paycheck)]) self.assertEqual(response.context['paycheck'], self.paycheck) deposit_formset = response.context['deposit_formset'] self.assertEqual(deposit_formset.total_form_count(), 5) # make sure all money accounts in deposit formset for form in deposit_formset: self.assertQuerysetEqual(form.fields['money_account'].queryset, [repr(m) for m in money_accounts], ordered=False) # make sure one transaction form per budget account minus flex transaction_formset = response.context['transaction_formset'] self.assertEqual( transaction_formset.total_form_count(), len([ b for b in budget_accounts if b.account_type.account_type != 'Flex' ]))
def test_clean_transaction_paystub(self): proto_money = MoneyAccountFactory.create() proto_budget = BudgetAccountFactory.create() proto_transaction = TransactionFactory.build() form = TransactionPaystubForm({ "amount_spent": proto_transaction.amount_spent, "budget_account": proto_budget.id, "money_account": proto_money.id, "monthly_contribution": 40.2, "month_contribution": 30.2 }) assert form.is_valid() # user, transaction_date, description still needed with self.assertRaises(IntegrityError): form.save() form.save(commit=False)
def create_flex_account(user): acc_type = BudgetAccountTypeFactory(account_type='Flex') return BudgetAccountFactory(account_type=acc_type, user=user)
def setUp(self): self.proto_stock = StockFactory() self.proto_broker = BrokerageAccountFactory() self.proto_budget = BudgetAccountFactory()
def setUp(self): self.budget_account = BudgetAccountFactory()