mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-15 03:25:42 +00:00
fix docstirns 9
This commit is contained in:
@ -48,18 +48,14 @@ class BomItemTest(TestCase):
|
||||
self.assertEqual(self.orphan.used_in_count, 1)
|
||||
|
||||
def test_self_reference(self):
|
||||
""" Test that we get an appropriate error when we create a BomItem which points to itself """
|
||||
|
||||
"""Test that we get an appropriate error when we create a BomItem which points to itself"""
|
||||
with self.assertRaises(django_exceptions.ValidationError):
|
||||
# A validation error should be raised here
|
||||
item = BomItem.objects.create(part=self.bob, sub_part=self.bob, quantity=7)
|
||||
item.clean() # pragma: no cover
|
||||
|
||||
def test_integer_quantity(self):
|
||||
"""
|
||||
Test integer validation for BomItem
|
||||
"""
|
||||
|
||||
"""Test integer validation for BomItem"""
|
||||
p = Part.objects.create(name="test", description="d", component=True, trackable=True)
|
||||
|
||||
# Creation of a BOMItem with a non-integer quantity of a trackable Part should fail
|
||||
@ -70,8 +66,7 @@ class BomItemTest(TestCase):
|
||||
BomItem.objects.create(part=self.bob, sub_part=p, quantity=21)
|
||||
|
||||
def test_overage(self):
|
||||
""" Test that BOM line overages are calculated correctly """
|
||||
|
||||
"""Test that BOM line overages are calculated correctly"""
|
||||
item = BomItem.objects.get(part=100, sub_part=50)
|
||||
|
||||
q = 300
|
||||
@ -106,8 +101,7 @@ class BomItemTest(TestCase):
|
||||
self.assertEqual(n, 3150)
|
||||
|
||||
def test_item_hash(self):
|
||||
""" Test BOM item hash encoding """
|
||||
|
||||
"""Test BOM item hash encoding"""
|
||||
item = BomItem.objects.get(part=100, sub_part=50)
|
||||
|
||||
h1 = item.get_item_hash()
|
||||
@ -135,10 +129,7 @@ class BomItemTest(TestCase):
|
||||
)
|
||||
|
||||
def test_substitutes(self):
|
||||
"""
|
||||
Tests for BOM item substitutes
|
||||
"""
|
||||
|
||||
"""Tests for BOM item substitutes"""
|
||||
# We will make some subtitute parts for the "orphan" part
|
||||
bom_item = BomItem.objects.get(
|
||||
part=self.bob,
|
||||
|
@ -5,8 +5,7 @@ from .models import Part, PartCategory, PartParameter, PartParameterTemplate
|
||||
|
||||
|
||||
class CategoryTest(TestCase):
|
||||
"""
|
||||
Tests to ensure that the relational category tree functions correctly.
|
||||
"""Tests to ensure that the relational category tree functions correctly.
|
||||
|
||||
Loads the following test fixtures:
|
||||
- category.yaml
|
||||
@ -29,9 +28,7 @@ class CategoryTest(TestCase):
|
||||
self.transceivers = PartCategory.objects.get(name='Transceivers')
|
||||
|
||||
def test_parents(self):
|
||||
""" Test that the parent fields are properly set,
|
||||
based on the test fixtures """
|
||||
|
||||
"""Test that the parent fields are properly set, based on the test fixtures"""
|
||||
self.assertEqual(self.resistors.parent, self.electronics)
|
||||
self.assertEqual(self.capacitors.parent, self.electronics)
|
||||
self.assertEqual(self.electronics.parent, None)
|
||||
@ -39,8 +36,7 @@ class CategoryTest(TestCase):
|
||||
self.assertEqual(self.fasteners.parent, self.mechanical)
|
||||
|
||||
def test_children_count(self):
|
||||
""" Test that categories have the correct number of children """
|
||||
|
||||
"""Test that categories have the correct number of children"""
|
||||
self.assertTrue(self.electronics.has_children)
|
||||
self.assertTrue(self.mechanical.has_children)
|
||||
|
||||
@ -48,8 +44,7 @@ class CategoryTest(TestCase):
|
||||
self.assertEqual(len(self.mechanical.children.all()), 1)
|
||||
|
||||
def test_unique_childs(self):
|
||||
""" Test the 'unique_children' functionality """
|
||||
|
||||
"""Test the 'unique_children' functionality"""
|
||||
childs = [item.pk for item in self.electronics.getUniqueChildren()]
|
||||
|
||||
self.assertIn(self.transceivers.id, childs)
|
||||
@ -58,8 +53,7 @@ class CategoryTest(TestCase):
|
||||
self.assertNotIn(self.fasteners.id, childs)
|
||||
|
||||
def test_unique_parents(self):
|
||||
""" Test the 'unique_parents' functionality """
|
||||
|
||||
"""Test the 'unique_parents' functionality"""
|
||||
parents = [item.pk for item in self.transceivers.getUniqueParents()]
|
||||
|
||||
self.assertIn(self.electronics.id, parents)
|
||||
@ -67,19 +61,16 @@ class CategoryTest(TestCase):
|
||||
self.assertNotIn(self.fasteners.id, parents)
|
||||
|
||||
def test_path_string(self):
|
||||
""" Test that the category path string works correctly """
|
||||
|
||||
"""Test that the category path string works correctly"""
|
||||
self.assertEqual(str(self.resistors), 'Electronics/Resistors - Resistors')
|
||||
self.assertEqual(str(self.transceivers.pathstring), 'Electronics/IC/Transceivers')
|
||||
|
||||
def test_url(self):
|
||||
""" Test that the PartCategory URL works """
|
||||
|
||||
"""Test that the PartCategory URL works"""
|
||||
self.assertEqual(self.capacitors.get_absolute_url(), '/part/category/3/')
|
||||
|
||||
def test_part_count(self):
|
||||
""" Test that the Category part count works """
|
||||
|
||||
"""Test that the Category part count works"""
|
||||
self.assertTrue(self.resistors.has_parts)
|
||||
self.assertTrue(self.fasteners.has_parts)
|
||||
self.assertFalse(self.transceivers.has_parts)
|
||||
@ -96,8 +87,7 @@ class CategoryTest(TestCase):
|
||||
self.assertEqual(self.electronics.item_count, self.electronics.partcount())
|
||||
|
||||
def test_parameters(self):
|
||||
""" Test that the Category parameters are correctly fetched """
|
||||
|
||||
"""Test that the Category parameters are correctly fetched"""
|
||||
# Check number of SQL queries to iterate other parameters
|
||||
with self.assertNumQueries(7):
|
||||
# Prefetch: 3 queries (parts, parameters and parameters_template)
|
||||
@ -135,8 +125,7 @@ class CategoryTest(TestCase):
|
||||
cat.save()
|
||||
|
||||
def test_delete(self):
|
||||
""" Test that category deletion moves the children properly """
|
||||
|
||||
"""Test that category deletion moves the children properly"""
|
||||
# Delete the 'IC' category and 'Transceiver' should move to be under 'Electronics'
|
||||
self.assertEqual(self.transceivers.parent, self.ic)
|
||||
self.assertEqual(self.ic.parent, self.electronics)
|
||||
@ -156,8 +145,7 @@ class CategoryTest(TestCase):
|
||||
self.assertEqual(f.category, self.mechanical)
|
||||
|
||||
def test_default_locations(self):
|
||||
""" Test traversal for default locations """
|
||||
|
||||
"""Test traversal for default locations"""
|
||||
self.assertEqual(str(self.fasteners.default_location), 'Office/Drawer_1 - In my desk')
|
||||
|
||||
# Any part under electronics should default to 'Home'
|
||||
@ -174,12 +162,11 @@ class CategoryTest(TestCase):
|
||||
self.assertIsNone(w.get_default_location())
|
||||
|
||||
def test_category_tree(self):
|
||||
"""
|
||||
Unit tests for the part category tree structure (MPTT)
|
||||
"""Unit tests for the part category tree structure (MPTT)
|
||||
|
||||
Ensure that the MPTT structure is rebuilt correctly,
|
||||
and the correct ancestor tree is observed.
|
||||
"""
|
||||
|
||||
# Clear out any existing parts
|
||||
Part.objects.all().delete()
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
"""
|
||||
Unit tests for the part model database migrations
|
||||
"""
|
||||
"""Unit tests for the part model database migrations"""
|
||||
|
||||
from django_test_migrations.contrib.unittest_case import MigratorTestCase
|
||||
|
||||
@ -8,18 +6,13 @@ from InvenTree import helpers
|
||||
|
||||
|
||||
class TestForwardMigrations(MigratorTestCase):
|
||||
"""
|
||||
Test entire schema migration sequence for the part app
|
||||
"""
|
||||
"""Test entire schema migration sequence for the part app"""
|
||||
|
||||
migrate_from = ('part', helpers.getOldestMigrationFile('part'))
|
||||
migrate_to = ('part', helpers.getNewestMigrationFile('part'))
|
||||
|
||||
def prepare(self):
|
||||
"""
|
||||
Create initial data
|
||||
"""
|
||||
|
||||
"""Create initial data"""
|
||||
Part = self.old_state.apps.get_model('part', 'part')
|
||||
|
||||
Part.objects.create(name='A', description='My part A')
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Tests for the Part model
|
||||
"""Tests for the Part model"""
|
||||
|
||||
import os
|
||||
|
||||
@ -21,7 +21,7 @@ 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):
|
||||
self.assertEqual(int(inventree_extras.define(3)), 3)
|
||||
@ -146,10 +146,7 @@ class PartTest(TestCase):
|
||||
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)
|
||||
@ -248,7 +245,6 @@ class PartTest(TestCase):
|
||||
|
||||
def test_metadata(self):
|
||||
"""Unit tests for the Part metadata field"""
|
||||
|
||||
p = Part.objects.get(pk=1)
|
||||
self.assertIsNone(p.metadata)
|
||||
|
||||
@ -324,8 +320,7 @@ 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.
|
||||
"""
|
||||
@ -344,20 +339,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 +355,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 +381,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')
|
||||
|
||||
@ -465,10 +448,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 +465,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 +482,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 +507,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 +524,7 @@ class PartSubscriptionTests(InvenTreeTestCase):
|
||||
|
||||
|
||||
class BaseNotificationIntegrationTest(InvenTreeTestCase):
|
||||
""" Integration test for notifications """
|
||||
"""Integration test for notifications"""
|
||||
|
||||
fixtures = [
|
||||
'location',
|
||||
@ -571,8 +542,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,7 +568,7 @@ class BaseNotificationIntegrationTest(InvenTreeTestCase):
|
||||
|
||||
|
||||
class PartNotificationTest(BaseNotificationIntegrationTest):
|
||||
""" Integration test for part notifications """
|
||||
"""Integration test for part notifications"""
|
||||
|
||||
def test_notification(self):
|
||||
self._notification_run(UIMessageNotification)
|
||||
|
@ -1,4 +1,4 @@
|
||||
""" Unit tests for Part Views (see views.py) """
|
||||
"""Unit tests for Part Views (see views.py)"""
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
@ -40,8 +40,7 @@ class PartListTest(PartViewTestCase):
|
||||
class PartDetailTest(PartViewTestCase):
|
||||
|
||||
def test_part_detail(self):
|
||||
""" Test that we can retrieve a part detail page """
|
||||
|
||||
"""Test that we can retrieve a part detail page"""
|
||||
pk = 1
|
||||
|
||||
response = self.client.get(reverse('part-detail', args=(pk,)))
|
||||
@ -58,8 +57,7 @@ class PartDetailTest(PartViewTestCase):
|
||||
self.assertEqual(response.context['category'], part.category)
|
||||
|
||||
def test_part_detail_from_ipn(self):
|
||||
"""
|
||||
Test that we can retrieve a part detail page from part IPN:
|
||||
"""Test that we can retrieve a part detail page from part IPN:
|
||||
- if no part with matching IPN -> return part index
|
||||
- if unique IPN match -> return part detail page
|
||||
- if multiple IPN matches -> return part index
|
||||
@ -108,7 +106,7 @@ class PartDetailTest(PartViewTestCase):
|
||||
test_ipn_match(index_result=True, detail_result=False)
|
||||
|
||||
def test_bom_download(self):
|
||||
""" Test downloading a BOM for a valid part """
|
||||
"""Test downloading a BOM for a valid part"""
|
||||
|
||||
response = self.client.get(reverse('bom-download', args=(1,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
@ -116,7 +114,7 @@ class PartDetailTest(PartViewTestCase):
|
||||
|
||||
|
||||
class PartQRTest(PartViewTestCase):
|
||||
""" Tests for the Part QR Code AJAX view """
|
||||
"""Tests for the Part QR Code AJAX view"""
|
||||
|
||||
def test_html_redirect(self):
|
||||
# A HTML request for a QR code should be redirected (use an AJAX request instead)
|
||||
@ -139,10 +137,10 @@ class PartQRTest(PartViewTestCase):
|
||||
|
||||
|
||||
class CategoryTest(PartViewTestCase):
|
||||
""" Tests for PartCategory related views """
|
||||
"""Tests for PartCategory related views"""
|
||||
|
||||
def test_set_category(self):
|
||||
""" Test that the "SetCategory" view works """
|
||||
"""Test that the "SetCategory" view works"""
|
||||
|
||||
url = reverse('part-set-category')
|
||||
|
||||
|
Reference in New Issue
Block a user