mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Convert test_part to use fixture data
This commit is contained in:
parent
663cc269b4
commit
3fda5a3925
@ -2,37 +2,42 @@ from django.test import TestCase
|
||||
|
||||
import os
|
||||
|
||||
from .models import Part, PartCategory
|
||||
from .models import Part
|
||||
from .models import rename_part_image
|
||||
|
||||
|
||||
class SimplePartTest(TestCase):
|
||||
""" Tests for the Part model """
|
||||
|
||||
fixtures = [
|
||||
'category',
|
||||
'part',
|
||||
'location',
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
self.R1 = Part.objects.get(name='R_2K2_0805')
|
||||
self.R2 = Part.objects.get(name='R_4K7_0603')
|
||||
|
||||
cat = PartCategory.objects.create(name='TLC', description='Top level category')
|
||||
|
||||
self.px = Part.objects.create(name='x', description='A part called x', buildable=True)
|
||||
self.py = Part.objects.create(name='y', description='A part called y', consumable=False)
|
||||
self.pz = Part.objects.create(name='z', description='A part called z', category=cat)
|
||||
self.C1 = Part.objects.get(name='C_22N_0805')
|
||||
|
||||
def test_metadata(self):
|
||||
self.assertEqual(self.px.name, 'x')
|
||||
self.assertEqual(self.py.get_absolute_url(), '/part/2/')
|
||||
self.assertEqual(str(self.pz), 'z - A part called z')
|
||||
self.assertEqual(self.R1.name, 'R_2K2_0805')
|
||||
self.assertEqual(self.R1.get_absolute_url(), '/part/3/')
|
||||
|
||||
def test_category(self):
|
||||
self.assertEqual(self.px.category_path, '')
|
||||
self.assertEqual(self.pz.category_path, 'TLC')
|
||||
self.assertEqual(str(self.C1.category), 'Electronics/Capacitors')
|
||||
|
||||
def test_rename_img(self):
|
||||
img = rename_part_image(self.px, 'hello.png')
|
||||
self.assertEqual(img, os.path.join('part_images', 'part_1_img.png'))
|
||||
img = rename_part_image(self.R1, 'hello.png')
|
||||
self.assertEqual(img, os.path.join('part_images', 'part_3_img.png'))
|
||||
|
||||
img = rename_part_image(self.pz, 'test')
|
||||
self.assertEqual(img, os.path.join('part_images', 'part_3_img'))
|
||||
img = rename_part_image(self.R2, 'test')
|
||||
self.assertEqual(img, os.path.join('part_images', 'part_4_img'))
|
||||
|
||||
def test_stock(self):
|
||||
# Stock should initially be zero
|
||||
self.assertEqual(self.px.total_stock, 0)
|
||||
self.assertEqual(self.py.available_stock, 0)
|
||||
# No stock of any resistors
|
||||
res = Part.objects.filter(description__contains='resistor')
|
||||
for r in res:
|
||||
self.assertEqual(r.total_stock, 0)
|
||||
self.assertEqual(r.available_stock, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user