test: fix broken tests

Fixture test:
This is broken cause it's trying to find doctype after it has been
deleted (wut?)
It was working so far because cache wasn't cleared correctly so you'd
still find it from cache.

db.set_value test:
converted to use last query instead of patching SQL
This commit is contained in:
Ankush Menat 2023-06-03 22:23:11 +05:30 committed by Ankush Menat
parent 84ef2cc89c
commit 0d056a3a2b
2 changed files with 17 additions and 16 deletions

View file

@ -796,21 +796,20 @@ class TestDBSetValue(FrappeTestCase):
def test_set_value(self):
self.todo1.reload()
with patch.object(Database, "sql") as sql_called:
frappe.db.set_value(
self.todo1.doctype,
self.todo1.name,
"description",
f"{self.todo1.description}-edit by `test_for_update`",
)
first_query = sql_called.call_args_list[0].args[0]
frappe.db.set_value(
self.todo1.doctype,
self.todo1.name,
"description",
f"{self.todo1.description}-edit by `test_for_update`",
)
query = frappe.db.last_query
if frappe.conf.db_type == "postgres":
from frappe.database.postgres.database import modify_query
if frappe.conf.db_type == "postgres":
from frappe.database.postgres.database import modify_query
self.assertTrue(modify_query("UPDATE `tabToDo` SET") in first_query)
if frappe.conf.db_type == "mariadb":
self.assertTrue("UPDATE `tabToDo` SET" in first_query)
self.assertTrue(modify_query("UPDATE `tabToDo` SET") in query)
if frappe.conf.db_type == "mariadb":
self.assertTrue("UPDATE `tabToDo` SET" in query)
def test_cleared_cache(self):
self.todo2.reload()

View file

@ -69,10 +69,12 @@ class TestFixtureImport(FrappeTestCase):
import_doc(path_to_exported_fixtures)
delete_doc("DocType", "temp_singles", delete_permanently=True)
os.remove(path_to_exported_fixtures)
data = frappe.db.get_single_value("temp_singles", "member_name")
truncate_query.run()
self.assertEqual(data, dummy_name_list[0])
delete_doc("DocType", "temp_singles", delete_permanently=True)
os.remove(path_to_exported_fixtures)
frappe.db.commit()