25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

56 lines
2.1 KiB

  1. # Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. #
  3. # MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. from __future__ import unicode_literals
  22. def insert_test_data(doctype, sort_fn=None):
  23. import webnotes.model
  24. data = get_test_doclist(doctype)
  25. if sort_fn:
  26. data = sorted(data, key=sort_fn)
  27. for doclist in data:
  28. webnotes.insert(doclist)
  29. def get_test_doclist(doctype, name=None):
  30. """get test doclist, collection of doclists"""
  31. import os, conf, webnotes
  32. from webnotes.modules.utils import peval_doclist
  33. from webnotes.modules import scrub
  34. doctype = scrub(doctype)
  35. doctype_path = os.path.join(os.path.dirname(os.path.abspath(conf.__file__)),
  36. conf.test_data_path, doctype)
  37. if name:
  38. with open(os.path.join(doctype_path, scrub(name) + '.txt'), 'r') as txtfile:
  39. doclist = peval_doclist(txtfile.read())
  40. return doclist
  41. else:
  42. all_doclists = []
  43. for fname in filter(lambda n: n.endswith('.txt'), os.listdir(doctype_path)):
  44. with open(os.path.join(doctype_path, scrub(fname)), 'r') as txtfile:
  45. all_doclists.append(peval_doclist(txtfile.read()))
  46. return all_doclists