From 934b795f9b8489da4a4b9385d2fba2a89f710e06 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 11 May 2022 12:54:01 +0200 Subject: [PATCH] split tests to functions tests --- .../{test_integration.py => test_mixins.py} | 78 +------------------ InvenTree/plugin/test_plugin.py | 76 ++++++++++++++++++ 2 files changed, 77 insertions(+), 77 deletions(-) rename InvenTree/plugin/{test_integration.py => test_mixins.py} (72%) diff --git a/InvenTree/plugin/test_integration.py b/InvenTree/plugin/test_mixins.py similarity index 72% rename from InvenTree/plugin/test_integration.py rename to InvenTree/plugin/test_mixins.py index 5b211e2d96..4fb97fe20f 100644 --- a/InvenTree/plugin/test_integration.py +++ b/InvenTree/plugin/test_mixins.py @@ -1,18 +1,14 @@ -""" Unit tests for integration plugins """ +""" Unit tests for base mixins for plugins """ from django.test import TestCase from django.conf import settings from django.urls import include, re_path from django.contrib.auth import get_user_model -from datetime import datetime - from plugin import IntegrationPluginBase from plugin.mixins import AppMixin, SettingsMixin, UrlsMixin, NavigationMixin, APICallMixin from plugin.urls import PLUGIN_BASE -from plugin.samples.integration.sample import SampleIntegrationPlugin - class BaseMixinDefinition: def test_mixin_name(self): @@ -216,75 +212,3 @@ class APICallMixinTest(BaseMixinDefinition, TestCase): with self.assertRaises(ValueError): self.mixin_wrong.has_api_call() - -class IntegrationPluginBaseTests(TestCase): - """ Tests for IntegrationPluginBase """ - - def setUp(self): - self.plugin = IntegrationPluginBase() - - class SimpeIntegrationPluginBase(IntegrationPluginBase): - PLUGIN_NAME = 'SimplePlugin' - - self.plugin_simple = SimpeIntegrationPluginBase() - - class NameIntegrationPluginBase(IntegrationPluginBase): - PLUGIN_NAME = 'Aplugin' - PLUGIN_SLUG = 'a' - PLUGIN_TITLE = 'a titel' - PUBLISH_DATE = "1111-11-11" - AUTHOR = 'AA BB' - DESCRIPTION = 'A description' - VERSION = '1.2.3a' - WEBSITE = 'http://aa.bb/cc' - LICENSE = 'MIT' - - self.plugin_name = NameIntegrationPluginBase() - self.plugin_sample = SampleIntegrationPlugin() - - def test_action_name(self): - """check the name definition possibilities""" - # plugin_name - self.assertEqual(self.plugin.plugin_name(), '') - self.assertEqual(self.plugin_simple.plugin_name(), 'SimplePlugin') - self.assertEqual(self.plugin_name.plugin_name(), 'Aplugin') - - # is_sampe - self.assertEqual(self.plugin.is_sample, False) - self.assertEqual(self.plugin_sample.is_sample, True) - - # slug - self.assertEqual(self.plugin.slug, '') - self.assertEqual(self.plugin_simple.slug, 'simpleplugin') - self.assertEqual(self.plugin_name.slug, 'a') - - # human_name - self.assertEqual(self.plugin.human_name, '') - self.assertEqual(self.plugin_simple.human_name, 'SimplePlugin') - self.assertEqual(self.plugin_name.human_name, 'a titel') - - # description - self.assertEqual(self.plugin.description, '') - self.assertEqual(self.plugin_simple.description, 'SimplePlugin') - self.assertEqual(self.plugin_name.description, 'A description') - - # author - self.assertEqual(self.plugin_name.author, 'AA BB') - - # pub_date - self.assertEqual(self.plugin_name.pub_date, datetime(1111, 11, 11, 0, 0)) - - # version - self.assertEqual(self.plugin.version, None) - self.assertEqual(self.plugin_simple.version, None) - self.assertEqual(self.plugin_name.version, '1.2.3a') - - # website - self.assertEqual(self.plugin.website, None) - self.assertEqual(self.plugin_simple.website, None) - self.assertEqual(self.plugin_name.website, 'http://aa.bb/cc') - - # license - self.assertEqual(self.plugin.license, None) - self.assertEqual(self.plugin_simple.license, None) - self.assertEqual(self.plugin_name.license, 'MIT') diff --git a/InvenTree/plugin/test_plugin.py b/InvenTree/plugin/test_plugin.py index c0835c2fb3..eee3230d2a 100644 --- a/InvenTree/plugin/test_plugin.py +++ b/InvenTree/plugin/test_plugin.py @@ -2,12 +2,15 @@ Unit tests for plugins """ +from datetime import datetime + from django.test import TestCase from plugin.samples.integration.sample import SampleIntegrationPlugin from plugin.samples.integration.another_sample import WrongIntegrationPlugin, NoIntegrationPlugin import plugin.templatetags.plugin_extras as plugin_tags from plugin import registry, InvenTreePluginBase +from plugin.plugin import IntegrationPluginBase class InvenTreePluginTests(TestCase): @@ -79,3 +82,76 @@ class PluginTagTests(TestCase): def test_tag_plugin_errors(self): """test that all errors are listed""" self.assertEqual(plugin_tags.plugin_errors(), registry.errors) + + +class IntegrationPluginBaseTests(TestCase): + """ Tests for IntegrationPluginBase """ + + def setUp(self): + self.plugin = IntegrationPluginBase() + + class SimpeIntegrationPluginBase(IntegrationPluginBase): + PLUGIN_NAME = 'SimplePlugin' + + self.plugin_simple = SimpeIntegrationPluginBase() + + class NameIntegrationPluginBase(IntegrationPluginBase): + PLUGIN_NAME = 'Aplugin' + PLUGIN_SLUG = 'a' + PLUGIN_TITLE = 'a titel' + PUBLISH_DATE = "1111-11-11" + AUTHOR = 'AA BB' + DESCRIPTION = 'A description' + VERSION = '1.2.3a' + WEBSITE = 'http://aa.bb/cc' + LICENSE = 'MIT' + + self.plugin_name = NameIntegrationPluginBase() + self.plugin_sample = SampleIntegrationPlugin() + + def test_action_name(self): + """check the name definition possibilities""" + # plugin_name + self.assertEqual(self.plugin.plugin_name(), '') + self.assertEqual(self.plugin_simple.plugin_name(), 'SimplePlugin') + self.assertEqual(self.plugin_name.plugin_name(), 'Aplugin') + + # is_sampe + self.assertEqual(self.plugin.is_sample, False) + self.assertEqual(self.plugin_sample.is_sample, True) + + # slug + self.assertEqual(self.plugin.slug, '') + self.assertEqual(self.plugin_simple.slug, 'simpleplugin') + self.assertEqual(self.plugin_name.slug, 'a') + + # human_name + self.assertEqual(self.plugin.human_name, '') + self.assertEqual(self.plugin_simple.human_name, 'SimplePlugin') + self.assertEqual(self.plugin_name.human_name, 'a titel') + + # description + self.assertEqual(self.plugin.description, '') + self.assertEqual(self.plugin_simple.description, 'SimplePlugin') + self.assertEqual(self.plugin_name.description, 'A description') + + # author + self.assertEqual(self.plugin_name.author, 'AA BB') + + # pub_date + self.assertEqual(self.plugin_name.pub_date, datetime(1111, 11, 11, 0, 0)) + + # version + self.assertEqual(self.plugin.version, None) + self.assertEqual(self.plugin_simple.version, None) + self.assertEqual(self.plugin_name.version, '1.2.3a') + + # website + self.assertEqual(self.plugin.website, None) + self.assertEqual(self.plugin_simple.website, None) + self.assertEqual(self.plugin_name.website, 'http://aa.bb/cc') + + # license + self.assertEqual(self.plugin.license, None) + self.assertEqual(self.plugin_simple.license, None) + self.assertEqual(self.plugin_name.license, 'MIT')