Add unit test for downloading Part data

This commit is contained in:
Oliver Walters 2022-05-18 07:52:29 +10:00
parent 1c6d79451e
commit b6c2ade940
3 changed files with 55 additions and 1 deletions

View File

@ -989,7 +989,7 @@ class SalesOrderDownloadTest(OrderTest):
},
expected_code=200,
expected_fn='InvenTree_SalesOrders.xls',
deode=False,
decode=False,
) as fo:
self.assertTrue(isinstance(fo, io.BytesIO))

View File

@ -45,6 +45,7 @@ class PartResource(ModelResource):
exclude = [
'bom_checksum', 'bom_checked_by', 'bom_checked_date',
'lft', 'rght', 'tree_id', 'level',
'metadata',
]
def get_queryset(self):
@ -98,6 +99,7 @@ class PartCategoryResource(ModelResource):
exclude = [
# Exclude MPTT internal model fields
'lft', 'rght', 'tree_id', 'level',
'metadata',
]
def after_import(self, dataset, result, using_transactions, dry_run, **kwargs):

View File

@ -822,6 +822,58 @@ class PartAPITest(InvenTreeAPITestCase):
response = self.get('/api/part/10004/', {})
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):
"""