style: format

This commit is contained in:
Ankush Menat 2023-12-28 19:16:11 +05:30
parent 9b458ad354
commit 4a8fb6c43c
2 changed files with 29 additions and 17 deletions

View file

@ -98,11 +98,12 @@ class TestHooks(FrappeTestCase):
def test_fixture_prefix(self):
import os
import shutil
from frappe import hooks
from frappe.utils.fixtures import export_fixtures
app = "frappe"
if(os.path.isdir(frappe.get_app_path(app, "fixtures"))):
if os.path.isdir(frappe.get_app_path(app, "fixtures")):
shutil.rmtree(frappe.get_app_path(app, "fixtures"))
# use any set of core doctypes for test purposes
@ -118,16 +119,20 @@ class TestHooks(FrappeTestCase):
if frappe._load_app_hooks.__wrapped__ in frappe.local.request_cache.keys():
del frappe.local.request_cache[frappe._load_app_hooks.__wrapped__]
self.assertEqual([False], frappe.get_hooks("fixture_auto_order", app_name=app))
self.assertEqual([
{"dt": "User"},
{"dt": "Contact"},
{"dt": "Role"},
], frappe.get_hooks("fixtures", app_name=app))
self.assertEqual(
[
{"dt": "User"},
{"dt": "Contact"},
{"dt": "Role"},
],
frappe.get_hooks("fixtures", app_name=app),
)
export_fixtures(app)
# use assertCountEqual (replaced assertItemsEqual), beacuse os.listdir might return the list in a different order, depending on OS
self.assertCountEqual(["user.json", "contact.json", "role.json"], os.listdir(frappe.get_app_path(app, "fixtures")))
self.assertCountEqual(
["user.json", "contact.json", "role.json"], os.listdir(frappe.get_app_path(app, "fixtures"))
)
hooks.fixture_auto_order = True
del frappe.local.request_cache[frappe._load_app_hooks.__wrapped__]
@ -135,13 +140,13 @@ class TestHooks(FrappeTestCase):
shutil.rmtree(frappe.get_app_path(app, "fixtures"))
export_fixtures(app)
self.assertCountEqual(["1_user.json", "2_contact.json", "3_role.json"], os.listdir(frappe.get_app_path(app, "fixtures")))
self.assertCountEqual(
["1_user.json", "2_contact.json", "3_role.json"],
os.listdir(frappe.get_app_path(app, "fixtures")),
)
hooks.fixtures = [
{
"dt": "User",
"prefix": "my_prefix"},
{"dt": "User", "prefix": "my_prefix"},
{"dt": "Contact"},
{"dt": "Role"},
]
@ -150,14 +155,19 @@ class TestHooks(FrappeTestCase):
del frappe.local.request_cache[frappe._load_app_hooks.__wrapped__]
shutil.rmtree(frappe.get_app_path(app, "fixtures"))
export_fixtures(app)
self.assertCountEqual(["my_prefix_user.json", "contact.json", "role.json"], os.listdir(frappe.get_app_path(app, "fixtures")))
self.assertCountEqual(
["my_prefix_user.json", "contact.json", "role.json"],
os.listdir(frappe.get_app_path(app, "fixtures")),
)
hooks.fixture_auto_order = True
del frappe.local.request_cache[frappe._load_app_hooks.__wrapped__]
shutil.rmtree(frappe.get_app_path(app, "fixtures"))
export_fixtures(app)
self.assertCountEqual(["1_my_prefix_user.json", "2_contact.json", "3_role.json"], os.listdir(frappe.get_app_path(app, "fixtures")))
self.assertCountEqual(
["1_my_prefix_user.json", "2_contact.json", "3_role.json"],
os.listdir(frappe.get_app_path(app, "fixtures")),
)
class TestAPIHooks(FrappeAPITestCase):

View file

@ -67,7 +67,9 @@ def export_fixtures(app=None):
else:
apps = frappe.get_installed_apps()
for app in apps:
fixture_auto_order = bool(next(iter(frappe.get_hooks("fixture_auto_order", app_name=app)), False))
fixture_auto_order = bool(
next(iter(frappe.get_hooks("fixture_auto_order", app_name=app)), False)
)
fixtures = frappe.get_hooks("fixtures", app_name=app)
for index, fixture in enumerate(fixtures, start=1):
filters = None