From 7a5be35f106576521d201260bb1da0f31d23a9de Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 4 May 2022 21:44:38 +1000 Subject: [PATCH] Add unit tests for new purchase order API endpoints: - PurchaseOrderCancel - PurchaseOrderComplete - PurchaseOrderIssue --- InvenTree/order/test_api.py | 92 +++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/InvenTree/order/test_api.py b/InvenTree/order/test_api.py index d3e405e5fa..8b3cf87b76 100644 --- a/InvenTree/order/test_api.py +++ b/InvenTree/order/test_api.py @@ -238,6 +238,98 @@ class PurchaseOrderTest(OrderTest): }, expected_code=201 ) + + def test_po_cancel(self): + """ + Test the PurchaseOrderCancel API endpoint + """ + + po = models.PurchaseOrder.objects.get(pk=1) + + self.assertEqual(po.status, PurchaseOrderStatus.PENDING) + + url = reverse('api-po-cancel', kwargs={'pk': po.pk}) + + # Try to cancel the PO, but without reqiured permissions + self.post( + url, + {}, + expected_code=403, + ) + + self.assignRole('purchase_order.add') + + self.post( + url, + {}, + expected_code=201, + ) + + po.refresh_from_db() + + self.assertEqual(po.status, PurchaseOrderStatus.CANCELLED) + + # Try to cancel again (should fail) + self.post( + url, + {}, + expected_code=400, + ) + + def test_po_complete(self): + """ Test the PurchaseOrderComplete API endpoint """ + + po = models.PurchaseOrder.objects.get(pk=3) + + url = reverse('api-po-complete', kwargs={'pk': po.pk}) + + self.assertEqual(po.status, PurchaseOrderStatus.PLACED) + + # Try to complete the PO, without required permissions + response = self.post( + url, + {}, + expected_code=403, + ) + + self.assignRole('purchase_order.add') + + response = self.post( + url, + {}, + expected_code=201, + ) + + po.refresh_from_db() + + self.assertEqual(po.status, PurchaseOrderStatus.COMPLETE) + + + def test_po_issue(self): + """ Test the PurchaseOrderIssue API endpoint """ + + po = models.PurchaseOrder.objects.get(pk=2) + + url = reverse('api-po-issue', kwargs={'pk': po.pk}) + + # Try to issue the PO, without required permissions + response = self.post( + url, + {}, + expected_code=403, + ) + + self.assignRole('purchase_order.add') + + response = self.post( + url, + {}, + expected_code=201, + ) + + po.refresh_from_db() + + self.assertEqual(po.status, PurchaseOrderStatus.PLACED) class PurchaseOrderReceiveTest(OrderTest):