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_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_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_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_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_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_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_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_validate_id(self): serializer = DeliverableSerializer(data={'id': 1, 'quantity': 1}) self.assertFalse(serializer.is_valid()) error_message = { 'id': { 'detail': ErrorDetail(string='Not found', code='invalid') } } self.assertEqual(serializer.errors, error_message) deliverable = DeliverableFactory() serializer = DeliverableSerializer(data={ 'id': deliverable.id, 'quantity': 1 }) self.assertTrue(serializer.is_valid())
def test_quantity_not_required(self): deliverable = DeliverableFactory() serializer = DeliverableSerializer(data={'id': deliverable.id}) self.assertTrue(serializer.is_valid())