upgraded test_runner, now can run multiple tests

This commit is contained in:
Rushabh Mehta 2013-02-12 19:20:39 +05:30
parent 9a8319dd0b
commit 4b9827a5fc
75 changed files with 508 additions and 662 deletions

View File

@ -208,31 +208,3 @@ def get_parent_account(doctype, txt, searchfield, start, page_len, filters):
and %s like %s order by name limit %s, %s""" % and %s like %s order by name limit %s, %s""" %
("%s", searchfield, "%s", "%s", "%s"), ("%s", searchfield, "%s", "%s", "%s"),
(filters["company"], "%%%s%%" % txt, start, page_len), as_list=1) (filters["company"], "%%%s%%" % txt, start, page_len), as_list=1)
def make_test_records(verbose):
from webnotes.test_runner import load_module_and_make_records, make_test_objects
load_module_and_make_records("Company", verbose)
accounts = [
# [account_name, parent_account, group_or_ledger]
["_Test Account Stock Expenses", "Direct Expenses - _TC", "Group"],
["_Test Account Shipping Charges", "_Test Account Stock Expenses - _TC", "Ledger"],
["_Test Account Customs Duty", "_Test Account Stock Expenses - _TC", "Ledger"],
["_Test Account Tax Assets", "Current Assets - _TC", "Group"],
["_Test Account VAT", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account Cost for Goods Sold", "Expenses - _TC", "Ledger"],
["_Test Account Excise Duty", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account Education Cess", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account S&H Education Cess", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account CST", "Direct Expenses - _TC", "Ledger"],
["_Test Account Discount", "Direct Expenses - _TC", "Ledger"]
]
return make_test_objects([[{
"doctype": "Account",
"account_name": account_name,
"parent_account": parent_account,
"company": "_Test Company",
"group_or_ledger": group_or_ledger
}] for account_name, parent_account, group_or_ledger in accounts])

View File

@ -0,0 +1,25 @@
def make_test_records(verbose):
from webnotes.test_runner import make_test_objects
accounts = [
# [account_name, parent_account, group_or_ledger]
["_Test Account Stock Expenses", "Direct Expenses - _TC", "Group"],
["_Test Account Shipping Charges", "_Test Account Stock Expenses - _TC", "Ledger"],
["_Test Account Customs Duty", "_Test Account Stock Expenses - _TC", "Ledger"],
["_Test Account Tax Assets", "Current Assets - _TC", "Group"],
["_Test Account VAT", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account Cost for Goods Sold", "Expenses - _TC", "Ledger"],
["_Test Account Excise Duty", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account Education Cess", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account S&H Education Cess", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account CST", "Direct Expenses - _TC", "Ledger"],
["_Test Account Discount", "Direct Expenses - _TC", "Ledger"]
]
return make_test_objects("Account", [[{
"doctype": "Account",
"account_name": account_name,
"parent_account": parent_account,
"company": "_Test Company",
"group_or_ledger": group_or_ledger
}] for account_name, parent_account, group_or_ledger in accounts])

View File

@ -0,0 +1 @@
test_records = []

View File

@ -98,13 +98,3 @@ class DocType(DocTypeNestedSet):
(cost_center_name, old)) (cost_center_name, old))
return " - ".join(parts) return " - ".join(parts)
test_records = [
[{
"doctype": "Cost Center",
"cost_center_name": "_Test Cost Center",
"parent_cost_center": "Root - _TC",
"company_name": "_Test Company",
"group_or_ledger": "Ledger"
}],
]

View File

@ -0,0 +1,9 @@
test_records = [
[{
"doctype": "Cost Center",
"cost_center_name": "_Test Cost Center",
"parent_cost_center": "Root - _TC",
"company_name": "_Test Company",
"group_or_ledger": "Ledger"
}],
]

View File

@ -30,17 +30,4 @@ class DocType:
webnotes.clear_cache() webnotes.clear_cache()
msgprint(self.doc.name + _(""" is now the default Fiscal Year. \ msgprint(self.doc.name + _(""" is now the default Fiscal Year. \
Please refresh your browser for the change to take effect.""")) Please refresh your browser for the change to take effect."""))
test_records = [
[{
"doctype": "Fiscal Year",
"year": "_Test Fiscal Year 2013",
"year_start_date": "2013-01-01"
}],
[{
"doctype": "Fiscal Year",
"year": "_Test Fiscal Year 2014",
"year_start_date": "2014-01-01"
}]
]

View File

@ -0,0 +1,14 @@
from __future__ import unicode_literals
test_records = [
[{
"doctype": "Fiscal Year",
"year": "_Test Fiscal Year 2013",
"year_start_date": "2013-01-01"
}],
[{
"doctype": "Fiscal Year",
"year": "_Test Fiscal Year 2014",
"year_start_date": "2014-01-01"
}]
]

View File

@ -21,23 +21,9 @@ import webnotes
import webnotes.model import webnotes.model
import json import json
test_dependencies = ["Item", "Cost Center"]
class TestPurchaseInvoice(unittest.TestCase): class TestPurchaseInvoice(unittest.TestCase):
def setUp(self):
webnotes.conn.begin()
self.load_test_data()
# webnotes.conn.set_value("Global Defaults", None,
# "automatic_inventory_accounting", 1)
def tearDown(self):
webnotes.conn.rollback()
def load_test_data(self):
from webnotes.test_runner import make_test_records
webnotes.test_objects = {}
make_test_records("Cost Center", verbose=0)
make_test_records("Item", verbose=0)
make_test_records("Purchase Invoice", verbose=0)
def test_gl_entries(self): def test_gl_entries(self):
wrapper = webnotes.model_wrapper(self.get_test_doclist()) wrapper = webnotes.model_wrapper(self.get_test_doclist())

View File

@ -1,233 +0,0 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import unittest
import webnotes
import webnotes.model
from webnotes.model.doclist import DocList
from webnotes.utils import nowdate
from stock.doctype.purchase_receipt import test_purchase_receipt
company = webnotes.conn.get_default("company")
abbr = webnotes.conn.get_value("Company", company, "abbr")
def load_data():
test_purchase_receipt.load_data()
# create customer group
webnotes.insert({"doctype": "Customer Group",
"customer_group_name": "_Test Customer Group",
"parent_customer_group": "All Customer Groups", "is_group": "No"})
# create customer
webnotes.insert({"doctype": "Customer", "customer_name": "West Wind Inc.",
"customer_type": "Company", "territory": "Default",
"customer_group": "_Test Customer Group", "company": company,
"credit_days": 50, "credit_limit": 0})
webnotes.insert({"doctype": "Account", "account_name": "_Test Account Sales",
"parent_account": "Income - %s" % abbr, "company": company,
"group_or_ledger": "Ledger"})
webnotes.insert({"doctype": "Account", "account_name": "Excise Duty",
"parent_account": "Tax Assets - %s" % abbr, "company": company,
"group_or_ledger": "Ledger"})
webnotes.insert({"doctype": "Account", "account_name": "Education Cess",
"parent_account": "Tax Assets - %s" % abbr, "company": company,
"group_or_ledger": "Ledger"})
webnotes.insert({"doctype": "Account", "account_name": "S&H Education Cess",
"parent_account": "Tax Assets - %s" % abbr, "company": company,
"group_or_ledger": "Ledger"})
webnotes.insert({"doctype": "Account", "account_name": "CST",
"parent_account": "Direct Expenses - %s" % abbr, "company": company,
"group_or_ledger": "Ledger"})
webnotes.insert({"doctype": "Account", "account_name": "adj_rate",
"parent_account": "Direct Expenses - %s" % abbr, "company": company,
"group_or_ledger": "Ledger"})
from webnotes.model.doc import Document
item = Document("Item", "Home Desktop 100")
# excise duty
item_tax = item.addchild("item_tax", "Item Tax")
item_tax.tax_type = "Excise Duty - %s" % abbr
item_tax.tax_rate = 10
item_tax.save()
import json
sales_invoice_doclist = [
# parent
{
"doctype": "Sales Invoice",
"debit_to": "West Wind Inc. - %s" % abbr,
"customer_name": "West Wind Inc.",
"naming_series": "INV", "posting_date": nowdate(),
"company": company, "fiscal_year": webnotes.conn.get_default("fiscal_year"),
"currency": webnotes.conn.get_default("currency"), "conversion_rate": 1.0,
"price_list_currency": webnotes.conn.get_default("currency"),
"plc_conversion_rate": 1.0, "net_total": 1250, "grand_total": 1627.05,
"grand_total_export": 1627.05
},
# items
{
"doctype": "Sales Invoice Item", "warehouse": "Default Warehouse",
"item_code": "Home Desktop 100", "qty": 10, "basic_rate": 50, "amount": 500,
"parentfield": "entries", "so_detail": None, "dn_detail": None,
"stock_uom": "Nos", "item_tax_rate": json.dumps({"Excise Duty - %s" % abbr: 10}),
"income_account": "_Test Account Sales - %s" % abbr,
"cost_center": "Default Cost Center - %s" % abbr
},
{
"doctype": "Sales Invoice Item", "warehouse": "Default Warehouse",
"item_code": "Home Desktop 200", "qty": 5, "basic_rate": 150, "amount": 750,
"so_detail": None, "dn_detail": None,
"parentfield": "entries", "stock_uom": "Nos", "income_account": "_Test Account Sales - %s" % abbr,
"cost_center": "Default Cost Center - %s" % abbr
},
# taxes
{
"doctype": "Sales Taxes and Charges", "charge_type": "Actual",
"account_head": "Shipping Charges - %s" % abbr, "rate": 100, "tax_amount": 100,
"parentfield": "other_charges",
"cost_center_other_charges": "Default Cost Center - %s" % abbr
},
{
"doctype": "Sales Taxes and Charges", "charge_type": "On Net Total",
"account_head": "Customs Duty - %s" % abbr, "rate": 10, "tax_amount": 125,
"parentfield": "other_charges",
"cost_center_other_charges": "Default Cost Center - %s" % abbr
},
{
"doctype": "Sales Taxes and Charges", "charge_type": "On Net Total",
"account_head": "Excise Duty - %s" % abbr, "rate": 12, "tax_amount": 140,
"parentfield": "other_charges"
},
{
"doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Amount",
"account_head": "Education Cess - %s" % abbr, "rate": 2, "row_id": 3, "tax_amount": 2.8,
"parentfield": "other_charges"
},
{
"doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Amount",
"account_head": "S&H Education Cess - %s" % abbr, "rate": 1, "row_id": 3,
"tax_amount": 1.4, "parentfield": "other_charges"
},
{
"doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Total",
"account_head": "CST - %s" % abbr, "rate": 2, "row_id": 5, "tax_amount": 32.38,
"parentfield": "other_charges",
"cost_center_other_charges": "Default Cost Center - %s" % abbr
},
{
"doctype": "Sales Taxes and Charges", "charge_type": "On Net Total",
"account_head": "VAT - Test - %s" % abbr, "rate": 12.5, "tax_amount": 156.25,
"parentfield": "other_charges"
},
{
"doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Total",
"account_head": "adj_rate - %s" % abbr, "rate": -10, "row_id": 7, "tax_amount": -180.78,
"parentfield": "other_charges",
"cost_center_other_charges": "Default Cost Center - %s" % abbr
},
]
class TestSalesInvoice(unittest.TestCase):
def setUp(self):
webnotes.conn.begin()
load_data()
#webnotes.conn.set_value("Global Defaults", None, "automatic_inventory_accounting", 1)
def test_sales_invoice(self):
doclist = [] + [d.copy() for d in sales_invoice_doclist]
controller = webnotes.insert(DocList(doclist))
controller.submit()
controller.load_from_db()
dl = controller.doclist
# test net total
self.assertEqual(dl[0].net_total, 1250)
# test item values calculation
expected_values = [
{
"item_code": "Home Desktop 100",
# "ref_rate": 50,
# "adj_rate": 0,
# "export_amount": 500,
# "base_ref_rate": 50,
"basic_rate": 50,
"amount": 500
},
{
"item_code": "Home Desktop 200",
# "ref_rate": 150,
# "adj_rate": 0,
# "export_amount": 750,
# "base_ref_rate": 150,
"basic_rate": 150,
"amount": 750
},
]
for i, item in enumerate(dl.get({"parentfield": "entries"})):
for key, val in expected_values[i].items():
self.assertEqual(item.fields.get(key), val)
# test tax amounts and totals
expected_values = [
["Shipping Charges - %s" % abbr, 100, 1350],
["Customs Duty - %s" % abbr, 125, 1475],
["Excise Duty - %s" % abbr, 140, 1615],
["Education Cess - %s" % abbr, 2.8, 1617.8],
["S&H Education Cess - %s" % abbr, 1.4, 1619.2],
["CST - %s" % abbr, 32.38, 1651.58],
["VAT - Test - %s" % abbr, 156.25, 1807.83],
["adj_rate - %s" % abbr, -180.78, 1627.05],
]
for i, tax in enumerate(dl.get({"parentfield": "other_charges"})):
# print tax.account_head, tax.tax_amount, tax.total
self.assertEqual(tax.account_head, expected_values[i][0])
self.assertEqual(tax.tax_amount, expected_values[i][1])
# self.assertEqual(tax.total, expected_values[i][2])
expected_gl_entries = {
"West Wind Inc. - %s" % abbr : [1627.05, 0.0],
"_Test Account Sales - %s" % abbr: [0.0, 1250.00],
"Shipping Charges - %s" % abbr: [0.0, 100],
"Customs Duty - %s" % abbr: [0, 125.0],
"Excise Duty - %s" % abbr: [0, 140],
"Education Cess - %s" % abbr: [0, 2.8],
"S&H Education Cess - %s" % abbr: [0, 1.4],
"CST - %s" % abbr: [0, 32.38],
"VAT - Test - %s" % abbr: [0, 156.25],
"adj_rate - %s" % abbr: [180.78, 0],
}
gl_entries = webnotes.conn.sql("""select account, debit, credit from `tabGL Entry`
where voucher_type = %s and voucher_no = %s""",
(controller.doc.doctype, controller.doc.name), as_dict=1)
for gle in gl_entries:
self.assertEqual([gle.debit, gle.credit], expected_gl_entries[gle.account])
def tearDown(self):
webnotes.conn.rollback()

View File

@ -182,12 +182,3 @@ class DocType(TransactionBase):
#update master_name in doctype account #update master_name in doctype account
webnotes.conn.sql("""update `tabAccount` set master_name = %s, webnotes.conn.sql("""update `tabAccount` set master_name = %s,
master_type = 'Supplier' where master_name = %s""" , (new,old)) master_type = 'Supplier' where master_name = %s""" , (new,old))
test_records = [
[{
"doctype": "Supplier",
"supplier_name": "_Test Supplier",
"supplier_type": "_Test Supplier Type",
"company": "_Test Company"
}]
]

View File

@ -0,0 +1,8 @@
test_records = [
[{
"doctype": "Supplier",
"supplier_name": "_Test Supplier",
"supplier_type": "_Test Supplier Type",
"company": "_Test Company"
}]
]

View File

@ -1,21 +1,32 @@
[ [
{ {
"owner": "Administrator", "creation": "2012-06-14 18:44:56",
"docstatus": 0, "docstatus": 0,
"creation": "2012-02-24 11:37:43", "modified": "2013-02-12 18:11:00",
"modified_by": "Administrator", "modified_by": "Administrator",
"modified": "2012-02-24 11:37:43" "owner": "Administrator"
}, },
{ {
"name": "__common__",
"title": "Desktop",
"module": "Home",
"doctype": "Page", "doctype": "Page",
"module": "Home",
"name": "__common__",
"page_name": "desktop", "page_name": "desktop",
"standard": "Yes" "standard": "Yes",
"title": "Desktop"
}, },
{ {
"name": "desktop", "doctype": "Page Role",
"doctype": "Page" "name": "__common__",
"parent": "desktop",
"parentfield": "roles",
"parenttype": "Page",
"role": "All"
},
{
"doctype": "Page",
"name": "desktop"
},
{
"doctype": "Page Role"
} }
] ]

View File

@ -21,4 +21,3 @@ class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
test_records = [[{"doctype":"Branch", "branch":"_Test Branch"}]]

View File

@ -0,0 +1 @@
test_records = [[{"doctype":"Branch", "branch":"_Test Branch"}]]

View File

@ -20,9 +20,4 @@ import webnotes
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
test_records = [
[{"doctype":"Department", "department_name":"_Test Department"}],
[{"doctype":"Department", "department_name":"_Test Department with Block List",
"holiday_block_list": "_Test Holiday Block List"}],
]

View File

@ -0,0 +1,5 @@
test_records = [
[{"doctype":"Department", "department_name":"_Test Department"}],
[{"doctype":"Department", "department_name":"_Test Department with Block List",
"holiday_block_list": "_Test Holiday Block List"}],
]

View File

@ -21,4 +21,3 @@ class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
test_records = [[{"doctype":"Designation", "designation_name":"_Test Designation"}]]

View File

@ -0,0 +1 @@
test_records = [[{"doctype":"Designation", "designation_name":"_Test Designation"}]]

View File

@ -128,26 +128,3 @@ class DocType:
if self.doc.status == 'Left' and not self.doc.relieving_date: if self.doc.status == 'Left' and not self.doc.relieving_date:
msgprint("Please enter relieving date.") msgprint("Please enter relieving date.")
raise Exception raise Exception
test_records = [[{
"doctype":"Employee",
"employee_name": "_Test Employee",
"naming_series": "_T-Employee-",
"date_of_joining": "2010-01-01",
"date_of_birth": "1980-01-01",
"gender": "Female",
"status": "Active",
"company": "_Test Company",
"user_id": "test@erpnext.com"
}],
[{
"doctype":"Employee",
"employee_name": "_Test Employee 1",
"naming_series": "_T-Employee-",
"date_of_joining": "2010-01-01",
"date_of_birth": "1980-01-01",
"gender": "Male",
"status": "Active",
"company": "_Test Company",
"user_id": "test1@erpnext.com"
}]]

View File

@ -0,0 +1,22 @@
test_records = [[{
"doctype":"Employee",
"employee_name": "_Test Employee",
"naming_series": "_T-Employee-",
"date_of_joining": "2010-01-01",
"date_of_birth": "1980-01-01",
"gender": "Female",
"status": "Active",
"company": "_Test Company",
"user_id": "test@erpnext.com"
}],
[{
"doctype":"Employee",
"employee_name": "_Test Employee 1",
"naming_series": "_T-Employee-",
"date_of_joining": "2010-01-01",
"date_of_birth": "1980-01-01",
"gender": "Male",
"status": "Active",
"company": "_Test Company",
"user_id": "test1@erpnext.com"
}]]

View File

@ -20,6 +20,4 @@ import webnotes
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
test_records = [[{"doctype":"Employment Type",
"employee_type_name": "_Test Employment Type"}]]

View File

@ -0,0 +1,2 @@
test_records = [[{"doctype":"Employment Type",
"employee_type_name": "_Test Employment Type"}]]

View File

@ -21,4 +21,3 @@ class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
test_records = [[{"doctype":"Grade", "grade_name":"Test Grade"}]]

View File

@ -0,0 +1 @@
test_records = [[{"doctype":"Grade", "grade_name":"_Test Grade"}]]

View File

@ -20,23 +20,3 @@ class DocType:
webnotes.msgprint(_("Date is repeated") + ":" + d.block_date, raise_exception=1) webnotes.msgprint(_("Date is repeated") + ":" + d.block_date, raise_exception=1)
dates.append(d.block_date) dates.append(d.block_date)
test_records = [[{
"doctype":"Holiday Block List",
"holiday_block_list_name": "_Test Holiday Block List",
"year": "_Test Fiscal Year 2013",
"company": "_Test Company"
}, {
"doctype": "Holiday Block List Date",
"parent": "_Test Holiday Block List",
"parenttype": "Holiday Block List",
"parentfield": "holiday_block_list_dates",
"block_date": "2013-01-02",
"reason": "First work day"
}, {
"doctype": "Holiday Block List Allow",
"parent": "_Test Holiday Block List",
"parenttype": "Holiday Block List",
"parentfield": "holiday_block_list_allowed",
"allow_user": "test1@erpnext.com",
}
]]

View File

@ -0,0 +1,20 @@
test_records = [[{
"doctype":"Holiday Block List",
"holiday_block_list_name": "_Test Holiday Block List",
"year": "_Test Fiscal Year 2013",
"company": "_Test Company"
}, {
"doctype": "Holiday Block List Date",
"parent": "_Test Holiday Block List",
"parenttype": "Holiday Block List",
"parentfield": "holiday_block_list_dates",
"block_date": "2013-01-02",
"reason": "First work day"
}, {
"doctype": "Holiday Block List Allow",
"parent": "_Test Holiday Block List",
"parenttype": "Holiday Block List",
"parentfield": "holiday_block_list_allowed",
"allow_user": "test1@erpnext.com",
}
]]

View File

@ -89,16 +89,3 @@ class DocType:
def update_default_holiday_list(self): def update_default_holiday_list(self):
webnotes.conn.sql("""update `tabHoliday List` set is_default = 0 webnotes.conn.sql("""update `tabHoliday List` set is_default = 0
where ifnull(is_default, 0) = 1 and fiscal_year = %s""", (self.doc.fiscal_year,)) where ifnull(is_default, 0) = 1 and fiscal_year = %s""", (self.doc.fiscal_year,))
test_records = [[{
"doctype": "Holiday List",
"holiday_list_name": "_Test Holiday List",
"fiscal_year": "_Test Fiscal Year 2013"
}, {
"doctype": "Holiday",
"parent": "_Test Holiday List",
"parenttype": "Holiday List",
"parentfield": "holiday_list_details",
"holiday_date": "2013-01-01",
"description": "New Year"
}]]

View File

@ -0,0 +1,12 @@
test_records = [[{
"doctype": "Holiday List",
"holiday_list_name": "_Test Holiday List",
"fiscal_year": "_Test Fiscal Year 2013"
}, {
"doctype": "Holiday",
"parent": "_Test Holiday List",
"parenttype": "Holiday List",
"parentfield": "holiday_list_details",
"holiday_date": "2013-01-01",
"description": "New Year"
}]]

View File

@ -1,9 +1,6 @@
import sys import webnotes
import unittest import unittest
if __name__=="__main__":
sys.path.extend([".", "app", "lib"])
from hr.doctype.leave_application.leave_application import LeaveDayBlockedError from hr.doctype.leave_application.leave_application import LeaveDayBlockedError
class TestLeaveApplication(unittest.TestCase): class TestLeaveApplication(unittest.TestCase):
@ -54,13 +51,3 @@ test_records = [
"employee": "_T-Employee-0001", "employee": "_T-Employee-0001",
"company": "_Test Company" "company": "_Test Company"
}]] }]]
if __name__=="__main__":
import webnotes
webnotes.connect()
from webnotes.test_runner import make_test_records
make_test_records("Leave Application")
unittest.main()

