InvenTree/InvenTree/part/test_part.py

39 lines
1.3 KiB
Python
Raw Normal View History

2019-04-24 14:59:34 +00:00
from django.test import TestCase
import os
2019-04-24 14:59:34 +00:00
from .models import Part, PartCategory
from .models import rename_part_image
2019-04-24 14:59:34 +00:00
2019-04-24 17:20:25 +00:00
2019-04-24 14:59:34 +00:00
class SimplePartTest(TestCase):
def setUp(self):
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)
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')
def test_category(self):
self.assertEqual(self.px.category_path, '')
2019-04-24 17:20:25 +00:00
self.assertEqual(self.pz.category_path, 'TLC')
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.pz, 'test')
self.assertEqual(img, os.path.join('part_images', 'part_3_img'))
def test_stock(self):
# Stock should initially be zero
self.assertEqual(self.px.total_stock, 0)
2019-04-25 08:50:22 +00:00
self.assertEqual(self.py.available_stock, 0)