mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-02 19:50:59 +00:00
Add Metadata to more models (#4898)
* Update models: add MetadataMixin * Fix name of model in Metadata API definition * Add API endpoints * Update API version * Fix syntax * Add API endpoint for RO, RO line, RO line extra item * Add Metadata to Contacts * Fix link in API version * Fix name of model * Fix error? * Fix error? * Fix all errors, hopefully.. * Add tests for order, line, extraline metadata Extend for PO, SO * Add tests for metadata for Company-related models * Fix spelling * Consolidate metadata test for all part models into one test * Add test for all Stock metadata * Update stock test_api * Add all metadata tests for orders * Fix various errors in tests * Fix model name * Add migration files * Update tests for metadata * Resolve conflict around API version number * Rename migration file * Rename migration file * Will Contact edit endpoint work better? * Revert changes in URL definitions * Remove test, duplicate * Fix tests with fixed PK, not from fixtures, to use a dynamic PK * Fix migration overlap
This commit is contained in:
@ -1693,3 +1693,62 @@ class StockMergeTest(StockAPITestCase):
|
||||
|
||||
# Total number of stock items has been reduced!
|
||||
self.assertEqual(StockItem.objects.filter(part=self.part).count(), n - 2)
|
||||
|
||||
|
||||
class StockMetadataAPITest(InvenTreeAPITestCase):
|
||||
"""Unit tests for the various metadata endpoints of API."""
|
||||
|
||||
fixtures = [
|
||||
'category',
|
||||
'part',
|
||||
'bom',
|
||||
'company',
|
||||
'location',
|
||||
'supplier_part',
|
||||
'stock',
|
||||
'stock_tests',
|
||||
]
|
||||
|
||||
roles = [
|
||||
'stock.change',
|
||||
'stock_location.change',
|
||||
]
|
||||
|
||||
def metatester(self, apikey, model):
|
||||
"""Generic tester"""
|
||||
|
||||
modeldata = model.objects.first()
|
||||
|
||||
# Useless test unless a model object is found
|
||||
self.assertIsNotNone(modeldata)
|
||||
|
||||
url = reverse(apikey, kwargs={'pk': modeldata.pk})
|
||||
|
||||
# Metadata is initially null
|
||||
self.assertIsNone(modeldata.metadata)
|
||||
|
||||
numstr = f'12{len(apikey)}'
|
||||
|
||||
self.patch(
|
||||
url,
|
||||
{
|
||||
'metadata': {
|
||||
f'abc-{numstr}': f'xyz-{apikey}-{numstr}',
|
||||
}
|
||||
},
|
||||
expected_code=200
|
||||
)
|
||||
|
||||
# Refresh
|
||||
modeldata.refresh_from_db()
|
||||
self.assertEqual(modeldata.get_metadata(f'abc-{numstr}'), f'xyz-{apikey}-{numstr}')
|
||||
|
||||
def test_metadata(self):
|
||||
"""Test all endpoints"""
|
||||
|
||||
for apikey, model in {
|
||||
'api-location-metadata': StockLocation,
|
||||
'api-stock-test-result-metadata': StockItemTestResult,
|
||||
'api-stock-item-metadata': StockItem,
|
||||
}.items():
|
||||
self.metatester(apikey, model)
|
||||
|
Reference in New Issue
Block a user