Simple tests for price breaks

This commit is contained in:
Oliver Walters 2019-05-21 13:53:25 +10:00
parent 6f73c379c2
commit cdcc4f9ca1
3 changed files with 90 additions and 5 deletions

View File

@ -0,0 +1,47 @@
# Price breaks for supplier parts
# Price breaks for ACME0001
- model: company.supplierpricebreak
fields:
part: 1
quantity: 1
cost: 10
- model: company.supplierpricebreak
fields:
part: 1
quantity: 5
cost: 7.50
- model: company.supplierpricebreak
fields:
part: 1
quantity: 25
cost: 3.50
# Price breaks for ACME0002
- model: company.supplierpricebreak
fields:
part: 2
quantity: 5
cost: 7.00
- model: company.supplierpricebreak
fields:
part: 2
quantity: 50
cost: 1.25
# Price breaks for ZERGLPHS
- model: company.supplierpricebreak
fields:
part: 3
quantity: 5
cost: 8
- model: company.supplierpricebreak
fields:
part: 3
quantity: 100
cost: 1.25

View File

@ -21,4 +21,11 @@
fields:
part: 1
supplier: 3
SKU: 'ZERGLPHS'
SKU: 'ZERGLPHS'
- model: company.supplierpart
pk: 4
fields:
part: 2
supplier: 2
SKU: 'ZERGM312'

View File

@ -2,7 +2,7 @@ from django.test import TestCase
import os
from .models import Company, Contact
from .models import Company, Contact, SupplierPart, SupplierPriceBreak
from .models import rename_company_image
@ -15,6 +15,7 @@ class CompanySimpleTest(TestCase):
'location',
'bom',
'supplier_part',
'price_breaks',
]
def setUp(self):
@ -25,6 +26,11 @@ class CompanySimpleTest(TestCase):
is_customer=False,
is_supplier=True)
self.acme0001 = SupplierPart.objects.get(SKU='ACME0001')
self.acme0002 = SupplierPart.objects.get(SKU='ACME0002')
self.zerglphs = SupplierPart.objects.get(SKU='ZERGLPHS')
self.zergm312 = SupplierPart.objects.get(SKU='ZERGM312')
def test_company_model(self):
c = Company.objects.get(name='ABC Co.')
self.assertEqual(c.name, 'ABC Co.')
@ -51,15 +57,40 @@ class CompanySimpleTest(TestCase):
self.assertTrue(acme.has_parts)
self.assertEqual(acme.part_count, 2)
self.assertFalse(appel.has_parts)
self.assertEqual(appel.part_count, 0)
self.assertTrue(appel.has_parts)
self.assertEqual(appel.part_count, 1)
self.assertTrue(zerg.has_parts)
self.assertEqual(zerg.part_count, 1)
def test_price_breaks(self):
self.assertTrue(self.acme0001.has_price_breaks)
self.assertTrue(self.acme0002.has_price_breaks)
self.assertTrue(self.zerglphs.has_price_breaks)
self.assertFalse(self.zergm312.has_price_breaks)
self.assertEqual(self.acme0001.price_breaks.count(), 3)
self.assertEqual(self.acme0002.price_breaks.count(), 2)
self.assertEqual(self.zerglphs.price_breaks.count(), 2)
self.assertEqual(self.zergm312.price_breaks.count(), 0)
# TODO - Add some supplier parts here
def test_quantity_pricing(self):
""" Simple test for quantity pricing """
p = self.acme0001.get_price
self.assertEqual(p(1), 10)
self.assertEqual(p(4), 40)
self.assertEqual(p(11), 82.5)
self.assertEqual(p(23), 172.5)
self.assertEqual(p(100), 350)
p = self.acme0002.get_price
self.assertEqual(p(1), None)
self.assertEqual(p(2), None)
self.assertEqual(p(5), 35)
self.assertEqual(p(45), 315)
self.assertEqual(p(55), 68.75)
class ContactSimpleTest(TestCase):