More tests and improved coverage (hopefully)

This commit is contained in:
eeintech 2021-04-06 14:30:03 -04:00
parent 7b4d3a3c07
commit 52b2b9582d
3 changed files with 57 additions and 16 deletions

View File

@ -142,12 +142,6 @@ class ManufacturerPartList(generics.ListCreateAPIView):
if part is not None:
queryset = queryset.filter(part=part)
# Filter by supplier part?
supplier_part = params.get('supplier_part', None)
if supplier_part is not None:
queryset = queryset.filter(supplier_parts=supplier_part)
# Filter by 'active' status of the part?
active = params.get('active', None)

View File

@ -78,6 +78,7 @@ class ManufacturerTest(InvenTreeAPITestCase):
]
roles = [
'part.add',
'part.change',
]
@ -88,25 +89,30 @@ class ManufacturerTest(InvenTreeAPITestCase):
response = self.get(url)
self.assertEqual(len(response.data), 3)
# Create manufacturer part
data = {
'part': 1,
'manufacturer': 7,
'MPN': 'MPN_TEST',
}
response = self.client.post(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(response.data['MPN'], 'MPN_TEST')
# Filter by manufacturer
data = {'company': 7}
response = self.get(url, data)
self.assertEqual(len(response.data), 2)
self.assertEqual(len(response.data), 3)
# Filter by part
data = {'part': 5}
response = self.get(url, data)
self.assertEqual(len(response.data), 2)
# Filter by supplier part (should return only one manufacturer part)
data = {'supplier_part': 10}
response = self.get(url, data)
self.assertEqual(len(response.data), 1)
def test_manufacturer_part_detail(self):
url = reverse('api-manufacturer-part-detail', kwargs={'pk': 1})
response = self.get(url)
self.assertEqual(response.data['MPN'], 'MPN123')
# Change the MPN
@ -123,3 +129,22 @@ class ManufacturerTest(InvenTreeAPITestCase):
data = {'search': 'MPN'}
response = self.get(url, data)
self.assertEqual(len(response.data), 3)
def test_supplier_part_create(self):
url = reverse('api-supplier-part-list')
# Create supplier part
data = {
'part': 1,
'supplier': 1,
'SKU': 'SKU_TEST',
'manufacturer': 7,
'MPN': 'PART_NUMBER',
}
response = self.client.post(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
# Check manufacturer part
url = reverse('api-manufacturer-part-detail', kwargs={'pk': 5})
response = self.get(url)
self.assertEqual(response.data['MPN'], 'PART_NUMBER')

View File

@ -183,12 +183,34 @@ class ManufacturerPartSimpleTest(TestCase):
# Create a manufacturer part
self.part = Part.objects.get(pk=1)
manufacturer = Company.objects.get(pk=1)
MPN = 'MPN_TEST'
self.mp = ManufacturerPart.create(
part=self.part,
manufacturer=manufacturer,
mpn='PART_NUMBER',
description='THIS IS A MANUFACTURER PART',
)
# Create a supplier part
supplier = Company.objects.get(pk=5)
supplier_part = SupplierPart.objects.create(
part=self.part,
supplier=supplier,
SKU='SKU_TEST',
)
self.mp = ManufacturerPart.objects.create(part=self.part, manufacturer=manufacturer, MPN=MPN)
kwargs = {
'manufacturer': manufacturer.id,
'MPN': 'MPN_TEST',
}
supplier_part.save(**kwargs)
def test_exists(self):
self.assertEqual(ManufacturerPart.objects.count(), 4)
self.assertEqual(ManufacturerPart.objects.count(), 5)
# Check that manufacturer part was created from supplier part creation
manufacturer_parts = ManufacturerPart.objects.filter(manufacturer=1)
self.assertEqual(manufacturer_parts.count(), 2)
def test_delete(self):
# Remove a part