2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 03:00:54 +00:00

Merge branch 'master' of https://github.com/inventree/InvenTree into style-fixes

This commit is contained in:
Matthias Mair
2022-05-21 23:57:41 +02:00
28 changed files with 296 additions and 483 deletions

View File

@ -1,8 +1,8 @@
""" Unit tests for action plugins """
from django.contrib.auth import get_user_model
from django.test import TestCase
from InvenTree.helpers import InvenTreeTestCase
from plugin import InvenTreePlugin
from plugin.mixins import ActionMixin
@ -65,15 +65,9 @@ class ActionMixinTests(TestCase):
})
class APITests(TestCase):
class APITests(InvenTreeTestCase):
""" 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"""

View File

@ -4,16 +4,15 @@
Unit tests for Barcode endpoints
"""
from django.contrib.auth import get_user_model
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APITestCase
from InvenTree.api_tester import InvenTreeAPITestCase
from stock.models import StockItem
class BarcodeAPITest(APITestCase):
class BarcodeAPITest(InvenTreeAPITestCase):
fixtures = [
'category',
@ -23,11 +22,7 @@ class BarcodeAPITest(APITestCase):
]
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')
super().setUp()
self.scan_url = reverse('api-barcode-scan')
self.assign_url = reverse('api-barcode-link')

View File

@ -1,13 +1,12 @@
""" Unit tests for base mixins for plugins """
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.test import TestCase
from django.urls import include, re_path, reverse
from error_report.models import Error
from InvenTree.helpers import InvenTreeTestCase
from plugin import InvenTreePlugin
from plugin.helpers import MixinNotImplementedError
from plugin.mixins import (APICallMixin, AppMixin, NavigationMixin,
@ -24,7 +23,7 @@ class BaseMixinDefinition:
self.assertIn(self.MIXIN_HUMAN_NAME, [item['human_name'] for item in self.mixin.registered_mixins])
class SettingsMixinTest(BaseMixinDefinition, TestCase):
class SettingsMixinTest(BaseMixinDefinition, InvenTreeTestCase):
MIXIN_HUMAN_NAME = 'Settings'
MIXIN_NAME = 'settings'
MIXIN_ENABLE_CHECK = 'has_settings'
@ -40,9 +39,7 @@ class SettingsMixinTest(BaseMixinDefinition, TestCase):
pass
self.mixin_nothing = NoSettingsCls()
user = get_user_model()
self.test_user = user.objects.create_user('testuser', 'test@testing.com', 'password')
self.test_user.is_staff = True
super().setUp()
def test_function(self):
# settings variable
@ -54,7 +51,7 @@ class SettingsMixinTest(BaseMixinDefinition, TestCase):
self.assertEqual(self.mixin_nothing.get_setting('ABCD'), '')
# right setting
self.mixin.set_setting('SETTING1', '12345', self.test_user)
self.mixin.set_setting('SETTING1', '12345', self.user)
self.assertEqual(self.mixin.get_setting('SETTING1'), '12345')
# no setting
@ -251,7 +248,7 @@ class APICallMixinTest(BaseMixinDefinition, TestCase):
self.mixin_wrong2.has_api_call()
class PanelMixinTests(TestCase):
class PanelMixinTests(InvenTreeTestCase):
"""Test that the PanelMixin plugin operates correctly"""
fixtures = [
@ -261,32 +258,7 @@ class PanelMixinTests(TestCase):
'stock',
]
def setUp(self):
super().setUp()
# Create a user which has all the privelages
user = get_user_model()
self.user = user.objects.create_user(
username='username',
email='user@email.com',
password='password'
)
# Put the user into a group with the correct permissions
group = Group.objects.create(name='mygroup')
self.user.groups.add(group)
# Give the group *all* the permissions!
for rule in group.rule_sets.all():
rule.can_view = True
rule.can_change = True
rule.can_add = True
rule.can_delete = True
rule.save()
self.client.login(username='username', password='password')
roles = 'all'
def test_installed(self):
"""Test that the sample panel plugin is installed"""

View File

@ -1,20 +1,15 @@
""" Unit tests for action plugins """
from django.contrib.auth import get_user_model
from django.test import TestCase
from InvenTree.helpers import InvenTreeTestCase
from plugin.builtin.action.simpleactionplugin import SimpleActionPlugin
class SimpleActionPluginTests(TestCase):
class SimpleActionPluginTests(InvenTreeTestCase):
""" 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')
super().setUp()
self.client.login(username='testuser', password='password')
self.plugin = SimpleActionPlugin()
def test_name(self):
@ -33,7 +28,7 @@ class SimpleActionPluginTests(TestCase):
"action": 'simple',
"result": True,
"info": {
"user": "testuser",
"user": self.username,
"hello": "world",
},
}

View File

@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
"""Unit tests for InvenTreeBarcodePlugin"""
from django.contrib.auth import get_user_model
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APITestCase
from InvenTree.api_tester import InvenTreeAPITestCase
class TestInvenTreeBarcode(APITestCase):
class TestInvenTreeBarcode(InvenTreeAPITestCase):
fixtures = [
'category',
@ -17,13 +17,6 @@ class TestInvenTreeBarcode(APITestCase):
'stock'
]
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_errors(self):
"""
Test all possible error cases for assigment action

View File

@ -1,19 +1,11 @@
""" Unit tests for action plugins """
from django.contrib.auth import get_user_model
from django.test import TestCase
from InvenTree.helpers import InvenTreeTestCase
class SampleIntegrationPluginTests(TestCase):
class SampleIntegrationPluginTests(InvenTreeTestCase):
""" 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 """
response = self.client.get('/plugin/sample/ho/he/')