def get_test_doclist(doctype, name=None): """get test doclist, collection of doclists""" import os, webnotes from webnotes import conf from webnotes.modules.utils import peval_doclist from webnotes.modules import scrub doctype = scrub(doctype) doctype_path = os.path.join( os.path.dirname(os.path.abspath(conf.__file__)), conf.test_data_path, doctype) if name: with open(os.path.join(doctype_path, scrub(name) + '.txt'), 'r') as txtfile: doclist = peval_doclist(txtfile.read()) return doclist else: all_doclists = [] for fname in filter(lambda n: n.endswith('.txt'), os.listdir(doctype_path)): with open(os.path.join(doctype_path, scrub(fname)), 'r') as txtfile: all_doclists.append(peval_doclist(txtfile.read())) return all_doclists
def import_file_by_path(path, force=False): if os.path.exists(path): from webnotes.modules.utils import peval_doclist with open(path, 'r') as f: doclist = peval_doclist(f.read()) if doclist: doc = doclist[0] if not force: # check if timestamps match if doc['modified'] == str( webnotes.conn.get_value(doc['doctype'], doc['name'], 'modified')): return False original_modified = doc["modified"] import_doclist(doclist) # since there is a new timestamp on the file, update timestamp in webnotes.conn.sql("update `tab%s` set modified=%s where name=%s" % \ (doc['doctype'], '%s', '%s'), (original_modified, doc['name'])) return True else: raise Exception, '%s missing' % path
def import_file_by_path(path, force=False): if os.path.exists(path): from webnotes.modules.utils import peval_doclist with open(path, 'r') as f: doclist = peval_doclist(f.read()) if doclist: doc = doclist[0] if not force: # check if timestamps match if doc['modified']==str(webnotes.conn.get_value(doc['doctype'], doc['name'], 'modified')): return False original_modified = doc["modified"] import_doclist(doclist) # since there is a new timestamp on the file, update timestamp in webnotes.conn.sql("update `tab%s` set modified=%s where name=%s" % \ (doc['doctype'], '%s', '%s'), (original_modified, doc['name'])) return True else: raise Exception, '%s missing' % path
def sync_doctype(module_name, docname, force=0): """sync doctype from file if modified""" with open(get_file_path(module_name, docname), 'r') as f: from webnotes.modules.utils import peval_doclist doclist = peval_doclist(f.read()) if merge_doctype(doclist, force): print module_name, '|', docname #raise Exception return doclist[0].get('name')
def sync(module_name, docname, force=0): """sync doctype from file if modified""" with open(get_file_path(module_name, docname), 'r') as f: from webnotes.modules.utils import peval_doclist doclist = peval_doclist(f.read()) if merge_doctype(doclist, force): print module_name, '|', docname #raise Exception return doclist[0].get('name')
def get_test_doclist(doctype, name=None): """get test doclist, collection of doclists""" import os, webnotes from webnotes import conf from webnotes.modules.utils import peval_doclist from webnotes.modules import scrub doctype = scrub(doctype) doctype_path = os.path.join(os.path.dirname(os.path.abspath(conf.__file__)), conf.test_data_path, doctype) if name: with open(os.path.join(doctype_path, scrub(name) + ".txt"), "r") as txtfile: doclist = peval_doclist(txtfile.read()) return doclist else: all_doclists = [] for fname in filter(lambda n: n.endswith(".txt"), os.listdir(doctype_path)): with open(os.path.join(doctype_path, scrub(fname)), "r") as txtfile: all_doclists.append(peval_doclist(txtfile.read())) return all_doclists
def _run_test(path, filename, verbose): import os, imp from webnotes.modules.utils import peval_doclist test_suite = unittest.TestSuite() if os.path.basename(os.path.dirname(path))=="doctype": txt_file = os.path.join(path, filename[5:].replace(".py", ".txt")) with open(txt_file, 'r') as f: doctype_doclist = peval_doclist(f.read()) doctype = doctype_doclist[0]["name"] make_test_records(doctype, verbose) module = imp.load_source(filename[:-3], os.path.join(path, filename)) test_suite.addTest(unittest.TestLoader().loadTestsFromModule(module)) unittest.TextTestRunner(verbosity=1+(verbose and 1 or 0)).run(test_suite)
def _run_test(path, filename, verbose): import os, imp from webnotes.modules.utils import peval_doclist test_suite = unittest.TestSuite() if os.path.basename(os.path.dirname(path)) == "doctype": txt_file = os.path.join(path, filename[5:].replace(".py", ".txt")) with open(txt_file, 'r') as f: doctype_doclist = peval_doclist(f.read()) doctype = doctype_doclist[0]["name"] make_test_records(doctype, verbose) module = imp.load_source(filename[:-3], os.path.join(path, filename)) test_suite.addTest(unittest.TestLoader().loadTestsFromModule(module)) unittest.TextTestRunner(verbosity=1 + (verbose and 1 or 0)).run(test_suite)
def run_all_tests(verbose): import os, imp from webnotes.modules.utils import peval_doclist for path, folders, files in os.walk("."): for filename in files: if filename.startswith("test_") and filename.endswith(".py"): test_suite = unittest.TestSuite() if os.path.basename(os.path.dirname(path))=="doctype": txt_file = os.path.join(path, filename[5:].replace(".py", ".txt")) with open(txt_file, 'r') as f: doctype_doclist = peval_doclist(f.read()) doctype = doctype_doclist[0]["name"] make_test_records(doctype, verbose) module = imp.load_source('test', os.path.join(path, filename)) test_suite.addTest(unittest.TestLoader().loadTestsFromModule(module)) unittest.TextTestRunner(verbosity=1+(verbose and 1 or 0)).run(test_suite)
def get_doctypes(m): doctypes = webnotes.conn.sql_list("""select name from tabDocType where module=%s order by name""", m) prefix = "docs.dev.modules." + m + ".doctype." docs = { "_icon": "th", "_label": "DocTypes", "_toc": [prefix + d for d in doctypes] } for d in doctypes: meta = webnotes.get_doctype(d) meta_p = webnotes.get_doctype(d, True) doc_path = get_doc_path(m, "DocType", d) mydocs = docs[d] = { "_label": d, "_icon": meta[0].icon, "_type": "doctype", "_gh_source": get_gh_url(doc_path), "_toc": [ prefix + d + ".model", prefix + d + ".permissions", prefix + d + ".controller_server" ], } update_readme(mydocs, m, "DocType", d) # parents and links links, parents = [], [] for df in webnotes.conn.sql("""select * from tabDocField where options=%s""", d, as_dict=True): if df.parent: if df.fieldtype=="Table": parents.append(df.parent) if df.fieldtype=="Link": links.append(df.parent) if parents: mydocs["_intro"] += "\n\n#### Child Table Of:\n\n- " + "\n- ".join(list(set(parents))) + "\n\n" if links: mydocs["_intro"] += "\n\n#### Linked In:\n\n- " + "\n- ".join(list(set(links))) + "\n\n" if meta[0].issingle: mydocs["_intro"] += "\n\n#### Single DocType\n\nThere is no table for this DocType and the values of the Single instance are stored in `tabSingles`" # model modeldocs = mydocs["model"] = { "_label": d + " Model", "_icon": meta[0].icon, "_type": "model", "_intro": "Properties and fields for " + d, "_gh_source": get_gh_url(os.path.join(doc_path, scrub(d) + ".txt")), "_fields": [df.fields for df in meta.get({"doctype": "DocField"})], "_properties": meta[0].fields, "_modified": meta[0].modified } # permissions from webnotes.modules.utils import peval_doclist with open(os.path.join(doc_path, scrub(d) + ".txt"), "r") as txtfile: doclist = peval_doclist(txtfile.read()) permission_docs = mydocs["permissions"] = { "_label": d + " Permissions", "_type": "permissions", "_icon": meta[0].icon, "_gh_source": get_gh_url(os.path.join(doc_path, scrub(d) + ".txt")), "_intro": "Standard Permissions for " + d + ". These can be changed by the user.", "_permissions": [p for p in doclist if p.doctype=="DocPerm"], "_modified": doclist[0]["modified"] } # server controller server_controller_path = os.path.join(doc_path, scrub(d) + ".py") controller_docs = mydocs["controller_server"] = { "_label": d + " Server Controller", "_type": "_class", "_gh_source": get_gh_url(server_controller_path) } b = webnotes.bean([{"doctype": d}]) b.make_controller() if not getattr(b.controller, "__doc__"): b.controller.__doc__ = "Controller Class for handling server-side events for " + d inspect_object_and_update_docs(controller_docs, b.controller) # client controller if meta_p[0].fields.get("__js"): client_controller_path = os.path.join(doc_path, scrub(d) + ".js") if(os.path.exists(client_controller_path)): mydocs["_toc"].append(prefix + d + ".controller_client") client_controller = mydocs["controller_client"] = { "_label": d + " Client Controller", "_icon": meta[0].icon, "_type": "controller_client", "_gh_source": get_gh_url(client_controller_path), "_modified": get_timestamp(client_controller_path), "_intro": "Client side triggers and functions for " + d, "_code": meta_p[0].fields["__js"], "_fields": [d.fieldname for d in meta_p if d.doctype=="DocField"] } return docs
def get_doctypes(m): doctypes = webnotes.conn.sql_list( """select name from tabDocType where module=%s order by name""", m) prefix = "docs.dev.modules." + m + ".doctype." docs = { "_icon": "th", "_label": "DocTypes", "_toc": [prefix + d for d in doctypes] } for d in doctypes: meta = webnotes.get_doctype(d) meta_p = webnotes.get_doctype(d, True) doc_path = get_doc_path(m, "DocType", d) mydocs = docs[d] = { "_label": d, "_icon": meta[0].icon, "_type": "doctype", "_gh_source": get_gh_url(doc_path), "_toc": [ prefix + d + ".model", prefix + d + ".permissions", prefix + d + ".controller_server" ], } update_readme(mydocs, m, "DocType", d) # parents and links links, parents = [], [] for df in webnotes.conn.sql( """select * from tabDocField where options=%s""", d, as_dict=True): if df.parent: if df.fieldtype == "Table": parents.append(df.parent) if df.fieldtype == "Link": links.append(df.parent) if parents: mydocs["_intro"] += "\n\n#### Child Table Of:\n\n- " + "\n- ".join( list(set(parents))) + "\n\n" if links: mydocs["_intro"] += "\n\n#### Linked In:\n\n- " + "\n- ".join( list(set(links))) + "\n\n" if meta[0].issingle: mydocs[ "_intro"] += "\n\n#### Single DocType\n\nThere is no table for this DocType and the values of the Single instance are stored in `tabSingles`" # model modeldocs = mydocs["model"] = { "_label": d + " Model", "_icon": meta[0].icon, "_type": "model", "_intro": "Properties and fields for " + d, "_gh_source": get_gh_url(os.path.join(doc_path, scrub(d) + ".txt")), "_fields": [df.fields for df in meta.get({"doctype": "DocField"})], "_properties": meta[0].fields, "_modified": meta[0].modified } # permissions from webnotes.modules.utils import peval_doclist with open(os.path.join(doc_path, scrub(d) + ".txt"), "r") as txtfile: doclist = peval_doclist(txtfile.read()) permission_docs = mydocs["permissions"] = { "_label": d + " Permissions", "_type": "permissions", "_icon": meta[0].icon, "_gh_source": get_gh_url(os.path.join(doc_path, scrub(d) + ".txt")), "_intro": "Standard Permissions for " + d + ". These can be changed by the user.", "_permissions": [p for p in doclist if p.doctype == "DocPerm"], "_modified": doclist[0]["modified"] } # server controller server_controller_path = os.path.join(doc_path, scrub(d) + ".py") controller_docs = mydocs["controller_server"] = { "_label": d + " Server Controller", "_type": "_class", "_gh_source": get_gh_url(server_controller_path) } b = webnotes.bean([{"doctype": d}]) b.make_controller() if not getattr(b.controller, "__doc__"): b.controller.__doc__ = "Controller Class for handling server-side events for " + d inspect_object_and_update_docs(controller_docs, b.controller) # client controller if meta_p[0].fields.get("__js"): client_controller_path = os.path.join(doc_path, scrub(d) + ".js") if (os.path.exists(client_controller_path)): mydocs["_toc"].append(prefix + d + ".controller_client") client_controller = mydocs["controller_client"] = { "_label": d + " Client Controller", "_icon": meta[0].icon, "_type": "controller_client", "_gh_source": get_gh_url(client_controller_path), "_modified": get_timestamp(client_controller_path), "_intro": "Client side triggers and functions for " + d, "_code": meta_p[0].fields["__js"], "_fields": [d.fieldname for d in meta_p if d.doctype == "DocField"] } return docs