fixes to test cases

This commit is contained in:
Anand Doshi 2015-04-06 19:29:16 +05:30
parent 0dc79f4de0
commit c399709789
6 changed files with 73 additions and 61 deletions

View File

@ -55,7 +55,7 @@ class TestPurchaseInvoice(unittest.TestCase):
order by account asc""", pi.name, as_dict=1) order by account asc""", pi.name, as_dict=1)
self.assertTrue(gl_entries) self.assertTrue(gl_entries)
expected_values = sorted([ expected_values = dict((d[0], d) for d in [
["_Test Payable - _TC", 0, 720], ["_Test Payable - _TC", 0, 720],
["Stock Received But Not Billed - _TC", 750.0, 0], ["Stock Received But Not Billed - _TC", 750.0, 0],
["Expenses Included In Valuation - _TC", 0.0, 250.0], ["Expenses Included In Valuation - _TC", 0.0, 250.0],
@ -64,9 +64,9 @@ class TestPurchaseInvoice(unittest.TestCase):
]) ])
for i, gle in enumerate(gl_entries): for i, gle in enumerate(gl_entries):
self.assertEquals(expected_values[i][0], gle.account) self.assertEquals(expected_values[gle.account][0], gle.account)
self.assertEquals(expected_values[i][1], gle.debit) self.assertEquals(expected_values[gle.account][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit) self.assertEquals(expected_values[gle.account][2], gle.credit)
set_perpetual_inventory(0) set_perpetual_inventory(0)
@ -88,7 +88,7 @@ class TestPurchaseInvoice(unittest.TestCase):
order by account asc""", pi.name, as_dict=1) order by account asc""", pi.name, as_dict=1)
self.assertTrue(gl_entries) self.assertTrue(gl_entries)
expected_values = sorted([ expected_values = dict((d[0], d) for d in [
["_Test Payable - _TC", 0, 720], ["_Test Payable - _TC", 0, 720],
["Stock Received But Not Billed - _TC", 500.0, 0], ["Stock Received But Not Billed - _TC", 500.0, 0],
["_Test Account Shipping Charges - _TC", 100.0, 0], ["_Test Account Shipping Charges - _TC", 100.0, 0],
@ -96,9 +96,9 @@ class TestPurchaseInvoice(unittest.TestCase):
]) ])
for i, gle in enumerate(gl_entries): for i, gle in enumerate(gl_entries):
self.assertEquals(expected_values[i][0], gle.account) self.assertEquals(expected_values[gle.account][0], gle.account)
self.assertEquals(expected_values[i][1], gle.debit) self.assertEquals(expected_values[gle.account][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit) self.assertEquals(expected_values[gle.account][2], gle.credit)
set_perpetual_inventory(0) set_perpetual_inventory(0)

View File

@ -4,6 +4,7 @@ from __future__ import unicode_literals
import frappe import frappe
import unittest, copy import unittest, copy
import time
from erpnext.accounts.utils import get_stock_and_account_difference from erpnext.accounts.utils import get_stock_and_account_difference
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
from erpnext.projects.doctype.time_log_batch.test_time_log_batch import * from erpnext.projects.doctype.time_log_batch.test_time_log_batch import *
@ -221,7 +222,7 @@ class TestSalesInvoice(unittest.TestCase):
self.assertTrue(gl_entries) self.assertTrue(gl_entries)
expected_values = sorted([ expected_values = dict((d[0], d) for d in [
[si.debit_to, 1500, 0.0], [si.debit_to, 1500, 0.0],
[test_records[3]["items"][0]["income_account"], 0.0, 1163.45], [test_records[3]["items"][0]["income_account"], 0.0, 1163.45],
[test_records[3]["taxes"][0]["account_head"], 0.0, 130.31], [test_records[3]["taxes"][0]["account_head"], 0.0, 130.31],
@ -235,10 +236,10 @@ class TestSalesInvoice(unittest.TestCase):
["_Test Account Service Tax - _TC", 16.88, 0.0], ["_Test Account Service Tax - _TC", 16.88, 0.0],
]) ])
for i, gle in enumerate(gl_entries): for gle in gl_entries:
self.assertEquals(expected_values[i][0], gle.account) self.assertEquals(expected_values[gle.account][0], gle.account)
self.assertEquals(expected_values[i][1], gle.debit) self.assertEquals(expected_values[gle.account][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit) self.assertEquals(expected_values[gle.account][2], gle.credit)
# cancel # cancel
si.cancel() si.cancel()
@ -439,7 +440,7 @@ class TestSalesInvoice(unittest.TestCase):
self.assertTrue(gl_entries) self.assertTrue(gl_entries)
expected_values = sorted([ expected_values = dict((d[0], d) for d in [
[si.debit_to, 630.0, 0.0], [si.debit_to, 630.0, 0.0],
[test_records[1]["items"][0]["income_account"], 0.0, 500.0], [test_records[1]["items"][0]["income_account"], 0.0, 500.0],
[test_records[1]["taxes"][0]["account_head"], 0.0, 80.0], [test_records[1]["taxes"][0]["account_head"], 0.0, 80.0],
@ -447,9 +448,9 @@ class TestSalesInvoice(unittest.TestCase):
]) ])
for i, gle in enumerate(gl_entries): for i, gle in enumerate(gl_entries):
self.assertEquals(expected_values[i][0], gle.account) self.assertEquals(expected_values[gle.account][0], gle.account)
self.assertEquals(expected_values[i][1], gle.debit) self.assertEquals(expected_values[gle.account][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit) self.assertEquals(expected_values[gle.account][2], gle.credit)
# cancel # cancel
si.cancel() si.cancel()
@ -502,7 +503,8 @@ class TestSalesInvoice(unittest.TestCase):
[si.debit_to, 0.0, 600.0], [si.debit_to, 0.0, 600.0],
["_Test Account Bank Account - _TC", 600.0, 0.0] ["_Test Account Bank Account - _TC", 600.0, 0.0]
]) ])
for i, gle in enumerate(gl_entries):
for i, gle in enumerate(sorted(gl_entries, key=lambda gle: gle.account)):
self.assertEquals(expected_gl_entries[i][0], gle.account) self.assertEquals(expected_gl_entries[i][0], gle.account)
self.assertEquals(expected_gl_entries[i][1], gle.debit) self.assertEquals(expected_gl_entries[i][1], gle.debit)
self.assertEquals(expected_gl_entries[i][2], gle.credit) self.assertEquals(expected_gl_entries[i][2], gle.credit)
@ -574,16 +576,16 @@ class TestSalesInvoice(unittest.TestCase):
order by account asc, debit asc""", si.name, as_dict=1) order by account asc, debit asc""", si.name, as_dict=1)
self.assertTrue(gl_entries) self.assertTrue(gl_entries)
expected_gl_entries = sorted([ expected_gl_entries = dict((d[0], d) for d in [
[si.debit_to, 630.0, 0.0], [si.debit_to, 630.0, 0.0],
[si_doc.get("items")[0]["income_account"], 0.0, 500.0], [si_doc.get("items")[0]["income_account"], 0.0, 500.0],
[si_doc.get("taxes")[0]["account_head"], 0.0, 80.0], [si_doc.get("taxes")[0]["account_head"], 0.0, 80.0],
[si_doc.get("taxes")[1]["account_head"], 0.0, 50.0], [si_doc.get("taxes")[1]["account_head"], 0.0, 50.0],
]) ])
for i, gle in enumerate(gl_entries): for i, gle in enumerate(gl_entries):
self.assertEquals(expected_gl_entries[i][0], gle.account) self.assertEquals(expected_gl_entries[gle.account][0], gle.account)
self.assertEquals(expected_gl_entries[i][1], gle.debit) self.assertEquals(expected_gl_entries[gle.account][1], gle.debit)
self.assertEquals(expected_gl_entries[i][2], gle.credit) self.assertEquals(expected_gl_entries[gle.account][2], gle.credit)
si.cancel() si.cancel()
gle = frappe.db.sql("""select * from `tabGL Entry` gle = frappe.db.sql("""select * from `tabGL Entry`
@ -605,16 +607,16 @@ class TestSalesInvoice(unittest.TestCase):
order by account asc""", si.name, as_dict=1) order by account asc""", si.name, as_dict=1)
self.assertTrue(gl_entries) self.assertTrue(gl_entries)
expected_values = sorted([ expected_values = dict((d[0], d) for d in [
[si.debit_to, 630.0, 0.0], [si.debit_to, 630.0, 0.0],
[test_records[1]["items"][0]["income_account"], 0.0, 500.0], [test_records[1]["items"][0]["income_account"], 0.0, 500.0],
[test_records[1]["taxes"][0]["account_head"], 0.0, 80.0], [test_records[1]["taxes"][0]["account_head"], 0.0, 80.0],
[test_records[1]["taxes"][1]["account_head"], 0.0, 50.0], [test_records[1]["taxes"][1]["account_head"], 0.0, 50.0],
]) ])
for i, gle in enumerate(gl_entries): for i, gle in enumerate(gl_entries):
self.assertEquals(expected_values[i][0], gle.account) self.assertEquals(expected_values[gle.account][0], gle.account)
self.assertEquals(expected_values[i][1], gle.debit) self.assertEquals(expected_values[gle.account][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit) self.assertEquals(expected_values[gle.account][2], gle.credit)
set_perpetual_inventory(0) set_perpetual_inventory(0)
@ -630,16 +632,16 @@ class TestSalesInvoice(unittest.TestCase):
order by account asc""", si.name, as_dict=1) order by account asc""", si.name, as_dict=1)
self.assertTrue(gl_entries) self.assertTrue(gl_entries)
expected_values = sorted([ expected_values = dict((d[0], d) for d in [
[si.debit_to, 630.0, 0.0], [si.debit_to, 630.0, 0.0],
[test_records[1]["items"][0]["income_account"], 0.0, 500.0], [test_records[1]["items"][0]["income_account"], 0.0, 500.0],
[test_records[1]["taxes"][0]["account_head"], 0.0, 80.0], [test_records[1]["taxes"][0]["account_head"], 0.0, 80.0],
[test_records[1]["taxes"][1]["account_head"], 0.0, 50.0], [test_records[1]["taxes"][1]["account_head"], 0.0, 50.0],
]) ])
for i, gle in enumerate(gl_entries): for i, gle in enumerate(gl_entries):
self.assertEquals(expected_values[i][0], gle.account) self.assertEquals(expected_values[gle.account][0], gle.account)
self.assertEquals(expected_values[i][1], gle.debit) self.assertEquals(expected_values[gle.account][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit) self.assertEquals(expected_values[gle.account][2], gle.credit)
set_perpetual_inventory(0) set_perpetual_inventory(0)
@ -733,7 +735,7 @@ class TestSalesInvoice(unittest.TestCase):
"delivery_document_no")) "delivery_document_no"))
def test_serialize_status(self): def test_serialize_status(self):
from erpnext.stock.doctype.serial_no.serial_no import SerialNoStatusError, get_serial_nos from erpnext.stock.doctype.serial_no.serial_no import SerialNoStatusError, get_serial_nos, SerialNoDuplicateError
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item
se = make_serialized_item() se = make_serialized_item()
@ -752,6 +754,9 @@ class TestSalesInvoice(unittest.TestCase):
self.assertRaises(SerialNoStatusError, si.submit) self.assertRaises(SerialNoStatusError, si.submit)
# hack! because stock ledger entires are already inserted and are not rolled back!
self.assertRaises(SerialNoDuplicateError, si.cancel)
def create_sales_invoice(**args): def create_sales_invoice(**args):
si = frappe.new_doc("Sales Invoice") si = frappe.new_doc("Sales Invoice")
args = frappe._dict(args) args = frappe._dict(args)

View File

@ -237,7 +237,11 @@ def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for
if not existing_gle or not compare_existing_and_expected_gle(existing_gle, if not existing_gle or not compare_existing_and_expected_gle(existing_gle,
expected_gle): expected_gle):
_delete_gl_entries(voucher_type, voucher_no) _delete_gl_entries(voucher_type, voucher_no)
try:
voucher_obj.make_gl_entries(repost_future_gle=False) voucher_obj.make_gl_entries(repost_future_gle=False)
except:
print voucher_obj.as_json()
raise
else: else:
_delete_gl_entries(voucher_type, voucher_no) _delete_gl_entries(voucher_type, voucher_no)

View File

@ -197,7 +197,7 @@ def set_defaults(args):
"float_precision": 3, "float_precision": 3,
'date_format': frappe.db.get_value("Country", args.get("country"), "date_format"), 'date_format': frappe.db.get_value("Country", args.get("country"), "date_format"),
'number_format': number_format, 'number_format': number_format,
'enable_scheduler': 1 'enable_scheduler': 1 if not frappe.flags.in_test else 0
}) })
system_settings.save() system_settings.save()

View File

@ -6,9 +6,10 @@ import frappe
from erpnext.setup.page.setup_wizard.test_setup_data import args from erpnext.setup.page.setup_wizard.test_setup_data import args
from erpnext.setup.page.setup_wizard.setup_wizard import setup_account from erpnext.setup.page.setup_wizard.setup_wizard import setup_account
import frappe.utils.scheduler
if __name__=="__main__": if __name__=="__main__":
frappe.connect() frappe.connect()
frappe.local.form_dict = frappe._dict(args) frappe.local.form_dict = frappe._dict(args)
setup_account() setup_account()
frappe.utils.scheduler.disable_scheduler()

View File

@ -105,7 +105,9 @@ def create_stock_reconciliation(**args):
"qty": args.qty, "qty": args.qty,
"valuation_rate": args.rate "valuation_rate": args.rate
}) })
sr.insert() sr.insert()
sr.submit() sr.submit()
return sr return sr