You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 1.1 KiB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. def insert_test_data(doctype, sort_fn=None):
  5. import webnotes.model
  6. data = get_test_doclist(doctype)
  7. if sort_fn:
  8. data = sorted(data, key=sort_fn)
  9. for doclist in data:
  10. webnotes.insert(doclist)
  11. def get_test_doclist(doctype, name=None):
  12. """get test doclist, collection of doclists"""
  13. import os, webnotes
  14. from webnotes import conf
  15. from webnotes.modules.utils import peval_doclist
  16. from webnotes.modules import scrub
  17. doctype = scrub(doctype)
  18. doctype_path = os.path.join(os.path.dirname(os.path.abspath(conf.__file__)),
  19. conf.test_data_path, doctype)
  20. if name:
  21. with open(os.path.join(doctype_path, scrub(name) + '.txt'), 'r') as txtfile:
  22. doclist = peval_doclist(txtfile.read())
  23. return doclist
  24. else:
  25. all_doclists = []
  26. for fname in filter(lambda n: n.endswith('.txt'), os.listdir(doctype_path)):
  27. with open(os.path.join(doctype_path, scrub(fname)), 'r') as txtfile:
  28. all_doclists.append(peval_doclist(txtfile.read()))
  29. return all_doclists