Update test fixtures

- Can't assume that pk values will be assigned sensibly!
- Need to hard-code them in
This commit is contained in:
Oliver Walters 2020-09-02 19:47:07 +10:00
parent bc2f131144
commit 911727f7b7
15 changed files with 85 additions and 57 deletions

View File

@ -31,7 +31,8 @@ script:
- cd InvenTree && python3 manage.py makemigrations && cd ..
- python3 ci/check_migration_files.py
- invoke coverage
- invoke test --database=mysql
- cd InvenTree && python3 manage.py test --settings=InvenTree.ci_mysql && cd ..
- cd InvenTree && python3 manage.py test --settings=InvenTree.ci_postgresql && cd ..
- invoke translate
- invoke style

View File

@ -1,6 +1,7 @@
# Construct build objects
- model: build.build
pk: 1
fields:
part: 25
batch: 'B1'
@ -16,6 +17,7 @@
tree_id: 0
- model: build.build
pk: 2
fields:
part: 50
title: 'Making things'

View File

@ -203,22 +203,25 @@ class BuildTest(TestCase):
# - Three for the split items assigned to the build
self.assertEqual(StockItem.objects.count(), 16)
A = StockItem.objects.get(pk=self.stock_1_1.pk)
B = StockItem.objects.get(pk=self.stock_1_2.pk)
C = StockItem.objects.get(pk=self.stock_2_1.pk)
# Stock should have been subtracted from the original items
self.assertEqual(StockItem.objects.get(pk=1).quantity, 950)
self.assertEqual(StockItem.objects.get(pk=2).quantity, 50)
self.assertEqual(StockItem.objects.get(pk=3).quantity, 4750)
self.assertEqual(A.quantity, 950)
self.assertEqual(B.quantity, 50)
self.assertEqual(C.quantity, 4750)
# New stock items created and assigned to the build
self.assertEqual(StockItem.objects.get(pk=4).quantity, 50)
self.assertEqual(StockItem.objects.get(pk=4).build_order, self.build)
# New stock items should have also been allocated to the build
allocated = StockItem.objects.filter(build_order=self.build)
self.assertEqual(StockItem.objects.get(pk=5).quantity, 50)
self.assertEqual(StockItem.objects.get(pk=5).build_order, self.build)
self.assertEqual(allocated.count(), 3)
self.assertEqual(StockItem.objects.get(pk=6).quantity, 250)
self.assertEqual(StockItem.objects.get(pk=6).build_order, self.build)
q = sum([item.quantity for item in allocated.all()])
self.assertEqual(q, 350)
# And a new stock item created for the build output
self.assertEqual(StockItem.objects.get(pk=7).quantity, 1)
self.assertEqual(StockItem.objects.get(pk=7).serial, 1)
self.assertEqual(StockItem.objects.get(pk=7).build, self.build)
# And 10 new stock items created for the build output
outputs = StockItem.objects.filter(build=self.build)
self.assertEqual(outputs.count(), 10)

View File

@ -3,18 +3,21 @@
# Price breaks for ACME0001
- model: company.supplierpricebreak
pk: 1
fields:
part: 1
quantity: 1
cost: 10
- model: company.supplierpricebreak
pk: 2
fields:
part: 1
quantity: 5
cost: 7.50
- model: company.supplierpricebreak
pk: 3
fields:
part: 1
quantity: 25
@ -22,12 +25,14 @@
# Price breaks for ACME0002
- model: company.supplierpricebreak
pk: 4
fields:
part: 2
quantity: 5
cost: 7.00
- model: company.supplierpricebreak
pk: 5
fields:
part: 2
quantity: 50
@ -35,12 +40,14 @@
# Price breaks for ZERGLPHS
- model: company.supplierpricebreak
pk: 6
fields:
part: 4
quantity: 25
cost: 8
- model: company.supplierpricebreak
pk: 7
fields:
part: 4
quantity: 100

View File

@ -113,17 +113,17 @@ class ContactSimpleTest(TestCase):
def setUp(self):
# Create a simple company
c = Company.objects.create(name='Test Corp.', description='We make stuff good')
self.c = Company.objects.create(name='Test Corp.', description='We make stuff good')
# Add some contacts
Contact.objects.create(name='Joe Smith', company=c)
Contact.objects.create(name='Fred Smith', company=c)
Contact.objects.create(name='Sally Smith', company=c)
Contact.objects.create(name='Joe Smith', company=self.c)
Contact.objects.create(name='Fred Smith', company=self.c)
Contact.objects.create(name='Sally Smith', company=self.c)
def test_exists(self):
self.assertEqual(Contact.objects.count(), 3)
def test_delete(self):
# Remove the parent company
Company.objects.get(pk=1).delete()
Company.objects.get(pk=self.c.pk).delete()
self.assertEqual(Contact.objects.count(), 0)

