Merge pull request #3322 from nabinhait/test_case

Test case
This commit is contained in:
Nabin Hait 2015-05-25 16:19:03 +05:30
commit 2c6705ef83
16 changed files with 47 additions and 44 deletions

View File

@ -80,6 +80,8 @@ def create_purchase_order(**args):
po.company = args.company or "_Test Company" po.company = args.company or "_Test Company"
po.supplier = args.customer or "_Test Supplier" po.supplier = args.customer or "_Test Supplier"
po.is_subcontracted = args.is_subcontracted or "No" po.is_subcontracted = args.is_subcontracted or "No"
po.currency = args.currency or frappe.db.get_value("Company", po.company, "default_currency")
po.conversion_factor = args.conversion_factor or 1
po.append("items", { po.append("items", {
"item_code": args.item or args.item_code or "_Test Item", "item_code": args.item or args.item_code or "_Test Item",

View File

@ -279,7 +279,7 @@ class BuyingController(StockController):
def set_qty_as_per_stock_uom(self): def set_qty_as_per_stock_uom(self):
for d in self.get("items"): for d in self.get("items"):
if d.meta.get_field("stock_qty") and not d.stock_qty: if d.meta.get_field("stock_qty"):
if not d.conversion_factor: if not d.conversion_factor:
frappe.throw(_("Row {0}: Conversion Factor is mandatory").format(d.idx)) frappe.throw(_("Row {0}: Conversion Factor is mandatory").format(d.idx))
d.stock_qty = flt(d.qty) * flt(d.conversion_factor) d.stock_qty = flt(d.qty) * flt(d.conversion_factor)

View File

@ -92,7 +92,7 @@ def unsubscribe(email, name):
return return
subs_id = frappe.db.get_value("Newsletter List Subscriber", {"email": email, "newsletter_list": name}) subs_id = frappe.db.get_value("Newsletter List Subscriber", {"email": email, "newsletter_list": name})
if name: if subs_id:
subscriber = frappe.get_doc("Newsletter List Subscriber", subs_id) subscriber = frappe.get_doc("Newsletter List Subscriber", subs_id)
subscriber.unsubscribed = 1 subscriber.unsubscribed = 1
subscriber.save(ignore_permissions=True) subscriber.save(ignore_permissions=True)

View File

@ -9,7 +9,16 @@ from urllib import unquote
class TestNewsletter(unittest.TestCase): class TestNewsletter(unittest.TestCase):
def setUp(self): def setUp(self):
frappe.db.sql("update `tabNewsletter List Subscriber` set unsubscribed = 0") if not frappe.get_all("Newsletter List Subscriber"):
for email in ["test_subscriber1@example.com", "test_subscriber2@example.com",
"test_subscriber3@example.com"]:
frappe.get_doc({
"doctype": "Newsletter List Subscriber",
"email": email,
"newsletter_list": "_Test Newsletter List"
}).insert()
else:
frappe.db.sql("update `tabNewsletter List Subscriber` set unsubscribed = 0")
def test_send(self): def test_send(self):
self.send_newsletter() self.send_newsletter()
@ -39,6 +48,4 @@ class TestNewsletter(unittest.TestCase):
newsletter.send_emails() newsletter.send_emails()
test_dependencies = ["Newsletter List"] test_dependencies = ["Newsletter List"]

View File

@ -6,8 +6,6 @@ from __future__ import unicode_literals
import frappe import frappe
import unittest import unittest
# test_records = frappe.get_test_records('Newletter List')
class TestNewletterList(unittest.TestCase): class TestNewletterList(unittest.TestCase):
def test_import(self): def test_import(self):
new_list = frappe.get_doc({ new_list = frappe.get_doc({
@ -15,13 +13,13 @@ class TestNewletterList(unittest.TestCase):
"title": "_Test Newsletter List 1" "title": "_Test Newsletter List 1"
}).insert() }).insert()
n_leads = frappe.db.count("Lead") n_leads = frappe.db.sql("select count(distinct email_id) from `tabLead`")[0][0]
added = new_list.import_from("Lead") added = new_list.import_from("Lead")
self.assertEquals(added, n_leads) self.assertEquals(added, n_leads)
frappe.delete_doc("Newsletter List", new_list.name) def tearDown(self):
frappe.delete_doc("Newsletter List", "_Test Newsletter List 1")
test_dependencies = ["Lead"] test_dependencies = ["Lead"]

View File

@ -2,20 +2,5 @@
{ {
"doctype": "Newsletter List", "doctype": "Newsletter List",
"title": "_Test Newsletter List" "title": "_Test Newsletter List"
},
{
"doctype": "Newsletter List Subscriber",
"email": "test_subscriber1@example.com",
"newsletter_list": "_Test Newsletter List"
},
{
"doctype": "Newsletter List Subscriber",
"email": "test_subscriber2@example.com",
"newsletter_list": "_Test Newsletter List"
},
{
"doctype": "Newsletter List Subscriber",
"email": "test_subscriber3@example.com",
"newsletter_list": "_Test Newsletter List"
} }
] ]

View File

@ -10,4 +10,4 @@ class NewsletterListSubscriber(Document):
pass pass
def after_doctype_insert(): def after_doctype_insert():
frappe.db.add_unique("Newsletter List Subscriber", ("name", "email")) frappe.db.add_unique("Newsletter List Subscriber", ("newsletter_list", "email"))

View File

@ -12,6 +12,9 @@ class TestSalarySlip(unittest.TestCase):
def setUp(self): def setUp(self):
frappe.db.sql("""delete from `tabLeave Application`""") frappe.db.sql("""delete from `tabLeave Application`""")
frappe.db.sql("""delete from `tabSalary Slip`""") frappe.db.sql("""delete from `tabSalary Slip`""")
frappe.db.set_value("Holiday List", "_Test Holiday List", "is_default", 1)
from erpnext.hr.doctype.leave_application.test_leave_application import _test_records as leave_applications from erpnext.hr.doctype.leave_application.test_leave_application import _test_records as leave_applications
la = frappe.copy_doc(leave_applications[2]) la = frappe.copy_doc(leave_applications[2])
la.insert() la.insert()
@ -26,6 +29,7 @@ class TestSalarySlip(unittest.TestCase):
frappe.db.set_value("HR Settings", "HR Settings", "include_holidays_in_total_working_days", 1) frappe.db.set_value("HR Settings", "HR Settings", "include_holidays_in_total_working_days", 1)
ss = frappe.copy_doc(test_records[0]) ss = frappe.copy_doc(test_records[0])
ss.insert() ss.insert()
self.assertEquals(ss.total_days_in_month, 31) self.assertEquals(ss.total_days_in_month, 31)
self.assertEquals(ss.payment_days, 30) self.assertEquals(ss.payment_days, 30)
self.assertEquals(ss.earnings[0].e_modified_amount, 14516.13) self.assertEquals(ss.earnings[0].e_modified_amount, 14516.13)
@ -36,8 +40,10 @@ class TestSalarySlip(unittest.TestCase):
self.assertEquals(ss.net_pay, 14867.74) self.assertEquals(ss.net_pay, 14867.74)
def test_salary_slip_with_holidays_excluded(self): def test_salary_slip_with_holidays_excluded(self):
frappe.db.set_value("HR Settings", "HR Settings", "include_holidays_in_total_working_days", 0)
ss = frappe.copy_doc(test_records[0]) ss = frappe.copy_doc(test_records[0])
ss.insert() ss.insert()
self.assertEquals(ss.total_days_in_month, 30) self.assertEquals(ss.total_days_in_month, 30)
self.assertEquals(ss.payment_days, 29) self.assertEquals(ss.payment_days, 29)
self.assertEquals(ss.earnings[0].e_modified_amount, 14500) self.assertEquals(ss.earnings[0].e_modified_amount, 14500)
@ -102,6 +108,6 @@ class TestSalarySlip(unittest.TestCase):
return salary_slip return salary_slip
test_dependencies = ["Leave Application"] test_dependencies = ["Leave Application", "Holiday List"]
test_records = frappe.get_test_records('Salary Slip') test_records = frappe.get_test_records('Salary Slip')

View File

@ -130,10 +130,9 @@ class TestProductionOrder(unittest.TestCase):
prod_order = make_prod_order_test_record(item="_Test FG Item 2", prod_order = make_prod_order_test_record(item="_Test FG Item 2",
planned_start_date="2014-11-25 00:00:00", qty=1, do_not_save=True) planned_start_date="2014-11-25 00:00:00", qty=1, do_not_save=True)
prod_order.set_production_order_operations() prod_order.set_production_order_operations()
prod_order.save()
cost = prod_order.planned_operating_cost cost = prod_order.planned_operating_cost
prod_order.qty = 2 prod_order.qty = 2
prod_order.save() prod_order.set_production_order_operations()
self.assertEqual(prod_order.planned_operating_cost, cost*2) self.assertEqual(prod_order.planned_operating_cost, cost*2)
def make_prod_order_test_record(**args): def make_prod_order_test_record(**args):

View File

@ -34,7 +34,9 @@ class TestCustomer(unittest.TestCase):
make_test_records("Address") make_test_records("Address")
make_test_records("Contact") make_test_records("Contact")
frappe.db.set_value("Contact", "_Test Contact For _Test Customer-_Test Customer",
"is_primary_contact", 1)
details = get_party_details("_Test Customer") details = get_party_details("_Test Customer")
for key, value in to_check.iteritems(): for key, value in to_check.iteritems():

View File

@ -7,7 +7,7 @@ import unittest
import frappe import frappe
import json import json
import frappe.defaults import frappe.defaults
from frappe.utils import cint, nowdate, nowtime, cstr, add_days from frappe.utils import cint, nowdate, nowtime, cstr, add_days, flt
from erpnext.stock.stock_ledger import get_previous_sle from erpnext.stock.stock_ledger import get_previous_sle
from erpnext.accounts.utils import get_balance_on from erpnext.accounts.utils import get_balance_on
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt \ from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt \
@ -136,7 +136,7 @@ class TestDeliveryNote(unittest.TestCase):
# check stock in hand balance # check stock in hand balance
bal = get_balance_on(stock_in_hand_account) bal = get_balance_on(stock_in_hand_account)
self.assertEquals(bal, prev_bal - stock_value_diff) self.assertEquals(flt(bal, 2), flt(prev_bal - stock_value_diff, 2))
dn.cancel() dn.cancel()
self.assertFalse(get_gl_entries("Delivery Note", dn.name)) self.assertFalse(get_gl_entries("Delivery Note", dn.name))

View File

@ -34,6 +34,8 @@ class TestItem(unittest.TestCase):
se = make_stock_entry(item_code=item.name, target="Stores - _TC", qty=1, incoming_rate=1) se = make_stock_entry(item_code=item.name, target="Stores - _TC", qty=1, incoming_rate=1)
item.has_variants = 1 item.has_variants = 1
item.append("variants", {"item_attribute": "Test Size", "item_attribute_value": "Small"})
self.assertRaises(ItemTemplateCannotHaveStock, item.save) self.assertRaises(ItemTemplateCannotHaveStock, item.save)
def test_variant_item_codes(self): def test_variant_item_codes(self):

View File

@ -81,17 +81,21 @@ class TestStockEntry(unittest.TestCase):
template = frappe.get_doc("Item", item.variant_of) template = frappe.get_doc("Item", item.variant_of)
else: else:
template = item template = item
projected_qty, actual_qty = frappe.db.get_value("Bin", {"item_code": item_code,
"warehouse": "_Test Warehouse - _TC"}, ["projected_qty", "actual_qty"]) or [0, 0]
# stock entry reqd for auto-reorder # stock entry reqd for auto-reorder
create_stock_reconciliation(item_code=item_code, warehouse="_Test Warehouse - _TC", create_stock_reconciliation(item_code=item_code, warehouse="_Test Warehouse - _TC",
qty=10, rate=100) qty = actual_qty + abs(projected_qty) + 10, rate=100)
frappe.db.set_value("Stock Settings", None, "auto_indent", 1)
projected_qty = frappe.db.get_value("Bin", {"item_code": item_code, projected_qty = frappe.db.get_value("Bin", {"item_code": item_code,
"warehouse": "_Test Warehouse - _TC"}, "projected_qty") or 0 "warehouse": "_Test Warehouse - _TC"}, "projected_qty") or 0
frappe.db.set_value("Stock Settings", None, "auto_indent", 1)
# update re-level qty so that it is more than projected_qty # update re-level qty so that it is more than projected_qty
if projected_qty > template.reorder_levels[0].warehouse_reorder_level: if projected_qty >= template.reorder_levels[0].warehouse_reorder_level:
template.reorder_levels[0].warehouse_reorder_level += projected_qty template.reorder_levels[0].warehouse_reorder_level += projected_qty
template.save() template.save()

View File

@ -227,7 +227,7 @@ class StockReconciliation(StockController):
msgprint(_("Please enter Expense Account"), raise_exception=1) msgprint(_("Please enter Expense Account"), raise_exception=1)
elif not frappe.db.sql("""select name from `tabStock Ledger Entry` limit 1"""): elif not frappe.db.sql("""select name from `tabStock Ledger Entry` limit 1"""):
if frappe.db.get_value("Account", self.expense_account, "report_type") == "Profit and Loss": if frappe.db.get_value("Account", self.expense_account, "report_type") == "Profit and Loss":
frappe.throw(_("Difference Account must be a 'Liability' type account, since this Stock Reconciliation is an Opening Entry"), OpeningEntryAccountError) frappe.throw(_("Difference Account must be a Asset/Liability type account, since this Stock Reconciliation is an Opening Entry"), OpeningEntryAccountError)
def get_items_for(self, warehouse): def get_items_for(self, warehouse):
self.items = [] self.items = []

View File

@ -97,7 +97,8 @@ def create_stock_reconciliation(**args):
sr.posting_time = args.posting_time or nowtime() sr.posting_time = args.posting_time or nowtime()
sr.company = args.company or "_Test Company" sr.company = args.company or "_Test Company"
sr.fiscal_year = get_fiscal_year(sr.posting_date)[0] sr.fiscal_year = get_fiscal_year(sr.posting_date)[0]
sr.expense_account = args.expense_account or "Stock Adjustment - _TC" sr.expense_account = args.expense_account or \
("Stock Adjustment - _TC" if frappe.get_all("Stock Ledger Entry") else "Temporary Opening - _TC")
sr.cost_center = args.cost_center or "_Test Cost Center - _TC" sr.cost_center = args.cost_center or "_Test Cost Center - _TC"
sr.append("items", { sr.append("items", {
"item_code": args.item_code or "_Test Item", "item_code": args.item_code or "_Test Item",

View File

@ -11,10 +11,7 @@ def reorder_item():
if not frappe.db.sql("select name from `tabFiscal Year` limit 1"): if not frappe.db.sql("select name from `tabFiscal Year` limit 1"):
return return
if getattr(frappe.local, "auto_indent", None) is None: if cint(frappe.db.get_value('Stock Settings', None, 'auto_indent')):
frappe.local.auto_indent = cint(frappe.db.get_value('Stock Settings', None, 'auto_indent'))
if frappe.local.auto_indent:
return _reorder_item() return _reorder_item()
def _reorder_item(): def _reorder_item():