def test_404_on_not_users_paycheck(self): user2 = create_another_user() paycheck = PaycheckFactory(user=user2) request_url = reverse('paychecks:deduction_add') data = {'paycheck': paycheck.id} response = self.client.post(request_url, data) self.assertEqual(response.status_code, 404)
def test_404_on_unauthorized_paycheck(self): user2 = create_another_user() paycheck2 = PaycheckFactory(user=user2) request_url = reverse('paychecks:paystub_add', kwargs={'paycheck_id': paycheck2.id}) response = self.client.get(request_url) self.assertEqual(response.status_code, 404)
def test_error_deleting_other_user_deduction(self): user2 = create_another_user() paycheck = PaycheckFactory(user=user2) deduction = DeductionFactory(paycheck=paycheck, user=user2) request_url = reverse('paychecks:deduction_delete', kwargs={"pk": deduction.id}) response = self.client.post(request_url, {}, follow=True) self.assertEqual(response.status_code, 403)
def test_404_wrong_paycheck(self): '''404 Given if requested paycheck doesn't belong to user''' PaycheckFactory(user=self.user) user2 = create_another_user() paycheck2 = PaycheckFactory(user=user2) request_url = reverse('paychecks:paycheck', kwargs={"paycheck_id": paycheck2.id}) response = self.client.get(request_url) self.assertEqual(response.status_code, 404)
def test_error_deleting_other_user_paystub(self): '''Cannot delete another users paystub''' user2 = create_another_user() paycheck = PaycheckFactory(user=user2) paystub = PaystubFactory(paycheck=paycheck, user=user2) request_url = reverse('paychecks:paystub_delete', kwargs={"pk": paystub.id}) response = self.client.post(request_url, follow=True) self.assertEqual(response.status_code, 403)
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_one_paycheck(self): '''Responses given for one paycheck asked for''' first_paycheck = PaycheckFactory(user=self.user) # create random number of paychecks user_paychecks = PaycheckFactory.create_batch(randint(1, 10), user=self.user) user_paychecks.append(first_paycheck) user2 = create_another_user() paycheck_user2 = PaycheckFactory(user=user2) # proper response request_url = reverse('paychecks:paycheck', kwargs={"paycheck_id": first_paycheck.id}) response = self.client.get(request_url) self.assertEqual(response.status_code, 200) # check context self.assertIsInstance(response.context['paycheck'], Paycheck) self.assertTemplateUsed(response, 'paychecks/paychecks.html') # make sure other users paychecks not in response self.assertEqual(len(response.context['paychecks']), len(user_paychecks))