From aeaf15b37437fcdb27a3bfff6beee8a26e517339 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 15 May 2022 02:25:30 +0200 Subject: [PATCH] Test action error messages --- InvenTree/plugin/base/action/test_action.py | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/InvenTree/plugin/base/action/test_action.py b/InvenTree/plugin/base/action/test_action.py index 97768e94a0..9de672cd6f 100644 --- a/InvenTree/plugin/base/action/test_action.py +++ b/InvenTree/plugin/base/action/test_action.py @@ -1,6 +1,7 @@ """ Unit tests for action plugins """ from django.test import TestCase +from django.contrib.auth import get_user_model from plugin import InvenTreePlugin from plugin.mixins import ActionMixin @@ -62,3 +63,32 @@ class ActionMixinTests(TestCase): "result": self.ACTION_RETURN + 'result', "info": self.ACTION_RETURN + 'info', }) + + +class APITests(TestCase): + """ Tests for action api """ + + 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') + + def test_post_errors(self): + """Check the possible errors with post""" + + # Test empty request + response = self.client.post('/api/action/') + self.assertEqual(response.status_code, 200) + self.assertEqual( + response.data, + {'error': 'No action specified'} + ) + + # Test non-exsisting action + response = self.client.post('/api/action/', data={'action': "nonexsisting"}) + self.assertEqual(response.status_code, 200) + self.assertEqual( + response.data, + {'error': 'No matching action found', 'action': 'nonexsisting'} + )