mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 11:10:54 +00:00
refactor app
This commit is contained in:
0
InvenTree/plugin/builtin/__init__.py
Normal file
0
InvenTree/plugin/builtin/__init__.py
Normal file
0
InvenTree/plugin/builtin/action/__init__.py
Normal file
0
InvenTree/plugin/builtin/action/__init__.py
Normal file
25
InvenTree/plugin/builtin/action/simpleactionplugin.py
Normal file
25
InvenTree/plugin/builtin/action/simpleactionplugin.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""sample implementation for ActionPlugin"""
|
||||
from plugin.action import ActionPlugin
|
||||
|
||||
|
||||
class SimpleActionPlugin(ActionPlugin):
|
||||
"""
|
||||
An EXTREMELY simple action plugin which demonstrates
|
||||
the capability of the ActionPlugin class
|
||||
"""
|
||||
|
||||
PLUGIN_NAME = "SimpleActionPlugin"
|
||||
ACTION_NAME = "simple"
|
||||
|
||||
def perform_action(self):
|
||||
print("Action plugin in action!")
|
||||
|
||||
def get_info(self):
|
||||
return {
|
||||
"user": self.user.username,
|
||||
"hello": "world",
|
||||
}
|
||||
|
||||
def get_result(self):
|
||||
return True
|
40
InvenTree/plugin/builtin/action/test_samples_action.py
Normal file
40
InvenTree/plugin/builtin/action/test_samples_action.py
Normal file
@ -0,0 +1,40 @@
|
||||
""" Unit tests for action plugins """
|
||||
|
||||
from django.test import TestCase
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from plugin.builtin.action.simpleactionplugin import SimpleActionPlugin
|
||||
|
||||
|
||||
class SimpleActionPluginTests(TestCase):
|
||||
""" Tests for SampleIntegrationPlugin """
|
||||
|
||||
def setUp(self):
|
||||
# Create a user for auth
|
||||
user = get_user_model()
|
||||
self.test_user = user.objects.create_user('testuser', 'test@testing.com', 'password')
|
||||
|
||||
self.client.login(username='testuser', password='password')
|
||||
self.plugin = SimpleActionPlugin(user=self.test_user)
|
||||
|
||||
def test_name(self):
|
||||
"""check plugn names """
|
||||
self.assertEqual(self.plugin.plugin_name(), "SimpleActionPlugin")
|
||||
self.assertEqual(self.plugin.action_name(), "simple")
|
||||
|
||||
def test_function(self):
|
||||
"""check if functions work """
|
||||
# test functions
|
||||
response = self.client.post('/api/action/', data={'action': "simple", 'data': {'foo': "bar", }})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertJSONEqual(
|
||||
str(response.content, encoding='utf8'),
|
||||
{
|
||||
"action": 'simple',
|
||||
"result": True,
|
||||
"info": {
|
||||
"user": "testuser",
|
||||
"hello": "world",
|
||||
},
|
||||
}
|
||||
)
|
Reference in New Issue
Block a user