mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
100% coverage on company/models.py
This commit is contained in:
parent
19001b98f7
commit
3c40418f04
@ -1,6 +1,9 @@
|
|||||||
from django.test import TestCase
|
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):
|
class CompanySimpleTest(TestCase):
|
||||||
@ -16,4 +19,43 @@ class CompanySimpleTest(TestCase):
|
|||||||
def test_company_model(self):
|
def test_company_model(self):
|
||||||
c = Company.objects.get(pk=1)
|
c = Company.objects.get(pk=1)
|
||||||
self.assertEqual(c.name, 'ABC Co.')
|
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/')
|
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)
|
||||||
|
2
Makefile
2
Makefile
@ -12,7 +12,7 @@ style:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
python InvenTree/manage.py check
|
python InvenTree/manage.py check
|
||||||
python manage.py test build company part stock
|
python InvenTree/manage.py test build company part stock
|
||||||
|
|
||||||
migrate:
|
migrate:
|
||||||
python InvenTree/manage.py makemigrations company
|
python InvenTree/manage.py makemigrations company
|
||||||
|
Loading…
x
Reference in New Issue
Block a user