Increase unit testing for order API

This commit is contained in:
Oliver Walters 2021-01-14 22:06:53 +11:00
parent 02132fa495
commit fef5b7548e
5 changed files with 212 additions and 11 deletions

View File

@ -5,20 +5,29 @@
fields:
name: ACME
description: A Cool Military Enterprise
- model: company.company
pk: 2
fields:
name: Appel Computers
description: Think more differenter
- model: company.company
pk: 3
fields:
name: Zerg Corp
description: We eat the competition
- model: company.company
pk: 4
fields:
name: A customer
description: A company that we sell things to!
is_customer: True
- model: company.company
pk: 5
fields:
name: Another customer!
description: Yet another company
is_customer: True

View File

@ -7,6 +7,7 @@
reference: '0001'
description: "Ordering some screws"
supplier: 1
status: 10 # Pending
# Ordering some screws from Zerg Corp
- model: order.purchaseorder
@ -15,6 +16,39 @@
reference: '0002'
description: "Ordering some more screws"
supplier: 3
status: 10 # Pending
- model: order.purchaseorder
pk: 3
fields:
reference: '0003'
description: 'Another PO'
supplier: 3
status: 20 # Placed
- model: order.purchaseorder
pk: 4
fields:
reference: '0004'
description: 'Another PO'
supplier: 3
status: 20 # Placed
- model: order.purchaseorder
pk: 5
fields:
reference: '0005'
description: 'Another PO'
supplier: 3
status: 30 # Complete
- model: order.purchaseorder
pk: 6
fields:
reference: '0006'
description: 'Another PO'
supplier: 3
status: 40 # Cancelled
# Add some line items against PO 0001

View File

@ -0,0 +1,39 @@
- model: order.salesorder
pk: 1
fields:
reference: 'ABC123'
description: "One sales order, please"
customer: 4
status: 10 # Pending
- model: order.salesorder
pk: 2
fields:
reference: 'ABC124'
description: "One sales order, please"
customer: 4
status: 10 # Pending
- model: order.salesorder
pk: 3
fields:
reference: 'ABC125'
description: "One sales order, please"
customer: 4
status: 10 # Pending
- model: order.salesorder
pk: 4
fields:
reference: 'ABC126'
description: "One sales order, please"
customer: 5
status: 20 # Shipped
- model: order.salesorder
pk: 5
fields:
reference: 'ABC127'
description: "One sales order, please"
customer: 5
status: 60 # Returned

View File

@ -191,7 +191,7 @@ class PurchaseOrder(Order):
issue_date = models.DateField(
blank=True, null=True,
verbose_name=_('Issue Date'),
verbose_name=_('Issue Date'),
help_text=_('Date order was issued')
)

View File

@ -2,12 +2,16 @@
Tests for the Order API
"""
from datetime import datetime, timedelta
from rest_framework.test import APITestCase
from rest_framework import status
from django.urls import reverse
from django.contrib.auth import get_user_model
from .models import PurchaseOrder, SalesOrder
class OrderTest(APITestCase):
@ -18,6 +22,8 @@ class OrderTest(APITestCase):
'location',
'supplier_part',
'stock',
'order',
'sales_order',
]
def setUp(self):
@ -26,21 +32,80 @@ class OrderTest(APITestCase):
get_user_model().objects.create_user('testuser', 'test@testing.com', 'password')
self.client.login(username='testuser', password='password')
def doGet(self, url, options=''):
def doGet(self, url, data={}):
return self.client.get(url + "?" + options, format='json')
return self.client.get(url, data=data, format='json')
def doPost(self, url, data={}):
return self.client.post(url, data=data, format='json')
def filter(self, filters, count):
"""
Test API filters
"""
response = self.doGet(
self.LIST_URL,
filters
)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), count)
return response
class PurchaseOrderTest(OrderTest):
"""
Tests for the PurchaseOrder API
"""
LIST_URL = reverse('api-po-list')
def test_po_list(self):
url = reverse('api-po-list')
# List all order items
# List *ALL* PO items
self.filter({}, 6)
# Filter by supplier
self.filter({'supplier': 1}, 1)
self.filter({'supplier': 3}, 5)
# Filter by "outstanding"
self.filter({'outstanding': True}, 4)
self.filter({'outstanding': False}, 2)
# Filter by "status"
self.filter({'status': 10}, 2)
self.filter({'status': 40}, 1)
def test_overdue(self):
"""
Test "overdue" status
"""
self.filter({'overdue': True}, 0)
self.filter({'overdue': False}, 6)
order = PurchaseOrder.objects.get(pk=1)
order.target_date = datetime.now().date() - timedelta(days=10)
order.save()
self.filter({'overdue': True}, 1)
self.filter({'overdue': False}, 5)
def test_po_detail(self):
url = '/api/order/po/1/'
response = self.doGet(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.status_code, 200)
# Filter by stuff
response = self.doGet(url, 'status=10&part=1&supplier_part=1')
self.assertEqual(response.status_code, status.HTTP_200_OK)
data = response.data
self.assertEqual(data['pk'], 1)
self.assertEqual(data['description'], 'Ordering some screws')
def test_po_attachments(self):
@ -50,6 +115,60 @@ class OrderTest(APITestCase):
self.assertEqual(response.status_code, status.HTTP_200_OK)
class SalesOrderTest(OrderTest):
"""
Tests for the SalesOrder API
"""
LIST_URL = reverse('api-so-list')
def test_so_list(self):
# All orders
self.filter({}, 5)
# Filter by customer
self.filter({'customer': 4}, 3)
self.filter({'customer': 5}, 2)
# Filter by outstanding
self.filter({'outstanding': True}, 3)
self.filter({'outstanding': False}, 2)
# Filter by status
self.filter({'status': 10}, 3) # PENDING
self.filter({'status': 20}, 1) # SHIPPED
self.filter({'status': 99}, 0) # Invalid
def test_overdue(self):
"""
Test "overdue" status
"""
self.filter({'overdue': True}, 0)
self.filter({'overdue': False}, 5)
for pk in [1, 2]:
order = SalesOrder.objects.get(pk=pk)
order.target_date = datetime.now().date() - timedelta(days=10)
order.save()
self.filter({'overdue': True}, 2)
self.filter({'overdue': False}, 3)
def test_so_detail(self):
url = '/api/order/so/1/'
response = self.doGet(url)
self.assertEqual(response.status_code, 200)
data = response.data
self.assertEqual(data['pk'], 1)
def test_so_attachments(self):
url = reverse('api-so-attachment-list')