Metadata api fix (#7829)

* Fix for plugin metadata view

* Add simple unit test

* Bump API version
This commit is contained in:
Oliver 2024-08-08 09:27:10 +10:00 committed by GitHub
parent 5a98d1e239
commit 1d19196632
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 4 deletions

View File

@ -1,13 +1,16 @@
"""InvenTree API version information."""
# InvenTree API version
INVENTREE_API_VERSION = 233
INVENTREE_API_VERSION = 234
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """
v234 - 2024-08-08 : https://github.com/inventree/InvenTree/pull/7829
- Fixes bug in the plugin metadata endpoint
v233 - 2024-08-04 : https://github.com/inventree/InvenTree/pull/7807
- Adds new endpoints for managing state of build orders
- Adds new endpoints for managing state of purchase orders

View File

@ -414,6 +414,13 @@ class RegistryStatusView(APIView):
return Response(result)
class PluginMetadataView(MetadataView):
"""Metadata API endpoint for the PluginConfig model."""
lookup_field = 'key'
lookup_url_kwarg = 'plugin'
plugin_api_urls = [
path('action/', ActionPluginView.as_view(), name='api-action-plugin'),
path('barcode/', include(barcode_api_urls)),
@ -438,7 +445,7 @@ plugin_api_urls = [
)
]),
),
# Lookup for individual plugins (based on 'key', not 'pk')
# Lookup for individual plugins (based on 'plugin', not 'pk')
path(
'<str:plugin>/',
include([
@ -459,7 +466,7 @@ plugin_api_urls = [
),
path(
'metadata/',
MetadataView.as_view(),
PluginMetadataView.as_view(),
{'model': PluginConfig, 'lookup_field': 'key'},
name='api-plugin-metadata',
),

View File

@ -233,7 +233,7 @@ class PluginDetailAPITest(PluginMixin, InvenTreeAPITestCase):
# Activate the 'sample' plugin via the API
cfg = PluginConfig.objects.filter(key='sample').first()
assert cfg is not None
self.assertIsNotNone(cfg)
url = reverse('api-plugin-detail-activate', kwargs={'plugin': cfg.key})
self.client.patch(url, {}, expected_code=200)
@ -292,3 +292,14 @@ class PluginDetailAPITest(PluginMixin, InvenTreeAPITestCase):
)
self.assertEqual(response.data['value'], '456')
def test_plugin_metadata(self):
"""Test metadata endpoint for plugin."""
self.user.is_superuser = True
self.user.save()
cfg = PluginConfig.objects.filter(key='sample').first()
self.assertIsNotNone(cfg)
url = reverse('api-plugin-metadata', kwargs={'plugin': cfg.key})
self.get(url, expected_code=200)