mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-30 20:55:42 +00:00 
			
		
		
		
	Merge branch 'small-python-fixes-plugin' of https://github.com/matmair/InvenTree into not-working-tests
This commit is contained in:
		| @@ -271,9 +271,9 @@ class BaseInvenTreeSetting(models.Model): | ||||
|         plugin = kwargs.get('plugin', None) | ||||
|  | ||||
|         if plugin is not None: | ||||
|             from plugin import InvenTreePluginBase | ||||
|             from plugin import InvenTreePlugin | ||||
|  | ||||
|             if issubclass(plugin.__class__, InvenTreePluginBase): | ||||
|             if issubclass(plugin.__class__, InvenTreePlugin): | ||||
|                 plugin = plugin.plugin_config() | ||||
|  | ||||
|             filters['plugin'] = plugin | ||||
| @@ -375,9 +375,9 @@ class BaseInvenTreeSetting(models.Model): | ||||
|             filters['user'] = user | ||||
|  | ||||
|         if plugin is not None: | ||||
|             from plugin import InvenTreePluginBase | ||||
|             from plugin import InvenTreePlugin | ||||
|  | ||||
|             if issubclass(plugin.__class__, InvenTreePluginBase): | ||||
|             if issubclass(plugin.__class__, InvenTreePlugin): | ||||
|                 filters['plugin'] = plugin.plugin_config() | ||||
|             else: | ||||
|                 filters['plugin'] = plugin | ||||
|   | ||||
| @@ -108,7 +108,7 @@ class NotificationMethod: | ||||
|             return False | ||||
|  | ||||
|         # Check if method globally enabled | ||||
|         plg_instance = registry.plugins.get(plg_cls.PLUGIN_NAME.lower()) | ||||
|         plg_instance = registry.plugins.get(plg_cls.NAME.lower()) | ||||
|         if plg_instance and not plg_instance.get_setting(self.GLOBAL_SETTING): | ||||
|             return True | ||||
|  | ||||
|   | ||||
| @@ -10,7 +10,8 @@ from django.urls import reverse | ||||
|  | ||||
| from InvenTree.api_tester import InvenTreeAPITestCase | ||||
| from InvenTree.helpers import str2bool | ||||
| from plugin.models import NotificationUserSetting | ||||
| from plugin.models import NotificationUserSetting, PluginConfig | ||||
| from plugin import registry | ||||
|  | ||||
| from .models import InvenTreeSetting, InvenTreeUserSetting, WebhookEndpoint, WebhookMessage, NotificationEntry, ColorTheme | ||||
| from .api import WebhookView | ||||
| @@ -477,15 +478,36 @@ class PluginSettingsApiTest(InvenTreeAPITestCase): | ||||
|  | ||||
|         self.get(url, expected_code=200) | ||||
|  | ||||
|     def test_invalid_plugin_slug(self): | ||||
|         """Test that an invalid plugin slug returns a 404""" | ||||
|     def test_valid_plugin_slug(self): | ||||
|         """Test that an valid plugin slug runs through""" | ||||
|         # load plugin configs | ||||
|         fixtures = PluginConfig.objects.all() | ||||
|         if not fixtures: | ||||
|             registry.reload_plugins() | ||||
|             fixtures = PluginConfig.objects.all() | ||||
|  | ||||
|         # get data | ||||
|         url = reverse('api-plugin-setting-detail', kwargs={'plugin': 'sample', 'key': 'API_KEY'}) | ||||
|         response = self.get(url, expected_code=200) | ||||
|  | ||||
|         # check the right setting came through | ||||
|         self.assertTrue(response.data['key'], 'API_KEY') | ||||
|         self.assertTrue(response.data['plugin'], 'sample') | ||||
|         self.assertTrue(response.data['type'], 'string') | ||||
|         self.assertTrue(response.data['description'], 'Key required for accessing external API') | ||||
|  | ||||
|         # Failure mode tests | ||||
|  | ||||
|         # Non - exsistant plugin | ||||
|         url = reverse('api-plugin-setting-detail', kwargs={'plugin': 'doesnotexist', 'key': 'doesnotmatter'}) | ||||
|  | ||||
|         response = self.get(url, expected_code=404) | ||||
|  | ||||
|         self.assertIn("Plugin 'doesnotexist' not installed", str(response.data)) | ||||
|  | ||||
|         # Wrong key | ||||
|         url = reverse('api-plugin-setting-detail', kwargs={'plugin': 'sample', 'key': 'doesnotexsist'}) | ||||
|         response = self.get(url, expected_code=404) | ||||
|         self.assertIn("Plugin 'sample' has no setting matching 'doesnotexsist'", str(response.data)) | ||||
|  | ||||
|     def test_invalid_setting_key(self): | ||||
|         """Test that an invalid setting key returns a 404""" | ||||
|         ... | ||||
|   | ||||
		Reference in New Issue
	
	Block a user