From cfef5d63b3481b6abb4b9b02ca38d95524aacf92 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 29 Sep 2021 00:24:09 +0200 Subject: [PATCH] test sample code --- .../plugins/samples/action/test_samples.py | 38 +++++++++++++++++++ .../samples/integration/test_samples.py | 21 ++++++++++ 2 files changed, 59 insertions(+) create mode 100644 InvenTree/plugins/samples/action/test_samples.py create mode 100644 InvenTree/plugins/samples/integration/test_samples.py diff --git a/InvenTree/plugins/samples/action/test_samples.py b/InvenTree/plugins/samples/action/test_samples.py new file mode 100644 index 0000000000..d306828664 --- /dev/null +++ b/InvenTree/plugins/samples/action/test_samples.py @@ -0,0 +1,38 @@ +""" Unit tests for action plugins """ + +from django.test import TestCase +from django.contrib.auth import get_user_model + +from plugins.samples.action.simpleactionplugin import SimpleActionPlugin + + +class ActionPluginTests(TestCase): + """ Tests for SampleIntegrationPlugin """ + + def setUp(self): + # Create a user for auth + user = get_user_model() + user.objects.create_user('testuser', 'test@testing.com', 'password') + + self.client.login(username='testuser', password='password') + + self.plugin = SimpleActionPlugin + + 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 + respone = self.client.get('/action/sample/') + self.assertEqual(respone.status_code, 200) + self.assertEqual(respone.content, { + "action": 'simple', + "result": True, + "info": { + "user": "testuser", + "hello": "world", + }, + }) diff --git a/InvenTree/plugins/samples/integration/test_samples.py b/InvenTree/plugins/samples/integration/test_samples.py new file mode 100644 index 0000000000..7a82349df6 --- /dev/null +++ b/InvenTree/plugins/samples/integration/test_samples.py @@ -0,0 +1,21 @@ +""" Unit tests for action plugins """ + +from django.test import TestCase +from django.contrib.auth import get_user_model + + +class ActionPluginTests(TestCase): + """ Tests for SampleIntegrationPlugin """ + + def setUp(self): + # Create a user for auth + user = get_user_model() + user.objects.create_user('testuser', 'test@testing.com', 'password') + + self.client.login(username='testuser', password='password') + + def test_view(self): + """check the function of the custom sample plugin """ + respone = self.client.get('/plugin/SampleIntegrationPlugin/ho/he/') + self.assertEqual(respone.status_code, 200) + self.assertEqual(respone.content, b'Hi there testuser this work')