diff --git a/InvenTree/company/tests.py b/InvenTree/company/tests.py index 925d9eb104..e5f5d99869 100644 --- a/InvenTree/company/tests.py +++ b/InvenTree/company/tests.py @@ -1,6 +1,9 @@ from django.test import TestCase -from .models import Company +import os + +from .models import Company, Contact +from .models import rename_company_image class CompanySimpleTest(TestCase): @@ -16,4 +19,43 @@ class CompanySimpleTest(TestCase): def test_company_model(self): c = Company.objects.get(pk=1) self.assertEqual(c.name, 'ABC Co.') + self.assertEqual(str(c), 'ABC Co. - Seller of ABC products') + + def test_company_url(self): + c = Company.objects.get(pk=1) self.assertEqual(c.get_absolute_url(), '/company/1/') + + def test_image_renamer(self): + c = Company.objects.get(pk=1) + rn = rename_company_image(c, 'test.png') + self.assertEqual(rn, 'company_images' + os.path.sep + 'company_1_img.png') + + rn = rename_company_image(c, 'test2') + self.assertEqual(rn, 'company_images' + os.path.sep + 'company_1_img') + + def test_part_count(self): + # Initially the company should have no associated parts + c = Company.objects.get(pk=1) + self.assertEqual(c.has_parts, False) + + # TODO - Add some supplier parts here + + +class ContactSimpleTest(TestCase): + + def setUp(self): + # Create a simple company + c = Company.objects.create(name='Test Corp.', description='We make stuff good') + + # Add some contacts + Contact.objects.create(name='Joe Smith', company=c) + Contact.objects.create(name='Fred Smith', company=c) + Contact.objects.create(name='Sally Smith', company=c) + + def test_exists(self): + self.assertEqual(Contact.objects.count(), 3) + + def test_delete(self): + # Remove the parent company + Company.objects.get(pk=1).delete() + self.assertEqual(Contact.objects.count(), 0) diff --git a/Makefile b/Makefile index 8db2a2110c..dadbb44999 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ style: test: python InvenTree/manage.py check - python manage.py test build company part stock + python InvenTree/manage.py test build company part stock migrate: python InvenTree/manage.py makemigrations company