Test case fixes

This commit is contained in:
Nabin Hait 2014-11-26 10:54:54 +05:30
parent a2fdef2c50
commit c03bb49235
4 changed files with 41 additions and 79 deletions

View file

@ -116,7 +116,7 @@ def make(doctype=None, name=None, content=None, subject=None, sent_or_received =
"doctype":"Communication",
"subject": subject,
"content": content,
"sender": get_formatted_email(frappe.session.user),
"sender": sender or get_formatted_email(frappe.session.user),
"recipients": recipients,
"communication_medium": "Email",
"sent_or_received": sent_or_received,

View file

@ -7,251 +7,212 @@ from frappe.core.page.data_import_tool.data_import_tool import export_csv
import unittest
class TestDataImportFixtures(unittest.TestCase):
def setUp(self):
print "\nTeste for export explicit fixtures"
print "see fixtures csv test files in sites folder"
#start test for Custom Script
def test_Custom_Script_fixture_simple(self):
fixture = "Custom Script"
path = frappe.scrub(fixture) + "_original_style.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Script_fixture_simple_name_equal_default(self):
fixture = ["Custom Script", {"name":["Item-Client"]}]
path = frappe.scrub(fixture[0]) + "_simple_name_equal_default.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Script_fixture_simple_name_equal(self):
fixture = ["Custom Script", {"name":["Item-Client"],"op":"="}]
path = frappe.scrub(fixture[0]) + "_simple_name_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Script_fixture_simple_name_not_equal(self):
fixture = ["Custom Script", {"name":["Item-Client"],"op":"!="}]
path = frappe.scrub(fixture[0]) + "_simple_name_not_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
#without [] around the name...
def test_Custom_Script_fixture_simple_name_at_least_equal(self):
fixture = ["Custom Script", {"name":"Item-Cli"}]
path = frappe.scrub(fixture[0]) + "_simple_name_at_least_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Script_fixture_multi_name_equal(self):
fixture = ["Custom Script", {"name":["Item-Client", "Customer-Client"],"op":"="}]
path = frappe.scrub(fixture[0]) + "_multi_name_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Script_fixture_multi_name_not_equal(self):
fixture = ["Custom Script", {"name":["Item-Client", "Customer-Client"],"op":"!="}]
path = frappe.scrub(fixture[0]) + "_multi_name_not_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Script_fixture_empty_object(self):
fixture = ["Custom Script", {}]
path = frappe.scrub(fixture[0]) + "_empty_object_should_be_all.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Script_fixture_just_list(self):
fixture = ["Custom Script"]
path = frappe.scrub(fixture[0]) + "_just_list_should_be_all.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
# Custom Script regular expression
def test_Custom_Script_fixture_rex_no_flags(self):
fixture = ["Custom Script", {"name":r"^[i|A]"}]
path = frappe.scrub(fixture[0]) + "_rex_no_flags.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Script_fixture_rex_with_flags(self):
fixture = ["Custom Script", {"name":r"^[i|A]", "flags":"L,M"}]
path = frappe.scrub(fixture[0]) + "_rex_with_flags.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
#start test for Custom Field
def test_Custom_Field_fixture_simple(self):
fixture = "Custom Field"
path = frappe.scrub(fixture) + "_original_style.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Field_fixture_simple_name_equal_default(self):
fixture = ["Custom Field", {"name":["Item-vat"]}]
path = frappe.scrub(fixture[0]) + "_simple_name_equal_default.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Field_fixture_simple_name_equal(self):
fixture = ["Custom Field", {"name":["Item-vat"],"op":"="}]
path = frappe.scrub(fixture[0]) + "_simple_name_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Field_fixture_simple_name_not_equal(self):
fixture = ["Custom Field", {"name":["Item-vat"],"op":"!="}]
path = frappe.scrub(fixture[0]) + "_simple_name_not_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
#without [] around the name...
def test_Custom_Field_fixture_simple_name_at_least_equal(self):
fixture = ["Custom Field", {"name":"Item-va"}]
path = frappe.scrub(fixture[0]) + "_simple_name_at_least_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Field_fixture_multi_name_equal(self):
fixture = ["Custom Field", {"name":["Item-vat", "Bin-vat"],"op":"="}]
path = frappe.scrub(fixture[0]) + "_multi_name_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Field_fixture_multi_name_not_equal(self):
fixture = ["Custom Field", {"name":["Item-vat", "Bin-vat"],"op":"!="}]
path = frappe.scrub(fixture[0]) + "_multi_name_not_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Field_fixture_empty_object(self):
fixture = ["Custom Field", {}]
path = frappe.scrub(fixture[0]) + "_empty_object_should_be_all.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Field_fixture_just_list(self):
fixture = ["Custom Field"]
path = frappe.scrub(fixture[0]) + "_just_list_should_be_all.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
# Custom Field regular expression
def test_Custom_Field_fixture_rex_no_flags(self):
fixture = ["Custom Field", {"name":r"^[r|L]"}]
path = frappe.scrub(fixture[0]) + "_rex_no_flags.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Custom_Field_fixture_rex_with_flags(self):
fixture = ["Custom Field", {"name":r"^[i|A]", "flags":"L,M"}]
path = frappe.scrub(fixture[0]) + "_rex_with_flags.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
#start test for Doctype
def test_Doctype_fixture_simple(self):
fixture = "ToDo"
path = "Doctype_" + frappe.scrub(fixture) + "_original_style_should_be_all.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Doctype_fixture_simple_name_equal_default(self):
fixture = ["ToDo", {"name":["TDI00000008"]}]
path = "Doctype_" + frappe.scrub(fixture[0]) + "_simple_name_equal_default.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Doctype_fixture_simple_name_equal(self):
fixture = ["ToDo", {"name":["TDI00000002"],"op":"="}]
path = "Doctype_" + frappe.scrub(fixture[0]) + "_simple_name_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Doctype_simple_name_not_equal(self):
fixture = ["ToDo", {"name":["TDI00000002"],"op":"!="}]
path = "Doctype_" + frappe.scrub(fixture[0]) + "_simple_name_not_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
#without [] around the name...
def test_Doctype_fixture_simple_name_at_least_equal(self):
fixture = ["ToDo", {"name":"TDI"}]
path = "Doctype_" + frappe.scrub(fixture[0]) + "_simple_name_at_least_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Doctype_multi_name_equal(self):
fixture = ["ToDo", {"name":["TDI00000002", "TDI00000008"],"op":"="}]
path = "Doctype_" + frappe.scrub(fixture[0]) + "_multi_name_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Doctype_multi_name_not_equal(self):
fixture = ["ToDo", {"name":["TDI00000002", "TDI00000008"],"op":"!="}]
path = "Doctype_" + frappe.scrub(fixture[0]) + "_multi_name_not_equal.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Doctype_fixture_empty_object(self):
fixture = ["ToDo", {}]
path = "Doctype_" + frappe.scrub(fixture[0]) + "_empty_object_should_be_all.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Doctype_fixture_just_list(self):
fixture = ["ToDo"]
path = "Doctype_" + frappe.scrub(fixture[0]) + "_just_list_should_be_all.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
# Doctype regular expression
def test_Doctype_fixture_rex_no_flags(self):
fixture = ["ToDo", {"name":r"^TDi"}]
path = "Doctype_" + frappe.scrub(fixture[0]) + "_rex_no_flags_should_be_all.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)
def test_Doctype_fixture_rex_with_flags(self):
fixture = ["ToDo", {"name":r"^TDi", "flags":"L,M"}]
path = "Doctype_" + frappe.scrub(fixture[0]) + "_rex_with_flags_should_be_none.csv"
print "teste done {}".format(path)
export_csv(fixture, path)
self.assertTrue(True)

View file

@ -8,6 +8,7 @@ test_records = frappe.get_test_records('Email Account')
from frappe.core.doctype.communication.communication import make
from frappe.desk.form.load import get_attachments
from frappe.utils.file_manager import delete_file_from_filesystem
class TestEmailAccount(unittest.TestCase):
def test_incoming(self):
@ -24,6 +25,9 @@ class TestEmailAccount(unittest.TestCase):
def test_incoming_with_attach(self):
frappe.db.sql("delete from tabCommunication where sender='test_sender@example.com'")
existing_file = frappe.get_doc({'doctype': 'File Data', 'file_name': 'erpnext-conf-14.png'})
frappe.delete_doc("File Data", existing_file.name)
delete_file_from_filesystem(existing_file)
with open(os.path.join(os.path.dirname(__file__), "test_mails", "incoming-2.raw"), "r") as f:
test_mails = [f.read()]
@ -41,7 +45,7 @@ class TestEmailAccount(unittest.TestCase):
def test_outgoing(self):
frappe.flags.sent_mail = None
make(subject = "test-mail-000", content="test mail 000", recipients="test_receiver@example.com",
send_email=True)
send_email=True, sender="test_sender@example.com")
sent_mail = email.message_from_string(frappe.flags.sent_mail)
self.assertTrue("test-mail-000" in sent_mail.get("Subject"))

View file

@ -39,8 +39,6 @@ def upload():
comment = frappe.get_doc(dt, dn).add_comment("Attachment",
_("Added {0}").format("<a href='{file_url}' target='_blank'>{file_name}</a>".format(**filedata.as_dict())))
print dt, dn, comment
return {
"name": filedata.name,
"file_name": filedata.file_name,
@ -118,7 +116,6 @@ def save_file(fname, content, dt, dn, decode=False):
content_hash = get_content_hash(content)
content_type = mimetypes.guess_type(fname)[0]
fname = get_file_name(fname, content_hash[-6:])
file_data = get_file_data_from_hash(content_hash)
if not file_data:
method = get_hook_method('write_file', fallback=save_file_on_filesystem)