From e298a3adbf6995a2144b4c2fad436bb2ba9bace2 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 17 Feb 2022 11:45:44 +1100 Subject: [PATCH] Implement unit test for missing columns --- InvenTree/part/test_bom_import.py | 57 +++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/InvenTree/part/test_bom_import.py b/InvenTree/part/test_bom_import.py index 7061da77ec..06ff2a79d0 100644 --- a/InvenTree/part/test_bom_import.py +++ b/InvenTree/part/test_bom_import.py @@ -145,31 +145,58 @@ class BomUploadTest(InvenTreeAPITestCase): self.assertIn('No data rows found in file', str(response.data)) - def test_something(self): + def test_missing_columns(self): + """ + Upload extracted data, but with missing columns + """ - # Add the quantity field (or close enough) - dataset.headers.append('quAntiTy ') + url = reverse('api-bom-import-extract') + + rows = [ + ['1', 'test'], + ['2', 'test'], + ] - response = self.post_bom( - 'test.csv', - bytes(dataset.csv, 'utf8'), - content_type='text/csv', + # Post without columns + response = self.post( + url, + {}, expected_code=400, ) - self.assertIn('No part column found', str(response.data)) + self.assertIn('This field is required', str(response.data['rows'])) + self.assertIn('This field is required', str(response.data['columns'])) - dataset.headers.append('part_id') - dataset.headers.append('part_name') + response = self.post( + url, + { + 'rows': rows, + 'columns': ['part', 'reference'], + }, + expected_code=400 + ) - response = self.post_bom( - 'test.csv', - bytes(dataset.csv, 'utf8'), - content_type='text/csv', + self.assertIn("Missing required column: 'quantity'", str(response.data)) + + response = self.post( + url, + { + 'rows': rows, + 'columns': ['quantity', 'reference'], + }, expected_code=400, ) - self.assertIn('No data rows found', str(response.data)) + self.assertIn('No part column specified', str(response.data)) + + response = self.post( + url, + { + 'rows': rows, + 'columns': ['quantity', 'part'], + }, + expected_code=201, + ) def test_invalid_data(self): """