mirror of
https://github.com/inventree/InvenTree.git
synced 2025-08-03 02:21:34 +00:00
fix docstirns 9
This commit is contained in:
@@ -49,17 +49,13 @@ class BomItemTest(TestCase):
|
||||
|
||||
def test_self_reference(self):
|
||||
"""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
|
||||
@@ -71,7 +67,6 @@ class BomItemTest(TestCase):
|
||||
|
||||
def test_overage(self):
|
||||
"""Test that BOM line overages are calculated correctly"""
|
||||
|
||||
item = BomItem.objects.get(part=100, sub_part=50)
|
||||
|
||||
q = 300
|
||||
@@ -107,7 +102,6 @@ class BomItemTest(TestCase):
|
||||
|
||||
def test_item_hash(self):
|
||||
"""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)
|
||||
@@ -40,7 +37,6 @@ class CategoryTest(TestCase):
|
||||
|
||||
def test_children_count(self):
|
||||
"""Test that categories have the correct number of children"""
|
||||
|
||||
self.assertTrue(self.electronics.has_children)
|
||||
self.assertTrue(self.mechanical.has_children)
|
||||
|
||||
@@ -49,7 +45,6 @@ class CategoryTest(TestCase):
|
||||
|
||||
def test_unique_childs(self):
|
||||
"""Test the 'unique_children' functionality"""
|
||||
|
||||
childs = [item.pk for item in self.electronics.getUniqueChildren()]
|
||||
|
||||
self.assertIn(self.transceivers.id, childs)
|
||||
@@ -59,7 +54,6 @@ class CategoryTest(TestCase):
|
||||
|
||||
def test_unique_parents(self):
|
||||
"""Test the 'unique_parents' functionality"""
|
||||
|
||||
parents = [item.pk for item in self.transceivers.getUniqueParents()]
|
||||
|
||||
self.assertIn(self.electronics.id, parents)
|
||||
@@ -68,18 +62,15 @@ class CategoryTest(TestCase):
|
||||
|
||||
def test_path_string(self):
|
||||
"""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"""
|
||||
|
||||
self.assertEqual(self.capacitors.get_absolute_url(), '/part/category/3/')
|
||||
|
||||
def test_part_count(self):
|
||||
"""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)
|
||||
@@ -97,7 +88,6 @@ class CategoryTest(TestCase):
|
||||
|
||||
def test_parameters(self):
|
||||
"""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)
|
||||
@@ -136,7 +126,6 @@ class CategoryTest(TestCase):
|
||||
|
||||
def test_delete(self):
|
||||
"""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)
|
||||
@@ -157,7 +146,6 @@ class CategoryTest(TestCase):
|
||||
|
||||
def test_default_locations(self):
|
||||
"""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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
@@ -41,7 +41,6 @@ class PartDetailTest(PartViewTestCase):
|
||||
|
||||
def test_part_detail(self):
|
||||
"""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
|
||||
|
Reference in New Issue
Block a user