mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add tests for default location traversal
This commit is contained in:
parent
6d803d48b5
commit
ab6673caa3
@ -6,7 +6,7 @@
|
|||||||
name: Electronics
|
name: Electronics
|
||||||
description: Electronic components
|
description: Electronic components
|
||||||
parent: null
|
parent: null
|
||||||
default_location: null
|
default_location: 1 # Home
|
||||||
- model: part.partcategory
|
- model: part.partcategory
|
||||||
pk: 2
|
pk: 2
|
||||||
fields:
|
fields:
|
||||||
@ -54,3 +54,4 @@
|
|||||||
name: Fasteners
|
name: Fasteners
|
||||||
description: Screws, bolts, etc
|
description: Screws, bolts, etc
|
||||||
parent: 7
|
parent: 7
|
||||||
|
default_location: 5
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
name: 'R_4K7_0603'
|
name: 'R_4K7_0603'
|
||||||
description: '4.7kOhm resistor in 0603 package'
|
description: '4.7kOhm resistor in 0603 package'
|
||||||
category: 2
|
category: 2
|
||||||
|
default_location: 2 # Home/Bathroom
|
||||||
|
|
||||||
# Create some capacitors
|
# Create some capacitors
|
||||||
- model: part.part
|
- model: part.part
|
||||||
@ -30,3 +31,9 @@
|
|||||||
name: 'C_22N_0805'
|
name: 'C_22N_0805'
|
||||||
description: '22nF capacitor in 0805 package'
|
description: '22nF capacitor in 0805 package'
|
||||||
category: 3
|
category: 3
|
||||||
|
|
||||||
|
- model: part.part
|
||||||
|
fields:
|
||||||
|
name: 'Widget'
|
||||||
|
description: 'A watchamacallit'
|
||||||
|
category: 7
|
@ -13,6 +13,7 @@ class CategoryTest(TestCase):
|
|||||||
fixtures = [
|
fixtures = [
|
||||||
'category',
|
'category',
|
||||||
'part',
|
'part',
|
||||||
|
'location',
|
||||||
]
|
]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -104,3 +105,25 @@ class CategoryTest(TestCase):
|
|||||||
|
|
||||||
for f in fasteners:
|
for f in fasteners:
|
||||||
self.assertEqual(f.category, self.mechanical)
|
self.assertEqual(f.category, self.mechanical)
|
||||||
|
|
||||||
|
def test_default_locations(self):
|
||||||
|
""" Test traversal for default locations """
|
||||||
|
|
||||||
|
self.assertEqual(str(self.fasteners.default_location), 'Office/Drawer')
|
||||||
|
|
||||||
|
# Test that parts in this location return the same default location, too
|
||||||
|
for p in self.fasteners.children.all():
|
||||||
|
self.assert_equal(p.get_default_location(), 'Office/Drawer')
|
||||||
|
|
||||||
|
# Any part under electronics should default to 'Home'
|
||||||
|
R1 = Part.objects.get(name='R_2K2_0805')
|
||||||
|
self.assertIsNone(R1.default_location)
|
||||||
|
self.assertEqual(R1.get_default_location().name, 'Home')
|
||||||
|
|
||||||
|
# But one part has a default_location set
|
||||||
|
R2 = Part.objects.get(name='R_4K7_0603')
|
||||||
|
self.assertEqual(R2.get_default_location().name, 'Bathroom')
|
||||||
|
|
||||||
|
# And one part should have no default location at all
|
||||||
|
W = Part.objects.get(name='Widget')
|
||||||
|
self.assertIsNone(W.get_default_location())
|
31
InvenTree/stock/fixtures/location.yaml
Normal file
31
InvenTree/stock/fixtures/location.yaml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Create some locations for stock
|
||||||
|
|
||||||
|
- model: stock.stocklocation
|
||||||
|
pk: 1
|
||||||
|
fields:
|
||||||
|
name: 'Home'
|
||||||
|
description: 'My house'
|
||||||
|
- model: stock.stocklocation
|
||||||
|
pk: 2
|
||||||
|
fields:
|
||||||
|
name: 'Bathroom'
|
||||||
|
description: 'Where I keep my bath'
|
||||||
|
parent: 1
|
||||||
|
- model: stock.stocklocation
|
||||||
|
pk: 3
|
||||||
|
fields:
|
||||||
|
name: 'Dining Room'
|
||||||
|
description: 'A table lives here'
|
||||||
|
parent: 1
|
||||||
|
|
||||||
|
- model: stock.stocklocation
|
||||||
|
pk: 4
|
||||||
|
fields:
|
||||||
|
name: 'Office'
|
||||||
|
description: 'Place of work'
|
||||||
|
- model: stock.stocklocation
|
||||||
|
pk: 5
|
||||||
|
fields:
|
||||||
|
name: 'Drawer'
|
||||||
|
description: 'In my desk'
|
||||||
|
parent: 4
|
Loading…
Reference in New Issue
Block a user