View File

@ -20,10 +20,4 @@ import webnotes
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
test_records = [
[{
"leave_type_name": "_Test Leave Type",
"doctype": "Leave Type"
}]
]

View File

@ -0,0 +1,6 @@
test_records = [
[{
"leave_type_name": "_Test Leave Type",
"doctype": "Leave Type"
}]
]

View File

@ -166,5 +166,6 @@ patch_list = [
"patches.february_2013.remove_sales_order_pending_items", "patches.february_2013.remove_sales_order_pending_items",
"patches.february_2013.account_negative_balance", "patches.february_2013.account_negative_balance",
"patches.february_2013.remove_account_utils_folder", "patches.february_2013.remove_account_utils_folder",
"patches.february_2013.update_company_in_leave_application" "patches.february_2013.update_company_in_leave_application",
"execute:webnotes.conn.sql_ddl('alter table tabSeries change `name` `name` varchar(100)')"
] ]

View File

@ -19,4 +19,5 @@ import webnotes
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl

View File

@ -0,0 +1,4 @@
test_records = [
[{"doctype":"Campaign", "campaign_name":"_Test Campaign"}],
[{"doctype":"Campaign", "campaign_name":"_Test Campaign 1"}],
]

View File

@ -248,15 +248,4 @@ class DocType(TransactionBase):
#update master_name in doctype account #update master_name in doctype account
webnotes.conn.sql("""update `tabAccount` set master_name = %s, webnotes.conn.sql("""update `tabAccount` set master_name = %s,
master_type = 'Customer' where master_name = %s""", (new,old)) master_type = 'Customer' where master_name = %s""", (new,old))
test_records = [
[{
"doctype": "Customer",
"customer_name": "_Test Customer",
"customer_type": "Individual",
"customer_group": "_Test Customer Group",
"territory": "_Test Territory",
"company": "_Test Company"
}]
]

