mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Simple and View test units
This commit is contained in:
parent
94574b37ae
commit
bb69e38c1a
@ -31,3 +31,17 @@
|
|||||||
name: Another customer!
|
name: Another customer!
|
||||||
description: Yet another company
|
description: Yet another company
|
||||||
is_customer: True
|
is_customer: True
|
||||||
|
|
||||||
|
- model: company.company
|
||||||
|
pk: 6
|
||||||
|
fields:
|
||||||
|
name: A manufacturer
|
||||||
|
description: A company that makes parts!
|
||||||
|
is_manufacturer: True
|
||||||
|
|
||||||
|
- model: company.company
|
||||||
|
pk: 7
|
||||||
|
fields:
|
||||||
|
name: Another manufacturer
|
||||||
|
description: They build things and sell it to us
|
||||||
|
is_manufacturer: True
|
||||||
|
22
InvenTree/company/fixtures/manufacturer_part.yaml
Normal file
22
InvenTree/company/fixtures/manufacturer_part.yaml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Manufacturer Parts
|
||||||
|
|
||||||
|
- model: company.manufacturerpart
|
||||||
|
pk: 1
|
||||||
|
fields:
|
||||||
|
part: 5
|
||||||
|
manufacturer: 6
|
||||||
|
MPN: 'MPN123'
|
||||||
|
|
||||||
|
- model: company.manufacturerpart
|
||||||
|
pk: 2
|
||||||
|
fields:
|
||||||
|
part: 3
|
||||||
|
manufacturer: 7
|
||||||
|
MPN: 'MPN456'
|
||||||
|
|
||||||
|
- model: company.manufacturerpart
|
||||||
|
pk: 3
|
||||||
|
fields:
|
||||||
|
part: 5
|
||||||
|
manufacturer: 7
|
||||||
|
MPN: 'MPN789'
|
@ -52,3 +52,20 @@
|
|||||||
part: 2
|
part: 2
|
||||||
supplier: 2
|
supplier: 2
|
||||||
SKU: 'ZERGM312'
|
SKU: 'ZERGM312'
|
||||||
|
|
||||||
|
# Supplier parts linked to Manufacturer parts
|
||||||
|
- model: company.supplierpart
|
||||||
|
pk: 10
|
||||||
|
fields:
|
||||||
|
part: 3
|
||||||
|
manufacturer_part: 2
|
||||||
|
supplier: 2
|
||||||
|
SKU: 'MPN456-APPEL'
|
||||||
|
|
||||||
|
- model: company.supplierpart
|
||||||
|
pk: 11
|
||||||
|
fields:
|
||||||
|
part: 3
|
||||||
|
manufacturer_part: 2
|
||||||
|
supplier: 3
|
||||||
|
SKU: 'MPN456-ZERG'
|
||||||
|
@ -10,6 +10,7 @@ from django.urls import reverse
|
|||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
|
|
||||||
|
from .models import ManufacturerPart
|
||||||
from .models import SupplierPart
|
from .models import SupplierPart
|
||||||
|
|
||||||
|
|
||||||
@ -20,6 +21,7 @@ class CompanyViewTestBase(TestCase):
|
|||||||
'part',
|
'part',
|
||||||
'location',
|
'location',
|
||||||
'company',
|
'company',
|
||||||
|
'manufacturer_part',
|
||||||
'supplier_part',
|
'supplier_part',
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -200,3 +202,65 @@ class CompanyViewTest(CompanyViewTestBase):
|
|||||||
|
|
||||||
response = self.client.get(reverse('customer-create'), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
response = self.client.get(reverse('customer-create'), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||||
self.assertContains(response, 'Create new Customer')
|
self.assertContains(response, 'Create new Customer')
|
||||||
|
|
||||||
|
|
||||||
|
class ManufacturerPartViewTests(CompanyViewTestBase):
|
||||||
|
"""
|
||||||
|
Tests for the ManufacturerPart views.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_manufacturer_part_create(self):
|
||||||
|
"""
|
||||||
|
Test the ManufacturerPartCreate view.
|
||||||
|
"""
|
||||||
|
|
||||||
|
url = reverse('manufacturer-part-create')
|
||||||
|
|
||||||
|
# First check that we can GET the form
|
||||||
|
response = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# How many supplier parts are already in the database?
|
||||||
|
n = ManufacturerPart.objects.all().count()
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'part': 1,
|
||||||
|
'manufacturer': 6,
|
||||||
|
}
|
||||||
|
|
||||||
|
# MPN is required! (form should fail)
|
||||||
|
(response, errors) = self.post(url, data, valid=False)
|
||||||
|
|
||||||
|
self.assertIsNotNone(errors.get('MPN', None))
|
||||||
|
|
||||||
|
data['MPN'] = 'TEST-ME-123'
|
||||||
|
|
||||||
|
(response, errors) = self.post(url, data, valid=True)
|
||||||
|
|
||||||
|
# Check that the ManufacturerPart was created!
|
||||||
|
self.assertEqual(n + 1, ManufacturerPart.objects.all().count())
|
||||||
|
|
||||||
|
def test_manufacturer_part_delete(self):
|
||||||
|
"""
|
||||||
|
Test the ManufacturerPartDelete view
|
||||||
|
"""
|
||||||
|
|
||||||
|
url = reverse('manufacturer-part-delete')
|
||||||
|
|
||||||
|
# Get form using 'part' argument
|
||||||
|
response = self.client.get(url, {'part': '5'}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# POST to delete manufacturer part
|
||||||
|
n = ManufacturerPart.objects.count()
|
||||||
|
response = self.client.post(
|
||||||
|
url,
|
||||||
|
{
|
||||||
|
'manufacturer-part-2': 'manufacturer-part-2',
|
||||||
|
'confirm_delete': True
|
||||||
|
},
|
||||||
|
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
self.assertEqual(n - 1, ManufacturerPart.objects.count())
|
||||||
|
@ -6,7 +6,7 @@ from django.core.exceptions import ValidationError
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from .models import Company, Contact, SupplierPart
|
from .models import Company, Contact, ManufacturerPart, SupplierPart
|
||||||
from .models import rename_company_image
|
from .models import rename_company_image
|
||||||
from part.models import Part
|
from part.models import Part
|
||||||
|
|
||||||
@ -22,6 +22,7 @@ class CompanySimpleTest(TestCase):
|
|||||||
'part',
|
'part',
|
||||||
'location',
|
'location',
|
||||||
'bom',
|
'bom',
|
||||||
|
'manufacturer_part',
|
||||||
'supplier_part',
|
'supplier_part',
|
||||||
'price_breaks',
|
'price_breaks',
|
||||||
]
|
]
|
||||||
@ -74,10 +75,10 @@ class CompanySimpleTest(TestCase):
|
|||||||
self.assertEqual(acme.supplied_part_count, 4)
|
self.assertEqual(acme.supplied_part_count, 4)
|
||||||
|
|
||||||
self.assertTrue(appel.has_parts)
|
self.assertTrue(appel.has_parts)
|
||||||
self.assertEqual(appel.supplied_part_count, 2)
|
self.assertEqual(appel.supplied_part_count, 3)
|
||||||
|
|
||||||
self.assertTrue(zerg.has_parts)
|
self.assertTrue(zerg.has_parts)
|
||||||
self.assertEqual(zerg.supplied_part_count, 1)
|
self.assertEqual(zerg.supplied_part_count, 2)
|
||||||
|
|
||||||
def test_price_breaks(self):
|
def test_price_breaks(self):
|
||||||
|
|
||||||
@ -166,3 +167,31 @@ class ContactSimpleTest(TestCase):
|
|||||||
# Remove the parent company
|
# Remove the parent company
|
||||||
Company.objects.get(pk=self.c.pk).delete()
|
Company.objects.get(pk=self.c.pk).delete()
|
||||||
self.assertEqual(Contact.objects.count(), 0)
|
self.assertEqual(Contact.objects.count(), 0)
|
||||||
|
|
||||||
|
|
||||||
|
class ManufacturerPartSimpleTest(TestCase):
|
||||||
|
|
||||||
|
fixtures = [
|
||||||
|
'category',
|
||||||
|
'company',
|
||||||
|
'location',
|
||||||
|
'part',
|
||||||
|
'manufacturer_part',
|
||||||
|
]
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
# Create a manufacturer part
|
||||||
|
self.part = Part.objects.get(pk=1)
|
||||||
|
manufacturer = Company.objects.get(pk=1)
|
||||||
|
MPN = 'MPN_TEST'
|
||||||
|
|
||||||
|
self.mp = ManufacturerPart.objects.create(part=self.part, manufacturer=manufacturer, MPN=MPN)
|
||||||
|
|
||||||
|
def test_exists(self):
|
||||||
|
self.assertEqual(ManufacturerPart.objects.count(), 4)
|
||||||
|
|
||||||
|
def test_delete(self):
|
||||||
|
# Remove a part
|
||||||
|
Part.objects.get(pk=self.part.id).delete()
|
||||||
|
# Check that ManufacturerPart was deleted
|
||||||
|
self.assertEqual(ManufacturerPart.objects.count(), 3)
|
||||||
|
Loading…
Reference in New Issue
Block a user