mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	Logic fix for plugin.is_active (#10026)
* Logic fix for plugin.is_active - Previously were not considering the "mandatory" attribute * Fix unit tests * Allow more queries * Fix unit tests
This commit is contained in:
		| @@ -582,7 +582,7 @@ class GeneralApiTests(InvenTreeAPITestCase): | ||||
|         """Test that we can read the 'info-view' endpoint.""" | ||||
|         url = reverse('api-inventree-info') | ||||
|  | ||||
|         response = self.get(url) | ||||
|         response = self.get(url, max_query_count=275, expected_code=200) | ||||
|  | ||||
|         data = response.json() | ||||
|         self.assertIn('server', data) | ||||
|   | ||||
| @@ -52,7 +52,11 @@ class LabelMixinTests(PrintTestMixins, InvenTreeAPITestCase): | ||||
|  | ||||
|         # But, it is not 'active' | ||||
|         plugins = registry.with_mixin(PluginMixinEnum.LABELS, active=True) | ||||
|         self.assertEqual(len(plugins), 3) | ||||
|  | ||||
|         self.assertEqual(len(plugins), 2) | ||||
|         slugs = [p.slug for p in plugins] | ||||
|         self.assertIn('inventreelabel', slugs) | ||||
|         self.assertIn('inventreelabelmachine', slugs) | ||||
|  | ||||
|     def test_api(self): | ||||
|         """Test that we can filter the API endpoint by mixin.""" | ||||
| @@ -110,6 +114,7 @@ class LabelMixinTests(PrintTestMixins, InvenTreeAPITestCase): | ||||
|         self.assertIn('list may not be empty', str(response.data['items'])) | ||||
|  | ||||
|         # Plugin is not a label plugin | ||||
|         registry.set_plugin_state('digikeyplugin', True) | ||||
|         no_valid_plg = registry.get_plugin('digikeyplugin').plugin_config() | ||||
|  | ||||
|         response = self.post( | ||||
|   | ||||
| @@ -15,16 +15,17 @@ class SupplierBarcodeTests(InvenTreeAPITestCase): | ||||
|  | ||||
|     SCAN_URL = reverse('api-barcode-scan') | ||||
|  | ||||
|     def setUp(self): | ||||
|         """Ensure the digikey plugin is enabled.""" | ||||
|         super().setUp() | ||||
|         registry.set_plugin_state('digikeyplugin', True) | ||||
|  | ||||
|     @classmethod | ||||
|     def setUpTestData(cls): | ||||
|         """Create supplier parts for barcodes.""" | ||||
|         super().setUpTestData() | ||||
|  | ||||
|         # Enable the plugins | ||||
|         registry.set_plugin_state('digikeyplugin', True) | ||||
|         registry.set_plugin_state('mouserplugin', True) | ||||
|         registry.set_plugin_state('lcscplugin', True) | ||||
|         registry.set_plugin_state('tmeplugin', True) | ||||
|  | ||||
|         part = Part.objects.create(name='Test Part', description='Test Part') | ||||
|  | ||||
|         manufacturer = Company.objects.create( | ||||
| @@ -59,9 +60,11 @@ class SupplierBarcodeTests(InvenTreeAPITestCase): | ||||
|  | ||||
|         # Assign supplier information to the plugins | ||||
|         # Add supplier information to each custom plugin | ||||
|         registry.set_plugin_state('digikeyplugin', True) | ||||
|         digikey_plugin = registry.get_plugin('digikeyplugin') | ||||
|         digikey_plugin.set_setting('SUPPLIER_ID', digikey_supplier.pk) | ||||
|  | ||||
|         registry.set_plugin_state('mouserplugin', True) | ||||
|         mouser_plugin = registry.get_plugin('mouserplugin') | ||||
|         mouser_plugin.set_setting('SUPPLIER_ID', mouser_supplier.pk) | ||||
|  | ||||
| @@ -223,9 +226,11 @@ class SupplierBarcodePOReceiveTests(InvenTreeAPITestCase): | ||||
|             self.purchase_order2.add_line_item(supplier_part, 5, destination=self.loc_2) | ||||
|  | ||||
|         # Add supplier information to each custom plugin | ||||
|         registry.set_plugin_state('digikeyplugin', True) | ||||
|         digikey_plugin = registry.get_plugin('digikeyplugin') | ||||
|         digikey_plugin.set_setting('SUPPLIER_ID', digikey_supplier.pk) | ||||
|  | ||||
|         registry.set_plugin_state('mouserplugin', True) | ||||
|         mouser_plugin = registry.get_plugin('mouserplugin') | ||||
|         mouser_plugin.set_setting('SUPPLIER_ID', mouser.pk) | ||||
|  | ||||
|   | ||||
| @@ -131,14 +131,15 @@ class MetaBase: | ||||
|  | ||||
|     def is_active(self): | ||||
|         """Return True if this plugin is currently active.""" | ||||
|         # Builtin plugins are always considered "active" | ||||
|         if self.is_builtin: | ||||
|         # Mandatory plugins are always considered "active" | ||||
|         if self.is_builtin and self.is_mandatory: | ||||
|             return True | ||||
|  | ||||
|         config = self.plugin_config() | ||||
|  | ||||
|         if config: | ||||
|             return config.active | ||||
|  | ||||
|         return False  # pragma: no cover | ||||
|  | ||||
|  | ||||
| @@ -367,6 +368,13 @@ class InvenTreePlugin(VersionMixin, MixinBase, MetaBase): | ||||
|         """Is this plugin is builtin.""" | ||||
|         return self.check_is_builtin() | ||||
|  | ||||
|     @property | ||||
|     def is_mandatory(self) -> bool: | ||||
|         """Is this plugin mandatory (always forced to be active).""" | ||||
|         from plugin.registry import registry | ||||
|  | ||||
|         return self.slug in registry.MANDATORY_PLUGINS | ||||
|  | ||||
|     @classmethod | ||||
|     def check_package_path(cls): | ||||
|         """Path to the plugin.""" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user