refactor: toml test records for readability (#28065)
* refactor: toml test records for readability * fix: maintain backwards compatibility * refactor: transform in-tree records * chore: don't use deprecated functions (treewide) * chore: revert migration of tests which depend on old test records list * feat: add cls.globalTestRecords on IntegrationTestCase
This commit is contained in:
parent
afd5d73a5b
commit
443c38daa9
89 changed files with 595 additions and 696 deletions
|
|
@ -2168,18 +2168,7 @@ def are_emails_muted():
|
|||
return flags.mute_emails or cint(conf.get("mute_emails"))
|
||||
|
||||
|
||||
def get_test_records(doctype):
|
||||
"""Return list of objects from `test_records.json` in the given doctype's folder."""
|
||||
from frappe.modules import get_doctype_module, get_module_path
|
||||
|
||||
path = os.path.join(
|
||||
get_module_path(get_doctype_module(doctype)), "doctype", scrub(doctype), "test_records.json"
|
||||
)
|
||||
if os.path.exists(path):
|
||||
with open(path) as f:
|
||||
return json.loads(f.read())
|
||||
else:
|
||||
return []
|
||||
from frappe.deprecation_dumpster import frappe_get_test_records as get_test_records
|
||||
|
||||
|
||||
def format_value(*args, **kwargs):
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Contact",
|
||||
"salutation": "Mr",
|
||||
"first_name": "_Test Contact For _Test Customer",
|
||||
"is_primary_contact": 1,
|
||||
"status": "Open",
|
||||
"email_ids": [
|
||||
{
|
||||
"email_id": "test_contact@example.com",
|
||||
"is_primary": 1
|
||||
}
|
||||
],
|
||||
"phone_nos": [
|
||||
{
|
||||
"phone": "+91 0000000000",
|
||||
"is_primary_phone": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"doctype": "Contact",
|
||||
"first_name": "_Test Contact For _Test Supplier",
|
||||
"is_primary_contact": 1,
|
||||
"status": "Open",
|
||||
"email_ids": [
|
||||
{
|
||||
"email_id": "test_contact@example.com",
|
||||
"is_primary": 1
|
||||
}
|
||||
],
|
||||
"phone_nos": [
|
||||
{
|
||||
"phone": "+91 0000000001",
|
||||
"is_primary_phone": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
27
frappe/contacts/doctype/contact/test_records.toml
Normal file
27
frappe/contacts/doctype/contact/test_records.toml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
[[Contact]]
|
||||
salutation = "Mr"
|
||||
first_name = "_Test Contact For _Test Customer"
|
||||
is_primary_contact = 1
|
||||
status = "Open"
|
||||
[[Contact.email_ids]]
|
||||
email_id = "test_contact@example.com"
|
||||
is_primary = 1
|
||||
|
||||
[[Contact.phone_nos]]
|
||||
phone = "+91 0000000000"
|
||||
is_primary_phone = 1
|
||||
|
||||
|
||||
[[Contact]]
|
||||
first_name = "_Test Contact For _Test Supplier"
|
||||
is_primary_contact = 1
|
||||
status = "Open"
|
||||
[[Contact.email_ids]]
|
||||
email_id = "test_contact@example.com"
|
||||
is_primary = 1
|
||||
|
||||
[[Contact.phone_nos]]
|
||||
phone = "+91 0000000001"
|
||||
is_primary_phone = 1
|
||||
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[
|
||||
{
|
||||
"salutation": "Mr"
|
||||
},
|
||||
{
|
||||
"salutation": "Mrs"
|
||||
}
|
||||
]
|
||||
6
frappe/contacts/doctype/salutation/test_records.toml
Normal file
6
frappe/contacts/doctype/salutation/test_records.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[[Salutation]]
|
||||
salutation = "Mr"
|
||||
|
||||
[[Salutation]]
|
||||
salutation = "Mrs"
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ if TYPE_CHECKING:
|
|||
from frappe.contacts.doctype.contact.contact import Contact
|
||||
from frappe.email.doctype.email_account.email_account import EmailAccount
|
||||
|
||||
test_records = frappe.get_test_records("Communication")
|
||||
test_records = frappe.tests.utils.load_test_records_for("Communication")
|
||||
|
||||
|
||||
class UnitTestCommunication(UnitTestCase):
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Communication",
|
||||
"name": "_Test Communication 1",
|
||||
"subject": "Test Subject",
|
||||
"sent_or_received": "Received",
|
||||
"parenttype": "User",
|
||||
"parent": "Administrator"
|
||||
}
|
||||
]
|
||||
7
frappe/core/doctype/communication/test_records.toml
Normal file
7
frappe/core/doctype/communication/test_records.toml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[[Communication]]
|
||||
name = "_Test Communication 1"
|
||||
subject = "Test Subject"
|
||||
sent_or_received = "Received"
|
||||
parenttype = "User"
|
||||
parent = "Administrator"
|
||||
|
||||
|
|
@ -2,8 +2,6 @@
|
|||
# License: MIT. See LICENSE
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Custom DocPerm')
|
||||
|
||||
|
||||
class UnitTestCustomDocperm(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
# License: MIT. See LICENSE
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Custom Role')
|
||||
|
||||
|
||||
class UnitTestCustomRole(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
# License: MIT. See LICENSE
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Deleted Document')
|
||||
|
||||
|
||||
class UnitTestDeletedDocument(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
[]
|
||||
|
|
@ -8,8 +8,6 @@ import frappe
|
|||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
from frappe.utils.error import _is_ldap_exception, guess_exception_source
|
||||
|
||||
# test_records = frappe.get_test_records('Error Log')
|
||||
|
||||
|
||||
class UnitTestErrorLog(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
# License: MIT. See LICENSE
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Language')
|
||||
|
||||
|
||||
class UnitTestLanguage(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
# License: MIT. See LICENSE
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Module Def')
|
||||
|
||||
|
||||
class UnitTestModuleDef(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from unittest.mock import patch
|
|||
import frappe
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
test_records = frappe.get_test_records("Page")
|
||||
test_records = frappe.tests.utils.load_test_records_for("Page")
|
||||
|
||||
|
||||
class UnitTestPage(UnitTestCase):
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
[]
|
||||
|
|
@ -2,8 +2,6 @@
|
|||
# License: MIT. See LICENSE
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Patch Log')
|
||||
|
||||
|
||||
class UnitTestPatchLog(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Report",
|
||||
"name": "_Test Report 1",
|
||||
"report_name": "_Test Report 1",
|
||||
"report_type": "Query Report",
|
||||
"is_standard": "No",
|
||||
"ref_doctype": "Event"
|
||||
}
|
||||
]
|
||||
7
frappe/core/doctype/report/test_records.toml
Normal file
7
frappe/core/doctype/report/test_records.toml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[[Report]]
|
||||
name = "_Test Report 1"
|
||||
report_name = "_Test Report 1"
|
||||
report_type = "Query Report"
|
||||
is_standard = "No"
|
||||
ref_doctype = "Event"
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ from frappe.desk.reportview import delete_report
|
|||
from frappe.desk.reportview import save_report as _save_report
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
test_records = frappe.get_test_records("Report")
|
||||
test_records = frappe.tests.utils.load_test_records_for("Report")
|
||||
EXTRA_TEST_RECORD_DEPENDENCIES = ["User"]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Role",
|
||||
"role_name": "_Test Role",
|
||||
"desk_access": 1
|
||||
},
|
||||
{
|
||||
"doctype": "Role",
|
||||
"role_name": "_Test Role 2",
|
||||
"desk_access": 1
|
||||
},
|
||||
{
|
||||
"doctype": "Role",
|
||||
"role_name": "_Test Role 3",
|
||||
"desk_access": 1
|
||||
},
|
||||
{
|
||||
"doctype": "Role",
|
||||
"role_name": "_Test Role 4",
|
||||
"desk_access": 0
|
||||
}
|
||||
]
|
||||
16
frappe/core/doctype/role/test_records.toml
Normal file
16
frappe/core/doctype/role/test_records.toml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
[[Role]]
|
||||
role_name = "_Test Role"
|
||||
desk_access = 1
|
||||
|
||||
[[Role]]
|
||||
role_name = "_Test Role 2"
|
||||
desk_access = 1
|
||||
|
||||
[[Role]]
|
||||
role_name = "_Test Role 3"
|
||||
desk_access = 1
|
||||
|
||||
[[Role]]
|
||||
role_name = "_Test Role 4"
|
||||
desk_access = 0
|
||||
|
||||
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
import unittest
|
||||
|
||||
# test_records = frappe.get_test_records('SMS Log')
|
||||
|
||||
|
||||
class TestSMSLog(unittest.TestCase):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,95 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "User",
|
||||
"email": "test@example.com",
|
||||
"enabled": 1,
|
||||
"first_name": "_Test",
|
||||
"new_password": "Eastern_43A1W",
|
||||
"roles": [
|
||||
{
|
||||
"doctype": "Has Role",
|
||||
"parentfield": "roles",
|
||||
"role": "_Test Role"
|
||||
},
|
||||
{
|
||||
"doctype": "Has Role",
|
||||
"parentfield": "roles",
|
||||
"role": "System Manager"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"doctype": "User",
|
||||
"email": "test1@example.com",
|
||||
"first_name": "_Test1",
|
||||
"new_password": "Eastern_43A1W"
|
||||
},
|
||||
{
|
||||
"doctype": "User",
|
||||
"email": "test2@example.com",
|
||||
"first_name": "_Test2",
|
||||
"new_password": "Eastern_43A1W",
|
||||
"enabled": 1
|
||||
},
|
||||
{
|
||||
"doctype": "User",
|
||||
"email": "test3@example.com",
|
||||
"first_name": "_Test3",
|
||||
"new_password": "Eastern_43A1W",
|
||||
"enabled": 1
|
||||
},
|
||||
{
|
||||
"doctype": "User",
|
||||
"email": "test4@example.com",
|
||||
"first_name": "_Test4",
|
||||
"new_password": "Eastern_43A1W",
|
||||
"enabled": 1
|
||||
},
|
||||
{
|
||||
"doctype": "User",
|
||||
"email": "test'5@example.com",
|
||||
"first_name": "_Test'5",
|
||||
"new_password": "Eastern_43A1W",
|
||||
"enabled": 1
|
||||
},
|
||||
{
|
||||
"doctype": "User",
|
||||
"email": "testperm@example.com",
|
||||
"first_name": "_Test Perm",
|
||||
"new_password": "Eastern_43A1W",
|
||||
"enabled": 1
|
||||
},
|
||||
{
|
||||
"doctype": "User",
|
||||
"email": "testdelete@example.com",
|
||||
"enabled": 1,
|
||||
"first_name": "_Test",
|
||||
"new_password": "Eastern_43A1W",
|
||||
"roles": [
|
||||
{
|
||||
"doctype": "Has Role",
|
||||
"parentfield": "roles",
|
||||
"role": "_Test Role 2"
|
||||
},
|
||||
{
|
||||
"doctype": "Has Role",
|
||||
"parentfield": "roles",
|
||||
"role": "System Manager"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"doctype": "User",
|
||||
"email": "testpassword@example.com",
|
||||
"enabled": 1,
|
||||
"first_name": "_Test",
|
||||
"new_password": "Eastern_43A1W",
|
||||
"roles": [
|
||||
{
|
||||
"doctype": "Has Role",
|
||||
"parentfield": "roles",
|
||||
"role": "System Manager"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
78
frappe/core/doctype/user/test_records.toml
Normal file
78
frappe/core/doctype/user/test_records.toml
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
[[User]]
|
||||
email = "test@example.com"
|
||||
enabled = 1
|
||||
first_name = "_Test"
|
||||
new_password = "Eastern_43A1W"
|
||||
[[User.roles]]
|
||||
doctype = "Has Role"
|
||||
parentfield = "roles"
|
||||
role = "_Test Role"
|
||||
|
||||
[[User.roles]]
|
||||
doctype = "Has Role"
|
||||
parentfield = "roles"
|
||||
role = "System Manager"
|
||||
|
||||
|
||||
[[User]]
|
||||
email = "test1@example.com"
|
||||
first_name = "_Test1"
|
||||
new_password = "Eastern_43A1W"
|
||||
|
||||
[[User]]
|
||||
email = "test2@example.com"
|
||||
first_name = "_Test2"
|
||||
new_password = "Eastern_43A1W"
|
||||
enabled = 1
|
||||
|
||||
[[User]]
|
||||
email = "test3@example.com"
|
||||
first_name = "_Test3"
|
||||
new_password = "Eastern_43A1W"
|
||||
enabled = 1
|
||||
|
||||
[[User]]
|
||||
email = "test4@example.com"
|
||||
first_name = "_Test4"
|
||||
new_password = "Eastern_43A1W"
|
||||
enabled = 1
|
||||
|
||||
[[User]]
|
||||
email = "test'5@example.com"
|
||||
first_name = "_Test'5"
|
||||
new_password = "Eastern_43A1W"
|
||||
enabled = 1
|
||||
|
||||
[[User]]
|
||||
email = "testperm@example.com"
|
||||
first_name = "_Test Perm"
|
||||
new_password = "Eastern_43A1W"
|
||||
enabled = 1
|
||||
|
||||
[[User]]
|
||||
email = "testdelete@example.com"
|
||||
enabled = 1
|
||||
first_name = "_Test"
|
||||
new_password = "Eastern_43A1W"
|
||||
[[User.roles]]
|
||||
doctype = "Has Role"
|
||||
parentfield = "roles"
|
||||
role = "_Test Role 2"
|
||||
|
||||
[[User.roles]]
|
||||
doctype = "Has Role"
|
||||
parentfield = "roles"
|
||||
role = "System Manager"
|
||||
|
||||
|
||||
[[User]]
|
||||
email = "testpassword@example.com"
|
||||
enabled = 1
|
||||
first_name = "_Test"
|
||||
new_password = "Eastern_43A1W"
|
||||
[[User.roles]]
|
||||
doctype = "Has Role"
|
||||
parentfield = "roles"
|
||||
role = "System Manager"
|
||||
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
[]
|
||||
|
|
@ -2,8 +2,6 @@
|
|||
# License: MIT. See LICENSE
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Client Script')
|
||||
|
||||
|
||||
class UnitTestClientScript(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from frappe.custom.doctype.custom_field.custom_field import (
|
|||
)
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
test_records = frappe.get_test_records("Custom Field")
|
||||
test_records = frappe.tests.utils.load_test_records_for("Custom Field")
|
||||
|
||||
|
||||
class UnitTestCustomField(UnitTestCase):
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
[]
|
||||
|
|
@ -2,8 +2,6 @@
|
|||
# License: MIT. See LICENSE
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Property Setter')
|
||||
|
||||
|
||||
class UnitTestPropertySetter(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doc_type": "User",
|
||||
"doctype_or_field": "DocField",
|
||||
"field_name": "location",
|
||||
"property": "in_list_view",
|
||||
"property_type": "Check",
|
||||
"value": "1"
|
||||
}
|
||||
]
|
||||
8
frappe/custom/doctype/property_setter/test_records.toml
Normal file
8
frappe/custom/doctype/property_setter/test_records.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[["Property Setter"]]
|
||||
doc_type = "User"
|
||||
doctype_or_field = "DocField"
|
||||
field_name = "location"
|
||||
property = "in_list_view"
|
||||
property_type = "Check"
|
||||
value = "1"
|
||||
|
||||
|
|
@ -566,3 +566,32 @@ def tests_utils_get_dependencies(doctype):
|
|||
)
|
||||
def test_runner_get_dependencies(doctype):
|
||||
return tests_utils_get_dependencies(doctype)
|
||||
|
||||
|
||||
@deprecated(
|
||||
"frappe.get_test_records",
|
||||
"2024-20-09",
|
||||
"v17",
|
||||
"""refactor to use frappe.tests.utils.load_test_records_for
|
||||
Returns a dict with doctypes as keys and records as list items
|
||||
Hint: your current doctype and all its dependencies are automatically loaded by the framework.
|
||||
If you did this manually using test_dependencies = frappe.get_test_records("My Current Doc"),
|
||||
just remove that line and it should work.
|
||||
You have access to the global pool of test records via: cls.testRecords
|
||||
This includes the current records under cls.globalTestRecords["My Current Doc"] -> list
|
||||
IMPORTANT: Migrate do TOML test records, first: https://github.com/frappe/frappe/pull/28065
|
||||
""",
|
||||
)
|
||||
def frappe_get_test_records(doctype):
|
||||
from frappe.tests.utils.generators import load_test_records_for
|
||||
|
||||
records = load_test_records_for(doctype)
|
||||
if isinstance(records, dict):
|
||||
_records = []
|
||||
for doctype, docs in records.items():
|
||||
for doc in docs:
|
||||
_doc = doc.copy()
|
||||
_doc["doctype"] = doctype
|
||||
_records.append(_doc)
|
||||
return _records
|
||||
return records
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Event",
|
||||
"subject":"_Test Event 1",
|
||||
"starts_on": "2014-01-01",
|
||||
"event_type": "Public",
|
||||
"creation": "2014-01-01"
|
||||
},
|
||||
{
|
||||
"doctype": "Event",
|
||||
"subject":"_Test Event 2",
|
||||
"starts_on": "2014-01-01",
|
||||
"event_type": "Private",
|
||||
"creation": "2014-01-01"
|
||||
},
|
||||
{
|
||||
"doctype": "Event",
|
||||
"subject": "_Test Event 3",
|
||||
"starts_on": "2014-02-01",
|
||||
"event_type": "Private",
|
||||
"creation": "2014-02-01"
|
||||
}
|
||||
]
|
||||
18
frappe/desk/doctype/event/test_records.toml
Normal file
18
frappe/desk/doctype/event/test_records.toml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
[[Event]]
|
||||
subject = "_Test Event 1"
|
||||
starts_on = "2014-01-01"
|
||||
event_type = "Public"
|
||||
creation = "2014-01-01"
|
||||
|
||||
[[Event]]
|
||||
subject = "_Test Event 2"
|
||||
starts_on = "2014-01-01"
|
||||
event_type = "Private"
|
||||
creation = "2014-01-01"
|
||||
|
||||
[[Event]]
|
||||
subject = "_Test Event 3"
|
||||
starts_on = "2014-02-01"
|
||||
event_type = "Private"
|
||||
creation = "2014-02-01"
|
||||
|
||||
|
|
@ -2,8 +2,6 @@
|
|||
# License: MIT. See LICENSE
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Kanban Board')
|
||||
|
||||
|
||||
class UnitTestKanbanBoard(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
import frappe
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
test_records = frappe.get_test_records("Note")
|
||||
test_records = frappe.tests.utils.load_test_records_for("Note")
|
||||
|
||||
|
||||
class UnitTestNote(UnitTestCase):
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Note",
|
||||
"name": "_Test Note 1",
|
||||
"title": "Test Note Title"
|
||||
}
|
||||
]
|
||||
4
frappe/desk/doctype/note/test_records.toml
Normal file
4
frappe/desk/doctype/note/test_records.toml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[[Note]]
|
||||
name = "_Test Note 1"
|
||||
title = "Test Note Title"
|
||||
|
||||
|
|
@ -7,8 +7,6 @@ from frappe.tests import IntegrationTestCase, UnitTestCase
|
|||
from frappe.utils import add_to_date, get_link_to_form, today
|
||||
from frappe.utils.data import is_html
|
||||
|
||||
# test_records = frappe.get_test_records('Auto Email Report')
|
||||
|
||||
|
||||
class UnitTestAutoEmailReport(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
[
|
||||
{
|
||||
"is_default": 1,
|
||||
"is_global": 1,
|
||||
"doctype": "Email Account",
|
||||
"domain":"example.com",
|
||||
"email_account_name": "_Test Email Account 1",
|
||||
"enable_outgoing": 1,
|
||||
"smtp_server": "test.example.com",
|
||||
"email_id": "test@example.com",
|
||||
"password": "password",
|
||||
"add_signature": 1,
|
||||
"signature": "\nBest Wishes\nTest Signature",
|
||||
"enable_auto_reply": 1,
|
||||
"auto_reply_message": "",
|
||||
"enable_incoming": 1,
|
||||
"notify_if_unreplied": 1,
|
||||
"unreplied_for_mins": 20,
|
||||
"send_notification_to": "test_unreplied@example.com",
|
||||
"pop3_server": "pop.test.example.com",
|
||||
"append_to": "ToDo",
|
||||
"imap_folder": [{"folder_name": "INBOX", "append_to": "ToDo"}, {"folder_name": "Test Folder", "append_to": "Communication"}],
|
||||
"track_email_status": 1
|
||||
},
|
||||
{
|
||||
"doctype": "ToDo",
|
||||
"description":"test doctype"
|
||||
}
|
||||
]
|
||||
32
frappe/email/doctype/email_account/test_records.toml
Normal file
32
frappe/email/doctype/email_account/test_records.toml
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
[["Email Account"]]
|
||||
is_default = 1
|
||||
is_global = 1
|
||||
domain = "example.com"
|
||||
email_account_name = "_Test Email Account 1"
|
||||
enable_outgoing = 1
|
||||
smtp_server = "test.example.com"
|
||||
email_id = "test@example.com"
|
||||
password = "password"
|
||||
add_signature = 1
|
||||
signature = "\nBest Wishes\nTest Signature"
|
||||
enable_auto_reply = 1
|
||||
auto_reply_message = ""
|
||||
enable_incoming = 1
|
||||
notify_if_unreplied = 1
|
||||
unreplied_for_mins = 20
|
||||
send_notification_to = "test_unreplied@example.com"
|
||||
pop3_server = "pop.test.example.com"
|
||||
append_to = "ToDo"
|
||||
track_email_status = 1
|
||||
[["Email Account".imap_folder]]
|
||||
folder_name = "INBOX"
|
||||
append_to = "ToDo"
|
||||
|
||||
[["Email Account".imap_folder]]
|
||||
folder_name = "Test Folder"
|
||||
append_to = "Communication"
|
||||
|
||||
|
||||
[[ToDo]]
|
||||
description = "test doctype"
|
||||
|
||||
|
|
@ -4,7 +4,7 @@ import frappe
|
|||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
from frappe.tests.utils import make_test_objects
|
||||
|
||||
test_records = frappe.get_test_records("Email Domain")
|
||||
test_records = frappe.tests.utils.load_test_records_for("Email Domain")
|
||||
|
||||
|
||||
class UnitTestEmailDomain(UnitTestCase):
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Email Domain",
|
||||
"domain_name": "test.com",
|
||||
"email_id": "_test@test.com",
|
||||
"email_server": "imap.test.com",
|
||||
"use_imap": "imap.test.com",
|
||||
"use_ssl": 1,
|
||||
"use_tls": 1,
|
||||
"incoming_port": "993",
|
||||
"attachment_limit": "1",
|
||||
"smtp_server": "smtp.test.com",
|
||||
"smtp_port": "587",
|
||||
"password": "password"
|
||||
},
|
||||
{
|
||||
"doctype": "Email Account",
|
||||
"name": "_Test Email Account 1",
|
||||
"enable_incoming": 1,
|
||||
"email_id": "_test@test.com",
|
||||
"domain": "test.com",
|
||||
"email_server": "imap.test.com",
|
||||
"use_imap": 1,
|
||||
"use_ssl": 0,
|
||||
"use_tls": 1,
|
||||
"incoming_port": "143",
|
||||
"attachment_limit": "1",
|
||||
"smtp_server": "smtp.test.com",
|
||||
"smtp_port": "587",
|
||||
"password": "password"
|
||||
}
|
||||
]
|
||||
28
frappe/email/doctype/email_domain/test_records.toml
Normal file
28
frappe/email/doctype/email_domain/test_records.toml
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
[["Email Domain"]]
|
||||
domain_name = "test.com"
|
||||
email_id = "_test@test.com"
|
||||
email_server = "imap.test.com"
|
||||
use_imap = "imap.test.com"
|
||||
use_ssl = 1
|
||||
use_tls = 1
|
||||
incoming_port = "993"
|
||||
attachment_limit = "1"
|
||||
smtp_server = "smtp.test.com"
|
||||
smtp_port = "587"
|
||||
password = "password"
|
||||
|
||||
[["Email Account"]]
|
||||
name = "_Test Email Account 1"
|
||||
enable_incoming = 1
|
||||
email_id = "_test@test.com"
|
||||
domain = "test.com"
|
||||
email_server = "imap.test.com"
|
||||
use_imap = 1
|
||||
use_ssl = 0
|
||||
use_tls = 1
|
||||
incoming_port = "143"
|
||||
attachment_limit = "1"
|
||||
smtp_server = "smtp.test.com"
|
||||
smtp_port = "587"
|
||||
password = "password"
|
||||
|
||||
|
|
@ -2,8 +2,6 @@
|
|||
# License: MIT. See LICENSE
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Email Flag Queue')
|
||||
|
||||
|
||||
class UnitTestEmailFlagQueue(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ import frappe
|
|||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
from frappe.utils import validate_url
|
||||
|
||||
# test_records = frappe.get_test_records('Email Group')
|
||||
|
||||
|
||||
class UnitTestEmailGroup(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Email Group",
|
||||
"title": "_Test Email Group"
|
||||
}
|
||||
]
|
||||
3
frappe/email/doctype/email_group/test_records.toml
Normal file
3
frappe/email/doctype/email_group/test_records.toml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[["Email Group"]]
|
||||
title = "_Test Email Group"
|
||||
|
||||
|
|
@ -2,8 +2,6 @@
|
|||
# License: MIT. See LICENSE
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Email Group Member')
|
||||
|
||||
|
||||
class UnitTestEmailGroupMember(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
# License: MIT. See LICENSE
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Email Unsubscribe')
|
||||
|
||||
|
||||
class UnitTestEmailUnsubscribe(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,76 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Notification",
|
||||
"subject":"_Test Notification 1",
|
||||
"document_type": "Communication",
|
||||
"event": "New",
|
||||
"attach_print": 0,
|
||||
"message": "New comment {{ doc.content }} created",
|
||||
"condition": "doc.communication_type=='Comment'",
|
||||
"recipients": [
|
||||
{ "receiver_by_document_field": "owner" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"doctype": "Notification",
|
||||
"subject":"_Test Notification 2",
|
||||
"document_type": "Communication",
|
||||
"event": "Save",
|
||||
"attach_print": 0,
|
||||
"message": "New comment {{ doc.content }} saved",
|
||||
"condition": "doc.communication_type=='Comment'",
|
||||
"recipients": [
|
||||
{ "receiver_by_document_field": "owner" }
|
||||
],
|
||||
"set_property_after_alert": "subject",
|
||||
"property_value": "__testing__"
|
||||
},
|
||||
{
|
||||
"doctype": "Notification",
|
||||
"subject":"_Test Notification 3",
|
||||
"document_type": "Event",
|
||||
"event": "Save",
|
||||
"attach_print": 0,
|
||||
"condition": "doc.event_type=='Public'",
|
||||
"message": "A new public event {{ doc.subject }} on {{ doc.starts_on }} is created",
|
||||
"recipients": [
|
||||
{ "receiver_by_document_field": "owner" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"doctype": "Notification",
|
||||
"subject":"_Test Notification 4",
|
||||
"document_type": "Event",
|
||||
"event": "Value Change",
|
||||
"attach_print": 0,
|
||||
"value_changed": "description",
|
||||
"message": "Description changed",
|
||||
"recipients": [
|
||||
{ "receiver_by_document_field": "owner" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"doctype": "Notification",
|
||||
"subject":"_Test Notification 5",
|
||||
"document_type": "Event",
|
||||
"event": "Days Before",
|
||||
"attach_print": 0,
|
||||
"date_changed": "starts_on",
|
||||
"days_in_advance": 2,
|
||||
"message": "Description changed",
|
||||
"recipients": [
|
||||
{ "receiver_by_document_field": "owner" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"doctype": "Notification",
|
||||
"subject":"_Test Notification 6",
|
||||
"document_type": "User",
|
||||
"event": "New",
|
||||
"attach_print": 0,
|
||||
"message": "New user {{ doc.name }} created",
|
||||
"recipients": [
|
||||
{ "receiver_by_document_field": "owner", "cc": "{{ doc.email }}" }
|
||||
]
|
||||
}
|
||||
]
|
||||
69
frappe/email/doctype/notification/test_records.toml
Normal file
69
frappe/email/doctype/notification/test_records.toml
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
[[Notification]]
|
||||
subject = "_Test Notification 1"
|
||||
document_type = "Communication"
|
||||
event = "New"
|
||||
attach_print = 0
|
||||
message = "New comment {{ doc.content }} created"
|
||||
condition = "doc.communication_type=='Comment'"
|
||||
[[Notification.recipients]]
|
||||
receiver_by_document_field = "owner"
|
||||
|
||||
|
||||
[[Notification]]
|
||||
subject = "_Test Notification 2"
|
||||
document_type = "Communication"
|
||||
event = "Save"
|
||||
attach_print = 0
|
||||
message = "New comment {{ doc.content }} saved"
|
||||
condition = "doc.communication_type=='Comment'"
|
||||
set_property_after_alert = "subject"
|
||||
property_value = "__testing__"
|
||||
[[Notification.recipients]]
|
||||
receiver_by_document_field = "owner"
|
||||
|
||||
|
||||
[[Notification]]
|
||||
subject = "_Test Notification 3"
|
||||
document_type = "Event"
|
||||
event = "Save"
|
||||
attach_print = 0
|
||||
condition = "doc.event_type=='Public'"
|
||||
message = "A new public event {{ doc.subject }} on {{ doc.starts_on }} is created"
|
||||
[[Notification.recipients]]
|
||||
receiver_by_document_field = "owner"
|
||||
|
||||
|
||||
[[Notification]]
|
||||
subject = "_Test Notification 4"
|
||||
document_type = "Event"
|
||||
event = "Value Change"
|
||||
attach_print = 0
|
||||
value_changed = "description"
|
||||
message = "Description changed"
|
||||
[[Notification.recipients]]
|
||||
receiver_by_document_field = "owner"
|
||||
|
||||
|
||||
[[Notification]]
|
||||
subject = "_Test Notification 5"
|
||||
document_type = "Event"
|
||||
event = "Days Before"
|
||||
attach_print = 0
|
||||
date_changed = "starts_on"
|
||||
days_in_advance = 2
|
||||
message = "Description changed"
|
||||
[[Notification.recipients]]
|
||||
receiver_by_document_field = "owner"
|
||||
|
||||
|
||||
[[Notification]]
|
||||
subject = "_Test Notification 6"
|
||||
document_type = "User"
|
||||
event = "New"
|
||||
attach_print = 0
|
||||
message = "New user {{ doc.name }} created"
|
||||
[[Notification.recipients]]
|
||||
receiver_by_document_field = "owner"
|
||||
cc = "{{ doc.email }}"
|
||||
|
||||
|
||||
|
|
@ -2,8 +2,6 @@
|
|||
# License: MIT. See LICENSE
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Unhandled Emails')
|
||||
|
||||
|
||||
class UnitTestUnhandledEmail(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from frappe.geo.doctype.country.country import (
|
|||
from frappe.geo.doctype.currency.currency import enable_default_currencies
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
test_records = frappe.get_test_records("Country")
|
||||
test_records = frappe.tests.utils.load_test_records_for("Country")
|
||||
|
||||
|
||||
def get_table_snapshot(doctype):
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
[
|
||||
{
|
||||
"country_name": "_Test Country",
|
||||
"doctype": "Country"
|
||||
}
|
||||
]
|
||||
3
frappe/geo/doctype/country/test_records.toml
Normal file
3
frappe/geo/doctype/country/test_records.toml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[[Country]]
|
||||
country_name = "_Test Country"
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
[]
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Connected App",
|
||||
"provider_name": "frappe",
|
||||
"client_id": "test_client_id",
|
||||
"client_secret": "test_client_secret",
|
||||
"scopes": [
|
||||
{
|
||||
"scope": "all"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
[["Connected App"]]
|
||||
provider_name = "frappe"
|
||||
client_id = "test_client_id"
|
||||
client_secret = "test_client_secret"
|
||||
[["Connected App".scopes]]
|
||||
scope = "all"
|
||||
|
||||
|
||||
|
|
@ -3,8 +3,6 @@
|
|||
import frappe
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Integration Request')
|
||||
|
||||
|
||||
class UnitTestIntegrationRequest(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
import frappe
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('OAuth Authorization Code')
|
||||
|
||||
|
||||
class UnitTestOauthAuthorizationCode(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
import frappe
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('OAuth Bearer Token')
|
||||
|
||||
|
||||
class UnitTestOauthBearerToken(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
import frappe
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('OAuth Client')
|
||||
|
||||
|
||||
class UnitTestOauthClient(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Token Cache",
|
||||
"user": "test@example.com",
|
||||
"access_token": "test-access-token",
|
||||
"refresh_token": "test-refresh-token",
|
||||
"token_type": "Bearer",
|
||||
"expires_in": 1000,
|
||||
"scopes": [
|
||||
{
|
||||
"scope": "all"
|
||||
},
|
||||
{
|
||||
"scope": "openid"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
13
frappe/integrations/doctype/token_cache/test_records.toml
Normal file
13
frappe/integrations/doctype/token_cache/test_records.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[["Token Cache"]]
|
||||
user = "test@example.com"
|
||||
access_token = "test-access-token"
|
||||
refresh_token = "test-refresh-token"
|
||||
token_type = "Bearer"
|
||||
expires_in = 1000
|
||||
[["Token Cache".scopes]]
|
||||
scope = "all"
|
||||
|
||||
[["Token Cache".scopes]]
|
||||
scope = "openid"
|
||||
|
||||
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Print Format",
|
||||
"name": "_Test Print Format 1",
|
||||
"module": "Core",
|
||||
"doc_type": "User",
|
||||
"html": ""
|
||||
}
|
||||
]
|
||||
6
frappe/printing/doctype/print_format/test_records.toml
Normal file
6
frappe/printing/doctype/print_format/test_records.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[["Print Format"]]
|
||||
name = "_Test Print Format 1"
|
||||
module = "Core"
|
||||
doc_type = "User"
|
||||
html = ""
|
||||
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import copy
|
||||
import logging
|
||||
from contextlib import AbstractContextManager, contextmanager
|
||||
from types import MappingProxyType
|
||||
|
||||
import frappe
|
||||
from frappe.utils import cint
|
||||
|
|
@ -57,6 +58,7 @@ class IntegrationTestCase(UnitTestCase):
|
|||
cls._newly_created_test_records += make_test_records(doctype)
|
||||
# flush changes done so far to avoid flake
|
||||
frappe.db.commit()
|
||||
cls.globalTestRecords = MappingProxyType(frappe.local.test_objects)
|
||||
if cls.SHOW_TRANSACTION_COMMIT_WARNINGS:
|
||||
frappe.db.before_commit.add(_commit_watcher)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,19 @@
|
|||
import datetime
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from collections import defaultdict
|
||||
from functools import cache
|
||||
from importlib import reload
|
||||
from pathlib import Path
|
||||
from types import MappingProxyType
|
||||
from typing import Any
|
||||
|
||||
import tomli
|
||||
|
||||
import frappe
|
||||
from frappe.model.naming import revert_series_if_last
|
||||
from frappe.modules import load_doctype_module
|
||||
from frappe.modules import get_doctype_module, get_module_path, load_doctype_module
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
testing_logger = logging.getLogger("frappe.testing.generators")
|
||||
|
|
@ -21,6 +27,7 @@ __all__ = [
|
|||
"make_test_records",
|
||||
"make_test_records_for_doctype",
|
||||
"make_test_objects",
|
||||
"load_test_records_for",
|
||||
]
|
||||
|
||||
|
||||
|
|
@ -145,13 +152,40 @@ def _make_test_record(doctype, force=False, commit=False):
|
|||
elif hasattr(test_module, "test_records"):
|
||||
yield from _make_test_objects(doctype, test_module.test_records, force, commit=commit)
|
||||
else:
|
||||
test_records = frappe.get_test_records(doctype)
|
||||
test_records = load_test_records_for(doctype)
|
||||
if test_records:
|
||||
yield from _make_test_objects(doctype, test_records, force, commit=commit)
|
||||
else:
|
||||
print_mandatory_fields(doctype)
|
||||
|
||||
|
||||
def load_test_records_for(doctype) -> dict[str, Any] | list:
|
||||
module_path = get_module_path(get_doctype_module(doctype), "doctype", frappe.scrub(doctype))
|
||||
|
||||
json_path = os.path.join(module_path, "test_records.json")
|
||||
if os.path.exists(json_path):
|
||||
from frappe.deprecation_dumpster import deprecation_warning
|
||||
|
||||
deprecation_warning(
|
||||
"2024-10-09",
|
||||
"v17",
|
||||
"""Test records have been tranformed from json to toml for better readability and devx.
|
||||
Please run the script from the PR description and remove the json file afterwards:
|
||||
https://github.com/frappe/frappe/pull/28065
|
||||
""",
|
||||
)
|
||||
with open(json_path) as f:
|
||||
return json.load(f)
|
||||
|
||||
toml_path = os.path.join(module_path, "test_records.toml")
|
||||
if os.path.exists(toml_path):
|
||||
with open(toml_path, "rb") as f:
|
||||
return tomli.load(f)
|
||||
|
||||
else:
|
||||
return {}
|
||||
|
||||
|
||||
def _make_test_objects(doctype, test_records=None, reset=False, commit=False):
|
||||
"""Generator function to make test objects"""
|
||||
# NOTE: We use file-based, per-site persistence visited log in order to not
|
||||
|
|
@ -160,68 +194,76 @@ def _make_test_objects(doctype, test_records=None, reset=False, commit=False):
|
|||
if not reset and doctype in test_record_log_instance.get():
|
||||
yield from test_record_log_instance.yield_names(doctype)
|
||||
|
||||
if test_records is None:
|
||||
test_records = load_test_records_for(doctype)
|
||||
|
||||
# Deprecated JSON import - make it comply
|
||||
if isinstance(test_records, list):
|
||||
_test_records = defaultdict(list)
|
||||
for _record in test_records:
|
||||
_dt = _record.get("doctype", doctype)
|
||||
_test_records[_dt].append(_record)
|
||||
test_records = _test_records
|
||||
|
||||
for _doctype, records in test_records.items():
|
||||
for record in records:
|
||||
yield from _make_test_object(_doctype, record)
|
||||
|
||||
|
||||
def _make_test_object(doctype, record, reset=False, commit=False):
|
||||
def revert_naming(d):
|
||||
if getattr(d, "naming_series", None):
|
||||
revert_series_if_last(d.naming_series, d.name)
|
||||
|
||||
if test_records is None:
|
||||
test_records = frappe.get_test_records(doctype)
|
||||
if not reset:
|
||||
frappe.db.savepoint("creating_test_record")
|
||||
|
||||
for doc in test_records:
|
||||
if not reset:
|
||||
frappe.db.savepoint("creating_test_record")
|
||||
if not record.get("doctype"):
|
||||
record["doctype"] = doctype
|
||||
|
||||
if not doc.get("doctype"):
|
||||
doc["doctype"] = doctype
|
||||
d = frappe.copy_doc(record)
|
||||
|
||||
d = frappe.copy_doc(doc)
|
||||
if d.meta.get_field("naming_series"):
|
||||
if not d.naming_series:
|
||||
d.naming_series = "_T-" + d.doctype + "-"
|
||||
|
||||
if d.meta.get_field("naming_series"):
|
||||
if not d.naming_series:
|
||||
d.naming_series = "_T-" + d.doctype + "-"
|
||||
if record.get("name"):
|
||||
d.name = record.get("name")
|
||||
else:
|
||||
d.set_new_name()
|
||||
|
||||
if doc.get("name"):
|
||||
d.name = doc.get("name")
|
||||
else:
|
||||
d.set_new_name()
|
||||
if frappe.db.exists(d.doctype, d.name) and not reset:
|
||||
frappe.db.rollback(save_point="creating_test_record")
|
||||
# do not create test records, if already exists
|
||||
return
|
||||
|
||||
if frappe.db.exists(d.doctype, d.name) and not reset:
|
||||
frappe.db.rollback(save_point="creating_test_record")
|
||||
# do not create test records, if already exists
|
||||
continue
|
||||
# submit if docstatus is set to 1 for test record
|
||||
docstatus = d.docstatus
|
||||
|
||||
# submit if docstatus is set to 1 for test record
|
||||
docstatus = d.docstatus
|
||||
d.docstatus = 0
|
||||
|
||||
d.docstatus = 0
|
||||
try:
|
||||
d.run_method("before_test_insert")
|
||||
d.insert(ignore_if_duplicate=True)
|
||||
|
||||
try:
|
||||
d.run_method("before_test_insert")
|
||||
d.insert(ignore_if_duplicate=True)
|
||||
if docstatus == 1:
|
||||
d.submit()
|
||||
|
||||
if docstatus == 1:
|
||||
d.submit()
|
||||
except frappe.NameError:
|
||||
revert_naming(d)
|
||||
|
||||
except frappe.NameError:
|
||||
except Exception as e:
|
||||
if d.flags.ignore_these_exceptions_in_test and e.__class__ in d.flags.ignore_these_exceptions_in_test:
|
||||
revert_naming(d)
|
||||
else:
|
||||
logger.debug(f"Error in making test record for {d.doctype} {d.name}")
|
||||
raise
|
||||
|
||||
except Exception as e:
|
||||
if (
|
||||
d.flags.ignore_these_exceptions_in_test
|
||||
and e.__class__ in d.flags.ignore_these_exceptions_in_test
|
||||
):
|
||||
revert_naming(d)
|
||||
else:
|
||||
logger.debug(f"Error in making test record for {d.doctype} {d.name}")
|
||||
raise
|
||||
if commit:
|
||||
frappe.db.commit()
|
||||
|
||||
if commit:
|
||||
frappe.db.commit()
|
||||
|
||||
frappe.local.test_objects[doctype].append(d.name)
|
||||
yield d.name
|
||||
|
||||
test_record_log_instance.add(doctype, frappe.local.test_objects[doctype])
|
||||
frappe.local.test_objects[doctype].append(MappingProxyType(d.as_dict()))
|
||||
yield d.name
|
||||
|
||||
|
||||
def print_mandatory_fields(doctype):
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Blog Category",
|
||||
"parent_website_route": "blog",
|
||||
"title": "_Test Blog Category"
|
||||
},
|
||||
{
|
||||
"doctype": "Blog Category",
|
||||
"parent_website_route": "blog",
|
||||
"title": "_Test Blog Category 1"
|
||||
},
|
||||
{
|
||||
"doctype": "Blog Category",
|
||||
"parent_website_route": "blog",
|
||||
"title": "_Test Blog Category 2"
|
||||
}
|
||||
]
|
||||
12
frappe/website/doctype/blog_category/test_records.toml
Normal file
12
frappe/website/doctype/blog_category/test_records.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[["Blog Category"]]
|
||||
parent_website_route = "blog"
|
||||
title = "_Test Blog Category"
|
||||
|
||||
[["Blog Category"]]
|
||||
parent_website_route = "blog"
|
||||
title = "_Test Blog Category 1"
|
||||
|
||||
[["Blog Category"]]
|
||||
parent_website_route = "blog"
|
||||
title = "_Test Blog Category 2"
|
||||
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
[
|
||||
{
|
||||
"blog_category": "-test-blog-category",
|
||||
"blog_intro": "Test Blog Intro",
|
||||
"blogger": "_Test Blogger",
|
||||
"content": "Test Blog Content",
|
||||
"doctype": "Blog Post",
|
||||
"title": "_Test Blog Post",
|
||||
"published": 1
|
||||
},
|
||||
{
|
||||
"blog_category": "-test-blog-category-1",
|
||||
"blog_intro": "Test Blog Intro",
|
||||
"blogger": "_Test Blogger",
|
||||
"content": "Test Blog Content",
|
||||
"doctype": "Blog Post",
|
||||
"title": "_Test Blog Post 1",
|
||||
"published": 1
|
||||
},
|
||||
{
|
||||
"blog_category": "-test-blog-category-1",
|
||||
"blog_intro": "Test Blog Intro",
|
||||
"blogger": "_Test Blogger 1",
|
||||
"content": "Test Blog Content",
|
||||
"doctype": "Blog Post",
|
||||
"title": "_Test Blog Post 2",
|
||||
"published": 0
|
||||
},
|
||||
{
|
||||
"blog_category": "-test-blog-category-1",
|
||||
"blog_intro": "Test Blog Intro",
|
||||
"blogger": "_Test Blogger 2",
|
||||
"content": "Test Blog Content",
|
||||
"doctype": "Blog Post",
|
||||
"title": "_Test Blog Post 3",
|
||||
"published": 0
|
||||
}
|
||||
]
|
||||
32
frappe/website/doctype/blog_post/test_records.toml
Normal file
32
frappe/website/doctype/blog_post/test_records.toml
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
[["Blog Post"]]
|
||||
blog_category = "-test-blog-category"
|
||||
blog_intro = "Test Blog Intro"
|
||||
blogger = "_Test Blogger"
|
||||
content = "Test Blog Content"
|
||||
title = "_Test Blog Post"
|
||||
published = 1
|
||||
|
||||
[["Blog Post"]]
|
||||
blog_category = "-test-blog-category-1"
|
||||
blog_intro = "Test Blog Intro"
|
||||
blogger = "_Test Blogger"
|
||||
content = "Test Blog Content"
|
||||
title = "_Test Blog Post 1"
|
||||
published = 1
|
||||
|
||||
[["Blog Post"]]
|
||||
blog_category = "-test-blog-category-1"
|
||||
blog_intro = "Test Blog Intro"
|
||||
blogger = "_Test Blogger 1"
|
||||
content = "Test Blog Content"
|
||||
title = "_Test Blog Post 2"
|
||||
published = 0
|
||||
|
||||
[["Blog Post"]]
|
||||
blog_category = "-test-blog-category-1"
|
||||
blog_intro = "Test Blog Intro"
|
||||
blogger = "_Test Blogger 2"
|
||||
content = "Test Blog Content"
|
||||
title = "_Test Blog Post 3"
|
||||
published = 0
|
||||
|
||||
|
|
@ -3,4 +3,4 @@
|
|||
|
||||
import frappe
|
||||
|
||||
test_records = frappe.get_test_records("Blogger")
|
||||
test_records = frappe.tests.utils.load_test_records_for("Blogger")
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Blogger",
|
||||
"full_name": "_Test Blogger",
|
||||
"short_name": "_Test Blogger"
|
||||
},
|
||||
{
|
||||
"doctype": "Blogger",
|
||||
"full_name": "_Test Blogger 1",
|
||||
"short_name": "_Test Blogger 1"
|
||||
},
|
||||
{
|
||||
"doctype": "Blogger",
|
||||
"full_name": "_Test Blogger 2",
|
||||
"short_name": "_Test Blogger 2"
|
||||
}
|
||||
]
|
||||
12
frappe/website/doctype/blogger/test_records.toml
Normal file
12
frappe/website/doctype/blogger/test_records.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[[Blogger]]
|
||||
full_name = "_Test Blogger"
|
||||
short_name = "_Test Blogger"
|
||||
|
||||
[[Blogger]]
|
||||
full_name = "_Test Blogger 1"
|
||||
short_name = "_Test Blogger 1"
|
||||
|
||||
[[Blogger]]
|
||||
full_name = "_Test Blogger 2"
|
||||
short_name = "_Test Blogger 2"
|
||||
|
||||
|
|
@ -3,8 +3,6 @@
|
|||
import frappe
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Help Article')
|
||||
|
||||
|
||||
class UnitTestHelpArticle(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
import frappe
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Help Category')
|
||||
|
||||
|
||||
class UnitTestHelpCategory(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
[{
|
||||
"allow_comments": 0,
|
||||
"allow_edit": 1,
|
||||
"allow_multiple": 1,
|
||||
"show_list": 1,
|
||||
"doc_type": "Event",
|
||||
"docstatus": 0,
|
||||
"doctype": "Web Form",
|
||||
"introduction_text": "Add events",
|
||||
"login_required": 1,
|
||||
"name": "manage-events",
|
||||
"owner": "Administrator",
|
||||
"page_name": "manage-events",
|
||||
"published": 1,
|
||||
"success_url": "/manage-events",
|
||||
"title": "Manage Events",
|
||||
"meta_title": "Test Meta Form Title",
|
||||
"meta_description": "Test Meta Form Description",
|
||||
"meta_image": "https://frappe.io/files/frappe.png",
|
||||
"web_form_fields": [
|
||||
{
|
||||
"doctype": "Web Form Field",
|
||||
"fieldname": "subject",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"idx": 1,
|
||||
"label": "Title",
|
||||
"read_only": 0,
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"doctype": "Web Form Field",
|
||||
"fieldname": "starts_on",
|
||||
"fieldtype": "Date",
|
||||
"hidden": 0,
|
||||
"idx": 2,
|
||||
"label": "Event Date",
|
||||
"read_only": 0,
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"doctype": "Web Form Field",
|
||||
"fieldname": "description",
|
||||
"fieldtype": "Text",
|
||||
"hidden": 0,
|
||||
"idx": 3,
|
||||
"label": "Description",
|
||||
"read_only": 0,
|
||||
"reqd": 0
|
||||
}
|
||||
]
|
||||
}]
|
||||
49
frappe/website/doctype/web_form/test_records.toml
Normal file
49
frappe/website/doctype/web_form/test_records.toml
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
[["Web Form"]]
|
||||
allow_comments = 0
|
||||
allow_edit = 1
|
||||
allow_multiple = 1
|
||||
show_list = 1
|
||||
doc_type = "Event"
|
||||
docstatus = 0
|
||||
introduction_text = "Add events"
|
||||
login_required = 1
|
||||
name = "manage-events"
|
||||
owner = "Administrator"
|
||||
page_name = "manage-events"
|
||||
published = 1
|
||||
success_url = "/manage-events"
|
||||
title = "Manage Events"
|
||||
meta_title = "Test Meta Form Title"
|
||||
meta_description = "Test Meta Form Description"
|
||||
meta_image = "https://frappe.io/files/frappe.png"
|
||||
[["Web Form".web_form_fields]]
|
||||
doctype = "Web Form Field"
|
||||
fieldname = "subject"
|
||||
fieldtype = "Data"
|
||||
hidden = 0
|
||||
idx = 1
|
||||
label = "Title"
|
||||
read_only = 0
|
||||
reqd = 1
|
||||
|
||||
[["Web Form".web_form_fields]]
|
||||
doctype = "Web Form Field"
|
||||
fieldname = "starts_on"
|
||||
fieldtype = "Date"
|
||||
hidden = 0
|
||||
idx = 2
|
||||
label = "Event Date"
|
||||
read_only = 0
|
||||
reqd = 1
|
||||
|
||||
[["Web Form".web_form_fields]]
|
||||
doctype = "Web Form Field"
|
||||
fieldname = "description"
|
||||
fieldtype = "Text"
|
||||
hidden = 0
|
||||
idx = 3
|
||||
label = "Description"
|
||||
read_only = 0
|
||||
reqd = 0
|
||||
|
||||
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
[
|
||||
{
|
||||
"doctype": "Web Page",
|
||||
"main_section": "Test Content 1",
|
||||
"published": 1,
|
||||
"title": "Test Web Page 1"
|
||||
},
|
||||
{
|
||||
"doctype": "Web Page",
|
||||
"main_section": "Test Content 2",
|
||||
"route": "test-web-page-1/test-web-page-2",
|
||||
"published": 1,
|
||||
"title": "Test Web Page 2"
|
||||
},
|
||||
{
|
||||
"doctype": "Web Page",
|
||||
"main_section": "Test Content 3",
|
||||
"route": "test-web-page-1/test-web-page-3",
|
||||
"published": 1,
|
||||
"title": "Test Web Page 3"
|
||||
},
|
||||
{
|
||||
"doctype": "Web Page",
|
||||
"main_section": "Test Content 4",
|
||||
"published": 1,
|
||||
"title": "Test Web Page 4"
|
||||
},
|
||||
{
|
||||
"doctype": "Web Page",
|
||||
"main_section": "Test Content 5",
|
||||
"route": "test-web-page-1/test-web-page-5",
|
||||
"published": 1,
|
||||
"title": "Test Web Page 5"
|
||||
}
|
||||
]
|
||||
28
frappe/website/doctype/web_page/test_records.toml
Normal file
28
frappe/website/doctype/web_page/test_records.toml
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
[["Web Page"]]
|
||||
main_section = "Test Content 1"
|
||||
published = 1
|
||||
title = "Test Web Page 1"
|
||||
|
||||
[["Web Page"]]
|
||||
main_section = "Test Content 2"
|
||||
route = "test-web-page-1/test-web-page-2"
|
||||
published = 1
|
||||
title = "Test Web Page 2"
|
||||
|
||||
[["Web Page"]]
|
||||
main_section = "Test Content 3"
|
||||
route = "test-web-page-1/test-web-page-3"
|
||||
published = 1
|
||||
title = "Test Web Page 3"
|
||||
|
||||
[["Web Page"]]
|
||||
main_section = "Test Content 4"
|
||||
published = 1
|
||||
title = "Test Web Page 4"
|
||||
|
||||
[["Web Page"]]
|
||||
main_section = "Test Content 5"
|
||||
route = "test-web-page-1/test-web-page-5"
|
||||
published = 1
|
||||
title = "Test Web Page 5"
|
||||
|
||||
|
|
@ -3,8 +3,6 @@
|
|||
import frappe
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Website Sidebar')
|
||||
|
||||
|
||||
class UnitTestWebsiteSidebar(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
import frappe
|
||||
from frappe.tests import IntegrationTestCase, UnitTestCase
|
||||
|
||||
# test_records = frappe.get_test_records('Website Slideshow')
|
||||
|
||||
|
||||
class UnitTestWebsiteSlideshow(UnitTestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
[]
|
||||
|
|
@ -1 +0,0 @@
|
|||
[]
|
||||
|
|
@ -2,4 +2,4 @@
|
|||
# License: MIT. See LICENSE
|
||||
import frappe
|
||||
|
||||
test_records = frappe.get_test_records("Workflow State")
|
||||
test_records = frappe.tests.utils.load_test_records_for("Workflow State")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue