fixes in Test Cases

This commit is contained in:
Neil Trini Lasrado 2015-04-14 12:43:17 +05:30
parent 9789d06b3e
commit 05f15bbb88
6 changed files with 30 additions and 24 deletions

View File

@ -9,8 +9,8 @@ test_records = frappe.get_test_records('Expense Claim')
class TestExpenseClaim(unittest.TestCase):
def test_total_expense_claim_for_project(self):
frappe.db.sql("delete from `tabTask`")
frappe.db.sql("delete from `tabProject`")
frappe.db.sql("""delete from `tabTask` where project = "_Test Project 1" """)
frappe.db.sql("""delete from `tabProject` where name = "_Test Project 1" """)
frappe.get_doc({
"project_name": "_Test Project 1",

View File

@ -7,7 +7,7 @@
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "",
"document_type": "Master",
"fields": [
{
"allow_on_submit": 0,
@ -135,7 +135,7 @@
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"modified": "2015-04-01 02:06:37.510007",
"modified": "2015-04-14 02:08:33.690406",
"modified_by": "Administrator",
"module": "Projects",
"name": "Activity Cost",

View File

@ -7,6 +7,8 @@ import frappe
from frappe import _
from frappe.model.document import Document
class DuplicationError(frappe.ValidationError): pass
class ActivityCost(Document):
def validate(self):
self.set_title()
@ -19,4 +21,4 @@ class ActivityCost(Document):
if frappe.db.sql("""select name from `tabActivity Cost` where employee_name= %s and activity_type= %s and name != %s""",
(self.employee_name, self.activity_type, self.name)):
frappe.throw(_("Activity Cost exists for Employee {0} against Activity Type - {1}")
.format(self.employee, self.activity_type))
.format(self.employee, self.activity_type), DuplicationError)

View File

@ -6,7 +6,19 @@ from __future__ import unicode_literals
import frappe
import unittest
test_records = frappe.get_test_records('Activity Cost')
from erpnext.projects.doctype.activity_cost.activity_cost import DuplicationError
class TestActivityCost(unittest.TestCase):
pass
def test_duplication(self):
frappe.db.sql("delete from `tabActivity Cost`")
activity_cost1 = frappe.new_doc('Activity Cost')
activity_cost1.update({
"employee": "_T-Employee-0001",
"employee_name": "_Test Employee",
"activity_type": "_Test Activity Type",
"billing_rate": 100,
"costing_rate": 50
})
activity_cost1.insert()
activity_cost2 = frappe.copy_doc(activity_cost1)
self.assertRaises(DuplicationError, activity_cost2.insert )

View File

@ -1,9 +1 @@
[
{
"employee": "_T-Employee-0001",
"employee_name": "_Test Employee",
"activity_type": "_Test Activity Type",
"billing_rate": 100,
"costing_rate": 50
}
]
[]

View File

@ -86,8 +86,8 @@ class TestTimeLog(unittest.TestCase):
frappe.db.sql("delete from `tabTime Log`")
def test_total_activity_cost_for_project(self):
frappe.db.sql("delete from `tabTask`")
frappe.db.sql("delete from `tabProject`")
frappe.db.sql("""delete from `tabTask` where project = "_Test Project 1" """)
frappe.db.sql("""delete from `tabProject` where name = "_Test Project 1" """)
frappe.get_doc({
"project_name": "_Test Project 1",
@ -116,8 +116,8 @@ class TestTimeLog(unittest.TestCase):
self.assertEqual(time_log.billing_amount, 200)
time_log.submit()
self.assertEqual(frappe.db.get_value("Task", task_name, "actual_cost"), 200)
self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_activity_cost"), 200)
self.assertEqual(frappe.db.get_value("Task", task_name, "total_billing_amount"), 200)
self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_billing_amount"), 200)
time_log2 = frappe.get_doc({
"activity_type": "_Test Activity Type",
@ -132,13 +132,13 @@ class TestTimeLog(unittest.TestCase):
})
time_log2.save()
self.assertEqual(frappe.db.get_value("Task", task_name, "actual_cost"), 400)
self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_activity_cost"), 400)
self.assertEqual(frappe.db.get_value("Task", task_name, "total_billing_amount"), 400)
self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_billing_amount"), 400)
time_log2.cancel()
self.assertEqual(frappe.db.get_value("Task", task_name, "actual_cost"), 200)
self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_activity_cost"), 200)
self.assertEqual(frappe.db.get_value("Task", task_name, "total_billing_amount"), 200)
self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_billing_amount"), 200)
test_records = frappe.get_test_records('Time Log')
test_ignore = ["Time Log Batch", "Sales Invoice"]