View File

@ -0,0 +1,10 @@
test_records = [
[{
"doctype": "Customer",
"customer_name": "_Test Customer",
"customer_type": "Individual",
"customer_group": "_Test Customer Group",
"territory": "_Test Territory",
"company": "_Test Company"
}]
]

View File

@ -19,4 +19,5 @@ import webnotes
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl

View File

@ -0,0 +1,4 @@
test_records = [
[{"doctype":"Industry Type", "industry":"_Test Industry"}],
[{"doctype":"Industry Type", "industry":"_Test Industry 1"}],
]

View File

@ -100,4 +100,4 @@ class DocType(SellingController):
webnotes.conn.sql("""delete from tabCommunication where lead=%s""", webnotes.conn.sql("""delete from tabCommunication where lead=%s""",
self.doc.name) self.doc.name)
webnotes.conn.sql("""update `tabSupport Ticket` set lead='' where lead=%s""", webnotes.conn.sql("""update `tabSupport Ticket` set lead='' where lead=%s""",
self.doc.name) self.doc.name)

View File

@ -0,0 +1,10 @@
test_records = [
[{"doctype":"Lead", "lead_name": "_Test Lead", "status":"Open",
"email_id":"test_lead@example.com"}],
[{"doctype":"Lead", "lead_name": "_Test Lead 1", "status":"Open",
"email_id":"test_lead1@example.com"}],
[{"doctype":"Lead", "lead_name": "_Test Lead 2", "status":"Contacted",
"email_id":"test_lead2@example.com"}],
[{"doctype":"Lead", "lead_name": "_Test Lead 3", "status":"Converted",
"email_id":"test_lead3@example.com"}],
]

