fix docstrings 6

This commit is contained in:
Matthias 2022-05-28 02:57:42 +02:00
parent 391c8b4ac1
commit bd4da62964
No known key found for this signature in database
GPG Key ID: AB6D0E6C4CB65093
12 changed files with 56 additions and 113 deletions

View File

@ -1,6 +1,4 @@
"""
Utility file to enable simper imports
"""
"""Utility file to enable simper imports"""
from .helpers import MixinImplementationError, MixinNotImplementedError
from .plugin import IntegrationPluginBase, InvenTreePlugin

View File

@ -1,4 +1,5 @@
"""APIs for action plugins"""
from django.utils.translation import gettext_lazy as _
from rest_framework import permissions
@ -9,9 +10,7 @@ from plugin import registry
class ActionPluginView(APIView):
"""
Endpoint for running custom action plugins.
"""
"""Endpoint for running custom action plugins."""
permission_classes = [
permissions.IsAuthenticated,

View File

@ -1,18 +1,14 @@
"""
Plugin mixin classes for action plugin
"""
"""Plugin mixin classes for action plugin"""
class ActionMixin:
"""
Mixin that enables custom actions
"""
"""Mixin that enables custom actions"""
ACTION_NAME = ""
class MixinMeta:
"""
meta options for this mixin
"""
"""Meta options for this mixin"""
MIXIN_NAME = 'Actions'
def __init__(self):
@ -20,8 +16,7 @@ class ActionMixin:
self.add_mixin('action', True, __class__)
def action_name(self):
"""
Action name for this plugin.
"""Action name for this plugin.
If the ACTION_NAME parameter is empty,
uses the NAME instead.
@ -31,28 +26,22 @@ class ActionMixin:
return self.name
def perform_action(self, user=None, data=None):
"""
Override this method to perform the action!
"""
"""Override this method to perform the action!"""
def get_result(self, user=None, data=None):
"""
Result of the action?
"""
"""Result of the action?"""
# Re-implement this for cutsom actions
return False
def get_info(self, user=None, data=None):
"""
Extra info? Can be a string / dict / etc
"""
"""Extra info? Can be a string / dict / etc"""
return None
def get_response(self, user=None, data=None):
"""
Return a response. Default implementation is a simple response
which can be overridden.
"""Return a response.
Default implementation is a simple response which can be overridden.
"""
return {
"action": self.action_name(),

View File

@ -1,4 +1,4 @@
""" Unit tests for action plugins """
"""Unit tests for action plugins"""
from django.test import TestCase
@ -8,7 +8,8 @@ from plugin.mixins import ActionMixin
class ActionMixinTests(TestCase):
""" Tests for ActionMixin """
"""Tests for ActionMixin"""
ACTION_RETURN = 'a action was performed'
def setUp(self):
@ -17,7 +18,7 @@ class ActionMixinTests(TestCase):
self.plugin = SimplePlugin()
class TestActionPlugin(ActionMixin, InvenTreePlugin):
"""a action plugin"""
"""An action plugin"""
ACTION_NAME = 'abc123'
def perform_action(self, user=None, data=None):
@ -37,13 +38,13 @@ class ActionMixinTests(TestCase):
self.action_name = NameActionPlugin()
def test_action_name(self):
"""check the name definition possibilities"""
"""Check the name definition possibilities"""
self.assertEqual(self.plugin.action_name(), '')
self.assertEqual(self.action_plugin.action_name(), 'abc123')
self.assertEqual(self.action_name.action_name(), 'Aplugin')
def test_function(self):
"""check functions"""
"""Check functions"""
# the class itself
self.assertIsNone(self.plugin.perform_action())
self.assertEqual(self.plugin.get_result(), False)
@ -66,11 +67,10 @@ class ActionMixinTests(TestCase):
class APITests(InvenTreeTestCase):
""" Tests for action api """
"""Tests for action api"""
def test_post_errors(self):
"""Check the possible errors with post"""
# Test empty request
response = self.client.post('/api/action/')
self.assertEqual(response.status_code, 200)

View File

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
from django.urls import path, re_path, reverse
from django.utils.translation import gettext_lazy as _
@ -15,8 +15,7 @@ from stock.serializers import StockItemSerializer
class BarcodeScan(APIView):
"""
Endpoint for handling generic barcode scan requests.
"""Endpoint for handling generic barcode scan requests.
Barcode data are decoded by the client application,
and sent to this endpoint (as a JSON object) for validation.
@ -42,10 +41,7 @@ class BarcodeScan(APIView):
]
def post(self, request, *args, **kwargs):
"""
Respond to a barcode POST request
"""
"""Respond to a barcode POST request"""
data = request.data
if 'barcode' not in data:
@ -133,8 +129,7 @@ class BarcodeScan(APIView):
class BarcodeAssign(APIView):
"""
Endpoint for assigning a barcode to a stock item.
"""Endpoint for assigning a barcode to a stock item.
- This only works if the barcode is not already associated with an object in the database
- If the barcode does not match an object, then the barcode hash is assigned to the StockItem

View File

@ -1,5 +1,4 @@
"""
Registry for loading and managing multiple plugins at run-time
"""Registry for loading and managing multiple plugins at run-time
- Holds the class and the object that contains all code to maintain plugin states
- Manages setup and teardown of plugin class instances

View File

@ -1,6 +1,4 @@
"""
JSON serializers for plugin app
"""
"""JSON serializers for plugin app"""
import os
import subprocess
@ -17,9 +15,7 @@ from plugin.models import NotificationUserSetting, PluginConfig, PluginSetting
class MetadataSerializer(serializers.ModelSerializer):
"""
Serializer class for model metadata API access.
"""
"""Serializer class for model metadata API access."""
metadata = serializers.JSONField(required=True)
@ -45,9 +41,7 @@ class MetadataSerializer(serializers.ModelSerializer):
class PluginConfigSerializer(serializers.ModelSerializer):
"""
Serializer for a PluginConfig:
"""
"""Serializer for a PluginConfig:"""
meta = serializers.DictField(read_only=True)
mixins = serializers.DictField(read_only=True)
@ -64,9 +58,7 @@ class PluginConfigSerializer(serializers.ModelSerializer):
class PluginConfigInstallSerializer(serializers.Serializer):
"""
Serializer for installing a new plugin
"""
"""Serializer for installing a new plugin"""
url = serializers.CharField(
required=False,
@ -156,9 +148,7 @@ class PluginConfigInstallSerializer(serializers.Serializer):
class PluginSettingSerializer(GenericReferencedSettingSerializer):
"""
Serializer for the PluginSetting model
"""
"""Serializer for the PluginSetting model"""
MODEL = PluginSetting
EXTRA_FIELDS = [
@ -169,9 +159,7 @@ class PluginSettingSerializer(GenericReferencedSettingSerializer):
class NotificationUserSettingSerializer(GenericReferencedSettingSerializer):
"""
Serializer for the PluginSetting model
"""
"""Serializer for the PluginSetting model"""
MODEL = NotificationUserSetting
EXTRA_FIELDS = ['method', ]

View File

@ -8,8 +8,7 @@ from plugin import registry
class PluginTemplateLoader(FilesystemLoader):
"""
A custom template loader which allows loading of templates from installed plugins.
"""A custom template loader which allows loading of templates from installed plugins.
Each plugin can register templates simply by providing a 'templates' directory in its root path.

View File

@ -5,9 +5,7 @@ from InvenTree.api_tester import InvenTreeAPITestCase
class PluginDetailAPITest(InvenTreeAPITestCase):
"""
Tests the plugin API endpoints
"""
"""Tests the plugin API endpoints"""
roles = [
'admin.add',
@ -24,9 +22,7 @@ class PluginDetailAPITest(InvenTreeAPITestCase):
super().setUp()
def test_plugin_install(self):
"""
Test the plugin install command
"""
"""Test the plugin install command"""
url = reverse('api-plugin-install')
# valid - Pypi
@ -73,9 +69,7 @@ class PluginDetailAPITest(InvenTreeAPITestCase):
self.assertEqual(data['confirm'][0].title().upper(), 'Installation not confirmed'.upper())
def test_admin_action(self):
"""
Test the PluginConfig action commands
"""
"""Test the PluginConfig action commands"""
from plugin import registry
from plugin.models import PluginConfig
@ -132,9 +126,7 @@ class PluginDetailAPITest(InvenTreeAPITestCase):
self.assertEqual(response.status_code, 200)
def test_model(self):
"""
Test the PluginConfig model
"""
"""Test the PluginConfig model"""
from plugin import registry
from plugin.models import PluginConfig

View File

@ -1,6 +1,4 @@
"""
Unit tests for plugins
"""
"""Unit tests for plugins"""
from datetime import datetime
@ -14,7 +12,7 @@ from plugin.samples.integration.sample import SampleIntegrationPlugin
class PluginTagTests(TestCase):
""" Tests for the plugin extras """
"""Tests for the plugin extras"""
def setUp(self):
self.sample = SampleIntegrationPlugin()
@ -22,22 +20,22 @@ class PluginTagTests(TestCase):
self.plugin_wrong = WrongIntegrationPlugin()
def test_tag_plugin_list(self):
"""test that all plugins are listed"""
"""Test that all plugins are listed"""
self.assertEqual(plugin_tags.plugin_list(), registry.plugins)
def test_tag_incative_plugin_list(self):
"""test that all inactive plugins are listed"""
"""Test that all inactive plugins are listed"""
self.assertEqual(plugin_tags.inactive_plugin_list(), registry.plugins_inactive)
def test_tag_plugin_settings(self):
"""check all plugins are listed"""
"""Check all plugins are listed"""
self.assertEqual(
plugin_tags.plugin_settings(self.sample),
registry.mixins_settings.get(self.sample)
)
def test_tag_mixin_enabled(self):
"""check that mixin enabled functions work"""
"""Check that mixin enabled functions work"""
key = 'urls'
# mixin enabled
self.assertEqual(plugin_tags.mixin_enabled(self.sample, key), True)
@ -47,19 +45,19 @@ class PluginTagTests(TestCase):
self.assertEqual(plugin_tags.mixin_enabled(self.plugin_no, key), False)
def test_tag_safe_url(self):
"""test that the safe url tag works expected"""
"""Test that the safe url tag works expected"""
# right url
self.assertEqual(plugin_tags.safe_url('api-plugin-install'), '/api/plugin/install/')
# wrong url
self.assertEqual(plugin_tags.safe_url('indexas'), None)
def test_tag_plugin_errors(self):
"""test that all errors are listed"""
"""Test that all errors are listed"""
self.assertEqual(plugin_tags.plugin_errors(), registry.errors)
class InvenTreePluginTests(TestCase):
""" Tests for InvenTreePlugin """
"""Tests for InvenTreePlugin"""
def setUp(self):
self.plugin = InvenTreePlugin()
@ -95,21 +93,21 @@ class InvenTreePluginTests(TestCase):
self.plugin_sample = SampleIntegrationPlugin()
def test_basic_plugin_init(self):
"""check if a basic plugin intis"""
"""Check if a basic plugin intis"""
self.assertEqual(self.plugin.NAME, '')
self.assertEqual(self.plugin.plugin_name(), '')
def test_basic_plugin_name(self):
"""check if the name of a basic plugin can be set"""
"""Check if the name of a basic plugin can be set"""
self.assertEqual(self.named_plugin.NAME, 'abc123')
self.assertEqual(self.named_plugin.plugin_name(), 'abc123')
def test_basic_is_active(self):
"""check if a basic plugin is active"""
"""Check if a basic plugin is active"""
self.assertEqual(self.plugin.is_active(), False)
def test_action_name(self):
"""check the name definition possibilities"""
"""Check the name definition possibilities"""
# plugin_name
self.assertEqual(self.plugin.plugin_name(), '')
self.assertEqual(self.plugin_simple.plugin_name(), 'SimplePlugin')
@ -157,7 +155,6 @@ class InvenTreePluginTests(TestCase):
def test_depreciation(self):
"""Check if depreciations raise as expected"""
# check deprecation warning is firing
with self.assertWarns(DeprecationWarning):
self.assertEqual(self.plugin_old.slug, 'old')

View File

@ -1,6 +1,4 @@
"""
URL lookup for plugin app
"""
"""URL lookup for plugin app"""
from django.urls import include, re_path
@ -10,10 +8,7 @@ PLUGIN_BASE = 'plugin' # Constant for links
def get_plugin_urls():
"""
Returns a urlpattern that can be integrated into the global urls
"""
"""Returns a urlpattern that can be integrated into the global urls"""
urls = []
for plugin in registry.plugins.values():

View File

@ -13,19 +13,14 @@ logger = logging.getLogger('inventree')
class InvenTreePluginViewMixin:
"""
Custom view mixin which adds context data to the view,
"""Custom view mixin which adds context data to the view,
based on loaded plugins.
This allows rendered pages to be augmented by loaded plugins.
"""
def get_plugin_panels(self, ctx):
"""
Return a list of extra 'plugin panels' associated with this view
"""
"""Return a list of extra 'plugin panels' associated with this view"""
panels = []
for plug in registry.with_mixin('panel', active=True):
@ -50,10 +45,7 @@ class InvenTreePluginViewMixin:
return panels
def get_context_data(self, **kwargs):
"""
Add plugin context data to the view
"""
"""Add plugin context data to the view"""
ctx = super().get_context_data(**kwargs)
if settings.PLUGINS_ENABLED: