Docstring checks in QC checks (#3089)

* Add pre-commit to the stack

* exclude static

* Add locales to excludes

* fix style errors

* rename pipeline steps

* also wait on precommit

* make template matching simpler

* Use the same code for python setup everywhere

* use step and cache for python setup

* move regular settings up into general envs

* just use full update

* Use invoke instead of static references

* make setup actions more similar

* use python3

* refactor names to be similar

* fix runner version

* fix references

* remove incidential change

* use matrix for os

* Github can't do this right now

* ignore docstyle errors

* Add seperate docstring test

* update flake call

* do not fail on docstring

* refactor setup into workflow

* update reference

* switch to action

* resturcture

* add bash statements

* remove os from cache

* update input checks

* make code cleaner

* fix boolean

* no relative paths

* install wheel by python

* switch to install

* revert back to simple wheel

* refactor import export tests

* move setup keys back to not disturbe tests

* remove docstyle till that is fixed

* update references

* continue on error

* add docstring test

* use relativ action references

* Change step / job docstrings

* update to merge

* reformat comments 1

* fix docstrings 2

* fix docstrings 3

* fix docstrings 4

* fix docstrings 5

* fix docstrings 6

* fix docstrings 7

* fix docstrings 8

* fix docstirns 9

* fix docstrings 10

* docstring adjustments

* update the remaining docstrings

* small docstring changes

* fix function name

* update support files for docstrings

* Add missing args to docstrings

* Remove outdated function

* Add docstrings for the 'build' app

* Make API code cleaner

* add more docstrings for plugin app

* Remove dead code for plugin settings
No idea what that was even intended for

* ignore __init__ files for docstrings

* More docstrings

* Update docstrings for the 'part' directory

* Fixes for related_part functionality

* Fix removed stuff from merge 99676ee

* make more consistent

* Show statistics for docstrings

* add more docstrings

* move specific register statements to make them clearer to understant

* More docstrings for common

* and more docstrings

* and more

* simpler call

* docstrings for notifications

* docstrings for common/tests

* Add docs for common/models

* Revert "move specific register statements to make them clearer to understant"

This reverts commit ca96654622.

* use typing here

* Revert "Make API code cleaner"

This reverts commit 24fb68bd3e.

* docstring updates for the 'users' app

* Add generic Meta info to simple Meta classes

* remove unneeded unique_together statements

* More simple metas

* Remove unnecessary format specifier

* Remove extra json format specifiers

* Add docstrings for the 'plugin' app

* Docstrings for the 'label' app

* Add missing docstrings for the 'report' app

* Fix build test regression

* Fix top-level files

* docstrings for InvenTree/InvenTree

* reduce unneeded code

* add docstrings

* and more docstrings

* more docstrings

* more docstrings for stock

* more docstrings

* docstrings for order/views

* Docstrings for various files in the 'order' app

* Docstrings for order/test_api.py

* Docstrings for order/serializers.py

* Docstrings for order/admin.py

* More docstrings for the order app

* Add docstrings for the 'company' app

* Add unit tests for rebuilding the reference fields

* Prune out some more dead code

* remove more dead code

Co-authored-by: Oliver Walters <oliver.henry.walters@gmail.com>
This commit is contained in:
Matthias Mair
2022-06-01 17:37:39 +02:00
committed by GitHub
parent 66a6915213
commit 0c97a50e47
223 changed files with 4416 additions and 6980 deletions

View File

@ -1,26 +1,26 @@
# -*- coding: utf-8 -*-
"""sample implementation for ActionMixin"""
"""Sample implementation for ActionMixin."""
from plugin import InvenTreePlugin
from plugin.mixins import ActionMixin
class SimpleActionPlugin(ActionMixin, InvenTreePlugin):
"""
An EXTREMELY simple action plugin which demonstrates
the capability of the ActionMixin class
"""
"""An EXTREMELY simple action plugin which demonstrates the capability of the ActionMixin class."""
NAME = "SimpleActionPlugin"
ACTION_NAME = "simple"
def perform_action(self, user=None, data=None):
"""Sample method."""
print("Action plugin in action!")
def get_info(self, user, data=None):
"""Sample method."""
return {
"user": user.username,
"hello": "world",
}
def get_result(self, user=None, data=None):
"""Sample method."""
return True

View File

@ -1,24 +1,25 @@
""" Unit tests for action plugins """
"""Unit tests for action plugins."""
from InvenTree.helpers import InvenTreeTestCase
from plugin.builtin.action.simpleactionplugin import SimpleActionPlugin
class SimpleActionPluginTests(InvenTreeTestCase):
""" Tests for SampleIntegrationPlugin """
"""Tests for SampleIntegrationPlugin."""
def setUp(self):
"""Setup for tests."""
super().setUp()
self.plugin = SimpleActionPlugin()
def test_name(self):
"""check plugn names """
"""Check plugn names."""
self.assertEqual(self.plugin.plugin_name(), "SimpleActionPlugin")
self.assertEqual(self.plugin.action_name(), "simple")
def test_function(self):
"""check if functions work """
"""Check if functions work."""
# test functions
response = self.client.post('/api/action/', data={'action': "simple", 'data': {'foo': "bar", }})
self.assertEqual(response.status_code, 200)

View File

@ -1,6 +1,4 @@
"""
The InvenTreeBarcodePlugin validates barcodes generated by InvenTree itself.
It can be used as a template for developing third-party barcode plugins.
"""The InvenTreeBarcodePlugin validates barcodes generated by InvenTree itself. It can be used as a template for developing third-party barcode plugins.
The data format is very simple, and maps directly to database objects,
via the "id" parameter.
@ -9,8 +7,6 @@ Parsing an InvenTree barcode simply involves validating that the
references model objects actually exist in the database.
"""
# -*- coding: utf-8 -*-
import json
from rest_framework.exceptions import ValidationError
@ -22,20 +18,19 @@ from stock.models import StockItem, StockLocation
class InvenTreeBarcodePlugin(BarcodeMixin, InvenTreePlugin):
"""Builtin BarcodePlugin for matching and generating internal barcodes."""
NAME = "InvenTreeBarcode"
def validate(self):
"""
An "InvenTree" barcode must be a jsonnable-dict with the following tags:
"""Validate a barcode.
An "InvenTree" barcode must be a jsonnable-dict with the following tags:
{
'tool': 'InvenTree',
'version': <anything>
}
"""
# The data must either be dict or be able to dictified
if type(self.data) is dict:
pass
@ -59,7 +54,7 @@ class InvenTreeBarcodePlugin(BarcodeMixin, InvenTreePlugin):
return True
def getStockItem(self):
"""Lookup StockItem by 'stockitem' key in barcode data."""
for k in self.data.keys():
if k.lower() == 'stockitem':
@ -88,7 +83,7 @@ class InvenTreeBarcodePlugin(BarcodeMixin, InvenTreePlugin):
return None
def getStockLocation(self):
"""Lookup StockLocation by 'stocklocation' key in barcode data."""
for k in self.data.keys():
if k.lower() == 'stocklocation':
@ -116,7 +111,7 @@ class InvenTreeBarcodePlugin(BarcodeMixin, InvenTreePlugin):
return None
def getPart(self):
"""Lookup Part by 'part' key in barcode data."""
for k in self.data.keys():
if k.lower() == 'part':

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
"""Unit tests for InvenTreeBarcodePlugin"""
"""Unit tests for InvenTreeBarcodePlugin."""
from django.urls import reverse
@ -9,6 +8,7 @@ from InvenTree.api_tester import InvenTreeAPITestCase
class TestInvenTreeBarcode(InvenTreeAPITestCase):
"""Tests for the integrated InvenTreeBarcode barcode plugin."""
fixtures = [
'category',
@ -18,9 +18,7 @@ class TestInvenTreeBarcode(InvenTreeAPITestCase):
]
def test_errors(self):
"""
Test all possible error cases for assigment action
"""
"""Test all possible error cases for assigment action."""
def test_assert_error(barcode_data):
response = self.client.post(
@ -46,10 +44,7 @@ class TestInvenTreeBarcode(InvenTreeAPITestCase):
test_assert_error('{"blbla": 10004}')
def test_scan(self):
"""
Test that a barcode can be scanned
"""
"""Test that a barcode can be scanned."""
response = self.client.post(reverse('api-barcode-scan'), format='json', data={'barcode': 'blbla=10004'})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertIn('success', response.data)

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""Core set of Notifications as a Plugin"""
"""Core set of Notifications as a Plugin."""
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _
@ -11,14 +11,18 @@ from plugin.mixins import BulkNotificationMethod, SettingsMixin
class PlgMixin:
"""Mixin to access plugin easier.
This needs to be spit out to reference the class. Perks of python.
"""
def get_plugin(self):
"""Return plugin reference."""
return CoreNotificationsPlugin
class CoreNotificationsPlugin(SettingsMixin, InvenTreePlugin):
"""
Core notification methods for InvenTree
"""
"""Core notification methods for InvenTree."""
NAME = "CoreNotificationsPlugin"
AUTHOR = _('InvenTree contributors')
@ -34,6 +38,8 @@ class CoreNotificationsPlugin(SettingsMixin, InvenTreePlugin):
}
class EmailNotification(PlgMixin, BulkNotificationMethod):
"""Notificationmethod for delivery via Email."""
METHOD_NAME = 'mail'
METHOD_ICON = 'fa-envelope'
CONTEXT_EXTRA = [
@ -50,11 +56,7 @@ class CoreNotificationsPlugin(SettingsMixin, InvenTreePlugin):
}
def get_targets(self):
"""
Return a list of target email addresses,
only for users which allow email notifications
"""
"""Return a list of target email addresses, only for users which allow email notifications."""
allowed_users = []
for user in self.targets:
@ -68,6 +70,7 @@ class CoreNotificationsPlugin(SettingsMixin, InvenTreePlugin):
)
def send_bulk(self):
"""Send the notifications out via email."""
html_message = render_to_string(self.context['template']['html'], self.context)
targets = self.targets.values_list('email', flat=True)

View File

@ -1,3 +1,5 @@
"""Tests for core_notifications."""
from part.test_part import BaseNotificationIntegrationTest
from plugin import registry
from plugin.builtin.integration.core_notifications import \
@ -6,12 +8,10 @@ from plugin.models import NotificationUserSetting
class CoreNotificationTestTests(BaseNotificationIntegrationTest):
"""Tests for CoreNotificationsPlugin."""
def test_email(self):
"""
Ensure that the email notifications run
"""
"""Ensure that the email notifications run."""
# enable plugin and set mail setting to true
plugin = registry.plugins.get('corenotificationsplugin')
plugin.set_setting('ENABLE_NOTIFICATION_EMAILS', True)