View File

@ -29,6 +29,7 @@
# 250 x ACME0002 (M2x4 LPHS)
# Partially received (50)
- model: order.purchaseorderlineitem
pk: 2
fields:
order: 1
part: 2
@ -37,6 +38,7 @@
# 1000 x ACME0003
- model: order.purchaseorderlineitem
pk: 3
fields:
order: 1
part: 3

View File

@ -27,8 +27,8 @@ class SalesOrderTest(TestCase):
self.part = Part.objects.create(name='Spanner', salable=True, description='A spanner that I sell')
# Create some stock!
StockItem.objects.create(part=self.part, quantity=100)
StockItem.objects.create(part=self.part, quantity=200)
self.Sa = StockItem.objects.create(part=self.part, quantity=100)
self.Sb = StockItem.objects.create(part=self.part, quantity=200)
# Create a SalesOrder to ship against
self.order = SalesOrder.objects.create(
@ -57,15 +57,16 @@ class SalesOrderTest(TestCase):
SalesOrderLineItem.objects.create(order=self.order, part=self.part)
def allocate_stock(self, full=True):
# Allocate stock to the order
SalesOrderAllocation.objects.create(
line=self.line,
item=StockItem.objects.get(pk=1),
item=StockItem.objects.get(pk=self.Sa.pk),
quantity=25)
SalesOrderAllocation.objects.create(
line=self.line,
item=StockItem.objects.get(pk=2),
item=StockItem.objects.get(pk=self.Sb.pk),
quantity=25 if full else 20
)
@ -119,15 +120,23 @@ class SalesOrderTest(TestCase):
# There should now be 4 stock items
self.assertEqual(StockItem.objects.count(), 4)
self.assertEqual(StockItem.objects.get(pk=1).quantity, 75)
self.assertEqual(StockItem.objects.get(pk=2).quantity, 175)
self.assertEqual(StockItem.objects.get(pk=3).quantity, 25)
self.assertEqual(StockItem.objects.get(pk=3).quantity, 25)
Sa = StockItem.objects.get(pk=self.Sa.pk)
Sb = StockItem.objects.get(pk=self.Sb.pk)
# 25 units subtracted from each of the original items
self.assertEqual(Sa.quantity, 75)
self.assertEqual(Sb.quantity, 175)
# And 2 items created which are associated with the order
outputs = StockItem.objects.filter(sales_order=self.order)
self.assertEqual(outputs.count(), 2)
for item in outputs.all():
self.assertEqual(item.quantity, 25)
self.assertEqual(StockItem.objects.get(pk=1).sales_order, None)
self.assertEqual(StockItem.objects.get(pk=2).sales_order, None)
self.assertEqual(StockItem.objects.get(pk=3).sales_order, self.order)
self.assertEqual(StockItem.objects.get(pk=4).sales_order, self.order)
self.assertEqual(Sa.sales_order, None)
self.assertEqual(Sb.sales_order, None)
# And no allocations
self.assertEqual(SalesOrderAllocation.objects.count(), 0)

View File

@ -2,6 +2,7 @@
# 10 x M2x4 LPHS
- model: part.bomitem
pk: 1
fields:
part: 100
sub_part: 1
@ -9,6 +10,7 @@
# 40 x R_2K2_0805
- model: part.bomitem
pk: 2
fields:
part: 100
sub_part: 3
@ -16,6 +18,7 @@
# 25 x C_22N_0805
- model: part.bomitem
pk: 3
fields:
part: 100
sub_part: 5
@ -23,6 +26,7 @@
# 3 x Orphan
- model: part.bomitem
pk: 4
fields:
part: 100
sub_part: 50

View File

@ -20,12 +20,14 @@
# And some parameters (requires part.yaml)
- model: part.PartParameter
pk: 1
fields:
part: 1
template: 1
data: 4
- model: part.PartParameter
pk: 2
fields:
part: 2
template: 1

View File

@ -38,6 +38,7 @@
- model: part.part
pk: 4
fields:
name: 'R_4K7_0603'
description: '4.7kOhm resistor in 0603 package'
@ -50,6 +51,7 @@
# Create some capacitors
- model: part.part
pk: 5
fields:
name: 'C_22N_0805'
description: '22nF capacitor in 0805 package'

View File

@ -1,25 +1,30 @@
# Tests for the top-level "chair" part
- model: part.parttesttemplate
pk: 1
fields:
part: 10000
test_name: Test strength of chair
- model: part.parttesttemplate
pk: 2
fields:
part: 10000
test_name: Apply paint
- model: part.parttesttemplate
pk: 3
fields:
part: 10000
test_name: Sew cushion
- model: part.parttesttemplate
pk: 4
fields:
part: 10000
test_name: Attach legs
- model: part.parttesttemplate
pk: 5
fields:
part: 10000
test_name: Record weight
@ -27,12 +32,14 @@
# Add some tests for one of the variants
- model: part.parttesttemplate
pk: 6
fields:
part: 10003
test_name: Check that chair is green
required: true
- model: part.parttesttemplate
pk: 7
fields:
part: 10004
test_name: Check that chair is especially green

View File

@ -2,6 +2,7 @@
# 4,000 screws in the dining room
- model: stock.stockitem
pk: 1
fields:
part: 1
location: 3
@ -14,6 +15,7 @@
# 5,000 screws in the bathroom
- model: stock.stockitem
pk: 2
fields:
part: 1
location: 2

View File

@ -1,4 +1,5 @@
- model: stock.stockitemtestresult
pk: 1
fields:
stock_item: 105
test: "Firmware Version"
@ -7,6 +8,7 @@
date: 2020-02-02
- model: stock.stockitemtestresult
pk: 2
fields:
stock_item: 105
test: "Settings Checksum"
@ -15,6 +17,7 @@
date: 2020-02-02
- model: stock.stockitemtestresult
pk: 3
fields:
stock_item: 105
test: "Temperature Test"
@ -23,6 +26,7 @@
notes: 'Got too hot or something'
- model: stock.stockitemtestresult
pk: 4
fields:
stock_item: 105
test: "Temperature Test"
@ -31,6 +35,7 @@
notes: 'Passed temperature test by making it cooler'
- model: stock.stockitemtestresult
pk: 5
fields:
stock_item: 522
test: 'applypaint'
@ -38,6 +43,7 @@
date: 2020-05-17
- model: stock.stockitemtestresult
pk: 6
fields:
stock_item: 522
test: 'applypaint'
@ -45,6 +51,7 @@
date: 2020-05-18
- model: stock.stockitemtestresult
pk: 7
fields:
stock_item: 522
test: 'Attach Legs'
@ -52,6 +59,7 @@
date: 2020-05-17
- model: stock.stockitemtestresult
pk: 8
fields:
stock_item: 522
test: 'Check that chair is GreEn '

View File

@ -21,7 +21,7 @@ class StockAPITestCase(APITestCase):
def setUp(self):
# Create a user for auth
User = get_user_model()
User.objects.create_user('testuser', 'test@testing.com', 'password')
self.user = User.objects.create_user('testuser', 'test@testing.com', 'password')
self.client.login(username='testuser', password='password')
def doPost(self, url, data={}):
@ -308,4 +308,4 @@ class StockTestResultTest(StockAPITestCase):
test = response.data[0]
self.assertEqual(test['value'], '150kPa')
self.assertEqual(test['user'], 1)
self.assertEqual(test['user'], self.user.pk)

View File

@ -174,37 +174,16 @@ def style(c):
print("Running PEP style checks...")
c.run('flake8 InvenTree')
@task(help={'database': "Database framework to use (default=sqlite)"})
@task
def test(c, database=None):
"""
Run unit-tests for InvenTree codebase.
"""
if database is None:
database = 'sqlite'
database = database.lower()
allowed = {
'sqlite': 'InvenTree.settings',
'postgresql': 'InvenTree.ci_postgresql',
'mysql': 'InvenTree.ci_mysql',
}
if database not in allowed.keys():
print("Database framework not supported for testing:")
print("Choose from: '{a}'".format(a=allowed))
return False
# Run sanity check on the django install
manage(c, 'check')
# Run coverage tests
manage(c, 'test {apps} --settings={sett}'.format(
apps=' '.join(apps()),
sett=allowed[database]
))
manage(c, 'test', pty=True)
@task
def coverage(c):