Test action error messages

This commit is contained in:
Matthias 2022-05-15 02:25:30 +02:00
parent 9609d8ae09
commit aeaf15b374
No known key found for this signature in database
GPG Key ID: AB6D0E6C4CB65093

View File

@ -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'}
)