View File

@ -20,10 +20,3 @@ import webnotes
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
test_records = [
[{
"doctype": "Brand",
"brand": "_Test Brand"
}]
]

View File

@ -0,0 +1,6 @@
test_records = [
[{
"doctype": "Brand",
"brand": "_Test Brand"
}]
]

View File

@ -254,13 +254,4 @@ class DocType:
sql("update `tabCompany` set company_name = '%s' where name = '%s'" %(newdn,olddn)) sql("update `tabCompany` set company_name = '%s' where name = '%s'" %(newdn,olddn))
sql("update `tabSingles` set value = %s where doctype='Global Defaults' and field = 'default_company' and value = %s", (newdn, olddn)) sql("update `tabSingles` set value = %s where doctype='Global Defaults' and field = 'default_company' and value = %s", (newdn, olddn))
if get_defaults('company') == olddn: if get_defaults('company') == olddn:
set_default('company', newdn) set_default('company', newdn)
test_records = [
[{
"doctype": "Company",
"company_name": "_Test Company",
"abbr": "_TC",
"default_currency": "INR",
}],
]

View File

@ -0,0 +1,10 @@
test_ignore = ["Account"]
test_records = [
[{
"doctype": "Company",
"company_name": "_Test Company",
"abbr": "_TC",
"default_currency": "INR",
}],
]

