mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Improve unit testing
This commit is contained in:
parent
e298a3adbf
commit
47f6b709c9
@ -780,7 +780,7 @@ class BomImportExtractSerializer(DataFileExtractSerializer):
|
|||||||
row['errors']['part'] = _('No matching part found')
|
row['errors']['part'] = _('No matching part found')
|
||||||
else:
|
else:
|
||||||
if not part.component:
|
if not part.component:
|
||||||
row['errors']['part'] = _('Part is not designed as a component')
|
row['errors']['part'] = _('Part is not designated as a component')
|
||||||
|
|
||||||
# Update the 'part' value in the row
|
# Update the 'part' value in the row
|
||||||
row['part'] = part.pk if part is not None else None
|
row['part'] = part.pk if part is not None else None
|
||||||
|
@ -218,25 +218,31 @@ class BomUploadTest(InvenTreeAPITestCase):
|
|||||||
|
|
||||||
dataset.append([cmp.pk, idx])
|
dataset.append([cmp.pk, idx])
|
||||||
|
|
||||||
# Add a duplicate part too
|
url = reverse('api-bom-import-extract')
|
||||||
dataset.append([components.first().pk, 'invalid'])
|
|
||||||
|
|
||||||
response = self.post_bom(
|
response = self.post(
|
||||||
'test.csv',
|
url,
|
||||||
bytes(dataset.csv, 'utf8'),
|
{
|
||||||
content_type='text/csv',
|
'columns': dataset.headers,
|
||||||
expected_code=201
|
'rows': [row for row in dataset],
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
errors = response.data['errors']
|
rows = response.data['rows']
|
||||||
|
|
||||||
self.assertIn('Quantity must be greater than zero', str(errors[0]))
|
# Returned data must be the same as the original dataset
|
||||||
self.assertIn('Part is not designated as a component', str(errors[5]))
|
self.assertEqual(len(rows), len(dataset))
|
||||||
self.assertIn('Duplicate part selected', str(errors[-1]))
|
|
||||||
self.assertIn('Invalid quantity', str(errors[-1]))
|
|
||||||
|
|
||||||
for idx, row in enumerate(response.data['rows'][:-1]):
|
for idx, row in enumerate(rows):
|
||||||
self.assertEqual(str(row['part']), str(components[idx].pk))
|
data = row['data']
|
||||||
|
cmp = components[idx]
|
||||||
|
|
||||||
|
# Should have guessed the correct part
|
||||||
|
data['part'] = cmp.pk
|
||||||
|
|
||||||
|
# Check some specific error messages
|
||||||
|
self.assertEqual(rows[0]['data']['errors']['quantity'], 'Quantity must be greater than zero')
|
||||||
|
self.assertEqual(rows[5]['data']['errors']['part'], 'Part is not designated as a component')
|
||||||
|
|
||||||
def test_part_guess(self):
|
def test_part_guess(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user