From 2ab827667287664fc62dc253a9e69f19aa7c747e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 25 Apr 2019 17:51:02 +1000 Subject: [PATCH] better coverage for part/models - Increase from 57% to 67% --- InvenTree/part/test_category.py | 10 ++++++++++ InvenTree/part/test_part.py | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/InvenTree/part/test_category.py b/InvenTree/part/test_category.py index bebe2c96ac..4d2a5b4441 100644 --- a/InvenTree/part/test_category.py +++ b/InvenTree/part/test_category.py @@ -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) diff --git a/InvenTree/part/test_part.py b/InvenTree/part/test_part.py index c9ed2fd7b3..adb2a76413 100644 --- a/InvenTree/part/test_part.py +++ b/InvenTree/part/test_part.py @@ -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) \ No newline at end of file