Test case fixes in time log batch
diff --git a/erpnext/projects/doctype/time_log/test_time_log.py b/erpnext/projects/doctype/time_log/test_time_log.py
index 7aadf5c..4a312ad 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 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 d386000..0000000
--- 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 dceaee7..de57f28 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")
-test_records = frappe.get_test_records('Time Log Batch')
-test_dependencies = ["Time Log"]
+ 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_ignore = ["Sales Invoice"]