mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 20:46:47 +00:00
Add unit test for downloading Part data
This commit is contained in:
parent
1c6d79451e
commit
b6c2ade940
@ -989,7 +989,7 @@ class SalesOrderDownloadTest(OrderTest):
|
|||||||
},
|
},
|
||||||
expected_code=200,
|
expected_code=200,
|
||||||
expected_fn='InvenTree_SalesOrders.xls',
|
expected_fn='InvenTree_SalesOrders.xls',
|
||||||
deode=False,
|
decode=False,
|
||||||
) as fo:
|
) as fo:
|
||||||
self.assertTrue(isinstance(fo, io.BytesIO))
|
self.assertTrue(isinstance(fo, io.BytesIO))
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ class PartResource(ModelResource):
|
|||||||
exclude = [
|
exclude = [
|
||||||
'bom_checksum', 'bom_checked_by', 'bom_checked_date',
|
'bom_checksum', 'bom_checked_by', 'bom_checked_date',
|
||||||
'lft', 'rght', 'tree_id', 'level',
|
'lft', 'rght', 'tree_id', 'level',
|
||||||
|
'metadata',
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
@ -98,6 +99,7 @@ class PartCategoryResource(ModelResource):
|
|||||||
exclude = [
|
exclude = [
|
||||||
# Exclude MPTT internal model fields
|
# Exclude MPTT internal model fields
|
||||||
'lft', 'rght', 'tree_id', 'level',
|
'lft', 'rght', 'tree_id', 'level',
|
||||||
|
'metadata',
|
||||||
]
|
]
|
||||||
|
|
||||||
def after_import(self, dataset, result, using_transactions, dry_run, **kwargs):
|
def after_import(self, dataset, result, using_transactions, dry_run, **kwargs):
|
||||||
|
@ -822,6 +822,58 @@ class PartAPITest(InvenTreeAPITestCase):
|
|||||||
response = self.get('/api/part/10004/', {})
|
response = self.get('/api/part/10004/', {})
|
||||||
self.assertEqual(response.data['variant_stock'], 500)
|
self.assertEqual(response.data['variant_stock'], 500)
|
||||||
|
|
||||||
|
def test_part_download(self):
|
||||||
|
"""Test download of part data via the API"""
|
||||||
|
|
||||||
|
url = reverse('api-part-list')
|
||||||
|
|
||||||
|
required_cols = [
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'in_stock',
|
||||||
|
'category_name',
|
||||||
|
'keywords',
|
||||||
|
'is_template',
|
||||||
|
'virtual',
|
||||||
|
'trackable',
|
||||||
|
'active',
|
||||||
|
'notes',
|
||||||
|
'creation_date',
|
||||||
|
]
|
||||||
|
|
||||||
|
excluded_cols = [
|
||||||
|
'lft', 'rght', 'level', 'tree_id',
|
||||||
|
'metadata',
|
||||||
|
]
|
||||||
|
|
||||||
|
with self.download_file(
|
||||||
|
url,
|
||||||
|
{
|
||||||
|
'export': 'csv',
|
||||||
|
},
|
||||||
|
expected_fn='InvenTree_Parts.csv',
|
||||||
|
) as fo:
|
||||||
|
|
||||||
|
data = self.process_csv(
|
||||||
|
fo,
|
||||||
|
excluded_cols=excluded_cols,
|
||||||
|
required_cols=required_cols,
|
||||||
|
required_rows=Part.objects.count(),
|
||||||
|
)
|
||||||
|
|
||||||
|
for row in data:
|
||||||
|
part = Part.objects.get(pk=row['id'])
|
||||||
|
|
||||||
|
if part.IPN:
|
||||||
|
self.assertEqual(part.IPN, row['IPN'])
|
||||||
|
|
||||||
|
self.assertEqual(part.name, row['name'])
|
||||||
|
self.assertEqual(part.description, row['description'])
|
||||||
|
|
||||||
|
if part.category:
|
||||||
|
self.assertEqual(part.category.name, row['category_name'])
|
||||||
|
|
||||||
|
|
||||||
class PartDetailTests(InvenTreeAPITestCase):
|
class PartDetailTests(InvenTreeAPITestCase):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user