From 7e373010d7d507eb80a85ba05b04325a5aa6c8ea Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Sun, 11 May 2014 12:08:39 +0530 Subject: [PATCH] Test case fixes in time log batch --- .../doctype/time_log/test_time_log.py | 6 ++ .../doctype/time_log_batch/test_records.json | 14 ---- .../time_log_batch/test_time_log_batch.py | 75 ++++++++++++------- 3 files changed, 54 insertions(+), 41 deletions(-) delete mode 100644 erpnext/projects/doctype/time_log_batch/test_records.json diff --git a/erpnext/projects/doctype/time_log/test_time_log.py b/erpnext/projects/doctype/time_log/test_time_log.py index 7aadf5c2861..4a312adb41b 100644 --- a/erpnext/projects/doctype/time_log/test_time_log.py +++ b/erpnext/projects/doctype/time_log/test_time_log.py @@ -5,11 +5,17 @@ import frappe import unittest from erpnext.projects.doctype.time_log.time_log import OverlapError +from erpnext.projects.doctype.time_log_batch.test_time_log_batch import * class TestTimeLog(unittest.TestCase): def test_duplication(self): + frappe.db.sql("delete from `tabTime Log`") + frappe.get_doc(frappe.copy_doc(test_records[0])).insert() + ts = frappe.get_doc(frappe.copy_doc(test_records[0])) self.assertRaises(OverlapError, ts.insert) + frappe.db.sql("delete from `tabTime Log`") + test_records = frappe.get_test_records('Time Log') test_ignore = ["Time Log Batch", "Sales Invoice"] diff --git a/erpnext/projects/doctype/time_log_batch/test_records.json b/erpnext/projects/doctype/time_log_batch/test_records.json deleted file mode 100644 index d386000e34a..00000000000 --- a/erpnext/projects/doctype/time_log_batch/test_records.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "doctype": "Time Log Batch", - "rate": "500", - "time_log_batch_details": [ - { - "doctype": "Time Log Batch Detail", - "parentfield": "time_log_batch_details", - "parenttype": "Time Log Batch", - "time_log": "_T-Time Log-00001" - } - ] - } -] \ No newline at end of file diff --git a/erpnext/projects/doctype/time_log_batch/test_time_log_batch.py b/erpnext/projects/doctype/time_log_batch/test_time_log_batch.py index dceaee78ff5..de57f28e2cb 100644 --- a/erpnext/projects/doctype/time_log_batch/test_time_log_batch.py +++ b/erpnext/projects/doctype/time_log_batch/test_time_log_batch.py @@ -4,36 +4,57 @@ import frappe, unittest class TimeLogBatchTest(unittest.TestCase): - def setUp(self): - for name in frappe.db.sql_list("select name from `tabTime Log Batch` where docstatus=1"): - frappe.get_doc("Time Log Batch", name).cancel() - frappe.delete_doc("Time Log Batch", name) - - for name in frappe.db.sql_list("select name from `tabTime Log` where docstatus=1"): - frappe.get_doc("Time Log", name).cancel() - frappe.delete_doc("Time Log", name) - def test_time_log_status(self): - from erpnext.projects.doctype.time_log.test_time_log import test_records as time_log_records - time_log = frappe.copy_doc(time_log_records[0]) - time_log.update({ - "from_time": "2013-01-02 10:00:00.000000", - "to_time": "2013-01-02 11:00:00.000000", - "docstatus": 0 - }) - time_log.insert() - time_log.submit() + delete_time_log_and_batch() + time_log = create_time_log() - self.assertEquals(frappe.db.get_value("Time Log", time_log.name, "status"), "Submitted") - tlb = frappe.copy_doc(test_records[0]) - tlb.get("time_log_batch_details")[0].time_log = time_log.name - tlb.insert() - tlb.submit() + self.assertEquals(frappe.db.get_value("Time Log", time_log, "status"), "Submitted") - self.assertEquals(frappe.db.get_value("Time Log", time_log.name, "status"), "Batched for Billing") + tlb = create_time_log_batch(time_log) + + self.assertEquals(frappe.db.get_value("Time Log", time_log, "status"), "Batched for Billing") tlb.cancel() - self.assertEquals(frappe.db.get_value("Time Log", time_log.name, "status"), "Submitted") + self.assertEquals(frappe.db.get_value("Time Log", time_log, "status"), "Submitted") + + delete_time_log_and_batch() + +def delete_time_log_and_batch(): + for name in frappe.db.sql_list("select name from `tabTime Log Batch` where docstatus=1"): + frappe.get_doc("Time Log Batch", name).cancel() + frappe.delete_doc("Time Log Batch", name) + + for name in frappe.db.sql_list("select name from `tabTime Log` where docstatus=1"): + frappe.get_doc("Time Log", name).cancel() + frappe.delete_doc("Time Log", name) + +def create_time_log(): + from erpnext.projects.doctype.time_log.test_time_log import test_records as time_log_records + time_log = frappe.copy_doc(time_log_records[0]) + time_log.update({ + "from_time": "2013-01-02 10:00:00.000000", + "to_time": "2013-01-02 11:00:00.000000", + "docstatus": 0 + }) + time_log.insert() + time_log.submit() + return time_log.name + +def create_time_log_batch(time_log): + tlb = frappe.get_doc({ + "doctype": "Time Log Batch", + "rate": "500", + "time_log_batch_details": [ + { + "doctype": "Time Log Batch Detail", + "parentfield": "time_log_batch_details", + "parenttype": "Time Log Batch", + "time_log": time_log + } + ] + }) + + tlb.insert() + tlb.submit() + return tlb -test_records = frappe.get_test_records('Time Log Batch') -test_dependencies = ["Time Log"] test_ignore = ["Sales Invoice"]