test for action plugin

This commit is contained in:
Matthias 2021-09-28 22:55:52 +02:00
parent ed312b9cf1
commit ae66442156
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -0,0 +1,61 @@
""" Unit tests for action plugins """
from django.test import TestCase
from plugins.action import ActionPlugin
class ActionPluginTests(TestCase):
""" Tests for ActionPlugin """
ACTION_RETURN = 'a action was performed'
def setUp(self):
self.plugin = ActionPlugin('user')
class TestActionPlugin(ActionPlugin):
"""a action plugin"""
ACTION_NAME = 'abc123'
def perform_action():
return self.ACTION_RETURN + 'action'
def get_result():
return self.ACTION_RETURN + 'result'
def get_info():
return self.ACTION_RETURN + 'info'
self.action_plugin = TestActionPlugin('user')
class NameActionPlugin(ActionPlugin):
PLUGIN_NAME = 'Aplugin'
self.action_name = NameActionPlugin('user')
def test_action_name(self):
"""check the name definition possibilities"""
self.assertEqual(self.plugin.plugin_name(), '')
self.assertEqual(self.action_plugin.plugin_name(), 'abc123')
self.assertEqual(self.action_name.plugin_name(), 'Aplugin')
def test_function(self):
"""check functions"""
# the class itself
self.assertIsNone(self.plugin.perform_action())
self.assertEqual(self.plugin.get_result(), False)
self.assertIsNone(self.plugin.get_info())
self.assertEqual(self.plugin.get_response(), {
"action": '',
"result": False,
"info": None,
})
# overriden functions
self.assertEqual(self.plugin.perform_action(), self.ACTION_RETURN + 'action')
self.assertEqual(self.plugin.get_result(), self.ACTION_RETURN + 'result')
self.assertIsNone(self.plugin.get_info(), self.ACTION_RETURN + 'info')
self.assertEqual(self.plugin.get_response(), {
"action": 'abc123',
"result": self.ACTION_RETURN + 'result',
"info": self.ACTION_RETURN + 'info',
})