2019-04-24 14:59:34 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
|
2019-04-25 07:51:02 +00:00
|
|
|
import os
|
|
|
|
|
2019-04-24 14:59:34 +00:00
|
|
|
from .models import Part, PartCategory
|
2019-04-25 07:51:02 +00:00
|
|
|
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')
|
2019-04-25 07:51:02 +00:00
|
|
|
|
|
|
|
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)
|