mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
add testss for user creation
This commit is contained in:
parent
7d9edaea8b
commit
ad81439140
@ -30,6 +30,7 @@ class InvenTreeConfig(AppConfig):
|
||||
if not isInTestMode():
|
||||
self.update_exchange_rates()
|
||||
|
||||
if canAppAccessDatabase() or settings.TESTING:
|
||||
self.add_user_on_startup()
|
||||
|
||||
def remove_obsolete_tasks(self):
|
||||
@ -189,6 +190,8 @@ class InvenTreeConfig(AppConfig):
|
||||
logger.info(f'User {str(new_user)} was created!')
|
||||
except IntegrityError as _e:
|
||||
logger.warning(f'The user "{add_user}" could not be created due to the following error:\n{str(_e)}')
|
||||
if settings.TESTING:
|
||||
raise _e
|
||||
except Exception as _e:
|
||||
raise _e
|
||||
|
||||
|
@ -1,9 +1,13 @@
|
||||
|
||||
import json
|
||||
from test.support import EnvironmentVarGuard
|
||||
|
||||
from django.test import TestCase
|
||||
import django.core.exceptions as django_exceptions
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.conf import settings
|
||||
from django.db.utils import IntegrityError
|
||||
|
||||
from djmoney.money import Money
|
||||
from djmoney.contrib.exchange.models import Rate, convert_money
|
||||
@ -407,3 +411,47 @@ class TestStatus(TestCase):
|
||||
|
||||
def test_Importing(self):
|
||||
self.assertEqual(ready.isImportingData(), False)
|
||||
|
||||
|
||||
class TestSettings(TestCase):
|
||||
"""
|
||||
Unit tests for settings
|
||||
"""
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.user_mdl = get_user_model()
|
||||
self.env = EnvironmentVarGuard()
|
||||
|
||||
def run_reload(self):
|
||||
from plugin import registry
|
||||
|
||||
with self.env:
|
||||
settings.USER_ADDED = False
|
||||
registry.reload_plugins()
|
||||
|
||||
def test_set_user_to_few(self):
|
||||
# add shortcut
|
||||
user_count = self.user_mdl.objects.count
|
||||
|
||||
# nothing set
|
||||
self.assertEqual(user_count(), 0)
|
||||
|
||||
# not enough set
|
||||
self.env.set('INVENTREE_SET_USER', 'admin') # set username
|
||||
self.run_reload()
|
||||
self.assertEqual(user_count(), 0)
|
||||
|
||||
# enough set
|
||||
self.env.set('INVENTREE_SET_USER', 'admin') # set username
|
||||
self.env.set('INVENTREE_SET_EMAIL', 'info@example.com') # set email
|
||||
self.env.set('INVENTREE_SET_PASSWORD', 'password123') # set password
|
||||
self.run_reload()
|
||||
self.assertEqual(user_count(), 1)
|
||||
|
||||
# double adding should not work
|
||||
self.env.set('INVENTREE_SET_USER', 'admin') # set username
|
||||
self.env.set('INVENTREE_SET_EMAIL', 'info@example.com') # set email
|
||||
self.env.set('INVENTREE_SET_PASSWORD', 'password123') # set password
|
||||
with self.assertRaises(IntegrityError):
|
||||
self.run_reload()
|
||||
self.assertEqual(user_count(), 1)
|
||||
|
Loading…
Reference in New Issue
Block a user