diff --git a/docs/docs_data.py b/docs/docs_data.py index bb5a346249..5a5b09d9c5 100644 --- a/docs/docs_data.py +++ b/docs/docs_data.py @@ -183,7 +183,9 @@ def hook_config(site_url: Optional[str] = None) -> dict: spec = importlib.util.spec_from_file_location( 'inventree_docs_hooks', HERE.joinpath('docs', 'hooks.py') ) + assert spec is not None hooks = importlib.util.module_from_spec(spec) + assert spec.loader is not None spec.loader.exec_module(hooks) _hook_config = hooks.on_config({'site_url': site_url}) diff --git a/pyproject.toml b/pyproject.toml index d02c3326b4..c410d6f38b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -105,13 +105,16 @@ generate-hashes=true extra-paths = ["src/backend/InvenTree"] [tool.ty.rules] -unresolved-attribute="ignore" # 837 # need Plugin Mixin typing -call-non-callable="ignore" # 8 ## -invalid-assignment="ignore" # 40 # need to wait for better django field stubs -invalid-method-override="ignore" # 103 -invalid-return-type="ignore" # 44 ## -invalid-argument-type="ignore" # 49 -no-matching-overload="ignore" # 10 # need to wait for betterdjango field stubs +missing-attribute="ignore" # 732 # need Plugin Mixin typing +not-callable="ignore" # 12 ## +invalid-assignment="ignore" # 81 # need to wait for better django field stubs +incompatible-method-override="ignore" # 61 +invalid-explicit-return="ignore" # 53 ## +invalid-argument-type="ignore" # 437 +no-matching-overload="ignore" # 16 # need to wait for betterdjango field stubs +lost-keyword-for-regular-parameter = "ignore" # 52 +missing-union-attribute = "ignore" # 85 +incompatible-attribute-override = "ignore" # 36 # warn about unused ignore comments unused-ignore-comment = "error" diff --git a/src/backend/InvenTree/InvenTree/helpers.py b/src/backend/InvenTree/InvenTree/helpers.py index d51da8809d..27f07682cf 100644 --- a/src/backend/InvenTree/InvenTree/helpers.py +++ b/src/backend/InvenTree/InvenTree/helpers.py @@ -256,7 +256,7 @@ def regenerate_imagefile(_file, _name: str): _name: Name of the variation (e.g. 'thumbnail', 'preview') """ name = _file.field.attr_class.get_variation_name(_file.name, _name) - return ImageFieldFile(_file.instance, _file, name) # ty:ignore[too-many-positional-arguments] + return ImageFieldFile(_file.instance, _file, name) def image2name(img_obj: StdImageField, do_preview: bool, do_thumbnail: bool): diff --git a/src/backend/InvenTree/InvenTree/setting/ldap.py b/src/backend/InvenTree/InvenTree/setting/ldap.py index 3b39179701..462a8955a4 100644 --- a/src/backend/InvenTree/InvenTree/setting/ldap.py +++ b/src/backend/InvenTree/InvenTree/setting/ldap.py @@ -9,8 +9,8 @@ def get_ldap_config(debug: bool = False) -> dict: The returned settings will be updated into the globals() object, and will be used to configure the LDAP authentication backend. """ - import django_auth_ldap.config # ty: ignore[unresolved-import] - import ldap # ty: ignore[unresolved-import] + import django_auth_ldap.config # ty: ignore[import-not-found] + import ldap # ty: ignore[import-not-found] # get global options from dict and use ldap.OPT_* as keys and values global_options_dict = get_setting( diff --git a/src/backend/InvenTree/InvenTree/test_auth.py b/src/backend/InvenTree/InvenTree/test_auth.py index 162c5f1a0f..28d95d3732 100644 --- a/src/backend/InvenTree/InvenTree/test_auth.py +++ b/src/backend/InvenTree/InvenTree/test_auth.py @@ -51,57 +51,76 @@ class TestSsoGroupSync(TransactionTestCase): def test_group_added_to_user(self): """Check that a new SSO group is added to the user.""" user: User = self.sociallogin.account.user + assert user is not None self.assertEqual(user.groups.count(), 0) sso.ensure_sso_groups(None, self.sociallogin) self.assertEqual(user.groups.count(), 1) - self.assertEqual(user.groups.first().name, 'inventree_group') + group = user.groups.first() + assert group is not None + self.assertEqual(group.name, 'inventree_group') def test_group_already_exists(self): """Check that existing SSO group is not modified.""" user: User = self.sociallogin.account.user + assert user is not None user.groups.add(self.group) self.assertEqual(user.groups.count(), 1) - self.assertEqual(user.groups.first().name, 'inventree_group') + group = user.groups.first() + assert group is not None + self.assertEqual(group.name, 'inventree_group') sso.ensure_sso_groups(None, self.sociallogin) self.assertEqual(user.groups.count(), 1) - self.assertEqual(user.groups.first().name, 'inventree_group') + group = user.groups.first() + assert group is not None + self.assertEqual(group.name, 'inventree_group') @override_settings(SSO_REMOVE_GROUPS=True) def test_remove_non_sso_group(self): """Check that any group not provided by IDP is removed.""" user: User = self.sociallogin.account.user + assert user is not None # group must be saved to database first group = Group(name='local_group') group.save() user.groups.add(group) self.assertEqual(user.groups.count(), 1) - self.assertEqual(user.groups.first().name, 'local_group') + user_group = user.groups.first() + assert user_group is not None + self.assertEqual(user_group.name, 'local_group') sso.ensure_sso_groups(None, self.sociallogin) self.assertEqual(user.groups.count(), 1) - self.assertEqual(user.groups.first().name, 'inventree_group') + user_group = user.groups.first() + assert user_group is not None + self.assertEqual(user_group.name, 'inventree_group') def test_override_default_group_with_sso_group(self): """The default group should be overridden if SSO groups are available.""" user: User = self.sociallogin.account.user + assert user is not None self.assertEqual(user.groups.count(), 0) Group(id=42, name='default_group').save() InvenTreeSetting.set_setting('SIGNUP_GROUP', 42) sso.ensure_sso_groups(None, self.sociallogin) MockRegistrationMixin().save_user(None, user, None) self.assertEqual(user.groups.count(), 1) - self.assertEqual(user.groups.first().name, 'inventree_group') + group = user.groups.first() + assert group is not None + self.assertEqual(group.name, 'inventree_group') def test_default_group_without_sso_group(self): """If no SSO group is specified, the default group should be applied.""" self.sociallogin.account.extra_data = {} user: User = self.sociallogin.account.user + assert user is not None self.assertEqual(user.groups.count(), 0) Group(id=42, name='default_group').save() InvenTreeSetting.set_setting('SIGNUP_GROUP', 42) sso.ensure_sso_groups(None, self.sociallogin) MockRegistrationMixin().save_user(None, user, None) self.assertEqual(user.groups.count(), 1) - self.assertEqual(user.groups.first().name, 'default_group') + group = user.groups.first() + assert group is not None + self.assertEqual(group.name, 'default_group') @override_settings(SSO_REMOVE_GROUPS=True) def test_remove_groups_overrides_default_group(self): diff --git a/src/backend/InvenTree/InvenTree/test_tasks.py b/src/backend/InvenTree/InvenTree/test_tasks.py index f63134ec0f..eeb78c3491 100644 --- a/src/backend/InvenTree/InvenTree/test_tasks.py +++ b/src/backend/InvenTree/InvenTree/test_tasks.py @@ -760,6 +760,7 @@ class InvenTreeTaskTests(PluginRegistryMixin, TestCase): self.assertEqual(NotificationMessage.objects.count(), n_messages + 1) msg = NotificationMessage.objects.last() + assert msg is not None self.assertEqual(msg.name, 'Server Error') self.assertEqual(msg.message, 'An error has been logged by the server.') diff --git a/src/backend/InvenTree/InvenTree/test_views.py b/src/backend/InvenTree/InvenTree/test_views.py index a743236ac6..38e082092e 100644 --- a/src/backend/InvenTree/InvenTree/test_views.py +++ b/src/backend/InvenTree/InvenTree/test_views.py @@ -45,6 +45,7 @@ class ViewTests(InvenTreeTestCase): # The Redoc version must be pinned - '@latest' can (and did) change under us match = re.search(r'redoc@(\d+)(?:\.\d+)*/', src) + assert match is not None self.assertIsNotNone( match, f'Redoc distribution must be pinned to a version: {src}' ) diff --git a/src/backend/InvenTree/InvenTree/tests.py b/src/backend/InvenTree/InvenTree/tests.py index e4024c49fa..9a887c22ea 100644 --- a/src/backend/InvenTree/InvenTree/tests.py +++ b/src/backend/InvenTree/InvenTree/tests.py @@ -701,7 +701,7 @@ class TestHelpers(TestCase): # Correct usage part = Part().image self.assertEqual( - helpers.getMediaUrl(StdImageFieldFile(part, part, 'xx/yy.png')), # ty:ignore[too-many-positional-arguments] + helpers.getMediaUrl(StdImageFieldFile(part, part, 'xx/yy.png')), '/media/xx/yy.png', ) @@ -1593,6 +1593,7 @@ class TestInstanceName(InvenTreeTestCase): # The site should also be changed site_obj = Site.objects.all().order_by('id').first() + assert site_obj is not None self.assertEqual(site_obj.name, 'Testing title') @override_settings(SITE_URL=None) @@ -1612,6 +1613,7 @@ class TestInstanceName(InvenTreeTestCase): from django.contrib.sites.models import Site site_obj = Site.objects.all().order_by('id').first() + assert site_obj is not None self.assertEqual(site_obj.domain, 'http://127.1.2.3') except Exception: pass @@ -1941,7 +1943,7 @@ class ClassValidationMixinTest(TestCase): def test_valid_class(self): """Test that a valid class passes the validation.""" - class TestClass(self.BaseTestClass): + class TestClass(self.BaseTestClass): # ty: ignore[unsupported-base] """A valid class that inherits from BaseTestClass.""" NAME = 'Test' @@ -1957,7 +1959,7 @@ class ClassValidationMixinTest(TestCase): def test_invalid_class(self): """Test that an invalid class fails the validation.""" - class TestClass1(self.BaseTestClass): + class TestClass1(self.BaseTestClass): # ty: ignore[unsupported-base] """A bad class that inherits from BaseTestClass.""" with self.assertRaisesRegex( @@ -1966,7 +1968,7 @@ class ClassValidationMixinTest(TestCase): ): TestClass1.validate() - class TestClass2(self.BaseTestClass): + class TestClass2(self.BaseTestClass): # ty: ignore[unsupported-base] """A bad class that inherits from BaseTestClass.""" NAME = 'Test' diff --git a/src/backend/InvenTree/build/models.py b/src/backend/InvenTree/build/models.py index 77749b1b43..10acf575bc 100644 --- a/src/backend/InvenTree/build/models.py +++ b/src/backend/InvenTree/build/models.py @@ -1420,7 +1420,7 @@ class Build( output: stock.models.StockItem, quantity: Optional[decimal.Decimal] = None, required_tests=None, - ) -> bool: + ) -> None: """Determine if the given build output can be completed. Arguments: diff --git a/src/backend/InvenTree/build/test_api.py b/src/backend/InvenTree/build/test_api.py index 33ed277037..7960c4a722 100644 --- a/src/backend/InvenTree/build/test_api.py +++ b/src/backend/InvenTree/build/test_api.py @@ -878,6 +878,7 @@ class BuildAllocationTest(BuildAPITest): self.assertEqual(self.n + 1, BuildItem.objects.count()) allocation = BuildItem.objects.last() + assert allocation is not None self.assertEqual(allocation.quantity, 5000) self.assertEqual(allocation.bom_item.pk, 1) @@ -915,6 +916,7 @@ class BuildAllocationTest(BuildAPITest): self.assertEqual(self.n + 1, BuildItem.objects.count()) allocation = BuildItem.objects.last() + assert allocation is not None self.assertEqual(allocation.quantity, 3000) self.assertEqual(allocation.bom_item.pk, 1) @@ -1054,6 +1056,7 @@ class BuildAllocationTest(BuildAPITest): bi = BuildItem.objects.filter( stock_item=c, quantity=1, install_into=output ).first() + assert bi is not None self.assertIsNotNone(bi) self.assertEqual(bi.build, build) @@ -1209,6 +1212,7 @@ class BuildOverallocationTest(BuildAPITest): required = build_line.quantity + idx + 1 sub_part = build_line.bom_item.sub_part si = StockItem.objects.filter(part=sub_part, quantity__gte=required).first() + assert si is not None cls.state[sub_part] = (si, si.quantity, required) @@ -1285,6 +1289,7 @@ class BuildOverallocationTest(BuildAPITest): # Check stock items have reduced only by bom requirement (overallocation trimmed) for line in self.build.build_lines.all(): si, oq, _ = self.state[line.bom_item.sub_part] + assert si is not None rq = line.quantity si.refresh_from_db() self.assertEqual(si.quantity, oq - rq) @@ -1916,6 +1921,7 @@ class BuildLineTests(BuildAPITest): the consumed quantity does not match the stock which was actually consumed. """ line = BuildLine.objects.first() + assert line is not None self.assertEqual(line.consumed, 0) url = reverse('api-build-line-detail', kwargs={'pk': line.pk}) @@ -2845,6 +2851,7 @@ class BuildConsumeTest(BuildAPITest): ) self.assertEqual(consumed_items.count(), 1) consumed_item = consumed_items.first() + assert consumed_item is not None self.assertEqual(consumed_item.quantity, required_quantity) self.assertNotEqual(consumed_item.pk, stock_item.pk) @@ -3221,9 +3228,12 @@ class BuildAutoAllocateAPITest(InvenTreeAPITestCase): ) allocs = BuildItem.objects.filter(build_line__build=build) + assert allocs is not None self.assertEqual(allocs.count(), 1) - self.assertEqual(allocs.first().stock_item, large) - self.assertEqual(allocs.first().quantity, 15) + allocation = allocs.first() + assert allocation is not None + self.assertEqual(allocation.stock_item, large) + self.assertEqual(allocation.quantity, 15) # ------------------------------------------------------------------ # build_lines filtering @@ -3301,8 +3311,11 @@ class BuildAutoAllocateAPITest(InvenTreeAPITestCase): self.post(self._url(build.pk), {'interchangeable': True}, expected_code=200) allocs = BuildItem.objects.filter(build_line__build=build) + assert allocs is not None self.assertEqual(allocs.count(), 1) - self.assertEqual(allocs.first().stock_item, direct_stock) + allocation = allocs.first() + assert allocation is not None + self.assertEqual(allocation.stock_item, direct_stock) # ------------------------------------------------------------------ # Location filtering @@ -3324,8 +3337,11 @@ class BuildAutoAllocateAPITest(InvenTreeAPITestCase): ) allocs = BuildItem.objects.filter(build_line__build=build) + assert allocs is not None self.assertEqual(allocs.count(), 1) - self.assertEqual(allocs.first().stock_item, in_location) + allocation = allocs.first() + assert allocation is not None + self.assertEqual(allocation.stock_item, in_location) def test_exclude_location_filters_allocation(self): """The 'exclude_location' filter excludes stock within that location.""" @@ -3343,8 +3359,11 @@ class BuildAutoAllocateAPITest(InvenTreeAPITestCase): ) allocs = BuildItem.objects.filter(build_line__build=build) + assert allocs is not None self.assertEqual(allocs.count(), 1) - self.assertEqual(allocs.first().stock_item, allowed) + allocation = allocs.first() + assert allocation is not None + self.assertEqual(allocation.stock_item, allowed) # ------------------------------------------------------------------ # Large number of build lines (performance / bulk allocation) diff --git a/src/backend/InvenTree/build/test_build.py b/src/backend/InvenTree/build/test_build.py index fc6fae8198..7e7cfa2899 100644 --- a/src/backend/InvenTree/build/test_build.py +++ b/src/backend/InvenTree/build/test_build.py @@ -1111,6 +1111,7 @@ class BuildTest(BuildTestBase): for model in [Build, BuildItem]: p = model.objects.first() + assert p is not None self.assertEqual(len(p.metadata.keys()), 0) self.assertIsNone(p.get_metadata('test')) diff --git a/src/backend/InvenTree/common/test_audit.py b/src/backend/InvenTree/common/test_audit.py index 923e007bac..b2fe09c67e 100644 --- a/src/backend/InvenTree/common/test_audit.py +++ b/src/backend/InvenTree/common/test_audit.py @@ -778,10 +778,9 @@ class GlobalSettingAuditTest(InvenTreeAPITestCase): # ...except for changes to the audit log settings themselves self.assertEqual(AuditLogEntry.objects.count(), n + 1) - self.assertEqual( - AuditLogEntry.objects.order_by('pk').last().object_repr, - 'AUDIT_LOG_DELETE_DAYS', - ) + entry = AuditLogEntry.objects.order_by('pk').last() + assert entry is not None + self.assertEqual(entry.object_repr, 'AUDIT_LOG_DELETE_DAYS') self.set_value('AUDIT_LOG_ENABLED', True) diff --git a/src/backend/InvenTree/common/test_emails.py b/src/backend/InvenTree/common/test_emails.py index 0ba8b24b9f..7e164c6a28 100644 --- a/src/backend/InvenTree/common/test_emails.py +++ b/src/backend/InvenTree/common/test_emails.py @@ -129,6 +129,7 @@ class EmailTests(InvenTreeAPITestCase): # There should be an error logged on the message msg = EmailMessage.objects.first() + assert msg is not None self.assertEqual(msg.status, EmailMessage.EmailStatus.FAILED) self.assertEqual(msg.error_message, 'Test error sending email') @@ -249,6 +250,7 @@ class EmailEventsTests(TestCase): # Check that the email was saved msg = EmailMessage.objects.filter(to=['comments@example.net']).first() + assert msg is not None self.assertEqual(EmailMessage.objects.count(), 1) self.assertEqual(msg.status, EmailMessage.EmailStatus.READ) self.assertEqual(msg.direction, EmailMessage.EmailDirection.INBOUND) diff --git a/src/backend/InvenTree/common/tests.py b/src/backend/InvenTree/common/tests.py index b23e5da4be..4aaef7fb37 100644 --- a/src/backend/InvenTree/common/tests.py +++ b/src/backend/InvenTree/common/tests.py @@ -2162,6 +2162,7 @@ class ProjectCodesTest(InvenTreeAPITestCase): """Test that the 'active' field can be filtered via the API.""" # Mark one code as inactive code = ProjectCode.objects.first() + assert code is not None code.active = False code.save() diff --git a/src/backend/InvenTree/company/test_api.py b/src/backend/InvenTree/company/test_api.py index 4b9032bbce..7268e65607 100644 --- a/src/backend/InvenTree/company/test_api.py +++ b/src/backend/InvenTree/company/test_api.py @@ -149,8 +149,11 @@ class CompanyTest(InvenTreeAPITestCase): ) duplicate = Company.objects.get(pk=response.data['pk']) + assert duplicate is not None self.assertEqual(duplicate.notes.count(), 1) - self.assertEqual(duplicate.notes.first().content, '
Some notes
') + note = duplicate.notes.first() + assert note is not None + self.assertEqual(note.content, 'Some notes
') # Explicitly disabling copy_notes must not copy any notes response = self.post( @@ -230,6 +233,7 @@ class CompanyTest(InvenTreeAPITestCase): # Set one company to inactive c = Company.objects.first() c.active = False + assert c is not None c.save() self.assertEqual( @@ -358,6 +362,7 @@ class ContactTest(InvenTreeAPITestCase): # Get the contact again contact = Contact.objects.first() + assert contact is not None self.assertEqual(contact.role, 'x') def test_delete(self): @@ -552,6 +557,7 @@ class ManufacturerTest(InvenTreeAPITestCase): def test_barcode_hash_read_only(self): """The 'barcode_hash' field cannot be changed via the ManufacturerPart API.""" part = ManufacturerPart.objects.first() + assert part is not None self.assertEqual(part.barcode_hash, '') url = reverse('api-manufacturer-part-detail', kwargs={'pk': part.pk}) @@ -593,6 +599,7 @@ class ManufacturerTest(InvenTreeAPITestCase): def test_manufacturer_part_detail(self): """Tests for the ManufacturerPart detail endpoint.""" mp = ManufacturerPart.objects.first() + assert mp is not None self.assertIsNotNone(mp) @@ -623,6 +630,7 @@ class ManufacturerTest(InvenTreeAPITestCase): url = reverse('api-manufacturer-part-list') original = ManufacturerPart.objects.first() + assert original is not None self.assertIsNotNone(original) create_note(original) @@ -639,8 +647,11 @@ class ManufacturerTest(InvenTreeAPITestCase): ) duplicate = ManufacturerPart.objects.get(pk=response.data['pk']) + assert duplicate is not None self.assertEqual(duplicate.notes.count(), 1) - self.assertEqual(duplicate.notes.first().content, 'Some notes
') + note = duplicate.notes.first() + assert note is not None + self.assertEqual(note.content, 'Some notes
') # Explicitly disabling copy_notes must not copy any notes response = self.post( @@ -750,6 +761,7 @@ class SupplierPartTest(InvenTreeAPITestCase): url = reverse('api-supplier-part-list') original = SupplierPart.objects.first() + assert original is not None self.assertIsNotNone(original) create_note(original) @@ -766,8 +778,11 @@ class SupplierPartTest(InvenTreeAPITestCase): ) duplicate = SupplierPart.objects.get(pk=response.data['pk']) + assert duplicate is not None self.assertEqual(duplicate.notes.count(), 1) - self.assertEqual(duplicate.notes.first().content, 'Some notes
') + note = duplicate.notes.first() + assert note is not None + self.assertEqual(note.content, 'Some notes
') # Explicitly disabling copy_notes must not copy any notes response = self.post( @@ -786,6 +801,7 @@ class SupplierPartTest(InvenTreeAPITestCase): def test_output_options(self): """Test the output options for SupplierPart detail.""" sp = SupplierPart.objects.all().first() + assert sp is not None self.run_output_test( reverse('api-supplier-part-detail', kwargs={'pk': sp.pk}), [ diff --git a/src/backend/InvenTree/company/tests.py b/src/backend/InvenTree/company/tests.py index 8bc8af01d5..134a4a2c9a 100644 --- a/src/backend/InvenTree/company/tests.py +++ b/src/backend/InvenTree/company/tests.py @@ -120,6 +120,7 @@ class CompanySimpleTest(TestCase): def test_metadata(self): """Unit tests for the metadata field.""" p = Company.objects.first() + assert p is not None self.assertIn(p.metadata, [None, {}]) self.assertIsNone(p.get_metadata('test')) @@ -240,14 +241,20 @@ class AddressTest(TestCase): self.assertEqual(Address.objects.count(), 2) - self.assertTrue(Address.objects.first().primary) + address = Address.objects.first() + assert address is not None + self.assertTrue(address.primary) # Create another address, specify *this* as primary Address.objects.create(company=self.c, primary=True) self.assertEqual(Address.objects.count(), 3) - self.assertFalse(Address.objects.first().primary) - self.assertTrue(Address.objects.last().primary) + address = Address.objects.first() + assert address is not None + self.assertFalse(address.primary) + address = Address.objects.last() + assert address is not None + self.assertTrue(address.primary) def test_first_address_is_primary(self): """Test that first address related to company is always set to primary.""" @@ -330,6 +337,7 @@ class ManufacturerPartSimpleTest(TestCase): """Unit tests for the metadata field.""" for model in [ManufacturerPart, SupplierPart]: p = model.objects.first() + assert p is not None self.assertIn(p.metadata, [None, {}]) self.assertIsNone(p.get_metadata('test')) diff --git a/src/backend/InvenTree/data_exporter/serializers.py b/src/backend/InvenTree/data_exporter/serializers.py index c5d01d6196..dc14f30a17 100644 --- a/src/backend/InvenTree/data_exporter/serializers.py +++ b/src/backend/InvenTree/data_exporter/serializers.py @@ -29,7 +29,7 @@ class DataExportOptionsSerializer(serializers.Serializer): # object shared by every instance of this serializer - mutating its 'fields' # list in place would let concurrent requests selecting different plugins # corrupt each other's field list. - class Meta(self.Meta): + class Meta(self.Meta): # ty: ignore[unsupported-base] """Per-instance metaclass options for this serializer.""" fields = ['export_format', 'export_plugin'] diff --git a/src/backend/InvenTree/generic/states/deprecations.py b/src/backend/InvenTree/generic/states/deprecations.py index 42af31afa8..c1f3aaf48a 100644 --- a/src/backend/InvenTree/generic/states/deprecations.py +++ b/src/backend/InvenTree/generic/states/deprecations.py @@ -5,7 +5,9 @@ from typing import Any, Optional # py (3, 12) does not ship with depreciation decorator, so we need to import it from typing_extensions try: - from warnings import deprecated as warn_deprecated # ty: ignore[unresolved-import] + from warnings import ( + deprecated as warn_deprecated, # ty: ignore[missing-module-member] + ) except ImportError: from typing_extensions import deprecated as warn_deprecated diff --git a/src/backend/InvenTree/machine/machine_types/label_printer.py b/src/backend/InvenTree/machine/machine_types/label_printer.py index e8b1e28129..9a24bb9cbf 100644 --- a/src/backend/InvenTree/machine/machine_types/label_printer.py +++ b/src/backend/InvenTree/machine/machine_types/label_printer.py @@ -259,7 +259,7 @@ class LabelPrinterMachine(BaseMachineType): } } - MACHINE_STATUS: type[LabelPrinterStatus] = LabelPrinterStatus + MACHINE_STATUS: type[LabelPrinterStatus] = LabelPrinterStatus # ty: ignore[incompatible-mutable-override] default_machine_status = LabelPrinterStatus.UNKNOWN diff --git a/src/backend/InvenTree/machine/tests.py b/src/backend/InvenTree/machine/tests.py index 729d782cc5..ed2556e699 100755 --- a/src/backend/InvenTree/machine/tests.py +++ b/src/backend/InvenTree/machine/tests.py @@ -135,6 +135,8 @@ class TestDriverMachineInterface(TestMachineRegistryMixin, TestCase): # test get_machine machine = machines[0] + assert machine is not None + assert machine.machine is not None self.assertEqual(registry.get_machine(machine.pk), machine.machine) # Test machine restart hook diff --git a/src/backend/InvenTree/order/models.py b/src/backend/InvenTree/order/models.py index ec34e60701..7b2b94fedc 100644 --- a/src/backend/InvenTree/order/models.py +++ b/src/backend/InvenTree/order/models.py @@ -737,9 +737,9 @@ class PurchaseOrder(AuditedOrderMixin, TotalPriceMixin, Order): def report_context(self) -> PurchaseOrderReportContext: """Return report context data for this PurchaseOrder.""" - return_ctx = super().report_context() + return_ctx: PurchaseOrderReportContext = super().report_context() - return_ctx.update({'supplier': self.supplier}) # ty:ignore[invalid-key] + return_ctx.update({'supplier': self.supplier}) return return_ctx def get_absolute_url(self) -> str: @@ -1521,9 +1521,9 @@ class SalesOrder(AuditedOrderMixin, TotalPriceMixin, Order): def report_context(self) -> SalesOrderReportContext: """Generate report context data for this SalesOrder.""" - return_ctx = super().report_context() + return_ctx: SalesOrderReportContext = super().report_context() - return_ctx.update({'customer': self.customer}) # ty:ignore[invalid-key] + return_ctx.update({'customer': self.customer}) return return_ctx def get_absolute_url(self) -> str: @@ -1909,7 +1909,7 @@ class SalesOrder(AuditedOrderMixin, TotalPriceMixin, Order): raise ValidationError(_('Order is already cancelled')) # Only an open order can be marked as shipped - if self.is_open and not self.is_completed: + if self.is_open and not self.is_completed(): raise ValidationError(_('Only an open order can be marked as complete')) if self.pending_shipment_count > 0: @@ -3446,9 +3446,9 @@ class ReturnOrder(AuditedOrderMixin, TotalPriceMixin, Order): def report_context(self) -> ReturnOrderReportContext: """Generate report context data for this ReturnOrder.""" - return_ctx = super().report_context() + return_ctx: ReturnOrderReportContext = super().report_context() - return_ctx.update({'customer': self.customer}) # ty:ignore[invalid-key] + return_ctx.update({'customer': self.customer}) return return_ctx def get_absolute_url(self): diff --git a/src/backend/InvenTree/order/test_api.py b/src/backend/InvenTree/order/test_api.py index 9ae3364253..013ed8275a 100644 --- a/src/backend/InvenTree/order/test_api.py +++ b/src/backend/InvenTree/order/test_api.py @@ -748,10 +748,11 @@ class PurchaseOrderTest(OrderTest): ) po_dup = models.PurchaseOrder.objects.get(pk=response.data['pk']) + assert po_dup is not None self.assertEqual(po_dup.notes.count(), 1) - self.assertEqual( - po_dup.notes.first().content, 'Some purchase order notes
' - ) + note = po_dup.notes.first() + assert note is not None + self.assertEqual(note.content, 'Some purchase order notes
') # Explicitly disabling copy_notes must not copy any notes response = self.post( @@ -1973,23 +1974,29 @@ class PurchaseOrderReceiveTest(OrderTest): self.assertEqual(line_2.received, 250) stock_1 = StockItem.objects.filter(supplier_part=line_1.part) + assert stock_1 is not None stock_2 = StockItem.objects.filter(supplier_part=line_2.part) + assert stock_2 is not None # 1 new stock item created for each supplier part self.assertEqual(stock_1.count(), 1) self.assertEqual(stock_2.count(), 1) # Check received locations - self.assertEqual(stock_1.last().location.pk, 1) - self.assertEqual(stock_2.last().location.pk, 2) + received_1 = stock_1.last() + received_2 = stock_2.last() + assert received_1 is not None + assert received_2 is not None + self.assertEqual(received_1.location.pk, 1) + self.assertEqual(received_2.location.pk, 2) # Expiry dates should be set - self.assertEqual(stock_1.last().expiry_date, one_week_from_today) - self.assertEqual(stock_2.last().expiry_date, one_week_from_today) + self.assertEqual(received_1.expiry_date, one_week_from_today) + self.assertEqual(received_2.expiry_date, one_week_from_today) # creation_date must be populated on both received items - self.assertIsNotNone(stock_1.last().creation_date) - self.assertIsNotNone(stock_2.last().creation_date) + self.assertIsNotNone(received_1.creation_date) + self.assertIsNotNone(received_2.creation_date) # Barcodes should have been assigned to the stock items self.assertTrue( @@ -2023,7 +2030,9 @@ class PurchaseOrderReceiveTest(OrderTest): self.assertEqual(n + 2, StockItem.objects.count()) item_1 = StockItem.objects.filter(supplier_part=line_1.part).first() + assert item_1 is not None item_2 = StockItem.objects.filter(supplier_part=line_2.part).first() + assert item_2 is not None self.assertEqual(item_1.batch, 'B-abc-123') self.assertEqual(item_2.batch, 'B-xyz-789') @@ -2095,7 +2104,9 @@ class PurchaseOrderReceiveTest(OrderTest): self.assertEqual(n + 2, StockItem.objects.count()) item_1 = StockItem.objects.filter(supplier_part=line_1.part).first() + assert item_1 is not None item_2 = StockItem.objects.filter(supplier_part=line_2.part).first() + assert item_2 is not None # Line item 1 did not specify its own batch code - falls back to top-level value self.assertEqual(item_1.batch, 'B-top-level') @@ -2149,6 +2160,7 @@ class PurchaseOrderReceiveTest(OrderTest): self.assertEqual(items.count(), 1) item = items.first() + assert item is not None self.assertEqual(item.quantity, 10) self.assertEqual(item.batch, 'B-xyz-789') @@ -2195,6 +2207,7 @@ class PurchaseOrderReceiveTest(OrderTest): from stock.status_codes import StockStatus sp = SupplierPart.objects.first() + assert sp is not None # Create a new order po = models.PurchaseOrder.objects.create( @@ -2408,6 +2421,7 @@ class PurchaseOrderReceiveTest(OrderTest): InvenTreeSetting.set_setting('ENABLE_PLUGINS_EVENTS', True, change_user=None) sp = SupplierPart.objects.first() + assert sp is not None po = models.PurchaseOrder.objects.create( reference='PO-BENCHMARK-100', supplier=sp.supplier @@ -2470,9 +2484,11 @@ class PurchaseOrderReceiveTest(OrderTest): self.post(self.url, data, expected_code=201) item_1 = StockItem.objects.filter(supplier_part=line_1.part).first() + assert item_1 is not None self.assertEqual(item_1.packaging, 'Reel') item_2 = StockItem.objects.filter(supplier_part=line_2.part).first() + assert item_2 is not None self.assertEqual(item_2.packaging, 'Tube') # Receive items and override packaging data @@ -2487,9 +2503,11 @@ class PurchaseOrderReceiveTest(OrderTest): self.post(self.url, data, expected_code=201) item_1 = StockItem.objects.filter(supplier_part=line_1.part).last() + assert item_1 is not None self.assertEqual(item_1.packaging, 'Bag') item_2 = StockItem.objects.filter(supplier_part=line_2.part).last() + assert item_2 is not None self.assertEqual(item_2.packaging, 'Box') # Check that the expected number of stock items has been created @@ -2868,10 +2886,11 @@ class SalesOrderTest(OrderTest): ) duplicate_so = models.SalesOrder.objects.get(pk=response.data['pk']) + assert duplicate_so is not None self.assertEqual(duplicate_so.notes.count(), 1) - self.assertEqual( - duplicate_so.notes.first().content, 'Some sales order notes
' - ) + note = duplicate_so.notes.first() + assert note is not None + self.assertEqual(note.content, 'Some sales order notes
') # Explicitly disabling copy_notes must not copy any notes response = self.post( @@ -3880,8 +3899,11 @@ class SalesOrderAllocateTest(OrderTest): ) duplicate = models.SalesOrderShipment.objects.get(pk=response.data['pk']) + assert duplicate is not None self.assertEqual(duplicate.notes.count(), 1) - self.assertEqual(duplicate.notes.first().content, 'Some shipment notes
') + note = duplicate.notes.first() + assert note is not None + self.assertEqual(note.content, 'Some shipment notes
') # Explicitly disabling copy_notes must not copy any notes response = self.post( @@ -4178,6 +4200,7 @@ class ReturnOrderTests(InvenTreeAPITestCase): self.assignRole('return_order.add') rma = models.ReturnOrder.objects.first() + assert rma is not None url = reverse('api-return-order-receive', kwargs={'pk': rma.pk}) max_length = StockItem.TRACKING_NOTES_MAX_LENGTH @@ -4719,6 +4742,7 @@ class OrderDateReadOnlyTests(InvenTreeAPITestCase): with self.subTest(model=model.__name__): # Select a "pending" order, which can be freely edited order = model.objects.filter(status=10).first() + assert order is not None self.assertIsNotNone(order) # Start from a known state, without going via the API @@ -4757,6 +4781,7 @@ class ReturnOrderLineItemTests(InvenTreeAPITestCase): self.assignRole('return_order.change') line = models.ReturnOrderLineItem.objects.filter(received_date=None).first() + assert line is not None self.assertIsNotNone(line) url = reverse('api-return-order-line-detail', kwargs={'pk': line.pk}) @@ -6419,9 +6444,12 @@ class SalesOrderAutoAllocateAPITest(InvenTreeAPITestCase): self.post(self._url(order.pk), {}, expected_code=200) allocs = SalesOrderAllocation.objects.filter(line=line) + assert allocs is not None self.assertEqual(allocs.count(), 1) - self.assertEqual(allocs.first().item, item) - self.assertEqual(allocs.first().quantity, 30) + allocation = allocs.first() + assert allocation is not None + self.assertEqual(allocation.item, item) + self.assertEqual(allocation.quantity, 30) def test_line_items_subset_only_allocates_selected_lines(self): """When line_items is specified only those lines are allocated.""" @@ -6460,8 +6488,11 @@ class SalesOrderAutoAllocateAPITest(InvenTreeAPITestCase): ) allocs = SalesOrderAllocation.objects.filter(line=line) + assert allocs is not None self.assertEqual(allocs.count(), 1) - self.assertEqual(allocs.first().item, serial_item) + allocation = allocs.first() + assert allocation is not None + self.assertEqual(allocation.item, serial_item) def test_unserialized_stock_only(self): """serialized_stock='unserialized' skips serialized items.""" @@ -6511,8 +6542,11 @@ class SalesOrderAutoAllocateAPITest(InvenTreeAPITestCase): ) allocs = SalesOrderAllocation.objects.filter(line=line) + assert allocs is not None self.assertEqual(allocs.count(), 1) - self.assertEqual(allocs.first().quantity, 15) + allocation = allocs.first() + assert allocation is not None + self.assertEqual(allocation.quantity, 15) def test_location_filter(self): """Only stock within the specified location is used.""" @@ -6523,8 +6557,11 @@ class SalesOrderAutoAllocateAPITest(InvenTreeAPITestCase): self.post(self._url(order.pk), {'location': self.loc_a.pk}, expected_code=200) allocs = SalesOrderAllocation.objects.filter(line=line) + assert allocs is not None self.assertEqual(allocs.count(), 1) - self.assertEqual(allocs.first().item.location, self.loc_a) + allocation = allocs.first() + assert allocation is not None + self.assertEqual(allocation.item.location, self.loc_a) def test_exclude_location_filter(self): """Stock in the excluded location is not used.""" @@ -6537,8 +6574,11 @@ class SalesOrderAutoAllocateAPITest(InvenTreeAPITestCase): ) allocs = SalesOrderAllocation.objects.filter(line=line) + assert allocs is not None self.assertEqual(allocs.count(), 1) - self.assertEqual(allocs.first().item.location, self.loc_b) + allocation = allocs.first() + assert allocation is not None + self.assertEqual(allocation.item.location, self.loc_b) def test_shipment_assigned_to_allocations(self): """When a shipment is specified, all allocations are assigned to it.""" diff --git a/src/backend/InvenTree/order/test_sales_order.py b/src/backend/InvenTree/order/test_sales_order.py index 26e393d8be..4186ebcccd 100644 --- a/src/backend/InvenTree/order/test_sales_order.py +++ b/src/backend/InvenTree/order/test_sales_order.py @@ -101,6 +101,7 @@ class SalesOrderTest(InvenTreeAPITestCase): def test_validate_address(self): """Test validation of the linked Address.""" order = SalesOrder.objects.first() + assert order is not None # Create an address for a different company company = Company.objects.exclude(pk=order.customer.pk).first() @@ -115,6 +116,7 @@ class SalesOrderTest(InvenTreeAPITestCase): ) order.address = address + assert order is not None with self.assertRaises(ValidationError) as err: order.clean() @@ -127,6 +129,7 @@ class SalesOrderTest(InvenTreeAPITestCase): # Now validation should pass order.address = address + assert order is not None order.clean() order.save() @@ -803,6 +806,7 @@ class SalesOrderTest(InvenTreeAPITestCase): def test_shipment_address(self): """Unit tests for SalesOrderShipment address field.""" shipment = SalesOrderShipment.objects.first() + assert shipment is not None self.assertIsNotNone(shipment) # Set an address for the order @@ -812,6 +816,7 @@ class SalesOrderTest(InvenTreeAPITestCase): # Save the address against the order shipment.order.address = address_1 + assert shipment is not None shipment.order.clean() shipment.order.save() @@ -830,6 +835,7 @@ class SalesOrderTest(InvenTreeAPITestCase): ) shipment.shipment_address = address_2 + assert shipment is not None shipment.clean() shipment.save() @@ -855,6 +861,7 @@ class SalesOrderTest(InvenTreeAPITestCase): def test_shipment_contact(self): """Unit tests for SalesOrderShipment contact field.""" shipment = SalesOrderShipment.objects.first() + assert shipment is not None self.assertIsNotNone(shipment) self.assertIsNone(shipment.contact) @@ -863,6 +870,7 @@ class SalesOrderTest(InvenTreeAPITestCase): ) shipment.contact = contact + assert shipment is not None shipment.clean() shipment.save() @@ -876,6 +884,7 @@ class SalesOrderTest(InvenTreeAPITestCase): shipment.contact = Contact.objects.create( company=other_company, name='Other Contact' ) + assert shipment is not None with self.assertRaises(ValidationError) as err: shipment.clean() @@ -938,6 +947,7 @@ class SalesOrderTest(InvenTreeAPITestCase): SalesOrderShipment, ]: p = model.objects.first() + assert p is not None self.assertIsNone(p.get_metadata('test')) self.assertEqual(p.get_metadata('test', backup_value=123), 123) @@ -1143,8 +1153,11 @@ class SalesOrderAutoAllocateTest(InvenTreeTestCase): order.auto_allocate_stock() allocs = SalesOrderAllocation.objects.filter(line=line) + assert allocs is not None self.assertEqual(allocs.count(), 1) - self.assertEqual(allocs.first().item, serialized) + allocation = allocs.first() + assert allocation is not None + self.assertEqual(allocation.item, serialized) self.assertTrue(line.is_fully_allocated()) def test_shipment_assigned(self): @@ -1181,10 +1194,13 @@ class SalesOrderAutoAllocateTest(InvenTreeTestCase): order.auto_allocate_stock(stock_sort_by='-quantity', interchangeable=True) allocs = SalesOrderAllocation.objects.filter(line=line) + assert allocs is not None self.assertTrue(allocs.exists()) # Large lot should be the first consumed (fully covers 15) self.assertEqual(allocs.count(), 1) - self.assertEqual(allocs.first().item, large) + allocation = allocs.first() + assert allocation is not None + self.assertEqual(allocation.item, large) def test_task_resolves_pk_params(self): """auto_allocate_sales_order task resolves location/shipment pks to instances.""" diff --git a/src/backend/InvenTree/order/tests.py b/src/backend/InvenTree/order/tests.py index 2b9e31b055..71e5b1032c 100644 --- a/src/backend/InvenTree/order/tests.py +++ b/src/backend/InvenTree/order/tests.py @@ -74,6 +74,7 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase): order.start_date = current_date() order.target_date = current_date() - timedelta(days=5) + assert order is not None with self.assertRaises(django_exceptions.ValidationError) as err: order.clean() @@ -82,6 +83,7 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase): self.assertIn('Start date must be before target date', err.exception.messages) order.target_date = current_date() + timedelta(days=5) + assert order is not None # This should now pass order.clean() @@ -90,6 +92,7 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase): def test_validate_contact(self): """Test for validation of linked Contact.""" order = PurchaseOrder.objects.first() + assert order is not None # Create a contact which does does not match the company company = Company.objects.exclude(pk=order.supplier.pk).first() @@ -97,6 +100,7 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase): contact = Contact.objects.create(company=company, name='Harold Henderson') order.contact = contact + assert order is not None with self.assertRaises(django_exceptions.ValidationError) as err: order.clean() @@ -108,6 +112,7 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase): contact.save() order.contact = contact + assert order is not None order.clean() # Should not raise order.save() @@ -147,6 +152,7 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase): def test_validate_delivery_address(self): """Regression test for validation of the delivery address against the receiving company.""" order = PurchaseOrder.objects.first() + assert order is not None alpha = Company.objects.create(name='Alpha Internal', is_internal=True) beta = Company.objects.create(name='Beta Internal', is_internal=True) @@ -162,6 +168,7 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase): for address in [beta_address, supplier_address]: order.delivery_address = address + assert order is not None with self.assertRaises(django_exceptions.ValidationError) as err: order.clean() @@ -174,6 +181,7 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase): # Delivery address without a receiving company order.receiving_company = None order.delivery_address = alpha_address + assert order is not None with self.assertRaises(django_exceptions.ValidationError) as err: order.clean() @@ -186,6 +194,7 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase): # Receiving company which is not an internal company order.receiving_company = order.supplier order.delivery_address = None + assert order is not None with self.assertRaises(django_exceptions.ValidationError) as err: order.clean() @@ -195,15 +204,18 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase): # Valid combinations order.receiving_company = alpha order.delivery_address = alpha_address + assert order is not None order.clean() order.save() order.receiving_company = alpha order.delivery_address = None + assert order is not None order.clean() order.receiving_company = None order.delivery_address = None + assert order is not None order.clean() def test_rebuild_reference(self): @@ -527,6 +539,7 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase): # Ensure that received quantity and unit purchase price data are correct si = si.first() + assert si is not None self.assertEqual(si.quantity, 10) self.assertEqual(si.purchase_price, Money(100, 'USD')) @@ -535,6 +548,7 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase): # Ensure that received quantity and unit purchase price data are correct si = si.first() + assert si is not None self.assertEqual(si.quantity, 0.5) self.assertEqual(si.purchase_price, Money(100, 'USD')) @@ -619,6 +633,7 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase): self.assertTrue(messages.exists()) msg = messages.first() + assert msg is not None self.assertEqual(msg.target_object_id, str(1)) self.assertEqual(msg.name, 'Overdue Purchase Order') @@ -723,10 +738,12 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase): # Setting metadata to something *other* than a dict will fail with self.assertRaises(django_exceptions.ValidationError): p.metadata = 'test' + assert p is not None p.save() # Reset metadata to known state p.metadata = {} + assert p is not None self.assertIsNone(p.get_metadata('test')) self.assertEqual(p.get_metadata('test', backup_value=123), 123) diff --git a/src/backend/InvenTree/part/test_bom_item.py b/src/backend/InvenTree/part/test_bom_item.py index 9f340a1506..8eb6e2a0a0 100644 --- a/src/backend/InvenTree/part/test_bom_item.py +++ b/src/backend/InvenTree/part/test_bom_item.py @@ -333,6 +333,7 @@ class BomItemTest(TestCase): """Unit tests for the metadata field.""" for model in [BomItem]: p = model.objects.first() + assert p is not None self.assertIsNone(p.get_metadata('test')) self.assertEqual(p.get_metadata('test', backup_value=123), 123) @@ -836,6 +837,7 @@ class BomItemTest(TestCase): item = part.filters.annotate_bom_item_can_build( BomItem.objects.filter(pk=bom_item.pk) ).first() + assert item is not None self.assertAlmostEqual(item.can_build, 2) diff --git a/src/backend/InvenTree/part/test_param.py b/src/backend/InvenTree/part/test_param.py index c511af306b..662b0970de 100644 --- a/src/backend/InvenTree/part/test_param.py +++ b/src/backend/InvenTree/part/test_param.py @@ -79,6 +79,7 @@ class TestParams(TestCase): """Unit tests for the metadata field.""" for model in [ParameterTemplate]: p = model.objects.first() + assert p is not None self.assertIsNone(p.get_metadata('test')) self.assertEqual(p.get_metadata('test', backup_value=123), 123) diff --git a/src/backend/InvenTree/plugin/base/barcodes/test_barcode.py b/src/backend/InvenTree/plugin/base/barcodes/test_barcode.py index cd47b1f42d..fa4866ad56 100644 --- a/src/backend/InvenTree/plugin/base/barcodes/test_barcode.py +++ b/src/backend/InvenTree/plugin/base/barcodes/test_barcode.py @@ -89,6 +89,7 @@ class BarcodeAPITest(InvenTreeAPITestCase): def test_find_stock_item(self): """Test that we can lookup a stock item based on ID.""" item = StockItem.objects.first() + assert item is not None # Save barcode scan results to database set_global_setting('BARCODE_STORE_RESULTS', True) @@ -106,6 +107,7 @@ class BarcodeAPITest(InvenTreeAPITestCase): self.assertEqual(BarcodeScanResult.objects.count(), n + 1) result = BarcodeScanResult.objects.last() + assert result is not None self.assertTrue(result.result) self.assertEqual(result.data, item.format_barcode()) @@ -586,6 +588,7 @@ class SOAllocateTest(InvenTreeAPITestCase): # Test with a barcode that matches a *different* stock item item = StockItem.objects.exclude(pk=self.stock_item.pk).first() + assert item is not None item.assign_barcode(barcode_data='123456789') result = self.postBarcode( diff --git a/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py b/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py index 4ae09064af..5442b52c0d 100644 --- a/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py +++ b/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py @@ -80,12 +80,12 @@ class TestInvenTreeBarcode(InvenTreeAPITestCase): self.assertIn('Missing data: Provide one of', str(response.data['error'])) # Fail with too many fields provided + stock_item = stock.models.StockItem.objects.first() + part_item = part.models.Part.objects.first() + assert stock_item is not None + assert part_item is not None response = self.unassign( - { - 'stockitem': stock.models.StockItem.objects.first().pk, - 'part': part.models.Part.objects.first().pk, - }, - expected_code=400, + {'stockitem': stock_item.pk, 'part': part_item.pk}, expected_code=400 ) self.assertIn('Multiple conflicting fields:', str(response.data['error'])) diff --git a/src/backend/InvenTree/plugin/builtin/exporter/bom_exporter.py b/src/backend/InvenTree/plugin/builtin/exporter/bom_exporter.py index 43f3f0091e..b887264cbc 100644 --- a/src/backend/InvenTree/plugin/builtin/exporter/bom_exporter.py +++ b/src/backend/InvenTree/plugin/builtin/exporter/bom_exporter.py @@ -210,7 +210,7 @@ class BomExporterPlugin(DataExportMixin, InvenTreePlugin): def process_bom_row( self, bom_item, level: int = 1, multiplier: Optional[Decimal] = None, **kwargs - ) -> list: + ) -> Optional[list]: """Process a single BOM row. Arguments: diff --git a/src/backend/InvenTree/plugin/test_api.py b/src/backend/InvenTree/plugin/test_api.py index 69096a71ec..cc9397c9a2 100644 --- a/src/backend/InvenTree/plugin/test_api.py +++ b/src/backend/InvenTree/plugin/test_api.py @@ -368,6 +368,7 @@ class PluginDetailAPITest(PluginMixin, InvenTreeAPITestCase): # Activate the 'sample' plugin via the API cfg = PluginConfig.objects.filter(key='sample').first() + assert cfg is not None self.assertIsNotNone(cfg) url = reverse('api-plugin-detail-activate', kwargs={'plugin': cfg.key}) @@ -492,6 +493,7 @@ class PluginDetailAPITest(PluginMixin, InvenTreeAPITestCase): self.user.save() cfg = PluginConfig.objects.filter(key='sample').first() + assert cfg is not None self.assertIsNotNone(cfg) self.get(f'/api/plugins/{cfg.key}/metadata/', expected_code=200, follow=True) diff --git a/src/backend/InvenTree/plugin/test_plugin.py b/src/backend/InvenTree/plugin/test_plugin.py index 9944b312ab..b5972ecb0c 100644 --- a/src/backend/InvenTree/plugin/test_plugin.py +++ b/src/backend/InvenTree/plugin/test_plugin.py @@ -707,6 +707,7 @@ class RegistryTests(TestQueryMixin, PluginRegistryMixin, TestCase): set_global_setting('_PLUGIN_REGISTRY_HASH', 'other-process-hash') errors = Error.objects.filter(kind='Plugin Registry Mismatch') + assert errors is not None self.assertEqual(errors.count(), 0) # First reload does not reproduce the hash - retried, not yet reported @@ -722,7 +723,9 @@ class RegistryTests(TestQueryMixin, PluginRegistryMixin, TestCase): # Second reload still does not match - the error is reported self.assertTrue(registry.check_reload()) self.assertEqual(errors.count(), 1) - self.assertIn(local_hash, errors.first().data) + error = errors.first() + assert error is not None + self.assertIn(local_hash, error.data) # No further reloads (or errors) for the same hash self.assertFalse(registry.check_reload()) @@ -1244,6 +1247,7 @@ class RegistryTests(TestQueryMixin, PluginRegistryMixin, TestCase): for slug in loaded_but_unmatched: plugin = registry.plugins.get(slug) + assert plugin is not None cfg = registry.get_plugin_config(slug) try: mixin_result = f'mixin_enabled(base)={plugin.mixin_enabled("base")}' diff --git a/src/backend/InvenTree/report/apps.py b/src/backend/InvenTree/report/apps.py index adec77df93..24660630a6 100644 --- a/src/backend/InvenTree/report/apps.py +++ b/src/backend/InvenTree/report/apps.py @@ -74,7 +74,7 @@ class ReportConfig(AppConfig): """Cleanup old label and report outputs.""" try: from report.tasks import ( - cleanup_old_report_outputs, # type: ignore[import] # ty: ignore[unresolved-import] + cleanup_old_report_outputs, # ty: ignore[missing-module-member] ) cleanup_old_report_outputs() diff --git a/src/backend/InvenTree/report/serializers.py b/src/backend/InvenTree/report/serializers.py index fbe0160823..4d1d758a99 100644 --- a/src/backend/InvenTree/report/serializers.py +++ b/src/backend/InvenTree/report/serializers.py @@ -144,7 +144,7 @@ class LabelPrintSerializer(serializers.Serializer): # object shared by every instance of this serializer - mutating its 'fields' # list in place would let concurrent requests selecting different plugins # corrupt each other's field list. - class Meta(self.Meta): + class Meta(self.Meta): # ty: ignore[unsupported-base] """Per-instance metaclass options.""" fields = ['template', 'items', 'plugin'] diff --git a/src/backend/InvenTree/report/test_tags.py b/src/backend/InvenTree/report/test_tags.py index 2a801a1c38..16782e8f09 100644 --- a/src/backend/InvenTree/report/test_tags.py +++ b/src/backend/InvenTree/report/test_tags.py @@ -189,6 +189,7 @@ class ReportTagTest(PartImageTestMixin, InvenTreeTestCase): self.debug_mode(False) asset = report_tags.asset('test.txt') + assert asset is not None # Non-debug mode returns a base64 data: URI (no file:// URLs) self.assertIsNotNone(asset) self.assertTrue(asset.startswith('data:text/plain;base64,')) @@ -1247,7 +1248,9 @@ class BarcodeTagTest(TestCase): self.assertEqual(root.attrib['shape-rendering'], 'crispEdges') background = root.find(f'{namespace}rect') + assert background is not None path = root.find(f'{namespace}path') + assert path is not None self.assertIsNotNone(background) self.assertIsNotNone(path) self.assertEqual(background.attrib['fill'], '#0000ff') @@ -1275,7 +1278,9 @@ class BarcodeTagTest(TestCase): self.assertNotEqual(width, height) background = root.find(f'{namespace}rect') + assert background is not None path = root.find(f'{namespace}path') + assert path is not None self.assertIsNotNone(background) self.assertIsNotNone(path) self.assertEqual(background.attrib['fill'], '#ffffff') @@ -1304,14 +1309,18 @@ class BarcodeTagTest(TestCase): fmt='SVG', ) root = ElementTree.fromstring(base64.b64decode(data.split(',', 1)[1])) + assert root is not None self.assertEqual(root.attrib['viewBox'], f'0 0 {width} {height}') self.assertEqual(root.attrib['width'], str(int(width * scale))) self.assertEqual(root.attrib['height'], str(int(height * scale))) background = root.find(f'{namespace}rect') + assert background is not None self.assertEqual(background.attrib['width'], str(width)) self.assertEqual(background.attrib['height'], str(height)) - path = root.find(f'{namespace}path').attrib['d'] + path_element = root.find(f'{namespace}path') + assert path_element is not None + path = path_element.attrib['d'] modules = re.findall(r'M(\d+) (\d+)h1v1h-1z', path) self.assertEqual(len(modules), sum(map(sum, matrix))) self.assertEqual( @@ -1356,6 +1365,7 @@ class BarcodeTagTest(TestCase): reader = PdfReader(io.BytesIO(pdf)) self.assertEqual(len(reader.pages), 1) page = reader.pages[0] + assert page is not None self.assertEqual(len(page.images), 0) # Count closed module outlines painted in the selected foreground color. @@ -1363,7 +1373,9 @@ class BarcodeTagTest(TestCase): color = None closed_paths = 0 painted_modules = 0 - for operands, operator in page.get_contents().operations: + content_stream = page.get_contents() + assert content_stream is not None + for operands, operator in content_stream.operations: if operator == b'rg': color = tuple(operands) elif operator == b'h': diff --git a/src/backend/InvenTree/report/tests.py b/src/backend/InvenTree/report/tests.py index d68d226209..5a973ec6f6 100644 --- a/src/backend/InvenTree/report/tests.py +++ b/src/backend/InvenTree/report/tests.py @@ -72,6 +72,7 @@ class ReportTest(InvenTreeAPITestCase): from company.models import Company template = ReportTemplate.objects.first() + assert template is not None self.assertIsNone(template.base_context()['internal_company']) company = Company.objects.create( @@ -246,6 +247,7 @@ class ReportTest(InvenTreeAPITestCase): def test_metadata(self): """Unit tests for the metadata field.""" p = ReportTemplate.objects.first() + assert p is not None self.assertEqual(p.metadata, {}) @@ -323,16 +325,21 @@ class ReportTest(InvenTreeAPITestCase): template = ReportTemplate.objects.filter( enabled=True, model_type='stockitem' ).first() + assert template is not None # Gather some items items = StockItem.objects.all()[0:5] output = template.print(items) + assert output is not None self.assertTrue(output.complete) self.assertEqual(output.total, 5) self.assertIsNotNone(output.output) - self.assertTrue(output.output.name.endswith('.pdf')) + assert output.output is not None + output_name = output.output.name + assert output_name is not None + self.assertTrue(output_name.endswith('.pdf')) def test_print_build_order(self): """Test that the built-in Build Order report renders correctly. @@ -357,10 +364,14 @@ class ReportTest(InvenTreeAPITestCase): ) output = template.print([build]) + assert output is not None self.assertTrue(output.complete) self.assertIsNotNone(output.output) - self.assertTrue(output.output.name.endswith('.pdf')) + assert output.output is not None + output_name = output.output.name + assert output_name is not None + self.assertTrue(output_name.endswith('.pdf')) def test_print_stock_location(self): """Test that the built-in Stock Location report renders each item's note. @@ -434,6 +445,7 @@ class ReportTest(InvenTreeAPITestCase): ) item = StockItem.objects.first() + assert item is not None test_strings = [ f'Hello {self.user.username}', @@ -522,6 +534,7 @@ class LabelTest(InvenTreeAPITestCase): """Test manual printing of label templates.""" # Find a suitable label template template = LabelTemplate.objects.filter(enabled=True, model_type='part').first() + assert template is not None # Gather some items parts = Part.objects.all()[0:10] @@ -533,20 +546,29 @@ class LabelTest(InvenTreeAPITestCase): self.assertIsNotNone(plugin) output = template.print(items=parts, plugin=plugin) + assert output is not None self.assertTrue(output.complete) self.assertEqual(output.total, 10) self.assertIsNotNone(output.output) + assert output.output is not None self.assertEqual(output.plugin, 'inventreelabel') - self.assertTrue(output.output.name.endswith('.pdf')) + output_name = output.output.name + assert output_name is not None + self.assertTrue(output_name.endswith('.pdf')) # Filename patterns without an extension must still produce PDF filenames. template.filename_pattern = 'unit_test_label' + assert template is not None template.save() output = template.print(items=parts[:1], plugin=plugin) + assert output is not None - self.assertTrue(output.output.name.endswith('.pdf')) + assert output.output is not None + output_name = output.output.name + assert output_name is not None + self.assertTrue(output_name.endswith('.pdf')) def test_generated_file_filename(self): """PDF filenames retain existing suffixes and default when empty.""" @@ -576,7 +598,9 @@ class LabelTest(InvenTreeAPITestCase): OrmQ.objects.all().delete() template = LabelTemplate.objects.filter(enabled=True, model_type='part').first() + assert template is not None part = Part.objects.first() + assert part is not None with patch('InvenTree.status.is_worker_running', return_value=True): response = self.post( @@ -604,6 +628,7 @@ class LabelTest(InvenTreeAPITestCase): def test_print_failure(self): """Printing failures retain their details and propagate to the caller.""" template = LabelTemplate.objects.filter(enabled=True, model_type='part').first() + assert template is not None parts = list(Part.objects.all()[:1]) for worker in [False, True]: @@ -659,11 +684,13 @@ class LabelTest(InvenTreeAPITestCase): def test_print_unavailable_plugin(self): """An unavailable worker plugin records a failure instead of hanging.""" template = LabelTemplate.objects.filter(enabled=True, model_type='part').first() + assert template is not None output = report_models.DataOutput.objects.create( output_type=report_models.DataOutput.DataOutputTypes.LABEL, template_name=template.name, plugin='unavailable-label', ) + assert output is not None with ( patch.object(registry, 'get_plugin', return_value=None) as get_plugin, @@ -686,6 +713,7 @@ class LabelTest(InvenTreeAPITestCase): def test_print_task_duplicate(self): """Duplicate tasks skip completed or deleted outputs before plugin lookup.""" template = LabelTemplate.objects.filter(enabled=True, model_type='part').first() + assert template is not None for deleted in [False, True]: with self.subTest(deleted=deleted): @@ -749,7 +777,9 @@ class LabelTest(InvenTreeAPITestCase): filename_pattern='unit_test_label.pdf', ) - location = StockItem.objects.exclude(location=None).first().location + stock_item = StockItem.objects.exclude(location=None).first() + assert stock_item is not None + location = stock_item.location url = reverse('api-label-print') post_data = {'template': template.pk, 'items': [location.pk]} @@ -817,10 +847,12 @@ class LabelTest(InvenTreeAPITestCase): for f in invalid: with self.assertRaises(ValidationError): template.filters = f + assert template is not None template.clean() for f in valid: template.filters = f + assert template is not None template.clean() # Test a specific example @@ -1039,6 +1071,7 @@ class TestReportTest(PrintTestMixins, ReportTest): # Now print with a valid StockItem item = StockItem.objects.first() + assert item is not None n = item.attachments.count() @@ -1058,6 +1091,7 @@ class TestReportTest(PrintTestMixins, ReportTest): # Now try again, but attach the generated PDF to the StockItem template.attach_to_model = True + assert template is not None template.save() response = self.post( @@ -1078,6 +1112,7 @@ class TestReportTest(PrintTestMixins, ReportTest): template_merge = ReportTemplate.objects.filter( enabled=True, model_type='stockitem', merge=True ).first() + assert template_merge is not None # Grab the first 3 stock items items = StockItem.objects.all()[:3] @@ -1143,6 +1178,7 @@ class ReportPrintPermissionTest(InvenTreeAPITestCase): template = ReportTemplate.objects.filter( enabled=True, model_type='purchaseorder' ).first() + assert template is not None self.assertIsNotNone(template) items = PurchaseOrder.objects.all()[:2] @@ -1169,6 +1205,7 @@ class ReportPrintPermissionTest(InvenTreeAPITestCase): template = ReportTemplate.objects.filter( enabled=True, model_type='purchaseorder' ).first() + assert template is not None self.assertIsNotNone(template) items = PurchaseOrder.objects.all()[:2] @@ -1182,6 +1219,7 @@ class ReportPrintPermissionTest(InvenTreeAPITestCase): # Disable the template and retry: should be rejected template.enabled = False + assert template is not None template.save() self.post(url, data=post_data, expected_code=400) @@ -1204,6 +1242,7 @@ class LabelPrintPermissionTest(InvenTreeAPITestCase): def test_label_print_model_permission(self): """A user without VIEW permission on the model type must receive 403; granting the role allows printing.""" template = LabelTemplate.objects.filter(enabled=True, model_type='part').first() + assert template is not None self.assertIsNotNone(template) self.assertGreater(template.width, 0) self.assertGreater(template.height, 0) @@ -1230,6 +1269,7 @@ class LabelPrintPermissionTest(InvenTreeAPITestCase): cache.clear() template = LabelTemplate.objects.filter(enabled=True, model_type='part').first() + assert template is not None self.assertIsNotNone(template) self.assertGreater(template.width, 0) self.assertGreater(template.height, 0) @@ -1245,6 +1285,7 @@ class LabelPrintPermissionTest(InvenTreeAPITestCase): # Disable the template and retry: should be rejected template.enabled = False + assert template is not None template.save() self.post(url, data=post_data, expected_code=400) @@ -1294,6 +1335,7 @@ class URLFetcherE2ETest(ReportTest): template_pk = response.data['pk'] item = StockItem.objects.first() + assert item is not None self.assertIsNotNone(item) # Render the template. WeasyPrint catches the ValueError from our fetcher and @@ -1346,6 +1388,7 @@ class URLFetcherE2ETest(ReportTest): template_pk = response.data['pk'] item = StockItem.objects.first() + assert item is not None self.assertIsNotNone(item) # Render the template. WeasyPrint catches the ValueError from our fetcher and @@ -1402,6 +1445,7 @@ class URLFetcherE2ETest(ReportTest): template_pk = response.data['pk'] item = StockItem.objects.first() + assert item is not None self.assertIsNotNone(item) set_global_setting('REPORT_FETCH_URLS', False, change_user=None) diff --git a/src/backend/InvenTree/script/update_icons.py b/src/backend/InvenTree/script/update_icons.py index 716ffeb878..ea24479456 100644 --- a/src/backend/InvenTree/script/update_icons.py +++ b/src/backend/InvenTree/script/update_icons.py @@ -19,7 +19,7 @@ if __name__ == '__main__': os.mkdir(STATIC_FOLDER) print('Downloading tabler icons...') - os.system(f'npm install --prefix {TMP_FOLDER} @tabler/icons @tabler/icons-webfont') # ty:ignore[deprecated] + os.system(f'npm install --prefix {TMP_FOLDER} @tabler/icons @tabler/icons-webfont') print(f'Copying tabler icons to {STATIC_FOLDER}...') diff --git a/src/backend/InvenTree/stock/test_api.py b/src/backend/InvenTree/stock/test_api.py index bb2b58c641..a2dadafb74 100644 --- a/src/backend/InvenTree/stock/test_api.py +++ b/src/backend/InvenTree/stock/test_api.py @@ -2089,8 +2089,11 @@ class StockItemTest(StockAPITestCase): ) new_item = StockItem.objects.get(pk=response.data[0]['pk']) + assert new_item is not None self.assertEqual(new_item.notes.count(), 1) - self.assertEqual(new_item.notes.first().content, 'Some stock item notes
') + note = new_item.notes.first() + assert note is not None + self.assertEqual(note.content, 'Some stock item notes
') # Explicitly disabling copy_notes must not copy any notes response = self.post( diff --git a/src/backend/InvenTree/stock/tests.py b/src/backend/InvenTree/stock/tests.py index d4b3d2a5fb..8633c7fc7f 100644 --- a/src/backend/InvenTree/stock/tests.py +++ b/src/backend/InvenTree/stock/tests.py @@ -297,6 +297,7 @@ class StockTest(StockTestBase): # Check that a tracking item was added track = stock_events(it).last() + assert track self.assertEqual(track.event_type, StockHistoryCode.STOCK_MOVE) self.assertEqual(track.notes, 'Moved to the bathroom') @@ -367,6 +368,7 @@ class StockTest(StockTestBase): parent_entry = stock_events( parent, event_type=StockHistoryCode.SPLIT_CHILD_ITEM ).first() + assert parent_entry self.assertIsNotNone(parent_entry) self.assertEqual( @@ -378,8 +380,11 @@ class StockTest(StockTestBase): grandparent = StockItem.objects.get(id=1234) parent = grandparent.splitStock(200, None, self.user) + assert parent child_a = parent.splitStock(50, None, self.user) + assert child_a child_b = parent.splitStock(50, None, self.user) + assert child_b self.assertEqual(parent.parent, grandparent) self.assertEqual(child_a.parent, parent) @@ -409,7 +414,9 @@ class StockTest(StockTestBase): # An item depleted to zero with delete_on_deplete set is deleted parent = grandparent.splitStock(200, None, self.user) + assert parent child = parent.splitStock(50, None, self.user) + assert child parent.delete_on_deplete = True parent.save() @@ -422,7 +429,9 @@ class StockTest(StockTestBase): # An item absorbed by a merge is also deleted source = grandparent.splitStock(100, None, self.user) + assert source kid = source.splitStock(25, None, self.user) + assert kid target = StockItem.objects.create( part=grandparent.part, @@ -462,6 +471,7 @@ class StockTest(StockTestBase): # History records the quantity which was *actually* removed entry = stock_events(item).last() + assert entry self.assertEqual(entry.additional_data['deltas']['removed'], 10.0) self.assertEqual( [Decimal(value) for value in entry.changes_dict['quantity']], [10, 0] @@ -478,6 +488,7 @@ class StockTest(StockTestBase): item = StockItem.objects.create(part=part, quantity=10) allocated = item.allocateToCustomer(customer, quantity=25, user=self.user) + assert allocated # The whole item is allocated (no split occurs) self.assertEqual(allocated.pk, item.pk) @@ -485,6 +496,7 @@ class StockTest(StockTestBase): # History records the quantity which was *actually* allocated entry = stock_events(allocated).last() + assert entry self.assertEqual(entry.additional_data['deltas']['quantity'], 10.0) # A zero quantity is rejected outright @@ -513,11 +525,13 @@ class StockTest(StockTestBase): entry = stock_events( component, event_type=StockHistoryCode.INSTALLED_INTO_ASSEMBLY ).last() + assert entry self.assertEqual(entry.additional_data['deltas']['quantity'], 10.0) entry = stock_events( parent_item, event_type=StockHistoryCode.INSTALLED_CHILD_ITEM ).last() + assert entry self.assertEqual(entry.additional_data['deltas']['quantity'], 10.0) # A zero quantity is rejected outright @@ -571,6 +585,7 @@ class StockTest(StockTestBase): ) parent = StockItem.objects.create(part=part, quantity=100) + assert parent self.assertEqual(parent.children.count(), 0) self.assertEqual(parent.child_count, 0) @@ -578,6 +593,7 @@ class StockTest(StockTestBase): # Split off two child items child_1 = parent.splitStock(10, None, self.user) + assert child_1 child_2 = parent.splitStock(20, None, self.user) parent.refresh_from_db() @@ -636,6 +652,7 @@ class StockTest(StockTestBase): item.take_stock(500, self.user) child = item_d.splitStock(300, None, self.user) + assert child item.refresh_from_db() self.assertEqual(item.quantity, 200) @@ -679,6 +696,7 @@ class StockTest(StockTestBase): # Check that a tracking item was added track = stock_events(it).last() + assert track self.assertEqual(track.event_type, StockHistoryCode.STOCK_COUNT) self.assertIn('Counted items', track.notes) @@ -764,6 +782,7 @@ class StockTest(StockTestBase): InvenTreeSetting.set_setting('ENABLE_PLUGINS_EVENTS', True, change_user=None) item = StockItem.objects.get(pk=2) + assert item OrmQ.objects.all().delete() @@ -788,6 +807,7 @@ class StockTest(StockTestBase): # Check that a tracking item was added track = stock_events(it).last() + assert track self.assertEqual(track.event_type, StockHistoryCode.STOCK_ADD) self.assertIn('Added some items', track.notes) @@ -804,6 +824,7 @@ class StockTest(StockTestBase): ait = it.allocateToCustomer( customer, quantity=an, order=order, user=None, notes='Allocated some stock' ) + assert ait # Check if new stockitem is created self.assertTrue(ait) @@ -818,6 +839,7 @@ class StockTest(StockTestBase): # Check that a tracking item was added track = stock_events(ait).last() + assert track self.assertEqual(track.event_type, StockHistoryCode.SHIPPED_AGAINST_SALES_ORDER) self.assertIn('Allocated some stock', track.notes) @@ -839,6 +861,7 @@ class StockTest(StockTestBase): ait = it.allocateToCustomer( customer, quantity=an, order=order, user=None, notes='Allocated some stock' ) + assert ait self.assertEqual(ait.quantity, an) self.assertTrue(ait.parent, it) @@ -858,6 +881,7 @@ class StockTest(StockTestBase): ait = it.allocateToCustomer( customer, quantity=an, order=order, user=None, notes='Allocated some stock' ) + assert ait ait.return_from_customer( self.drawer3, None, notes='Stock removed from customer' ) @@ -875,6 +899,7 @@ class StockTest(StockTestBase): # Check that a tracking item was added track = stock_events(ait).last() + assert track self.assertEqual(track.event_type, StockHistoryCode.RETURNED_FROM_CUSTOMER) self.assertIn('Stock removed from customer', track.notes) @@ -895,6 +920,7 @@ class StockTest(StockTestBase): # Check that a tracking item was added track = stock_events(it).last() + assert track self.assertEqual(track.event_type, StockHistoryCode.STOCK_REMOVE) self.assertIn('Removed some items', track.notes) @@ -1010,6 +1036,8 @@ class StockTest(StockTestBase): item_next = item.get_next_serialized_item() item_prev = item.get_next_serialized_item(reverse=True) + assert item_next + assert item_prev self.assertEqual(item_next.serial_int, 101) self.assertEqual(item_prev.serial_int, 99) @@ -1085,6 +1113,7 @@ class StockTest(StockTestBase): """Unit tests for the metadata field.""" for model in [StockItem, StockLocation]: p = model.objects.first() + assert p self.assertIsNone(p.get_metadata('test')) self.assertEqual(p.get_metadata('test', backup_value=123), 123) @@ -1103,6 +1132,7 @@ class StockTest(StockTestBase): from djmoney.money import Money part = Part.objects.first() + assert part part.stock_items.all().delete() # Test simple merge without any pricing information @@ -1120,6 +1150,7 @@ class StockTest(StockTestBase): merge_entry = stock_events( s1, event_type=StockHistoryCode.MERGED_STOCK_ITEMS ).first() + assert merge_entry self.assertIsNotNone(merge_entry) self.assertEqual(merge_entry.additional_data['deltas']['added'], 50.0) self.assertEqual( @@ -1171,6 +1202,7 @@ class StockTest(StockTestBase): allowing e.g. a build output to be merged away and deleted. """ part = Part.objects.first() + assert part part.stock_items.all().delete() target = StockItem.objects.create(part=part, quantity=10) @@ -1351,6 +1383,7 @@ class TrackingEventBatchTests(StockTestBase): for item in items: entry = self.history(item).last() + assert entry self.assertEqual(entry.event_type, StockHistoryCode.STOCK_COUNT) self.assertEqual(entry.notes, 'Batch stocktake') @@ -1793,6 +1826,7 @@ class TestResultTest(StockTestBase): # Split some items out item2 = item.splitStock(20, None, None) + assert item2 self.assertEqual(item.quantity, 30) diff --git a/src/backend/InvenTree/users/models.py b/src/backend/InvenTree/users/models.py index f4949f319a..3ae9276a78 100644 --- a/src/backend/InvenTree/users/models.py +++ b/src/backend/InvenTree/users/models.py @@ -53,7 +53,7 @@ User.add_to_class('__str__', user_model_str) # Overriding User.__str__ if settings.LDAP_AUTH: # pragma: no cover - from django_auth_ldap.backend import populate_user # ty: ignore[unresolved-import] + from django_auth_ldap.backend import populate_user # ty: ignore[import-not-found] @receiver(populate_user) def create_email_address(user, **kwargs): diff --git a/src/backend/InvenTree/users/test_api.py b/src/backend/InvenTree/users/test_api.py index 45841a57dc..1124d6f478 100644 --- a/src/backend/InvenTree/users/test_api.py +++ b/src/backend/InvenTree/users/test_api.py @@ -675,8 +675,11 @@ class UserTokenTests(InvenTreeAPITestCase): self.assertTrue(any('INVE-W7' in msg for msg in logs.output)) msgs = NotificationMessage.objects.filter(category=category, user=self.user) + assert msgs is not None self.assertEqual(msgs.count(), 1) - self.assertIn("'notify'", msgs.first().message) + message = msgs.first() + assert message is not None + self.assertIn("'notify'", message.message) # Re-issuing a token with the same name sends another notification self.get(url, data={'name': 'notify'}, expected_code=200) @@ -691,6 +694,7 @@ class UserTokenTests(InvenTreeAPITestCase): self.user.is_superuser = True self.user.save() other = User.objects.exclude(pk=self.user.pk).first() + assert other is not None data = self.post( reverse('api-token-list'), diff --git a/src/backend/InvenTree/users/tests.py b/src/backend/InvenTree/users/tests.py index fefef59a7a..c0e0377eff 100644 --- a/src/backend/InvenTree/users/tests.py +++ b/src/backend/InvenTree/users/tests.py @@ -350,6 +350,7 @@ class OwnerModelTest(InvenTreeTestCase): raw_token = response['token'] self.assertTrue(raw_token.startswith('inv-2-')) token = ApiToken.get_from_string(raw_token) + assert token is not None self.assertTrue(token.validate(raw_token)) # test user is associated with token diff --git a/src/backend/requirements-dev-3.14.txt b/src/backend/requirements-dev-3.14.txt index 4ed468f382..cdf2f3fbb1 100644 --- a/src/backend/requirements-dev-3.14.txt +++ b/src/backend/requirements-dev-3.14.txt @@ -995,37 +995,37 @@ sqlparse==0.6.1 \ # -c src/backend/requirements.txt # django # django-silk -ty==0.0.76 \ - --hash=sha256:103b8792e437d640e56b7fe6a9e84dd574142427f0e13440897f12603b01c78b \ - --hash=sha256:11cb5155c71d74ae4662f7e880462fbcd343980a635d79d6bb35fa98cf115b16 \ - --hash=sha256:12a5567e8278afb398b16251df142b2926809c7365aa7c395f3f9c72782ad052 \ - --hash=sha256:26029f10116db099896be693b316ba972dcbec00c115caafb646fd7c00dbdd37 \ - --hash=sha256:470e6c618f3712d7b32435f83550144384fb42b0c2e127c6446e1d6a907a8b4f \ - --hash=sha256:4ac9762bff39bee64679dba416151e88d4067a873eff737cd9c902ae7a325cc9 \ - --hash=sha256:4f546fb03f4c1e2506e894560a5d37729eca81560fcdfd0f860e5314f427ac9a \ - --hash=sha256:575f707b3ce40ed249394b5c8b2dc4b523e50730d7d60985d93bf956fc4dcf65 \ - --hash=sha256:6e91c4d6d6f3d1f2a114655b2b43b1859af90ee9aed6120b2b8d873956c63e9e \ - --hash=sha256:73c0f786dee77040b87784c35b390f40dc331c52cb63ede67f006414d892351f \ - --hash=sha256:886bc8b0fed79a7315f21efee2579a9cef69f33c1a20fbd6bc87fa87616164bb \ - --hash=sha256:b08468a66067858aeaf68b0cb9938cd4cab8647049018e76466ddca417a2290c \ - --hash=sha256:b6911a50d3c675a9f07bc651d77784adc4615faeff97f8aeb16b7607bae50c73 \ - --hash=sha256:b9193de7942f7f6eeb95b88b9026acc6090aa8038446323b37c6481c296b8617 \ - --hash=sha256:ca28d51020b9c9c2c1302d738a9e11857278aa1d0b830f9ee3a35b01144135da \ - --hash=sha256:e3c1bffbac96a81a41ed1b7f233dbb312e13c48c9490721fa65684c541059d25 \ - --hash=sha256:fc616d1ab7e27c5255742701f6b5da4d1a5102dba64632884366e4b04c81b927 \ - --hash=sha256:ffa1cffbc62a1dfe627f852d3d20c4e49441dc0e2c5d44dd6538c844a3f6d62e +ty==0.0.109 \ + --hash=sha256:202919a6429e504cfe1b88d34ca231b4b4625816c688fb368dbcfda9d324bb5a \ + --hash=sha256:267fa530665c437f5f490c55a3d60aea8be00795462f614009913418737b3a99 \ + --hash=sha256:3425dd066d43e6125dd2ddc42c348d1e0801b7ae35b886d63916a37a9ec80830 \ + --hash=sha256:5bb6fc5faca2f2a584a5fe1cd5c57e2a11d0c65dd6b55ba78610d96548c837f9 \ + --hash=sha256:66d382a0022de5c9ce0d082bca23a696e24c890cd8316f3461d485cf0c8b6aa7 \ + --hash=sha256:7e9dc77a3a1e1124c08fb094dcadc7068081a8579859017b5d5de37b257969c8 \ + --hash=sha256:897796fe1d8a5ac1122900e19d31eeb8272b542f9934cb40cf1377050f477200 \ + --hash=sha256:8de0ee28bca7b7e25164a52e2b3e914d0f4380cb440c24a0cf5a9fc9c4d0085b \ + --hash=sha256:9268e9c21dc056d4320a5f5eadfe8175e23082b2b213dad89a27e492999f31d7 \ + --hash=sha256:b706b0f4cff9ceed46c813e7132dbbacce9f7fb9524cb5b7a6f8ad63677e8436 \ + --hash=sha256:b856cb4ae2a51a81b2bc2f4de108091d0000845fb262a095f14a2430397d4321 \ + --hash=sha256:c95ccb6fd99830e314165ed909f0160a54cd6365265ec7a89ad971a4ef83e123 \ + --hash=sha256:cee52815e6114aa5981483ff2eddc17f756275e19a61de45c8d0031ec6b52cd6 \ + --hash=sha256:d404b7cafbb3af0d1c4754f61fe6cedc6c67bd839b5821e05998468f2e0a9a53 \ + --hash=sha256:e8cfb207bba2335aecc42ece4ec17eecb644935475e80e4d3907e0b57aa9dee1 \ + --hash=sha256:ec3330a2ed852eecedb663d7db67b100b21971c74f4c95e4f9a1e9d706b0677e \ + --hash=sha256:f22795bea2a7ff99ddbf9b38c8fa54f0b2e85047f21cab34d8492cbfad07cba7 \ + --hash=sha256:f5948f669f8a9ed429c087f2a496fff87594ce0c31a8b2401f47483496446d06 # via # -c src/backend/requirements-dev.txt # -r src/backend/requirements-dev.in -types-psycopg2==2.9.21.20261030 \ - --hash=sha256:7850716d731d6bf45c53f2d26179e2bcf7273d1d3acfd56b0201adc1dec4ba20 \ - --hash=sha256:e51ed54722bc7bc3cfb635a8623d9915d1816ed789c926c40b5f61d5f417a4ab +types-psycopg2==2.9.21.20261122 \ + --hash=sha256:2f8288d554d59c3091c4a5b781a087e52663866e4aadf3ab5aa7e4a7eb8bc5e8 \ + --hash=sha256:4c045b8b0add828c75f00d7d602a5375ccd433521582af1a78bb153795e7d80c # via # -c src/backend/requirements-dev.txt # django-types -types-pyyaml==6.0.12.20261113 \ - --hash=sha256:0828be2580fd94151182364f4d0158e4de62fdbeeb8d4296f7f7d2b6c22bb640 \ - --hash=sha256:3600749e613748afdc4327f0b17c3296cf880cdbc7335f320007abd9dd815f67 +types-pyyaml==6.0.12.20261122 \ + --hash=sha256:689fbbe883b60471166dede9dba6ac0dbdbcf0ea98062d7ec195430f5bbdb009 \ + --hash=sha256:7fa577c893a1db255cbb02320884ffcb97b7a219fe515bec6c5f15d5d3af41ed # via # -c src/backend/requirements-dev.txt # django-stubs diff --git a/src/backend/requirements-dev.txt b/src/backend/requirements-dev.txt index 9949548d97..9437070b8e 100644 --- a/src/backend/requirements-dev.txt +++ b/src/backend/requirements-dev.txt @@ -900,33 +900,33 @@ sqlparse==0.6.1 \ # -c src/backend/requirements.txt # django # django-silk -ty==0.0.76 \ - --hash=sha256:103b8792e437d640e56b7fe6a9e84dd574142427f0e13440897f12603b01c78b \ - --hash=sha256:11cb5155c71d74ae4662f7e880462fbcd343980a635d79d6bb35fa98cf115b16 \ - --hash=sha256:12a5567e8278afb398b16251df142b2926809c7365aa7c395f3f9c72782ad052 \ - --hash=sha256:26029f10116db099896be693b316ba972dcbec00c115caafb646fd7c00dbdd37 \ - --hash=sha256:470e6c618f3712d7b32435f83550144384fb42b0c2e127c6446e1d6a907a8b4f \ - --hash=sha256:4ac9762bff39bee64679dba416151e88d4067a873eff737cd9c902ae7a325cc9 \ - --hash=sha256:4f546fb03f4c1e2506e894560a5d37729eca81560fcdfd0f860e5314f427ac9a \ - --hash=sha256:575f707b3ce40ed249394b5c8b2dc4b523e50730d7d60985d93bf956fc4dcf65 \ - --hash=sha256:6e91c4d6d6f3d1f2a114655b2b43b1859af90ee9aed6120b2b8d873956c63e9e \ - --hash=sha256:73c0f786dee77040b87784c35b390f40dc331c52cb63ede67f006414d892351f \ - --hash=sha256:886bc8b0fed79a7315f21efee2579a9cef69f33c1a20fbd6bc87fa87616164bb \ - --hash=sha256:b08468a66067858aeaf68b0cb9938cd4cab8647049018e76466ddca417a2290c \ - --hash=sha256:b6911a50d3c675a9f07bc651d77784adc4615faeff97f8aeb16b7607bae50c73 \ - --hash=sha256:b9193de7942f7f6eeb95b88b9026acc6090aa8038446323b37c6481c296b8617 \ - --hash=sha256:ca28d51020b9c9c2c1302d738a9e11857278aa1d0b830f9ee3a35b01144135da \ - --hash=sha256:e3c1bffbac96a81a41ed1b7f233dbb312e13c48c9490721fa65684c541059d25 \ - --hash=sha256:fc616d1ab7e27c5255742701f6b5da4d1a5102dba64632884366e4b04c81b927 \ - --hash=sha256:ffa1cffbc62a1dfe627f852d3d20c4e49441dc0e2c5d44dd6538c844a3f6d62e +ty==0.0.109 \ + --hash=sha256:202919a6429e504cfe1b88d34ca231b4b4625816c688fb368dbcfda9d324bb5a \ + --hash=sha256:267fa530665c437f5f490c55a3d60aea8be00795462f614009913418737b3a99 \ + --hash=sha256:3425dd066d43e6125dd2ddc42c348d1e0801b7ae35b886d63916a37a9ec80830 \ + --hash=sha256:5bb6fc5faca2f2a584a5fe1cd5c57e2a11d0c65dd6b55ba78610d96548c837f9 \ + --hash=sha256:66d382a0022de5c9ce0d082bca23a696e24c890cd8316f3461d485cf0c8b6aa7 \ + --hash=sha256:7e9dc77a3a1e1124c08fb094dcadc7068081a8579859017b5d5de37b257969c8 \ + --hash=sha256:897796fe1d8a5ac1122900e19d31eeb8272b542f9934cb40cf1377050f477200 \ + --hash=sha256:8de0ee28bca7b7e25164a52e2b3e914d0f4380cb440c24a0cf5a9fc9c4d0085b \ + --hash=sha256:9268e9c21dc056d4320a5f5eadfe8175e23082b2b213dad89a27e492999f31d7 \ + --hash=sha256:b706b0f4cff9ceed46c813e7132dbbacce9f7fb9524cb5b7a6f8ad63677e8436 \ + --hash=sha256:b856cb4ae2a51a81b2bc2f4de108091d0000845fb262a095f14a2430397d4321 \ + --hash=sha256:c95ccb6fd99830e314165ed909f0160a54cd6365265ec7a89ad971a4ef83e123 \ + --hash=sha256:cee52815e6114aa5981483ff2eddc17f756275e19a61de45c8d0031ec6b52cd6 \ + --hash=sha256:d404b7cafbb3af0d1c4754f61fe6cedc6c67bd839b5821e05998468f2e0a9a53 \ + --hash=sha256:e8cfb207bba2335aecc42ece4ec17eecb644935475e80e4d3907e0b57aa9dee1 \ + --hash=sha256:ec3330a2ed852eecedb663d7db67b100b21971c74f4c95e4f9a1e9d706b0677e \ + --hash=sha256:f22795bea2a7ff99ddbf9b38c8fa54f0b2e85047f21cab34d8492cbfad07cba7 \ + --hash=sha256:f5948f669f8a9ed429c087f2a496fff87594ce0c31a8b2401f47483496446d06 # via -r src/backend/requirements-dev.in -types-psycopg2==2.9.21.20261030 \ - --hash=sha256:7850716d731d6bf45c53f2d26179e2bcf7273d1d3acfd56b0201adc1dec4ba20 \ - --hash=sha256:e51ed54722bc7bc3cfb635a8623d9915d1816ed789c926c40b5f61d5f417a4ab +types-psycopg2==2.9.21.20261122 \ + --hash=sha256:2f8288d554d59c3091c4a5b781a087e52663866e4aadf3ab5aa7e4a7eb8bc5e8 \ + --hash=sha256:4c045b8b0add828c75f00d7d602a5375ccd433521582af1a78bb153795e7d80c # via django-types -types-pyyaml==6.0.12.20261113 \ - --hash=sha256:0828be2580fd94151182364f4d0158e4de62fdbeeb8d4296f7f7d2b6c22bb640 \ - --hash=sha256:3600749e613748afdc4327f0b17c3296cf880cdbc7335f320007abd9dd815f67 +types-pyyaml==6.0.12.20261122 \ + --hash=sha256:689fbbe883b60471166dede9dba6ac0dbdbcf0ea98062d7ec195430f5bbdb009 \ + --hash=sha256:7fa577c893a1db255cbb02320884ffcb97b7a219fe515bec6c5f15d5d3af41ed # via django-stubs typing-extensions==4.16.0 \ --hash=sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8 \