2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-10 23:14:13 +00:00

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 4414 additions and 6978 deletions

View File

@ -1,4 +1,4 @@
# Tests for the Part model
"""Tests for the Part model."""
import os
@ -21,42 +21,45 @@ from .templatetags import inventree_extras
class TemplateTagTest(InvenTreeTestCase):
""" Tests for the custom template tag code """
"""Tests for the custom template tag code."""
def test_define(self):
"""Test the 'define' template tag"""
self.assertEqual(int(inventree_extras.define(3)), 3)
def test_str2bool(self):
"""Various test for the str2bool template tag"""
self.assertEqual(int(inventree_extras.str2bool('true')), True)
self.assertEqual(int(inventree_extras.str2bool('yes')), True)
self.assertEqual(int(inventree_extras.str2bool('none')), False)
self.assertEqual(int(inventree_extras.str2bool('off')), False)
def test_inrange(self):
self.assertEqual(inventree_extras.inrange(3), range(3))
def test_multiply(self):
self.assertEqual(int(inventree_extras.multiply(3, 5)), 15)
def test_add(self):
"""Test that the 'add"""
self.assertEqual(int(inventree_extras.add(3, 5)), 8)
def test_plugins_enabled(self):
"""Test the plugins_enabled tag"""
self.assertEqual(inventree_extras.plugins_enabled(), True)
def test_inventree_instance_name(self):
"""Test the 'instance name' setting"""
self.assertEqual(inventree_extras.inventree_instance_name(), 'InvenTree server')
def test_inventree_base_url(self):
"""Test that the base URL tag returns correctly"""
self.assertEqual(inventree_extras.inventree_base_url(), '')
def test_inventree_is_release(self):
"""Test that the release version check functions as expected"""
self.assertEqual(inventree_extras.inventree_is_release(), not version.isInvenTreeDevelopmentVersion())
def test_inventree_docs_version(self):
"""Test that the documentation version template tag returns correctly"""
self.assertEqual(inventree_extras.inventree_docs_version(), version.inventreeDocsVersion())
def test_hash(self):
"""Test that the commit hash template tag returns correctly"""
result_hash = inventree_extras.inventree_commit_hash()
if settings.DOCKER: # pragma: no cover
# Testing inside docker environment *may* return an empty git commit hash
@ -66,6 +69,7 @@ class TemplateTagTest(InvenTreeTestCase):
self.assertGreater(len(result_hash), 5)
def test_date(self):
"""Test that the commit date template tag returns correctly"""
d = inventree_extras.inventree_commit_date()
if settings.DOCKER: # pragma: no cover
# Testing inside docker environment *may* return an empty git commit hash
@ -75,26 +79,33 @@ class TemplateTagTest(InvenTreeTestCase):
self.assertEqual(len(d.split('-')), 3)
def test_github(self):
"""Test that the github URL template tag returns correctly"""
self.assertIn('github.com', inventree_extras.inventree_github_url())
def test_docs(self):
"""Test that the documentation URL template tag returns correctly"""
self.assertIn('inventree.readthedocs.io', inventree_extras.inventree_docs_url())
def test_keyvalue(self):
"""Test keyvalue template tag"""
self.assertEqual(inventree_extras.keyvalue({'a': 'a'}, 'a'), 'a')
def test_mail_configured(self):
"""Test that mail configuration returns False"""
self.assertEqual(inventree_extras.mail_configured(), False)
def test_user_settings(self):
"""Test user settings"""
result = inventree_extras.user_settings(self.user)
self.assertEqual(len(result), len(InvenTreeUserSetting.SETTINGS))
def test_global_settings(self):
"""Test global settings"""
result = inventree_extras.global_settings()
self.assertEqual(len(result), len(InvenTreeSetting.SETTINGS))
def test_visible_global_settings(self):
"""Test that hidden global settings are actually hidden"""
result = inventree_extras.visible_global_settings()
n = len(result)
@ -112,7 +123,7 @@ class TemplateTagTest(InvenTreeTestCase):
class PartTest(TestCase):
""" Tests for the Part model """
"""Tests for the Part model."""
fixtures = [
'category',
@ -122,6 +133,9 @@ class PartTest(TestCase):
]
def setUp(self):
"""Create some Part instances as part of init routine"""
super().setUp()
self.r1 = Part.objects.get(name='R_2K2_0805')
self.r2 = Part.objects.get(name='R_4K7_0603')
@ -130,7 +144,7 @@ class PartTest(TestCase):
Part.objects.rebuild()
def test_tree(self):
# Test that the part variant tree is working properly
"""Test that the part variant tree is working properly"""
chair = Part.objects.get(pk=10000)
self.assertEqual(chair.get_children().count(), 3)
self.assertEqual(chair.get_descendant_count(), 4)
@ -142,14 +156,12 @@ class PartTest(TestCase):
self.assertEqual(Part.objects.filter(tree_id=chair.tree_id).count(), 5)
def test_str(self):
"""Test string representation of a Part"""
p = Part.objects.get(pk=100)
self.assertEqual(str(p), "BOB | Bob | A2 - Can we build it?")
def test_duplicate(self):
"""
Test that we cannot create a "duplicate" Part
"""
"""Test that we cannot create a "duplicate" Part."""
n = Part.objects.count()
cat = PartCategory.objects.get(pk=1)
@ -201,10 +213,12 @@ class PartTest(TestCase):
part_2.validate_unique()
def test_attributes(self):
"""Test Part attributes"""
self.assertEqual(self.r1.name, 'R_2K2_0805')
self.assertEqual(self.r1.get_absolute_url(), '/part/3/')
def test_category(self):
"""Test PartCategory path"""
self.assertEqual(str(self.c1.category), 'Electronics/Capacitors - Capacitors')
orphan = Part.objects.get(name='Orphan')
@ -212,26 +226,29 @@ class PartTest(TestCase):
self.assertEqual(orphan.category_path, '')
def test_rename_img(self):
"""Test that an image can be renamed"""
img = rename_part_image(self.r1, 'hello.png')
self.assertEqual(img, os.path.join('part_images', 'hello.png'))
def test_stock(self):
# No stock of any resistors
"""Test case where there is zero stock"""
res = Part.objects.filter(description__contains='resistor')
for r in res:
self.assertEqual(r.total_stock, 0)
self.assertEqual(r.available_stock, 0)
def test_barcode(self):
"""Test barcode format functionality"""
barcode = self.r1.format_barcode(brief=False)
self.assertIn('InvenTree', barcode)
self.assertIn(self.r1.name, barcode)
def test_copy(self):
"""Test that we can 'deep copy' a Part instance"""
self.r2.deep_copy(self.r1, image=True, bom=True)
def test_sell_pricing(self):
# check that the sell pricebreaks were loaded
"""Check that the sell pricebreaks were loaded"""
self.assertTrue(self.r1.has_price_breaks)
self.assertEqual(self.r1.price_breaks.count(), 2)
# check that the sell pricebreaks work
@ -239,7 +256,7 @@ class PartTest(TestCase):
self.assertEqual(float(self.r1.get_price(10)), 1.0)
def test_internal_pricing(self):
# check that the sell pricebreaks were loaded
"""Check that the sell pricebreaks were loaded"""
self.assertTrue(self.r1.has_internal_price_breaks)
self.assertEqual(self.r1.internal_price_breaks.count(), 2)
# check that the sell pricebreaks work
@ -247,8 +264,7 @@ class PartTest(TestCase):
self.assertEqual(float(self.r1.get_internal_price(10)), 0.5)
def test_metadata(self):
"""Unit tests for the Part metadata field"""
"""Unit tests for the Part metadata field."""
p = Part.objects.get(pk=1)
self.assertIsNone(p.metadata)
@ -266,6 +282,7 @@ class PartTest(TestCase):
class TestTemplateTest(TestCase):
"""Unit test for the TestTemplate class"""
fixtures = [
'category',
@ -275,7 +292,7 @@ class TestTemplateTest(TestCase):
]
def test_template_count(self):
"""Tests for the test template functions"""
chair = Part.objects.get(pk=10000)
# Tests for the top-level chair object (nothing above it!)
@ -292,8 +309,7 @@ class TestTemplateTest(TestCase):
self.assertEqual(variant.getTestTemplates(required=True).count(), 5)
def test_uniqueness(self):
# Test names must be unique for this part and also parts above
"""Test names must be unique for this part and also parts above"""
variant = Part.objects.get(pk=10004)
with self.assertRaises(ValidationError):
@ -324,17 +340,13 @@ class TestTemplateTest(TestCase):
class PartSettingsTest(InvenTreeTestCase):
"""
Tests to ensure that the user-configurable default values work as expected.
"""Tests to ensure that the user-configurable default values work as expected.
Some fields for the Part model can have default values specified by the user.
"""
def make_part(self):
"""
Helper function to create a simple part
"""
"""Helper function to create a simple part."""
part = Part.objects.create(
name='Test Part',
description='I am but a humble test part',
@ -344,20 +356,14 @@ class PartSettingsTest(InvenTreeTestCase):
return part
def test_defaults(self):
"""
Test that the default values for the part settings are correct
"""
"""Test that the default values for the part settings are correct."""
self.assertTrue(part.settings.part_component_default())
self.assertTrue(part.settings.part_purchaseable_default())
self.assertFalse(part.settings.part_salable_default())
self.assertFalse(part.settings.part_trackable_default())
def test_initial(self):
"""
Test the 'initial' default values (no default values have been set)
"""
"""Test the 'initial' default values (no default values have been set)"""
part = self.make_part()
self.assertTrue(part.component)
@ -366,10 +372,7 @@ class PartSettingsTest(InvenTreeTestCase):
self.assertFalse(part.trackable)
def test_custom(self):
"""
Update some of the part values and re-test
"""
"""Update some of the part values and re-test."""
for val in [True, False]:
InvenTreeSetting.set_setting('PART_COMPONENT', val, self.user)
InvenTreeSetting.set_setting('PART_PURCHASEABLE', val, self.user)
@ -395,10 +398,7 @@ class PartSettingsTest(InvenTreeTestCase):
Part.objects.filter(pk=part.pk).delete()
def test_duplicate_ipn(self):
"""
Test the setting which controls duplicate IPN values
"""
"""Test the setting which controls duplicate IPN values."""
# Create a part
Part.objects.create(name='Hello', description='A thing', IPN='IPN123', revision='A')
@ -444,6 +444,7 @@ class PartSettingsTest(InvenTreeTestCase):
class PartSubscriptionTests(InvenTreeTestCase):
"""Unit tests for part 'subscription'"""
fixtures = [
'location',
@ -452,6 +453,7 @@ class PartSubscriptionTests(InvenTreeTestCase):
]
def setUp(self):
"""Create category and part data as part of setup routine"""
super().setUp()
# electronics / IC / MCU
@ -465,10 +467,7 @@ class PartSubscriptionTests(InvenTreeTestCase):
)
def test_part_subcription(self):
"""
Test basic subscription against a part
"""
"""Test basic subscription against a part."""
# First check that the user is *not* subscribed to the part
self.assertFalse(self.part.is_starred_by(self.user))
@ -485,10 +484,7 @@ class PartSubscriptionTests(InvenTreeTestCase):
self.assertFalse(self.part.is_starred_by(self.user))
def test_variant_subscription(self):
"""
Test subscription against a parent part
"""
"""Test subscription against a parent part."""
# Construct a sub-part to star against
sub_part = Part.objects.create(
name='sub_part',
@ -505,10 +501,7 @@ class PartSubscriptionTests(InvenTreeTestCase):
self.assertTrue(sub_part.is_starred_by(self.user))
def test_category_subscription(self):
"""
Test subscription against a PartCategory
"""
"""Test subscription against a PartCategory."""
self.assertEqual(PartCategoryStar.objects.count(), 0)
self.assertFalse(self.part.is_starred_by(self.user))
@ -533,10 +526,7 @@ class PartSubscriptionTests(InvenTreeTestCase):
self.assertFalse(self.part.is_starred_by(self.user))
def test_parent_category_subscription(self):
"""
Check that a parent category can be subscribed to
"""
"""Check that a parent category can be subscribed to."""
# Top-level "electronics" category
cat = PartCategory.objects.get(pk=1)
@ -553,7 +543,7 @@ class PartSubscriptionTests(InvenTreeTestCase):
class BaseNotificationIntegrationTest(InvenTreeTestCase):
""" Integration test for notifications """
"""Integration test for notifications."""
fixtures = [
'location',
@ -563,6 +553,7 @@ class BaseNotificationIntegrationTest(InvenTreeTestCase):
]
def setUp(self):
"""Add an email address as part of initialization"""
super().setUp()
# Add Mailadress
EmailAddress.objects.create(user=self.user, email='test@testing.com')
@ -571,8 +562,8 @@ class BaseNotificationIntegrationTest(InvenTreeTestCase):
self.part = Part.objects.get(name='R_2K2_0805')
def _notification_run(self, run_class=None):
"""
Run a notification test suit through.
"""Run a notification test suit through.
If you only want to test one class pass it to run_class
"""
# reload notification methods
@ -597,9 +588,10 @@ class BaseNotificationIntegrationTest(InvenTreeTestCase):
class PartNotificationTest(BaseNotificationIntegrationTest):
""" Integration test for part notifications """
"""Integration test for part notifications."""
def test_notification(self):
"""Test that a notification is generated"""
self._notification_run(UIMessageNotification)
# There should be 1 notification message right now