[minor] don't rollback when running all tests, fixed test cases

This commit is contained in:
Anand Doshi 2013-10-15 19:52:29 +05:30
parent 8ae6520129
commit a295bf5421
15 changed files with 160 additions and 47 deletions

View File

@ -8,6 +8,9 @@ import webnotes
class TestPeriodClosingVoucher(unittest.TestCase):
def test_closing_entry(self):
# clear GL Entries
webnotes.conn.sql("""delete from `tabGL Entry`""")
from accounts.doctype.journal_voucher.test_journal_voucher import test_records as jv_records
jv = webnotes.bean(copy=jv_records[2])
jv.insert()

View File

@ -434,7 +434,7 @@ class DocType(BuyingController):
def update_raw_material_cost(self):
if self.sub_contracted_items:
for d in self.doclist.get({"parentfield": "entries"}):
rm_cost = webnotes.conn.sql(""" select raw_material_cost / quantity
rm_cost = webnotes.conn.sql("""select raw_material_cost / quantity
from `tabBOM` where item = %s and is_default = 1 and docstatus = 1
and is_active = 1 """, (d.item_code,))
rm_cost = rm_cost and flt(rm_cost[0][0]) or 0

View File

@ -7,6 +7,9 @@ import unittest
from hr.doctype.leave_application.leave_application import LeaveDayBlockedError, OverlapError
class TestLeaveApplication(unittest.TestCase):
def tearDown(self):
webnotes.session.user = "Administrator"
def _clear_roles(self):
webnotes.conn.sql("""delete from `tabUserRole` where parent in
("test@example.com", "test1@example.com", "test2@example.com")""")
@ -15,6 +18,7 @@ class TestLeaveApplication(unittest.TestCase):
webnotes.conn.sql("""delete from `tabLeave Application`""")
def _add_employee_leave_approver(self, employee, leave_approver):
temp_session_user = webnotes.session.user
webnotes.session.user = "Administrator"
employee = webnotes.bean("Employee", employee)
employee.doclist.append({
@ -23,6 +27,7 @@ class TestLeaveApplication(unittest.TestCase):
"leave_approver": leave_approver
})
employee.save()
webnotes.session.user = temp_session_user
def get_application(self, doclist):
application = webnotes.bean(copy=doclist)
@ -31,7 +36,6 @@ class TestLeaveApplication(unittest.TestCase):
return application
def test_block_list(self):
webnotes.session.user = "Administrator"
self._clear_roles()
from webnotes.profile import add_role
@ -54,7 +58,6 @@ class TestLeaveApplication(unittest.TestCase):
self.assertTrue(application.insert())
def test_overlap(self):
webnotes.session.user = "Administrator"
self._clear_roles()
self._clear_applications()
@ -72,7 +75,6 @@ class TestLeaveApplication(unittest.TestCase):
self.assertRaises(OverlapError, application.insert)
def test_global_block_list(self):
webnotes.session.user = "Administrator"
self._clear_roles()
from webnotes.profile import add_role
@ -98,7 +100,6 @@ class TestLeaveApplication(unittest.TestCase):
"applies_to_all_departments", 0)
def test_leave_approval(self):
webnotes.session.user = "Administrator"
self._clear_roles()
from webnotes.profile import add_role

View File

@ -7,6 +7,9 @@ import unittest
from hr.doctype.leave_block_list.leave_block_list import get_applicable_block_dates
class TestLeaveBlockList(unittest.TestCase):
def tearDown(self):
webnotes.session.user = "Administrator"
def test_get_applicable_block_dates(self):
webnotes.session.user = "test@example.com"
webnotes.conn.set_value("Department", "_Test Department", "leave_block_list",

View File

@ -332,6 +332,7 @@ class DocType:
d.amount = flt(d.rate) * flt(d.qty)
d.qty_consumed_per_unit = flt(d.qty) / flt(self.doc.quantity)
total_rm_cost += d.amount
self.doc.raw_material_cost = total_rm_cost
def update_exploded_items(self):

View File

@ -10,7 +10,7 @@ test_records = [
[
{
"doctype": "BOM",
"item": "_Test Item Home Desktop 100",
"item": "_Test Item Home Desktop Manufactured",
"quantity": 1.0,
"is_active": 1,
"is_default": 1,
@ -58,7 +58,36 @@ test_records = [
"doctype": "BOM Item",
"item_code": "_Test Item Home Desktop 100",
"parentfield": "bom_materials",
"bom_no": "BOM/_Test Item Home Desktop 100/001",
"qty": 2.0,
"rate": 1000.0,
"amount": 2000.0,
"stock_uom": "_Test UOM"
}
],
[
{
"doctype": "BOM",
"item": "_Test FG Item 2",
"quantity": 1.0,
"is_active": 1,
"is_default": 1,
"docstatus": 1
},
{
"doctype": "BOM Item",
"item_code": "_Test Item",
"parentfield": "bom_materials",
"qty": 1.0,
"rate": 5000.0,
"amount": 5000.0,
"stock_uom": "_Test UOM"
},
{
"doctype": "BOM Item",
"item_code": "_Test Item Home Desktop Manufactured",
"bom_no": "BOM/_Test Item Home Desktop Manufactured/001",
"parentfield": "bom_materials",
"qty": 2.0,
"rate": 1000.0,
"amount": 2000.0,
@ -70,21 +99,21 @@ test_records = [
class TestBOM(unittest.TestCase):
def test_get_items(self):
from manufacturing.doctype.bom.bom import get_bom_items_as_dict
items_dict = get_bom_items_as_dict(bom="BOM/_Test FG Item/001", qty=1, fetch_exploded=0)
self.assertTrue(test_records[1][1]["item_code"] in items_dict)
self.assertTrue(test_records[1][2]["item_code"] in items_dict)
items_dict = get_bom_items_as_dict(bom="BOM/_Test FG Item 2/001", qty=1, fetch_exploded=0)
self.assertTrue(test_records[2][1]["item_code"] in items_dict)
self.assertTrue(test_records[2][2]["item_code"] in items_dict)
self.assertEquals(len(items_dict.values()), 2)
def test_get_items_exploded(self):
from manufacturing.doctype.bom.bom import get_bom_items_as_dict
items_dict = get_bom_items_as_dict(bom="BOM/_Test FG Item/001", qty=1, fetch_exploded=1)
self.assertTrue(test_records[1][1]["item_code"] in items_dict)
self.assertFalse(test_records[1][2]["item_code"] in items_dict)
items_dict = get_bom_items_as_dict(bom="BOM/_Test FG Item 2/001", qty=1, fetch_exploded=1)
self.assertTrue(test_records[2][1]["item_code"] in items_dict)
self.assertFalse(test_records[2][2]["item_code"] in items_dict)
self.assertTrue(test_records[0][1]["item_code"] in items_dict)
self.assertTrue(test_records[0][2]["item_code"] in items_dict)
self.assertEquals(len(items_dict.values()), 3)
def test_get_items_list(self):
from manufacturing.doctype.bom.bom import get_bom_items
self.assertEquals(len(get_bom_items(bom="BOM/_Test FG Item/001", qty=1, fetch_exploded=1)), 3)
self.assertEquals(len(get_bom_items(bom="BOM/_Test FG Item 2/001", qty=1, fetch_exploded=1)), 3)

View File

@ -5,15 +5,31 @@ import webnotes, unittest
class TimeLogBatchTest(unittest.TestCase):
def test_time_log_status(self):
self.assertEquals(webnotes.conn.get_value("Time Log", "_T-Time Log-00001", "status"), "Submitted")
tlb = webnotes.bean("Time Log Batch", "_T-Time Log Batch-00001")
from projects.doctype.time_log.test_time_log import test_records as time_log_records
time_log = webnotes.bean(copy=time_log_records[0])
time_log.doc.fields.update({
"from_time": "2013-01-02 10:00:00",
"to_time": "2013-01-02 11:00:00",
"docstatus": 0
})
time_log.insert()
time_log.submit()
self.assertEquals(webnotes.conn.get_value("Time Log", time_log.doc.name, "status"), "Submitted")
tlb = webnotes.bean(copy=test_records[0])
tlb.doclist[1].time_log = time_log.doc.name
tlb.insert()
tlb.submit()
self.assertEquals(webnotes.conn.get_value("Time Log", "_T-Time Log-00001", "status"), "Batched for Billing")
self.assertEquals(webnotes.conn.get_value("Time Log", time_log.doc.name, "status"), "Batched for Billing")
tlb.cancel()
self.assertEquals(webnotes.conn.get_value("Time Log", "_T-Time Log-00001", "status"), "Submitted")
self.assertEquals(webnotes.conn.get_value("Time Log", time_log.doc.name, "status"), "Submitted")
test_records = [[
{"rate": "500"},
{
"doctype": "Time Log Batch",
"rate": "500"
},
{
"doctype": "Time Log Batch Detail",
"parenttype": "Time Log Batch",

View File

@ -17,6 +17,8 @@ class TestCustomer(unittest.TestCase):
(("_Test Customer 1 Renamed",),))
self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer 1"), ())
webnotes.rename_doc("Customer", "_Test Customer 1 Renamed", "_Test Customer 1")
def test_merge(self):
from webnotes.test_runner import make_test_records
make_test_records("Sales Invoice")
@ -57,6 +59,9 @@ class TestCustomer(unittest.TestCase):
# check that old name doesn't exist
self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer"), ())
self.assertEqual(webnotes.conn.exists("Account", "_Test Customer - _TC"), ())
# create back _Test Customer
webnotes.bean(copy=test_records[0]).insert()
test_ignore = ["Price List"]

View File

@ -11,17 +11,19 @@ class TestQuotation(unittest.TestCase):
def test_make_sales_order(self):
from selling.doctype.quotation.quotation import make_sales_order
self.assertRaises(webnotes.ValidationError, make_sales_order, "_T-Quotation-00001")
quotation = webnotes.bean(copy=test_records[0])
quotation.insert()
self.assertRaises(webnotes.ValidationError, make_sales_order, quotation.doc.name)
quotation = webnotes.bean("Quotation","_T-Quotation-00001")
quotation.submit()
sales_order = make_sales_order("_T-Quotation-00001")
sales_order = make_sales_order(quotation.doc.name)
self.assertEquals(sales_order[0]["doctype"], "Sales Order")
self.assertEquals(len(sales_order), 2)
self.assertEquals(sales_order[1]["doctype"], "Sales Order Item")
self.assertEquals(sales_order[1]["prevdoc_docname"], "_T-Quotation-00001")
self.assertEquals(sales_order[1]["prevdoc_docname"], quotation.doc.name)
self.assertEquals(sales_order[0]["customer"], "_Test Customer")
sales_order[0]["delivery_date"] = "2014-01-01"

View File

@ -72,6 +72,10 @@ class TestSalesOrder(unittest.TestCase):
def create_dn_against_so(self, so, delivered_qty=0):
from stock.doctype.delivery_note.test_delivery_note import test_records as dn_test_records
from stock.doctype.delivery_note.test_delivery_note import _insert_purchase_receipt
_insert_purchase_receipt(so.doclist[1].item_code)
dn = webnotes.bean(webnotes.copy_doclist(dn_test_records[0]))
dn.doclist[1].item_code = so.doclist[1].item_code
dn.doclist[1].against_sales_order = so.doc.name
@ -272,14 +276,13 @@ class TestSalesOrder(unittest.TestCase):
so.doclist[1].reserved_warehouse, 20.0)
def test_warehouse_user(self):
webnotes.session.user = "test@example.com"
webnotes.bean("Profile", "test@example.com").get_controller()\
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
webnotes.bean("Profile", "test2@example.com").get_controller()\
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
webnotes.session.user = "test@example.com"
from stock.utils import UserNotAllowedForWarehouse
so = webnotes.bean(copy = test_records[0])

View File

@ -9,20 +9,22 @@ import webnotes.defaults
from webnotes.utils import cint
from stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries, set_perpetual_inventory, test_records as pr_test_records
def _insert_purchase_receipt(item_code=None):
if not item_code:
item_code = pr_test_records[0][1]["item_code"]
pr = webnotes.bean(copy=pr_test_records[0])
pr.doclist[1].item_code = item_code
pr.insert()
pr.submit()
class TestDeliveryNote(unittest.TestCase):
def _insert_purchase_receipt(self, item_code=None):
pr = webnotes.bean(copy=pr_test_records[0])
if item_code:
pr.doclist[1].item_code = item_code
pr.insert()
pr.submit()
def test_over_billing_against_dn(self):
self.clear_stock_account_balance()
self._insert_purchase_receipt()
_insert_purchase_receipt()
from stock.doctype.delivery_note.delivery_note import make_sales_invoice
self._insert_purchase_receipt()
_insert_purchase_receipt()
dn = webnotes.bean(copy=test_records[0]).insert()
self.assertRaises(webnotes.ValidationError, make_sales_invoice,
@ -44,7 +46,7 @@ class TestDeliveryNote(unittest.TestCase):
set_perpetual_inventory(0)
self.assertEqual(cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")), 0)
self._insert_purchase_receipt()
_insert_purchase_receipt()
dn = webnotes.bean(copy=test_records[0])
dn.insert()
@ -69,7 +71,7 @@ class TestDeliveryNote(unittest.TestCase):
self.assertEqual(cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")), 1)
webnotes.conn.set_value("Item", "_Test Item", "valuation_method", "FIFO")
self._insert_purchase_receipt()
_insert_purchase_receipt()
dn = webnotes.bean(copy=test_records[0])
dn.doclist[1].expense_account = "Cost of Goods Sold - _TC"
@ -123,8 +125,8 @@ class TestDeliveryNote(unittest.TestCase):
self.clear_stock_account_balance()
set_perpetual_inventory()
self._insert_purchase_receipt()
self._insert_purchase_receipt("_Test Item Home Desktop 100")
_insert_purchase_receipt()
_insert_purchase_receipt("_Test Item Home Desktop 100")
dn = webnotes.bean(copy=test_records[0])
dn.doclist[1].item_code = "_Test Sales BOM Item"

View File

@ -81,9 +81,9 @@ test_records = [
"is_sales_item": "Yes",
"is_service_item": "No",
"inspection_required": "No",
"is_pro_applicable": "Yes",
"is_pro_applicable": "No",
"is_sub_contracted_item": "No",
"is_manufactured_item": "Yes",
"is_manufactured_item": "No",
"stock_uom": "_Test UOM"
},
{
@ -109,6 +109,7 @@ test_records = [
"inspection_required": "No",
"is_pro_applicable": "No",
"is_sub_contracted_item": "No",
"is_manufactured_item": "No",
"stock_uom": "_Test UOM"
}],
[{
@ -207,4 +208,45 @@ test_records = [
"is_sub_contracted_item": "No",
"stock_uom": "_Test UOM"
}],
[{
"doctype": "Item",
"item_code": "_Test Item Home Desktop Manufactured",
"item_name": "_Test Item Home Desktop Manufactured",
"description": "_Test Item Home Desktop Manufactured",
"item_group": "_Test Item Group Desktops",
"default_warehouse": "_Test Warehouse - _TC",
"default_income_account": "Sales - _TC",
"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",
"inspection_required": "No",
"is_pro_applicable": "Yes",
"is_sub_contracted_item": "No",
"is_manufactured_item": "Yes",
"stock_uom": "_Test UOM"
}],
[{
"doctype": "Item",
"item_code": "_Test FG Item 2",
"item_name": "_Test FG Item 2",
"description": "_Test FG Item 2",
"item_group": "_Test Item Group Desktops",
"is_stock_item": "Yes",
"default_warehouse": "_Test Warehouse - _TC",
"default_income_account": "Sales - _TC",
"is_asset_item": "No",
"has_batch_no": "No",
"has_serial_no": "No",
"is_purchase_item": "Yes",
"is_sales_item": "Yes",
"is_service_item": "No",
"inspection_required": "No",
"is_pro_applicable": "Yes",
"is_sub_contracted_item": "Yes",
"stock_uom": "_Test UOM"
}],
]

View File

@ -76,14 +76,17 @@ class DocType():
sender = self.doc.send_from or webnotes.utils.get_formatted_email(self.doc.owner)
from webnotes.utils.email_lib.bulk import send
webnotes.conn.auto_commit_on_many_writes = True
if not webnotes.flags.in_test:
webnotes.conn.auto_commit_on_many_writes = True
send(recipients = self.recipients, sender = sender,
subject = self.doc.subject, message = self.doc.message,
doctype = self.send_to_doctype, email_field = "email_id",
ref_doctype = self.doc.doctype, ref_docname = self.doc.name)
webnotes.conn.auto_commit_on_many_writes = False
if not webnotes.flags.in_test:
webnotes.conn.auto_commit_on_many_writes = False
def validate_send(self):
if self.doc.fields.get("__islocal"):

View File

@ -45,20 +45,23 @@ test_records =[
"subject": "_Test Newsletter to Lead",
"send_to_type": "Lead",
"lead_source": "All",
"message": "This is a test newsletter"
"message": "This is a test newsletter",
"send_from": "admin@example.com"
}],
[{
"doctype": "Newsletter",
"subject": "_Test Newsletter to Contact",
"send_to_type": "Contact",
"contact_type": "Customer",
"message": "This is a test newsletter"
"message": "This is a test newsletter",
"send_from": "admin@example.com"
}],
[{
"doctype": "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"
"message": "This is a test newsletter",
"send_from": "admin@example.com"
}],
]

View File

@ -426,7 +426,7 @@ def import_data(dt, submit=False, overwrite=False):
for doctype in dt:
print "Importing", doctype.replace("_", " "), "..."
webnotes.form_dict = webnotes._dict()
webnotes.local.form_dict = webnotes._dict()
if submit:
webnotes.form_dict["params"] = json.dumps({"_submit": 1})
webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", doctype+".csv")