View File

@ -20,10 +20,3 @@ import webnotes
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
test_records = [
[{
"doctype": "Country",
"country_name": "_Test Country"
}]
]

View File

@ -0,0 +1,6 @@
test_records = [
[{
"doctype": "Country",
"country_name": "_Test Country"
}]
]

View File

@ -0,0 +1,2 @@
# pre loaded
test_records = []

View File

@ -61,12 +61,3 @@ class DocType(DocTypeNestedSet):
# rebuild tree # rebuild tree
super(DocType, self).on_trash() super(DocType, self).on_trash()
test_records = [
[{
"doctype": "Customer Group",
"customer_group_name": "_Test Customer Group",
"parent_customer_group": "All Customer Groups",
"is_group": "No"
}]
]

View File

@ -0,0 +1,8 @@
test_records = [
[{
"doctype": "Customer Group",
"customer_group_name": "_Test Customer Group",
"parent_customer_group": "All Customer Groups",
"is_group": "No"
}]
]

View File

@ -68,18 +68,3 @@ class DocType(DocTypeNestedSet):
if self.doc.slideshow: if self.doc.slideshow:
from website.helpers.slideshow import get_slideshow from website.helpers.slideshow import get_slideshow
get_slideshow(self) get_slideshow(self)
test_records = [
[{
"doctype": "Item Group",
"item_group_name": "_Test Item Group",
"parent_item_group": "All Item Groups",
"is_group": "No"
}],
[{
"doctype": "Item Group",
"item_group_name": "_Test Item Group Desktops",
"parent_item_group": "All Item Groups",
"is_group": "No"
}],
]

View File

@ -0,0 +1,14 @@
test_records = [
[{
"doctype": "Item Group",
"item_group_name": "_Test Item Group",
"parent_item_group": "All Item Groups",
"is_group": "No"
}],
[{
"doctype": "Item Group",
"item_group_name": "_Test Item Group Desktops",
"parent_item_group": "All Item Groups",
"is_group": "No"
}],
]

View File

@ -0,0 +1,6 @@
test_records = [
[{
"doctype": "Price List",
"price_list_name": "_Test Price List"
}]
]

View File

@ -19,4 +19,4 @@ import webnotes
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl

View File

@ -0,0 +1 @@
test_records = [[{"doctype":"Quotation Lost Reason", "order_lost_reason": "_Test Quotation Lost Reason"}]]

View File

@ -0,0 +1 @@
test_records = []

View File

