mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
fix test transactions
This commit is contained in:
parent
3b1bfddd8b
commit
4e898d5eac
@ -6,6 +6,7 @@ from django.apps import AppConfig
|
|||||||
from django.core.exceptions import AppRegistryNotReady
|
from django.core.exceptions import AppRegistryNotReady
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.db import transaction
|
||||||
from django.db.utils import IntegrityError
|
from django.db.utils import IntegrityError
|
||||||
|
|
||||||
from InvenTree.ready import isInTestMode, canAppAccessDatabase
|
from InvenTree.ready import isInTestMode, canAppAccessDatabase
|
||||||
@ -186,7 +187,8 @@ class InvenTreeConfig(AppConfig):
|
|||||||
# good to go -> create user
|
# good to go -> create user
|
||||||
user = get_user_model()
|
user = get_user_model()
|
||||||
try:
|
try:
|
||||||
new_user = user.objects.create_user(add_user, add_email, add_password)
|
with transaction.atomic():
|
||||||
|
new_user = user.objects.create_user(add_user, add_email, add_password)
|
||||||
logger.info(f'User {str(new_user)} was created!')
|
logger.info(f'User {str(new_user)} was created!')
|
||||||
except IntegrityError as _e:
|
except IntegrityError as _e:
|
||||||
logger.warning(f'The user "{add_user}" could not be created due to the following error:\n{str(_e)}')
|
logger.warning(f'The user "{add_user}" could not be created due to the following error:\n{str(_e)}')
|
||||||
|
@ -453,6 +453,6 @@ class TestSettings(TestCase):
|
|||||||
self.env.set('INVENTREE_SET_USER', 'admin') # set username
|
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_EMAIL', 'info@example.com') # set email
|
||||||
self.env.set('INVENTREE_SET_PASSWORD', 'password123') # set password
|
self.env.set('INVENTREE_SET_PASSWORD', 'password123') # set password
|
||||||
with self.assertRaises(IntegrityError, IntegrationPluginError):
|
with self.assertRaises(IntegrationPluginError):
|
||||||
self.run_reload()
|
self.run_reload()
|
||||||
self.assertEqual(user_count(), 1)
|
self.assertEqual(user_count(), 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user