mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
Use unierest mock for env setting
This commit is contained in:
parent
b630fb2856
commit
a40f189c7a
@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from test import support
|
from unittest import mock
|
||||||
|
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
import django.core.exceptions as django_exceptions
|
import django.core.exceptions as django_exceptions
|
||||||
@ -450,12 +450,11 @@ class TestSettings(TestCase):
|
|||||||
|
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
self.user_mdl = get_user_model()
|
self.user_mdl = get_user_model()
|
||||||
self.env = support.EnvironmentVarGuard()
|
|
||||||
|
|
||||||
def run_reload(self):
|
def run_reload(self, envs):
|
||||||
from plugin import registry
|
from plugin import registry
|
||||||
|
|
||||||
with self.env:
|
with mock.patch.dict(os.environ, envs):
|
||||||
settings.USER_ADDED = False
|
settings.USER_ADDED = False
|
||||||
registry.reload_plugins()
|
registry.reload_plugins()
|
||||||
|
|
||||||
@ -471,15 +470,17 @@ class TestSettings(TestCase):
|
|||||||
self.assertEqual(user_count(), 0)
|
self.assertEqual(user_count(), 0)
|
||||||
|
|
||||||
# not enough set
|
# not enough set
|
||||||
self.env.set('INVENTREE_ADMIN_USER', 'admin') # set username
|
envs = {}
|
||||||
self.run_reload()
|
envs['INVENTREE_ADMIN_USER'] = 'admin'
|
||||||
|
self.run_reload(envs)
|
||||||
self.assertEqual(user_count(), 0)
|
self.assertEqual(user_count(), 0)
|
||||||
|
|
||||||
# enough set
|
# enough set
|
||||||
self.env.set('INVENTREE_ADMIN_USER', 'admin') # set username
|
envs = {'INVENTREE_ADMIN_USER': 'admin', # set username
|
||||||
self.env.set('INVENTREE_ADMIN_EMAIL', 'info@example.com') # set email
|
'INVENTREE_ADMIN_EMAIL': 'info@example.com', # set email
|
||||||
self.env.set('INVENTREE_ADMIN_PASSWORD', 'password123') # set password
|
'INVENTREE_ADMIN_PASSWORD': 'password123' # set password
|
||||||
self.run_reload()
|
}
|
||||||
|
self.run_reload(envs)
|
||||||
self.assertEqual(user_count(), 1)
|
self.assertEqual(user_count(), 1)
|
||||||
|
|
||||||
# make sure to clean up
|
# make sure to clean up
|
||||||
|
Loading…
x
Reference in New Issue
Block a user