def test_doest_show_active_payment_requests_when_paid_or_declined(self): project = ProjectFactory(lead=self.user) PaymentRequestFactory(project=project, status=PAID) PaymentRequestFactory(project=project, status=DECLINED) response = self.get_page() self.assertNotContains(response, "Active requests for payment")
def test_doest_show_active_invoices_when_paid_or_declined(self): project = ProjectFactory(lead=self.user) InvoiceFactory(project=project, status=PAID) InvoiceFactory(project=project, status=DECLINED) response = self.get_page() self.assertNotContains(response, "Active Invoices")
def test_doesnt_show_active_payment_requests_when_not_mine(self): project = ProjectFactory() PaymentRequestFactory(project=project, status=SUBMITTED) PaymentRequestFactory(project=project, status=CHANGES_REQUESTED) PaymentRequestFactory(project=project, status=UNDER_REVIEW) response = self.get_page() self.assertNotContains(response, "Active requests for payment")
def test_doesnt_show_active_invoices_when_not_mine(self): project = ProjectFactory() InvoiceFactory(project=project, status=SUBMITTED) InvoiceFactory(project=project, status=CHANGES_REQUESTED) InvoiceFactory(project=project, status=RESUBMITTED) response = self.get_page() self.assertNotContains(response, "Active Invoices")
def test_active_invoices_with_invoices_in_correct_state(self): project = ProjectFactory(lead=self.user) InvoiceFactory(project=project, status=SUBMITTED) InvoiceFactory(project=project, status=CHANGES_REQUESTED) InvoiceFactory(project=project, status=RESUBMITTED) response = self.get_page() self.assertContains(response, "Active Invoices")
def test_finance1_can_get_required_valid_checks(self): user = FinanceFactory() project = ProjectFactory() invoice = InvoiceFactory(project=project, status=APPROVED_BY_STAFF, valid_checks=True) self.client.force_login(user) response = self.get_to_retrieve(project.id, invoice.id) self.assertEqual(response.status_code, 200) self.assertTrue(response.data.get('valid_checks'))
def test_active_payment_requests_with_payment_requests_in_correct_state( self): project = ProjectFactory(lead=self.user) PaymentRequestFactory(project=project, status=SUBMITTED) PaymentRequestFactory(project=project, status=CHANGES_REQUESTED) PaymentRequestFactory(project=project, status=UNDER_REVIEW) response = self.get_page() self.assertContains(response, "Active requests for payment")
def test_finance2_can_add_deliverables(self): user = Finance2Factory() project = ProjectFactory() invoice = InvoiceFactory(project=project, status=APPROVED_BY_FINANCE_1) deliverable = DeliverableFactory(project=project) self.client.force_login(user) response = self.post_to_add(project.id, invoice.id, deliverable.id) self.assertEqual(response.status_code, 201)
def test_staff_can_add_deliverables(self): user = StaffFactory() project = ProjectFactory() invoice = InvoiceFactory(project=project, status=SUBMITTED) deliverable = DeliverableFactory(project=project) self.client.force_login(user) response = self.post_to_add(project.id, invoice.id, deliverable.id) self.assertEqual(response.status_code, 201)
def test_applicant_cant_add_deliverables(self): user = ApplicantFactory() project = ProjectFactory() invoice = InvoiceFactory(project=project) deliverable = DeliverableFactory(project=project) self.client.force_login(user) response = self.post_to_add(project.id, invoice.id, deliverable.id) self.assertEqual(response.status_code, 403)
def test_project_approver_can_see_projects_awaiting_review_stats_or_table( self): ProjectFactory(is_locked=True, status=COMMITTED) user = StaffFactory() user.groups.add(GroupFactory(name=APPROVER_GROUP_NAME)) self.client.force_login(user) response = self.get_page() self.assertContains(response, "Projects awaiting approval")
def test_finance1_can_set_required_valid_checks(self): user = FinanceFactory() project = ProjectFactory() invoice = InvoiceFactory(project=project, status=APPROVED_BY_STAFF) valid_checks = True valid_checks_link = 'https://google.com' self.client.force_login(user) response = self.post_to_set(project.id, invoice.id, valid_checks, valid_checks_link) self.assertEqual(response.status_code, 201)
def test_applicant_cant_remove_deliverables(self): user = ApplicantFactory() project = ProjectFactory() invoice = InvoiceFactory(project=project) deliverable = DeliverableFactory(project=project) invoice_deliverable = InvoiceDeliverableFactory(deliverable=deliverable) invoice.deliverables.add(invoice_deliverable) self.client.force_login(user) response = self.delete_to_remove(project.id, invoice.id, invoice_deliverable.id) self.assertEqual(response.status_code, 403)
def test_deliverable_dont_exists_in_project_deliverables(self): user = StaffFactory() project = ProjectFactory() invoice = InvoiceFactory(project=project, status=SUBMITTED) deliverable = DeliverableFactory() self.client.force_login(user) response = self.post_to_add(project.id, invoice.id, deliverable.id) self.assertEqual(response.status_code, 400) error_message = {'detail': ErrorDetail(string='Not Found', code='invalid')} self.assertEqual(response.data, error_message)
def test_staff_can_remove_deliverables(self): user = StaffFactory() project = ProjectFactory() invoice = InvoiceFactory(project=project, status=SUBMITTED) deliverable = DeliverableFactory(project=project) invoice_deliverable = InvoiceDeliverableFactory(deliverable=deliverable) invoice.deliverables.add(invoice_deliverable) self.client.force_login(user) response = self.delete_to_remove(project.id, invoice.id, invoice_deliverable.id) self.assertEqual(response.status_code, 200)
def test_staff_cant_remove_deliverables_after_staff_approval(self): user = StaffFactory() project = ProjectFactory() invoice = InvoiceFactory(project=project, status=APPROVED_BY_STAFF) deliverable = DeliverableFactory(project=project) invoice_deliverable = InvoiceDeliverableFactory(deliverable=deliverable) invoice.deliverables.add(invoice_deliverable) self.client.force_login(user) response = self.delete_to_remove(project.id, invoice.id, invoice_deliverable.id) self.assertEqual(response.status_code, 403)
def test_finance2_can_remove_deliverables(self): user = Finance2Factory() project = ProjectFactory() invoice = InvoiceFactory(project=project, status=APPROVED_BY_FINANCE_1) deliverable = DeliverableFactory(project=project) invoice_deliverable = InvoiceDeliverableFactory(deliverable=deliverable) invoice.deliverables.add(invoice_deliverable) self.client.force_login(user) response = self.delete_to_remove(project.id, invoice.id, invoice_deliverable.id) self.assertEqual(response.status_code, 200)
def test_deliverable_available_gte_quantity(self): user = StaffFactory() project = ProjectFactory() invoice = InvoiceFactory(project=project, status=SUBMITTED) deliverable = DeliverableFactory(project=project) self.client.force_login(user) response = self.post_to_add(project.id, invoice.id, deliverable.id, quantity=3) self.assertEqual(response.status_code, 400) error_message = {'detail': ErrorDetail(string='Required quantity is more than available', code='invalid')} self.assertEqual(response.data, error_message)
def test_cant_get_set_required_checks_without_login(self): project = ProjectFactory() invoice = InvoiceFactory(project=project, status=APPROVED_BY_STAFF) valid_checks = True valid_checks_link = 'https://google.com' response = self.post_to_set(project.id, invoice.id, valid_checks, valid_checks_link) self.assertEqual(response.status_code, 403) response = self.get_to_retrieve(project.id, invoice.id) self.assertEqual(response.status_code, 403)
def test_cant_add_or_remove_wihtout_login(self): project = ProjectFactory() invoice = InvoiceFactory(project=project) deliverable = DeliverableFactory(project=project) invoice_deliverable = InvoiceDeliverableFactory(deliverable=deliverable) response = self.post_to_add(project.id, invoice.id, deliverable.id) self.assertEqual(response.status_code, 403) response = self.delete_to_remove(project.id, invoice.id, invoice_deliverable.id) self.assertEqual(response.status_code, 403)
def test_deliverable_already_exists_in_invoice(self): user = StaffFactory() project = ProjectFactory() invoice = InvoiceFactory(project=project, status=SUBMITTED) deliverable = DeliverableFactory(project=project) invoice_deliverable = InvoiceDeliverableFactory(deliverable=deliverable) invoice.deliverables.add(invoice_deliverable) self.client.force_login(user) response = self.post_to_add(project.id, invoice.id, deliverable.id) self.assertEqual(response.status_code, 400) error_message = {'detail': ErrorDetail(string='Invoice Already has this deliverable', code='invalid')} self.assertEqual(response.data, error_message)
def test_deliverables_cant_removed_after_finance2_approval(self): project = ProjectFactory() invoice = InvoiceFactory(project=project, status=APPROVED_BY_FINANCE_2) deliverable = DeliverableFactory(project=project) invoice_deliverable = InvoiceDeliverableFactory(deliverable=deliverable) invoice.deliverables.add(invoice_deliverable) finance1 = FinanceFactory() finance2 = Finance2Factory() staff = StaffFactory() for user in [staff, finance1, finance2]: self.client.force_login(user) response = self.delete_to_remove(project.id, invoice.id, invoice_deliverable.id) self.assertEqual(response.status_code, 403)
def test_project_required(self): factory = RequestFactory() submission = ApplicationSubmissionFactory() request = factory.get(f'/submission/{submission.pk}') request.user = StaffFactory() with self.assertRaises(Http404): SubmissionDetailSimplifiedView.as_view()(request, pk=submission.pk) ProjectFactory(submission=submission) response = SubmissionDetailSimplifiedView.as_view()(request, pk=submission.pk) self.assertEqual(response.status_code, 200)
def test_can_save_source_project(self): other = ProjectFactory() activity = ActivityFactory(source=other) self.assertEqual(other, activity.source) self.assertTrue(str(activity))
def test_non_project_approver_cannot_see_projects_awaiting_review_stats_or_table( self): ProjectFactory(is_locked=True, status=COMMITTED) response = self.get_page() self.assertNotContains(response, "Projects awaiting approval")
def test_doesnt_show_active_invoices_with_none(self): ProjectFactory(lead=self.user) response = self.get_page() self.assertNotContains(response, "Active Invoices")
def test_doesnt_show_active_payment_requests_with_none(self): ProjectFactory(lead=self.user) response = self.get_page() self.assertNotContains(response, "Active requests for payment")