add special env testing flag

This commit is contained in:
Matthias 2022-02-28 21:08:27 +01:00
parent 737d397705
commit 12c4296261
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
3 changed files with 8 additions and 2 deletions

View File

@ -31,7 +31,7 @@ class InvenTreeConfig(AppConfig):
if not isInTestMode():
self.update_exchange_rates()
if canAppAccessDatabase() or settings.TESTING:
if canAppAccessDatabase() or settings.TESTING_ENV:
self.add_user_on_startup()
def remove_obsolete_tasks(self):
@ -192,7 +192,7 @@ 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:
if settings.TESTING_ENV:
raise _e
# do not try again

View File

@ -37,6 +37,7 @@ def _is_true(x):
# Determine if we are running in "test" mode e.g. "manage.py test"
TESTING = 'test' in sys.argv
TESTING_ENV = False
# New requirement for django 3.2+
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

View File

@ -432,6 +432,8 @@ class TestSettings(TestCase):
def test_set_user_to_few(self):
# add shortcut
user_count = self.user_mdl.objects.count
# enable testing mode
settings.TESTING_ENV = True
# nothing set
self.assertEqual(user_count(), 0)
@ -455,3 +457,6 @@ class TestSettings(TestCase):
with self.assertRaises(IntegrationPluginError):
self.run_reload()
self.assertEqual(user_count(), 1)
# make sure to clean up
settings.TESTING_ENV = False