Merge pull request #12177 from pilou-/create_notification_settings_remove_commit

fix: Ensure rollback works with User entity
This commit is contained in:
mergify[bot] 2021-02-09 16:55:07 +00:00 committed by GitHub
commit 1e375a2345
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View file

@ -2,7 +2,7 @@
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe, unittest
import frappe, unittest, uuid
from frappe.model.delete_doc import delete_doc
from frappe.utils.data import today, add_to_date
@ -240,6 +240,29 @@ class TestUser(unittest.TestCase):
self.assertRaises(frappe.ValidationError, user.reset_password, False)
def test_user_rollback(self):
""" """
frappe.db.commit()
frappe.db.begin()
user_id = str(uuid.uuid4())
email = f'{user_id}@example.com'
try:
frappe.flags.in_import = True # disable throttling
frappe.get_doc(dict(
doctype='User',
email=email,
first_name=user_id,
)).insert()
finally:
frappe.flags.in_import = False
# Check user has been added
self.assertIsNotNone(frappe.db.get("User", {"email": email}))
# Check that rollback works
frappe.db.rollback()
self.assertIsNone(frappe.db.get("User", {"email": email}))
def delete_contact(user):
frappe.db.sql("DELETE FROM `tabContact` WHERE `email_id`= %s", user)

View file

@ -42,7 +42,6 @@ def create_notification_settings(user):
_doc = frappe.new_doc('Notification Settings')
_doc.name = user
_doc.insert(ignore_permissions=True)
frappe.db.commit()
@frappe.whitelist()