From 1c0fba0fca2cec8c55fc82ba0fe8617867ccc786 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 4 May 2022 21:51:09 +1000 Subject: [PATCH] Add unit test for SalesOrderCancel API endpoint --- InvenTree/order/test_api.py | 61 +++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/InvenTree/order/test_api.py b/InvenTree/order/test_api.py index 8b3cf87b76..2ac7689434 100644 --- a/InvenTree/order/test_api.py +++ b/InvenTree/order/test_api.py @@ -9,7 +9,7 @@ from rest_framework import status from django.urls import reverse from InvenTree.api_tester import InvenTreeAPITestCase -from InvenTree.status_codes import PurchaseOrderStatus +from InvenTree.status_codes import PurchaseOrderStatus, SalesOrderStatus from part.models import Part from stock.models import StockItem @@ -238,7 +238,7 @@ class PurchaseOrderTest(OrderTest): }, expected_code=201 ) - + def test_po_cancel(self): """ Test the PurchaseOrderCancel API endpoint @@ -251,11 +251,7 @@ class PurchaseOrderTest(OrderTest): 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.post(url, {}, expected_code=403) self.assignRole('purchase_order.add') @@ -270,11 +266,7 @@ class PurchaseOrderTest(OrderTest): self.assertEqual(po.status, PurchaseOrderStatus.CANCELLED) # Try to cancel again (should fail) - self.post( - url, - {}, - expected_code=400, - ) + self.post(url, {}, expected_code=400) def test_po_complete(self): """ Test the PurchaseOrderComplete API endpoint """ @@ -286,25 +278,16 @@ class PurchaseOrderTest(OrderTest): self.assertEqual(po.status, PurchaseOrderStatus.PLACED) # Try to complete the PO, without required permissions - response = self.post( - url, - {}, - expected_code=403, - ) + self.post(url, {}, expected_code=403) self.assignRole('purchase_order.add') - response = self.post( - url, - {}, - expected_code=201, - ) + 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 """ @@ -313,19 +296,11 @@ class PurchaseOrderTest(OrderTest): 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.post(url, {}, expected_code=403) self.assignRole('purchase_order.add') - response = self.post( - url, - {}, - expected_code=201, - ) + self.post(url, {}, expected_code=201) po.refresh_from_db() @@ -880,6 +855,26 @@ class SalesOrderTest(OrderTest): expected_code=201 ) + def test_so_cancel(self): + """ Test API endpoint for cancelling a SalesOrder """ + + so = models.SalesOrder.objects.get(pk=1) + + self.assertEqual(so.status, SalesOrderStatus.PENDING) + + url = reverse('api-so-cancel', kwargs={'pk': so.pk}) + + # Try to cancel, without permission + self.post(url, {}, expected_code=403) + + self.assignRole('sales_order.add') + + self.post(url, {}, expected_code=201) + + so.refresh_from_db() + + self.assertEqual(so.status, SalesOrderStatus.CANCELLED) + class SalesOrderAllocateTest(OrderTest): """