mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add unit test for SalesOrderCancel API endpoint
This commit is contained in:
parent
7a5be35f10
commit
1c0fba0fca
@ -9,7 +9,7 @@ from rest_framework import status
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from InvenTree.api_tester import InvenTreeAPITestCase
|
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 part.models import Part
|
||||||
from stock.models import StockItem
|
from stock.models import StockItem
|
||||||
@ -251,11 +251,7 @@ class PurchaseOrderTest(OrderTest):
|
|||||||
url = reverse('api-po-cancel', kwargs={'pk': po.pk})
|
url = reverse('api-po-cancel', kwargs={'pk': po.pk})
|
||||||
|
|
||||||
# Try to cancel the PO, but without reqiured permissions
|
# Try to cancel the PO, but without reqiured permissions
|
||||||
self.post(
|
self.post(url, {}, expected_code=403)
|
||||||
url,
|
|
||||||
{},
|
|
||||||
expected_code=403,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assignRole('purchase_order.add')
|
self.assignRole('purchase_order.add')
|
||||||
|
|
||||||
@ -270,11 +266,7 @@ class PurchaseOrderTest(OrderTest):
|
|||||||
self.assertEqual(po.status, PurchaseOrderStatus.CANCELLED)
|
self.assertEqual(po.status, PurchaseOrderStatus.CANCELLED)
|
||||||
|
|
||||||
# Try to cancel again (should fail)
|
# Try to cancel again (should fail)
|
||||||
self.post(
|
self.post(url, {}, expected_code=400)
|
||||||
url,
|
|
||||||
{},
|
|
||||||
expected_code=400,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_po_complete(self):
|
def test_po_complete(self):
|
||||||
""" Test the PurchaseOrderComplete API endpoint """
|
""" Test the PurchaseOrderComplete API endpoint """
|
||||||
@ -286,25 +278,16 @@ class PurchaseOrderTest(OrderTest):
|
|||||||
self.assertEqual(po.status, PurchaseOrderStatus.PLACED)
|
self.assertEqual(po.status, PurchaseOrderStatus.PLACED)
|
||||||
|
|
||||||
# Try to complete the PO, without required permissions
|
# Try to complete the PO, without required permissions
|
||||||
response = self.post(
|
self.post(url, {}, expected_code=403)
|
||||||
url,
|
|
||||||
{},
|
|
||||||
expected_code=403,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assignRole('purchase_order.add')
|
self.assignRole('purchase_order.add')
|
||||||
|
|
||||||
response = self.post(
|
self.post(url, {}, expected_code=201)
|
||||||
url,
|
|
||||||
{},
|
|
||||||
expected_code=201,
|
|
||||||
)
|
|
||||||
|
|
||||||
po.refresh_from_db()
|
po.refresh_from_db()
|
||||||
|
|
||||||
self.assertEqual(po.status, PurchaseOrderStatus.COMPLETE)
|
self.assertEqual(po.status, PurchaseOrderStatus.COMPLETE)
|
||||||
|
|
||||||
|
|
||||||
def test_po_issue(self):
|
def test_po_issue(self):
|
||||||
""" Test the PurchaseOrderIssue API endpoint """
|
""" Test the PurchaseOrderIssue API endpoint """
|
||||||
|
|
||||||
@ -313,19 +296,11 @@ class PurchaseOrderTest(OrderTest):
|
|||||||
url = reverse('api-po-issue', kwargs={'pk': po.pk})
|
url = reverse('api-po-issue', kwargs={'pk': po.pk})
|
||||||
|
|
||||||
# Try to issue the PO, without required permissions
|
# Try to issue the PO, without required permissions
|
||||||
response = self.post(
|
self.post(url, {}, expected_code=403)
|
||||||
url,
|
|
||||||
{},
|
|
||||||
expected_code=403,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assignRole('purchase_order.add')
|
self.assignRole('purchase_order.add')
|
||||||
|
|
||||||
response = self.post(
|
self.post(url, {}, expected_code=201)
|
||||||
url,
|
|
||||||
{},
|
|
||||||
expected_code=201,
|
|
||||||
)
|
|
||||||
|
|
||||||
po.refresh_from_db()
|
po.refresh_from_db()
|
||||||
|
|
||||||
@ -880,6 +855,26 @@ class SalesOrderTest(OrderTest):
|
|||||||
expected_code=201
|
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):
|
class SalesOrderAllocateTest(OrderTest):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user