From d30023abace16b726351a171c29cfec3f42d82f1 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 9 Apr 2020 16:43:13 +0530 Subject: [PATCH] fix: failing tests --- .../test_healthcare_service_unit_type.py | 4 ---- .../inpatient_record/test_inpatient_record.py | 17 +++-------------- .../doctype/patient/test_patient.py | 6 +++--- .../test_patient_appointment.py | 19 +++++++++++-------- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/erpnext/healthcare/doctype/healthcare_service_unit_type/test_healthcare_service_unit_type.py b/erpnext/healthcare/doctype/healthcare_service_unit_type/test_healthcare_service_unit_type.py index 2f019df02a8..01cf4b0a494 100644 --- a/erpnext/healthcare/doctype/healthcare_service_unit_type/test_healthcare_service_unit_type.py +++ b/erpnext/healthcare/doctype/healthcare_service_unit_type/test_healthcare_service_unit_type.py @@ -6,10 +6,6 @@ import unittest import frappe class TestHealthcareServiceUnitType(unittest.TestCase): - def setUp(self): - frappe.db.sql("""delete from `tabHealthcare Service Unit Type`""") - frappe.db.sql("""delete from `tabItem`""") - def test_item_creation(self): unit_type = get_unit_type() self.assertTrue(frappe.db.exists('Item', unit_type.item)) diff --git a/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py b/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py index 6154a745dea..e15324c55bf 100644 --- a/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py +++ b/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py @@ -8,11 +8,12 @@ import unittest from frappe.utils import now_datetime, today from frappe.utils.make_random import get_random from erpnext.healthcare.doctype.inpatient_record.inpatient_record import admit_patient, discharge_patient, schedule_discharge +from erpnext.healthcare.doctype.patient_appointment.test_patient_appointment import create_patient class TestInpatientRecord(unittest.TestCase): def test_admit_and_discharge(self): frappe.db.sql("""delete from `tabInpatient Record`""") - patient = get_patient() + patient = create_patient() # Schedule Admission ip_record = create_inpatient(patient) ip_record.save(ignore_permissions = True) @@ -41,7 +42,7 @@ class TestInpatientRecord(unittest.TestCase): def test_validate_overlap_admission(self): frappe.db.sql("""delete from `tabInpatient Record`""") - patient = get_patient() + patient = create_patient() ip_record = create_inpatient(patient) ip_record.save(ignore_permissions = True) @@ -75,18 +76,6 @@ def create_inpatient(patient): inpatient_record.scheduled_date = today() return inpatient_record -def get_patient(): - patient = get_random("Patient") - if not patient: - patient = frappe.new_doc("Patient") - patient.first_name = "_Test Patient" - patient.sex = "Male" - patient.mobile = 9876345675 - patient.save(ignore_permissions=True) - return patient.name - return patient - - def get_healthcare_service_unit(): service_unit = get_random("Healthcare Service Unit", filters={"inpatient_occupancy": 1}) if not service_unit: diff --git a/erpnext/healthcare/doctype/patient/test_patient.py b/erpnext/healthcare/doctype/patient/test_patient.py index 23695e7467d..9274b6f5e85 100644 --- a/erpnext/healthcare/doctype/patient/test_patient.py +++ b/erpnext/healthcare/doctype/patient/test_patient.py @@ -5,13 +5,13 @@ from __future__ import unicode_literals import unittest import frappe -from erpnext.healthcare.doctype.inpatient_record.test_inpatient_record import get_patient +from erpnext.healthcare.doctype.patient_appointment.test_patient_appointment import create_patient class TestPatient(unittest.TestCase): def test_customer_created(self): frappe.db.sql("""delete from `tabPatient`""") frappe.db.set_value('Healthcare Settings', None, 'link_customer_to_patient', 1) - patient = get_patient() + patient = create_patient() self.assertTrue(frappe.db.get_value('Patient', patient, 'customer')) def test_patient_registration(self): @@ -21,7 +21,7 @@ class TestPatient(unittest.TestCase): settings.registration_fee = 500 settings.save() - patient = get_patient() + patient = create_patient() patient = frappe.get_doc('Patient', patient) self.assertEqual(patient.status, 'Disabled') diff --git a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py index 4668e812879..7075af5d00c 100644 --- a/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/test_patient_appointment.py @@ -58,17 +58,10 @@ class TestPatientAppointment(unittest.TestCase): def create_healthcare_docs(): - patient = get_random('Patient') + patient = create_patient() practitioner = frappe.db.exists('Healthcare Practitioner', '_Test Healthcare Practitioner') medical_department = frappe.db.exists('Medical Department', '_Test Medical Department') - if not patient: - patient = frappe.new_doc('Patient') - patient.first_name = '_Test Patient' - patient.sex = 'Female' - patient.save(ignore_permissions=True) - patient = patient.name - if not medical_department: medical_department = frappe.new_doc('Medical Department') medical_department.department = '_Test Medical Department' @@ -87,6 +80,16 @@ def create_healthcare_docs(): return patient, medical_department, practitioner +def create_patient(): + patient = frappe.db.exists('Patient', '_Test Patient') + if not patient: + patient = frappe.new_doc('Patient') + patient.first_name = '_Test Patient' + patient.sex = 'Female' + patient.save(ignore_permissions=True) + patient = patient.name + return patient + def create_encounter(appointment=None): encounter = frappe.new_doc('Patient Encounter') if appointment: