activate plugins before testing

This commit is contained in:
Matthias 2021-11-12 17:44:35 +01:00
parent c612cfcfba
commit 938f8bab2d
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
3 changed files with 19 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import InvenTree.version
from common.models import InvenTreeSetting
from .settings import MEDIA_URL, STATIC_URL
from common.settings import currency_code_default
from plugin.models import PluginConfig
from djmoney.money import Money
@ -711,3 +712,12 @@ def inheritors(cls):
subcls.add(child)
work.append(child)
return subcls
def setup_plugin(plg_key, plg_name):
"""
Enables plugins by reference
"""
plg_setting, _ = PluginConfig.objects.get_or_create(key=plg_key, name=plg_name)
plg_setting.active = True
plg_setting.save()

View File

@ -3,6 +3,10 @@
from django.test import TestCase
from django.contrib.auth import get_user_model
from InvenTree.helpers import setup_plugin
from plugin.samples.integration.sample import SampleIntegrationPlugin
class SampleIntegrationPluginTests(TestCase):
""" Tests for SampleIntegrationPlugin """
@ -13,6 +17,7 @@ class SampleIntegrationPluginTests(TestCase):
user.objects.create_user('testuser', 'test@testing.com', 'password')
self.client.login(username='testuser', password='password')
setup_plugin(SampleIntegrationPlugin.PLUGIN_SLUG, SampleIntegrationPlugin.PLUGIN_NAME)
def test_view(self):
"""check the function of the custom sample plugin """

View File

@ -7,7 +7,9 @@ from django.contrib.auth import get_user_model
from datetime import datetime
from InvenTree.helpers import setup_plugin
from plugin.integration import AppMixin, IntegrationPluginBase, SettingsMixin, UrlsMixin, NavigationMixin
from plugin.samples.integration.sample import SampleIntegrationPlugin
class BaseMixinDefinition:
@ -110,6 +112,8 @@ class AppMixinTest(BaseMixinDefinition, TestCase):
pass
self.mixin = TestCls()
setup_plugin(SampleIntegrationPlugin.PLUGIN_SLUG, SampleIntegrationPlugin.PLUGIN_NAME)
def test_function(self):
# test that this plugin is in settings
self.assertIn('plugin.samples.integration', settings.INSTALLED_APPS)