@ -0,0 +1,8 @@
test_records = [
[{
"doctype": "Sales Person",
"sales_person_name": "_Test Sales Person",
"parent_sales_person": "All Sales Persons",
"is_group": "No"
}]
]

View File

@ -20,11 +20,3 @@ import webnotes
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
test_records = [
[{
"doctype": "Supplier Type",
"supplier_type": "_Test Supplier Type",
}]
]

View File

@ -0,0 +1,6 @@
test_records = [
[{
"doctype": "Supplier Type",
"supplier_type": "_Test Supplier Type",
}]
]

View File

@ -33,12 +33,4 @@ class DocType(DocTypeNestedSet):
if not flt(d.target_qty) and not flt(d.target_amount): if not flt(d.target_qty) and not flt(d.target_amount):
msgprint("Either target qty or target amount is mandatory.") msgprint("Either target qty or target amount is mandatory.")
raise Exception raise Exception
test_records = [
[{
"doctype": "Territory",
"territory_name": "_Test Territory",
"parent_territory": "All Territories",
"is_group": "No",
}]
]

View File

@ -0,0 +1,8 @@
test_records = [
[{
"doctype": "Territory",
"territory_name": "_Test Territory",
"parent_territory": "All Territories",
"is_group": "No",
}]
]

View File

@ -0,0 +1,6 @@
test_records = [
[{
"doctype": "UOM",
"uom_name": "_Test UOM"
}]
]

View File

@ -20,10 +20,3 @@ import webnotes
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
test_records = [
[{
"doctype": "UOM",
"uom_name": "_Test UOM"
}]
]

View File

@ -0,0 +1,6 @@
test_records = [
[{
"doctype": "Warehouse Type",
"warehouse_type": "_Test Warehouse Type"
}]
]

View File

@ -20,10 +20,3 @@ import webnotes
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
test_records = [
[{
"doctype": "Warehouse Type",
"warehouse_type": "_Test Warehouse Type"
}]
]

View File

@ -39,7 +39,9 @@ profile_defaults = {
"Company": "company", "Company": "company",
"Territory": "territory" "Territory": "territory"
} }
application_home_page = "desktop"
# add startup propertes # add startup propertes
mail_footer = """<div style="padding: 7px; text-align: right; color: #888"><small>Sent via mail_footer = """<div style="padding: 7px; text-align: right; color: #888"><small>Sent via
<a style="color: #888" href="https://erpnext.com">ERPNext</a></div>""" <a style="color: #888" href="https://erpnext.com">ERPNext</a></div>"""

View File

@ -221,49 +221,3 @@ class DocType:
if self.doc.slideshow: if self.doc.slideshow:
from website.helpers.slideshow import get_slideshow from website.helpers.slideshow import get_slideshow
get_slideshow(self) get_slideshow(self)
test_records = [
[{
"doctype": "Item",
"item_code": "_Test Item Home Desktop 100",
"item_name": "_Test Item Home Desktop 100",
"description": "_Test Item Home Desktop 100",
"item_group": "_Test Item Group Desktops",
"is_stock_item": "Yes",
"is_asset_item": "No",
"has_batch_no": "No",
"has_serial_no": "No",
"is_purchase_item": "Yes",
"is_sales_item": "Yes",
"is_service_item": "No",
"is_sample_item": "No",
"inspection_required": "No",
"is_pro_applicable": "No",
"is_sub_contracted_item": "No",
"stock_uom": "_Test UOM"
},
{
"doctype": "Item Tax",
"tax_type": "_Test Account Excise Duty - _TC",
"tax_rate": 10
}],
[{
"doctype": "Item",
"item_code": "_Test Item Home Desktop 200",
"item_name": "_Test Item Home Desktop 200",
"description": "_Test Item Home Desktop 200",
"item_group": "_Test Item Group Desktops",
"is_stock_item": "Yes",
"is_asset_item": "No",
"has_batch_no": "No",
"has_serial_no": "No",
"is_purchase_item": "Yes",
"is_sales_item": "Yes",
"is_service_item": "No",
"is_sample_item": "No",
"inspection_required": "No",
"is_pro_applicable": "No",
"is_sub_contracted_item": "No",
"stock_uom": "_Test UOM"
}],
]

View File

@ -76,3 +76,48 @@ docok = [Document(fielddata=r) for r in tabOK]
docnotok = [Document(fielddata=r) for r in tabNotOK] docnotok = [Document(fielddata=r) for r in tabNotOK]
test_records = [
[{
"doctype": "Item",
"item_code": "_Test Item Home Desktop 100",
"item_name": "_Test Item Home Desktop 100",
"description": "_Test Item Home Desktop 100",
"item_group": "_Test Item Group Desktops",
"is_stock_item": "Yes",
"is_asset_item": "No",
"has_batch_no": "No",
"has_serial_no": "No",
"is_purchase_item": "Yes",
"is_sales_item": "Yes",
"is_service_item": "No",
"is_sample_item": "No",
"inspection_required": "No",
"is_pro_applicable": "No",
"is_sub_contracted_item": "No",
"stock_uom": "_Test UOM"
},
{
"doctype": "Item Tax",
"tax_type": "_Test Account Excise Duty - _TC",
"tax_rate": 10
}],
[{
"doctype": "Item",
"item_code": "_Test Item Home Desktop 200",
"item_name": "_Test Item Home Desktop 200",
"description": "_Test Item Home Desktop 200",
"item_group": "_Test Item Group Desktops",
"is_stock_item": "Yes",
"is_asset_item": "No",
"has_batch_no": "No",
"has_serial_no": "No",
"is_purchase_item": "Yes",
"is_sales_item": "Yes",
"is_service_item": "No",
"is_sample_item": "No",
"inspection_required": "No",
"is_pro_applicable": "No",
"is_sub_contracted_item": "No",
"stock_uom": "_Test UOM"
}],
]

View File

@ -0,0 +1,7 @@
test_records = [
[{
"doctype": "Warehouse",
"warehouse_name": "_Test Warehouse",
"warehouse_type": "_Test Warehouse Type"
}]
]

View File

