fix test transactions

This commit is contained in:
Matthias 2022-02-28 20:42:20 +01:00
parent 3b1bfddd8b
commit 4e898d5eac
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
2 changed files with 4 additions and 2 deletions

View File

@ -6,6 +6,7 @@ from django.apps import AppConfig
from django.core.exceptions import AppRegistryNotReady
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import transaction
from django.db.utils import IntegrityError
from InvenTree.ready import isInTestMode, canAppAccessDatabase
@ -186,7 +187,8 @@ class InvenTreeConfig(AppConfig):
# good to go -> create user
user = get_user_model()
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!')
except IntegrityError as _e:
logger.warning(f'The user "{add_user}" could not be created due to the following error:\n{str(_e)}')

View File

@ -453,6 +453,6 @@ class TestSettings(TestCase):
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, IntegrationPluginError):
with self.assertRaises(IntegrationPluginError):
self.run_reload()
self.assertEqual(user_count(), 1)