mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
more class use
This commit is contained in:
parent
43f714b96c
commit
e1ff4b6e87
@ -1,12 +1,11 @@
|
||||
""" Unit tests for Order views (see views.py) """
|
||||
|
||||
from django.test import TestCase
|
||||
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 = [
|
||||
'category',
|
||||
@ -19,27 +18,14 @@ class OrderViewTestCase(TestCase):
|
||||
'order',
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
# Create a user
|
||||
user = get_user_model().objects.create_user('username', 'user@email.com', 'password')
|
||||
|
||||
# Ensure that the user has the correct permissions!
|
||||
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')
|
||||
roles = [
|
||||
'purchase_order.change',
|
||||
'purchase_order.add',
|
||||
'purchase_order.delete',
|
||||
'sales_order.change',
|
||||
'sales_order.add',
|
||||
'sales_order.delete',
|
||||
]
|
||||
|
||||
|
||||
class OrderListTest(OrderViewTestCase):
|
||||
|
@ -1,8 +1,8 @@
|
||||
""" Unit tests for action plugins """
|
||||
|
||||
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.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"""
|
||||
|
||||
|
@ -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.test import APITestCase
|
||||
from rest_framework import status
|
||||
|
||||
from InvenTree.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')
|
||||
|
@ -1,7 +1,6 @@
|
||||
""" Unit tests for base mixins for plugins """
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import TestCase
|
||||
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])
|
||||
|
||||
|
||||
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
|
||||
|
@ -1,20 +1,15 @@
|
||||
""" Unit tests for action plugins """
|
||||
|
||||
from django.test import TestCase
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from InvenTree.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",
|
||||
},
|
||||
}
|
||||
|
@ -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.test import APITestCase
|
||||
from rest_framework import status
|
||||
|
||||
from InvenTree.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
|
||||
|
@ -1,19 +1,11 @@
|
||||
""" Unit tests for action plugins """
|
||||
|
||||
from django.test import TestCase
|
||||
from django.contrib.auth import get_user_model
|
||||
from InvenTree.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/')
|
||||
|
Loading…
Reference in New Issue
Block a user