[minor] enable all roles and domain before running tests cases (#10108)

* [minor] enable all roles and domain before running tests cases

* Update utils.py
This commit is contained in:
Makarand Bauskar 2017-07-26 16:29:22 +05:30 committed by Rushabh Mehta
parent b8a4a584e6
commit d0109a6fc0

View File

@ -50,6 +50,7 @@ def before_tests():
frappe.db.sql("delete from `tabItem Price`")
frappe.db.set_value("Stock Settings", None, "auto_insert_price_list_rate_if_missing", 0)
enable_all_roles_and_domains()
frappe.db.commit()
@ -94,3 +95,29 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None):
except:
frappe.msgprint(_("Unable to find exchange rate for {0} to {1} for key date {2}. Please create a Currency Exchange record manually").format(from_currency, to_currency, transaction_date))
return 0.0
def enable_all_roles_and_domains():
""" enable all roles and domain for testing """
roles = frappe.get_list("Role", filters={"disabled": 1})
for role in roles:
_role = frappe.get_doc("Role", role.get("name"))
_role.disabled = 0
_role.flags.ignore_mandatory = True
_role.flags.ignore_permissions = True
_role.save()
# add all roles to users
user = frappe.get_doc("User", "test@erpnext.com")
user.add_roles(*[role.get("name") for role in roles])
domains = frappe.get_list("Domain")
if not domains:
return
domain_settings = frappe.get_doc("Domain Settings", "Domain Settings")
domain_settings.set("active_domains", [])
for domain in domains:
row = domain_settings.append("active_domains", {})
row.domain=domain.get("name")
domain_settings.save()