seitime-frappe/frappe/tests/ui_test_helpers.py
Faris Ansari 8fb2a538ec test: Add UI test for Link control (#7809)
* test: Add UI test for Link control

- Add API cy.call
- Add API cy.create_records
- Add ui_test_helpers.py

* style: Missing semicolon

* style: Missing semicolon

* style: Missing semicolon

* style: Remove unused imports

* test: Robust test for setting invalid value

* style: Remove unused import
2019-07-03 07:55:36 +05:30

64 lines
1.5 KiB
Python

import frappe
from frappe.utils import add_to_date, now
@frappe.whitelist()
def create_if_not_exists(doc):
'''Create records if they dont exist.
Will check for uniqueness by checking if a record exists with these field value pairs
:param doc: dict of field value pairs. can be a list of dict for multiple records.
'''
doc = frappe.parse_json(doc)
if not isinstance(doc, list):
docs = [doc]
else:
docs = doc
names = []
for doc in docs:
filters = doc.copy()
filters.pop('doctype')
name = frappe.db.exists(doc.doctype, filters)
if not name:
d = frappe.get_doc(doc)
d.insert(ignore_permissions=True)
name = d.name
names.append(name)
return names
@frappe.whitelist()
def create_todo_records():
if frappe.db.get_all('ToDo', {'description': 'this is first todo'}):
return
frappe.get_doc({
"doctype": "ToDo",
"date": add_to_date(now(), days=3),
"description": "this is first todo"
}).insert()
frappe.get_doc({
"doctype": "ToDo",
"date": add_to_date(now(), days=-3),
"description": "this is second todo"
}).insert()
frappe.get_doc({
"doctype": "ToDo",
"date": add_to_date(now(), months=2),
"description": "this is third todo"
}).insert()
frappe.get_doc({
"doctype": "ToDo",
"date": add_to_date(now(), months=-2),
"description": "this is fourth todo"
}).insert()
@frappe.whitelist()
def setup_workflow():
from frappe.workflow.doctype.workflow.test_workflow import create_todo_workflow
create_todo_workflow()
create_todo_records()
frappe.clear_cache()