@ -207,11 +207,3 @@ class DocType:
exists for this warehouse.""", raise_exception=1) exists for this warehouse.""", raise_exception=1)
else: else:
sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name) sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)
test_records = [
[{
"doctype": "Warehouse",
"warehouse_name": "_Test Warehouse",
"warehouse_type": "_Test Warehouse Type"
}]
]

View File

@ -29,4 +29,13 @@ cur_frm.cscript.refresh = function(doc) {
cur_frm.set_value("send_from", cur_frm.set_value("send_from",
repl("%(fullname)s <%(email)s>", wn.user_info(doc.owner))); repl("%(fullname)s <%(email)s>", wn.user_info(doc.owner)));
} }
wn.call({
method: "support.doctype.newsletter.newsletter.get_lead_options",
type: "GET",
callback: function(r) {
set_field_options("lead_source", r.message.sources.join("\n"))
set_field_options("lead_status", r.message.statuses.join("\n"))
}
})
} }

View File

@ -25,100 +25,72 @@ from webnotes import _
class DocType(): class DocType():
def __init__(self, d, dl): def __init__(self, d, dl):
self.doc, self.doclist = d, dl self.doc, self.doclist = d, dl
self.dt_map = {
"Contact": { def test_send(self, doctype="Lead"):
"email_field": "email_id", self.recipients = self.doc.test_email_id.split(",")
"first_name_field": "first_name", self.send_bulk()
}, webnotes.msgprint("""Scheduled to send to %s""" % self.doc.test_email_id)
"Lead": {
"email_field": "email_id",
"first_name_field": "lead_name"
}
}
self.query_map = {
"contacts": """select distinct email_id from `tabContact`
where ifnull(email_id, '') != '' """,
"customer_contacts": """select distinct email_id from `tabContact`
where ifnull(customer, '') != '' and ifnull(email_id, '') != '' """,
"leads": """select distinct email_id from `tabLead`
where ifnull(email_id, '') != '' """,
"active_leads": """select distinct email_id from `tabLead`
where status = "Open" and ifnull(email_id, '') != '' """,
"blog_subscribers": """select distinct email_id from `tabLead`
where ifnull(blog_subscriber,0) = 1 and ifnull(email_id, '') != '' """
}
def send_emails(self): def send_emails(self):
"""send emails to leads and customers""" """send emails to leads and customers"""
if self.doc.email_sent: if self.doc.email_sent:
webnotes.msgprint("""Newsletter has already been sent""", raise_exception=1) webnotes.msgprint("""Newsletter has already been sent""", raise_exception=1)
self.all_recipients = [] self.recipients = self.get_recipients()
self.send_count = {} self.send_bulk()
if self.doc.contacts: webnotes.msgprint("""Scheduled to send to %d %s(s)""" % (len(self.recipients),
self.send("contacts", "Contact") self.send_to_doctype))
elif self.doc.customer_contacts:
self.send("customer_contacts", "Contact") webnotes.conn.set(self.doc, "email_sent", 1)
if self.doc.leads: def get_recipients(self):
self.send("leads", "Lead") if self.doc.send_to_type=="Contact":
else: self.send_to_doctype = "Contact"
if self.doc.active_leads: if self.doc.contact_type == "Customer":
self.send("active_leads", "Lead") return webnotes.conn.sql_list("""select email_id from tabContact
where ifnull(email_id, '') != '' and ifnull(customer, '') != ''""")
elif self.doc.contact_type == "Supplier":
return webnotes.conn.sql_list("""select email_id from tabContact
where ifnull(email_id, '') != '' and ifnull(supplier, '') != ''""")
elif self.doc.send_to_type=="Lead":
self.send_to_doctype = "Lead"
conditions = []
if self.doc.lead_source and self.doc.lead_source != "All":
conditions.append(" and source='%s'" % self.doc.lead_source)
if self.doc.lead_status and self.doc.lead_status != "All":
conditions.append(" and status='%s'" % self.doc.lead_status)
if conditions:
conditions = "".join(conditions)
if self.doc.blog_subscribers: return webnotes.conn.sql_list("""select email_id from tabLead
self.send("blog_subscribers", "Lead") where ifnull(email_id, '') != '' %s""" % (conditions or ""))
if self.doc.email_list: elif self.doc.email_list:
email_list = [cstr(email).strip() for email in self.doc.email_list.split(",")] email_list = [cstr(email).strip() for email in self.doc.email_list.split(",")]
for email in email_list: for email in email_list:
if not webnotes.conn.exists({"doctype": "Lead", "email_id": email}): if not webnotes.conn.exists({"doctype": "Lead", "email_id": email}):
create_lead(email) create_lead(email)
self.send(email_list, "Lead") self.send_to_doctype = "Lead"
return email_list
webnotes.msgprint("""Scheduled to send to %s""" % \
", ".join(["%d %s(s)" % (self.send_count[s], s) for s in self.send_count])) def send_bulk(self):
def test_send(self, doctype="Lead"):
self.validate_send() self.validate_send()
args = self.dt_map[doctype]
sender = self.doc.send_from or webnotes.utils.get_formatted_email(self.doc.owner) sender = self.doc.send_from or webnotes.utils.get_formatted_email(self.doc.owner)
recipients = self.doc.test_email_id.split(",")
from webnotes.utils.email_lib.bulk import send from webnotes.utils.email_lib.bulk import send
send(recipients = recipients, sender = sender,
subject = self.doc.subject, message = self.doc.message,
doctype = doctype, email_field = args["email_field"])
webnotes.msgprint("""Scheduled to send to %s""" % self.doc.test_email_id)
def get_recipients(self, key):
recipients = webnotes.conn.sql(self.query_map[key])
recipients = [r[0] for r in recipients if r not in self.all_recipients]
self.all_recipients += recipients
return recipients
def send(self, query_key, doctype):
self.validate_send()
webnotes.conn.auto_commit_on_many_writes = True webnotes.conn.auto_commit_on_many_writes = True
if isinstance(query_key, basestring) and self.query_map.has_key(query_key):
recipients = self.get_recipients(query_key)
else:
recipients = query_key
sender = self.doc.send_from or webnotes.utils.get_formatted_email(self.doc.owner)
args = self.dt_map[doctype]
self.send_count[doctype] = self.send_count.setdefault(doctype, 0) + \
len(recipients)
from webnotes.utils.email_lib.bulk import send send(recipients = self.recipients, sender = sender,
send(recipients = recipients, sender = sender,
subject = self.doc.subject, message = self.doc.message, subject = self.doc.subject, message = self.doc.message,
doctype = doctype, email_field = args["email_field"]) doctype = self.send_to_doctype, email_field = "email_id")
webnotes.conn.set(self.doc, "email_sent", 1) webnotes.conn.auto_commit_on_many_writes = False
def validate_send(self): def validate_send(self):
if self.doc.fields.get("__islocal"): if self.doc.fields.get("__islocal"):
@ -130,6 +102,14 @@ class DocType():
webnotes.msgprint(_("""Sending newsletters is not allowed for Trial users, \ webnotes.msgprint(_("""Sending newsletters is not allowed for Trial users, \
to prevent abuse of this feature."""), raise_exception=1) to prevent abuse of this feature."""), raise_exception=1)
@webnotes.whitelist()
def get_lead_options():
return {
"sources": ["All"] + webnotes.conn.sql_list("""select distinct source from tabLead"""),
"statuses": ["All"]+ webnotes.conn.sql_list("""select distinct status from tabLead""")
}
lead_naming_series = None lead_naming_series = None
def create_lead(email_id): def create_lead(email_id):
"""create a lead if it does not exist""" """create a lead if it does not exist"""

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-01-10 16:34:31", "creation": "2013-01-10 16:34:31",
"docstatus": 0, "docstatus": 0,
"modified": "2013-01-28 15:28:59", "modified": "2013-02-11 17:23:08",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -58,33 +58,10 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "contacts", "fieldname": "send_to_type",
"fieldtype": "Check", "fieldtype": "Select",
"label": "All Contacts" "label": "Send To Type",
}, "options": "Lead\nContact\nCustom"
{
"doctype": "DocField",
"fieldname": "customer_contacts",
"fieldtype": "Check",
"label": "All Customer Contacts"
},
{
"doctype": "DocField",
"fieldname": "leads",
"fieldtype": "Check",
"label": "All Leads"
},
{
"doctype": "DocField",
"fieldname": "active_leads",
"fieldtype": "Check",
"label": "All Active Leads"
},
{
"doctype": "DocField",
"fieldname": "blog_subscribers",
"fieldtype": "Check",
"label": "All Blog Subscribers"
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@ -92,6 +69,29 @@
"fieldtype": "Column Break" "fieldtype": "Column Break"
}, },
{ {
"depends_on": "eval:doc.send_to_type==\"Lead\"",
"doctype": "DocField",
"fieldname": "lead_source",
"fieldtype": "Select",
"label": "Lead Source"
},
{
"depends_on": "eval:doc.send_to_type==\"Lead\"",
"doctype": "DocField",
"fieldname": "lead_status",
"fieldtype": "Select",
"label": "Lead Status"
},
{
"depends_on": "eval:doc.send_to_type==\"Contact\"",
"doctype": "DocField",
"fieldname": "contact_type",
"fieldtype": "Select",
"label": "Contact Type",
"options": "Customer\nSupplier\nCustom"
},
{
"depends_on": "eval:doc.send_to_type==\"Custom\"",
"description": "Comma separated list of email addresses", "description": "Comma separated list of email addresses",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "email_list", "fieldname": "email_list",

View File

@ -0,0 +1,58 @@
import webnotes, unittest
class TestNewsletter(unittest.TestCase):
def test_get_recipients_lead(self):
w = webnotes.model_wrapper(test_records[0])
w.insert()
self.assertTrue("test_lead@example.com" in w.controller.get_recipients())
webnotes.conn.sql("""delete from `tabBulk Email`""")
w.controller.send_emails()
self.assertTrue(webnotes.conn.get_value("Bulk Email", {"recipient": "test_lead@example.com"}))
def test_get_recipients_lead_by_status(self):
w = webnotes.model_wrapper(test_records[0])
w.doc.lead_status="Converted"
w.insert()
self.assertTrue("test_lead3@example.com" in w.controller.get_recipients())
def test_get_recipients_contact_customer(self):
w = webnotes.model_wrapper(test_records[1])
w.insert()
self.assertTrue("test_contact_customer@example.com" in w.controller.get_recipients())
def test_get_recipients_contact_supplier(self):
w = webnotes.model_wrapper(test_records[1])
w.doc.contact_type="Supplier"
w.insert()
self.assertTrue("test_contact_supplier@example.com" in w.controller.get_recipients())
def test_get_recipients_custom(self):
w = webnotes.model_wrapper(test_records[2])
w.insert()
self.assertTrue("test_custom2@example.com" in w.controller.get_recipients())
self.assertTrue(webnotes.conn.get("Lead",
{"email_id": "test_custom2@example.com"}))
test_dependencies = ["Lead", "Contact"]
test_records =[
[{
"subject": "_Test Newsletter to Lead",
"send_to_type": "Lead",
"lead_source": "All",
"message": "This is a test newsletter"
}],
[{
"subject": "_Test Newsletter to Contact",
"send_to_type": "Contact",
"contact_type": "Customer",
"message": "This is a test newsletter"
}],
[{
"subject": "_Test Newsletter to Custom",
"send_to_type": "Custom",
"email_list": "test_custom@example.com, test_custom1@example.com, test_custom2@example.com",
"message": "This is a test newsletter"
}],
]

View File

@ -0,0 +1,22 @@
test_records = [
[{
"doctype": "Contact",
"customer": "_Test Customer",
"customer_name": "_Test Customer",
"first_name": "_Test Contact For _Test Customer",
"email_id": "test_contact_customer@example.com",
"phone": "+91 0000000000",
"status": "Open",
"is_primary_contact": 1
}],
[{
"doctype": "Contact",
"supplier": "_Test Supplier",
"supplier_name": "_Test Supplier",
"first_name": "_Test Contact For _Test Supplier",
"email_id": "test_contact_supplier@example.com",
"phone": "+91 0000000000",
"status": "Open",
"is_primary_contact": 1
}]
]