better coverage for part/models

- Increase from 57% to 67%
This commit is contained in:
Oliver Walters 2019-04-25 17:51:02 +10:00
parent f36f02b27f
commit 2ab8276672
2 changed files with 25 additions and 0 deletions

View File

@ -64,3 +64,13 @@ class CategoryTest(TestCase):
self.assertEqual(self.p1.partcount, 3)
self.assertEqual(self.p2.partcount, 3)
self.assertEqual(self.p3.partcount, 1)
def test_delete(self):
self.assertEqual(Part.objects.filter(category=self.p1).count(), 0)
# Delete p2 (it has 2 direct parts and one child category)
self.p2.delete()
self.assertEqual(Part.objects.filter(category=self.p1).count(), 2)
self.assertEqual(PartCategory.objects.get(pk=self.p3.id).parent, self.p1)

View File

@ -1,6 +1,9 @@
from django.test import TestCase
import os
from .models import Part, PartCategory
from .models import rename_part_image
class SimplePartTest(TestCase):
@ -21,3 +24,15 @@ class SimplePartTest(TestCase):
def test_category(self):
self.assertEqual(self.px.category_path, '')
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)
self.assertEqual(self.py.available_stock, 0)