More test

This commit is contained in:
Oliver Walters 2019-09-08 20:36:51 +10:00
parent 2a203be5cc
commit e4fc44c135
5 changed files with 26 additions and 15 deletions

View File

@ -59,4 +59,8 @@
name: 'Bob'
description: 'Can we build it?'
assembly: true
purchaseable: false
purchaseable: false
category: 7
active: False
IPN: BOB
revision: A2

View File

@ -265,17 +265,9 @@ class Part(models.Model):
def set_category(self, category):
if not type(category) == PartCategory:
raise ValidationError({
'category': _('Invalid object supplied to part.set_category')
})
try:
# Already in this category!
if category == self.category:
return
except PartCategory.DoesNotExist:
pass
# Ignore if the category is already the same
if self.category == category:
return
self.category = category
self.save()

View File

@ -19,7 +19,7 @@ class BomItemTest(TestCase):
def test_str(self):
b = BomItem.objects.get(id=1)
self.assertEqual(str(b), '10 x M2x4 LPHS to make Bob')
self.assertEqual(str(b), '10 x M2x4 LPHS to make BOB | Bob | A2')
def test_has_bom(self):
self.assertFalse(self.orphan.has_bom)

View File

@ -87,6 +87,12 @@ class CategoryTest(TestCase):
self.assertEqual(self.electronics.partcount(), 3)
self.assertEqual(self.mechanical.partcount(), 4)
self.assertEqual(self.mechanical.partcount(active=True), 3)
self.assertEqual(self.mechanical.partcount(False), 2)
self.assertEqual(self.electronics.item_count, self.electronics.partcount())
def test_delete(self):
""" Test that category deletion moves the children properly """

View File

@ -8,7 +8,7 @@ from django.test import TestCase
import os
from .models import Part
from .models import rename_part_image
from .models import rename_part_image, match_part_names
from .templatetags import inventree_extras
@ -44,6 +44,10 @@ class PartTest(TestCase):
self.C1 = Part.objects.get(name='C_22N_0805')
def test_str(self):
p = Part.objects.get(pk=100)
self.assertEqual(str(p), "BOB | Bob | A2 - Can we build it?")
def test_metadata(self):
self.assertEqual(self.R1.name, 'R_2K2_0805')
self.assertEqual(self.R1.get_absolute_url(), '/part/3/')
@ -75,5 +79,10 @@ class PartTest(TestCase):
self.assertIn(self.R1.name, barcode)
def test_copy(self):
self.R2.deepCopy(self.R1, image=True, bom=True)
def test_match_names(self):
matches = match_part_names('M2x5 LPHS')
self.assertTrue(len(matches) > 0)