2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-01 21:16:46 +00:00

more class use

This commit is contained in:
Matthias Mair 2022-05-20 23:01:20 +02:00
parent 43f714b96c
commit e1ff4b6e87
7 changed files with 28 additions and 76 deletions

View File

@ -1,12 +1,11 @@
""" Unit tests for Order views (see views.py) """ """ Unit tests for Order views (see views.py) """
from django.test import TestCase
from django.urls import reverse from django.urls import reverse
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group from InvenTree.helpers import InvenTreeTestCase
class OrderViewTestCase(TestCase): class OrderViewTestCase(InvenTreeTestCase):
fixtures = [ fixtures = [
'category', 'category',
@ -19,27 +18,14 @@ class OrderViewTestCase(TestCase):
'order', 'order',
] ]
def setUp(self): roles = [
super().setUp() 'purchase_order.change',
'purchase_order.add',
# Create a user 'purchase_order.delete',
user = get_user_model().objects.create_user('username', 'user@email.com', 'password') 'sales_order.change',
'sales_order.add',
# Ensure that the user has the correct permissions! 'sales_order.delete',
g = Group.objects.create(name='orders') ]
user.groups.add(g)
for rule in g.rule_sets.all():
if rule.name in ['purchase_order', 'sales_order']:
rule.can_change = True
rule.can_add = True
rule.can_delete = True
rule.save()
g.save()
self.client.login(username='username', password='password')
class OrderListTest(OrderViewTestCase): class OrderListTest(OrderViewTestCase):

View File

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

View File

@ -4,16 +4,15 @@
Unit tests for Barcode endpoints Unit tests for Barcode endpoints
""" """
from django.contrib.auth import get_user_model
from django.urls import reverse from django.urls import reverse
from rest_framework.test import APITestCase
from rest_framework import status from rest_framework import status
from InvenTree.InvenTree.api_tester import InvenTreeAPITestCase
from stock.models import StockItem from stock.models import StockItem
class BarcodeAPITest(APITestCase): class BarcodeAPITest(InvenTreeAPITestCase):
fixtures = [ fixtures = [
'category', 'category',
@ -23,11 +22,7 @@ class BarcodeAPITest(APITestCase):
] ]
def setUp(self): def setUp(self):
# Create a user for auth super().setUp()
user = get_user_model()
user.objects.create_user('testuser', 'test@testing.com', 'password')
self.client.login(username='testuser', password='password')
self.scan_url = reverse('api-barcode-scan') self.scan_url = reverse('api-barcode-scan')
self.assign_url = reverse('api-barcode-link') self.assign_url = reverse('api-barcode-link')

View File

@ -1,7 +1,6 @@
""" Unit tests for base mixins for plugins """ """ Unit tests for base mixins for plugins """
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model
from django.test import TestCase from django.test import TestCase
from django.urls import include, re_path, reverse from django.urls import include, re_path, reverse
@ -24,7 +23,7 @@ class BaseMixinDefinition:
self.assertIn(self.MIXIN_HUMAN_NAME, [item['human_name'] for item in self.mixin.registered_mixins]) 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_HUMAN_NAME = 'Settings'
MIXIN_NAME = 'settings' MIXIN_NAME = 'settings'
MIXIN_ENABLE_CHECK = 'has_settings' MIXIN_ENABLE_CHECK = 'has_settings'
@ -40,9 +39,7 @@ class SettingsMixinTest(BaseMixinDefinition, TestCase):
pass pass
self.mixin_nothing = NoSettingsCls() self.mixin_nothing = NoSettingsCls()
user = get_user_model() super().setUp()
self.test_user = user.objects.create_user('testuser', 'test@testing.com', 'password')
self.test_user.is_staff = True
def test_function(self): def test_function(self):
# settings variable # settings variable
@ -54,7 +51,7 @@ class SettingsMixinTest(BaseMixinDefinition, TestCase):
self.assertEqual(self.mixin_nothing.get_setting('ABCD'), '') self.assertEqual(self.mixin_nothing.get_setting('ABCD'), '')
# right setting # 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') self.assertEqual(self.mixin.get_setting('SETTING1'), '12345')
# no setting # no setting

View File

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

View File

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

View File

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