Implement unit test for missing columns

This commit is contained in:
Oliver 2022-02-17 11:45:44 +11:00
parent 371af2a34a
commit e298a3adbf

View File

@ -145,31 +145,58 @@ class BomUploadTest(InvenTreeAPITestCase):
self.assertIn('No data rows found in file', str(response.data)) 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) url = reverse('api-bom-import-extract')
dataset.headers.append('quAntiTy ')
rows = [
['1', 'test'],
['2', 'test'],
]
response = self.post_bom( # Post without columns
'test.csv', response = self.post(
bytes(dataset.csv, 'utf8'), url,
content_type='text/csv', {},
expected_code=400, 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') response = self.post(
dataset.headers.append('part_name') url,
{
'rows': rows,
'columns': ['part', 'reference'],
},
expected_code=400
)
response = self.post_bom( self.assertIn("Missing required column: 'quantity'", str(response.data))
'test.csv',
bytes(dataset.csv, 'utf8'), response = self.post(
content_type='text/csv', url,
{
'rows': rows,
'columns': ['quantity', 'reference'],
},
expected_code=400, 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): def test_invalid_data(self):
""" """