diff --git a/.gitignore b/.gitignore index 8c29650..795ebda 100644 --- a/.gitignore +++ b/.gitignore @@ -93,9 +93,5 @@ ENV/ # OS X *.DS_Store -*.idea -# Telegram Bot SSL settings -cert.pem -private.key .idea/ diff --git a/README.md b/README.md index 777a3da..bdc5873 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,19 @@ Install the dependencies by running `$ pip install -r requirements.txt` ### Tests -Use nosetests to run tests (with stdout) like this: -```$ nosetests --nocapture``` - +Use nosetests to run tests (with stdout) like so: + +```sh +$ nosetests --nocapture +$ nosetests healthtools/tests +$ nosetests healthtools/tests/doctor.py +$ nosetests healthtools/tests/nurse.py +$ nosetests healthtools/tests/clinical_officer.py +$ nosetests healthtools/tests/health_facilities.py +$ nosetests healthtools/tests/nhif_inpatient.py +$ nosetests healthtools/tests/nhif_outpatient.py +$ nosetests healthtools/tests/nhif_outpatient_cs.py +``` ## Contributing diff --git a/healthtools/tests/clinical_officer.py b/healthtools/tests/clinical_officer.py new file mode 100644 index 0000000..7e2e53a --- /dev/null +++ b/healthtools/tests/clinical_officer.py @@ -0,0 +1,71 @@ +""" +This test for clinical officers end point +""" +import unittest +from healthtools.manage import app + +class TestSetup(unittest.TestCase): + def setUp(self): + self.client = app.test_client() + +class TestClinicalOfficersAPIWithDoctype(TestSetup): + """ + This tests clinical officers search api with doctype + """ + def test_cos_endpoint_without_query(self): + """ + This tests running cos endpoint with valid doctype and no query + """ + response = self.client.get("search/clinical-officers?q=") + self.assertIn(b"ELIKANAH KEBAGENDI OMWENGA", response.data) + + + def test_cos_endpoint_gets_clinical_officers(self): + """ + This tests running cos endpoint with valid doctype and query + """ + response = self.client.get("search/clinical-officers?q=DABASO GARAMBODA") + self.assertIn(b"OK", response.data) + + def test_cos_endpoint_with_bad_endpoint(self): + """ + This tests running an endpoint with incorrect/unavailable doctype + """ + response = self.client.get("search/clinicalofficers?q=DABASO GARAMBODA") + self.assertIn(b'"status": "FAILED"', response.data) + + +class TestClinicalOfficersAPIWithoutDoctype(TestSetup): + """ + This tests clinical officers search api without doctype, keywords are used instead + """ + def test_cos_endpoint_without_keyword_in_query(self): + response = self.client.get("search?q=john") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_cos_endpoint_gets_clinical_officers(self): + response = self.client.get("search?q=clinical oficer DABASO GARAMBODA") + self.assertIn(b"OK", response.data) + + def test_cos_endpoint_with_keyword_only(self): + """ + This tests running cos endpoint with correct available keyword only + """ + response = self.client.get("search?q=CO") + self.assertIn(b'"status": "FAILED"', response.data) + + + def test_cos_endpoint_without_query(self): + """ + This tests running cos endpoint without query + """ + response = self.client.get("search?q=") + self.assertIn(b'"status": "FAILED"', response.data) + + + def test_cos_endpoint_with_nonkeyword(self): + """ + This tests running cos endpoint with a keyword that is unavailable. + """ + response = self.client.get("search?q=maji john") + self.assertIn(b'"status": "FAILED"', response.data) diff --git a/healthtools/tests/doctor.py b/healthtools/tests/doctor.py new file mode 100644 index 0000000..786a034 --- /dev/null +++ b/healthtools/tests/doctor.py @@ -0,0 +1,71 @@ +""" +This test for doctors end point +""" +import unittest +from healthtools.manage import app + +class TestSetup(unittest.TestCase): + def setUp(self): + self.client = app.test_client() + +class TestDoctorsAPIWithDoctype(TestSetup): + """ + This tests doctors search api with doctype + """ + + def test_doctors_endpoint_without_query(self): + """ + This tests running doctors endpoint with valid doctype and no query + """ + response = self.client.get("search/doctors?q=") + self.assertIn(b"DR NARAYAN VIJAYA KUMAR", response.data) + + + def test_doctors_endpoint_gets_doctors(self): + """ + This tests running doctors endpoint with valid doctype and query + """ + response = self.client.get("search/doctors?q=john") + self.assertIn(b"OK", response.data) + + def test_doctors_endpoint_with_bad_endpoint(self): + """ + This tests running an endpoint with incorrect/unavailable doctype + """ + response = self.client.get("search/doctor?q=john") + self.assertIn(b'"status": "FAILED"', response.data) + +class TestDoctorsAPIWithoutDoctype(TestSetup): + """ + This tests doctors search api without doctype, keywords are used instead + """ + def test_doctors_endpoint_without_keyword_in_query(self): + response = self.client.get("search?q=john") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_doctors_endpoint_gets_doctors(self): + response = self.client.get("search?q=daktari John") + self.assertIn(b"OK", response.data) + + def test_doctors_endpoint_with_keyword_only(self): + """ + This tests running doctors endpoint with correct available keyword only + """ + response = self.client.get("search?q=daktari") + self.assertIn(b'"status": "FAILED"', response.data) + + + def test_doctors_endpoint_without_query(self): + """ + This tests running doctors endpoint without query + """ + response = self.client.get("search?q=") + self.assertIn(b'"status": "FAILED"', response.data) + + + def test_doctors_endpoint_with_nonkeyword(self): + """ + This tests running doctors endpoint with a keyword that is unavailable. + """ + response = self.client.get("search?q=maji john") + self.assertIn(b'"status": "FAILED"', response.data) diff --git a/healthtools/tests/health_facilities.py b/healthtools/tests/health_facilities.py new file mode 100644 index 0000000..1e4e676 --- /dev/null +++ b/healthtools/tests/health_facilities.py @@ -0,0 +1,72 @@ +""" +This test for health facilitites end point +""" +import unittest +from healthtools.manage import app + + +class TestSetup(unittest.TestCase): + def setUp(self): + self.client = app.test_client() + + +class TestHealthFacilitiesAPIWithDoctype(TestSetup): + """ + This tests health-facilities search api with doctype + """ + + def test_health_facilities_endpoint_without_query(self): + """ + This tests running health-facilities endpoint with valid doctype and no query + """ + response = self.client.get("search/health-facilities?q=") + self.assertIn(b"Tamba Pwani", response.data) + + def test_health_facilities_endpoint_gets_health_facilities(self): + """ + This tests running health-facilities endpoint with valid doctype and query + """ + response = self.client.get("search/health-facilities?q=eldoret") + self.assertIn(b"OK", response.data) + + def test_health_facilities_endpoint_with_bad_endpoint(self): + """ + This tests running an endpoint with incorrect/unavailable doctype + """ + response = self.client.get("search/healthfacilities?q=Kitale") + self.assertIn(b'"status": "FAILED"', response.data) + + +class TestHealthFacilitiesAPIWithoutDoctype(TestSetup): + """ + This tests health-facilities search api without doctype, keywords are used instead + """ + + def test_health_facilities_endpoint_without_keyword_in_query(self): + response = self.client.get("search?q=kakamega") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_health_facilities_endpoint_gets_health_facilities(self): + response = self.client.get("search?q=dispensary Kilifi") + self.assertIn(b"OK", response.data) + + def test_health_facilities_endpoint_with_keyword_only(self): + """ + This tests running health-facilities endpoint with correct available keyword only + """ + response = self.client.get("search?q=hf") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_health_facilities_endpoint_without_query(self): + """ + This tests running health-facilities endpoint without query + """ + response = self.client.get("search?q=") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_health_facilities_endpoint_with_nonkeyword(self): + """ + This tests running health-facilities endpoint with a keyword that is unavailable. + """ + response = self.client.get("search?q=maji Mombasa") + self.assertIn(b'"status": "FAILED"', response.data) diff --git a/healthtools/tests/nhif_inpatient.py b/healthtools/tests/nhif_inpatient.py new file mode 100644 index 0000000..585bbbc --- /dev/null +++ b/healthtools/tests/nhif_inpatient.py @@ -0,0 +1,72 @@ +""" +This test for nhif inpatient end point +""" +import unittest +from healthtools.manage import app + + +class TestSetup(unittest.TestCase): + def setUp(self): + self.client = app.test_client() + + +class TestNhifInpatientAPIWithDoctype(TestSetup): + """ + This tests nhif-inpatient search api with doctype + """ + + def test_nhif_inpatient_endpoint_without_query(self): + """ + This tests running nhif-inpatient endpoint with valid doctype and no query + """ + response = self.client.get("search/nhif-inpatient?q=") + self.assertIn(b"MARIE STOPES KENYA LIMITED", response.data) + + def test_nhif_inpatient_endpoint_gets_nhif_inpatient(self): + """ + This tests running nhif-inpatient endpoint with valid doctype and query + """ + response = self.client.get("search/nhif-inpatient?q=MATHARE") + self.assertIn(b"OK", response.data) + + def test_nhif_inpatient_endpoint_with_bad_endpoint(self): + """ + This tests running an endpoint with incorrect/unavailable doctype + """ + response = self.client.get("search/nhifinpatient?q=MATHARE") + self.assertIn(b'"status": "FAILED"', response.data) + + +class TestNhifInpatientAPIWithoutDoctype(TestSetup): + """ + This tests nhif-inpatient search api without doctype, keywords are used instead + """ + + def test_nhif_inpatient_endpoint_without_keyword_in_query(self): + response = self.client.get("search?q=Kilifi") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nhif_inpatient_endpoint_gets_nhif_inpatient(self): + response = self.client.get("search?q=bima inpatient Kilifi") + self.assertIn(b"OK", response.data) + + def test_nhif_inpatient_endpoint_with_keyword_only(self): + """ + This tests running nhif-inpatient endpoint with correct available keyword only + """ + response = self.client.get("search?q=inpatient insurance") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nhif_inpatient_endpoint_without_query(self): + """ + This tests running nhif-inpatient endpoint without query + """ + response = self.client.get("search?q=") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nhif_inpatient_endpoint_with_nonkeyword(self): + """ + This tests running nhif-inpatient endpoint with a keyword that is unavailable. + """ + response = self.client.get("search?q=maji Kilifi") + self.assertIn(b'"status": "FAILED"', response.data) diff --git a/healthtools/tests/nhif_outpatient.py b/healthtools/tests/nhif_outpatient.py new file mode 100644 index 0000000..b37b036 --- /dev/null +++ b/healthtools/tests/nhif_outpatient.py @@ -0,0 +1,72 @@ +""" +This test for nhif outpatient end point +""" +import unittest +from healthtools.manage import app + + +class TestSetup(unittest.TestCase): + def setUp(self): + self.client = app.test_client() + + +class TestNhifOutpatientAPIWithDoctype(TestSetup): + """ + This tests nhif-outpatient search api with doctype + """ + + def test_nhif_outpatient_endpoint_without_query(self): + """ + This tests running nhif-outpatient endpoint with valid doctype and no query + """ + response = self.client.get("search/nhif-outpatient?q=") + self.assertIn(b"AMIN WOMEN'S CARE CLINIC", response.data) + + def test_nhif_outpatient_endpoint_gets_nhif_outpatient(self): + """ + This tests running nhif-outpatient endpoint with valid doctype and query + """ + response = self.client.get("search/nhif-outpatient?q=BRISTOL") + self.assertIn(b"OK", response.data) + + def test_nhif_outpatient_endpoint_with_bad_endpoint(self): + """ + This tests running an endpoint with incorrect/unavailable doctype + """ + response = self.client.get("search/nhifoutpatient?q=BRISTOL") + self.assertIn(b'"status": "FAILED"', response.data) + + +class TestNhifOutpatientAPIWithoutDoctype(TestSetup): + """ + This tests nhif-outpatient search api without doctype, keywords are used instead + """ + + def test_nhif_outpatient_endpoint_without_keyword_in_query(self): + response = self.client.get("search?q=Kenyatta") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nhif_outpatient_endpoint_gets_nhif_outpatient(self): + response = self.client.get("search?q=bima outpatient Kilifi") + self.assertIn(b"OK", response.data) + + def test_nhif_outpatient_endpoint_with_keyword_only(self): + """ + This tests running nhif-outpatient endpoint with correct available keyword only + """ + response = self.client.get("search?q=outpatient insurance") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nhif_outpatient_endpoint_without_query(self): + """ + This tests running nhif-outpatient endpoint without query + """ + response = self.client.get("search?q=") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nhif_outpatient_endpoint_with_nonkeyword(self): + """ + This tests running nhif-outpatient endpoint with a keyword that is unavailable. + """ + response = self.client.get("search?q=maji Kilifi") + self.assertIn(b'"status": "FAILED"', response.data) diff --git a/healthtools/tests/nhif_outpatient_cs.py b/healthtools/tests/nhif_outpatient_cs.py new file mode 100644 index 0000000..d24196e --- /dev/null +++ b/healthtools/tests/nhif_outpatient_cs.py @@ -0,0 +1,71 @@ +""" +This test for nhif outpatient cs end point +""" +import unittest +from healthtools.manage import app + + +class TestSetup(unittest.TestCase): + def setUp(self): + self.client = app.test_client() + + +class TestNhifOutpatientAPIWithDoctype(TestSetup): + """ + This tests nhif-outpatient-cs search api with doctype + """ + + def test_nhif_outpatient_cs_endpoint_without_query(self): + """ + This tests running nhif-outpatient-cs endpoint with valid doctype and no query + """ + response = self.client.get("search/nhif-outpatient-cs?q=") + self.assertIn(b"AMIN WOMEN'S CARE CLINIC", response.data) + + def test_nhif_outpatient_cs_endpoint_gets_nhif_outpatient_cs(self): + """ + This tests running nhif-outpatient-cs endpoint with valid doctype and query + """ + response = self.client.get("search/nhif-outpatient-cs?q=BRISTOL") + self.assertIn(b"OK", response.data) + + def test_nhif_outpatient_cs_endpoint_with_bad_endpoint(self): + """ + This tests running an endpoint with incorrect/unavailable doctype + """ + response = self.client.get("search/nhifoutpatient-cs?q=BRISTOL") + self.assertIn(b'"status": "FAILED"', response.data) + +class TestNhifOutpatientAPIWithoutDoctype(TestSetup): + """ + This tests nhif-outpatient-cs search api without doctype, keywords are used instead + """ + + def test_nhif_outpatient_cs_endpoint_without_keyword_in_query(self): + response = self.client.get("search?q=Kenyatta") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nhif_outpatient_cs_endpoint_gets_nhif_outpatient_cs(self): + response = self.client.get("search?q=bima outpatient-cs Kilifi") + self.assertIn(b"OK", response.data) + + def test_nhif_outpatient_cs_endpoint_with_keyword_only(self): + """ + This tests running nhif-outpatient-cs endpoint with correct available keyword only + """ + response = self.client.get("search?q=outpatient-cs insurance") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nhif_outpatient_cs_endpoint_without_query(self): + """ + This tests running nhif-outpatient-cs endpoint without query + """ + response = self.client.get("search?q=") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nhif_outpatient_cs_endpoint_with_nonkeyword(self): + """ + This tests running nhif-outpatient-cs endpoint with a keyword that is unavailable. + """ + response = self.client.get("search?q=maji Kilifi") + self.assertIn(b'"status": "FAILED"', response.data) diff --git a/healthtools/tests/nurse.py b/healthtools/tests/nurse.py new file mode 100644 index 0000000..bd4ef69 --- /dev/null +++ b/healthtools/tests/nurse.py @@ -0,0 +1,103 @@ +""" +This test for nurses end point +""" +import unittest +from healthtools.manage import app +from healthtools.search.nurses import get_nurses_from_nc_registry + +class TestSetup(unittest.TestCase): + def setUp(self): + self.client = app.test_client() + +class TestNurseRegistery(TestSetup): + """ + This tests nurses search api with defined doctype + """ + def test_gets_nurses_from_nc_registry(self): + nurses = get_nurses_from_nc_registry("Marie") + self.assertTrue(len(nurses) > 0) + + def test_gets_nurses_from_nc_registry_handle_inexistent_nurse(self): + nurses = get_nurses_from_nc_registry("ihoafiho39023u8") + self.assertEqual(len(nurses), 0) + + +class TestNursesAPI(TestSetup): + """ + This tests nurses search api with defined doctype + """ + + def test_nurses_endpoint_handles_bad_query(self): + """ + This tests running nurses endpoint with valid doctype and no query + """ + response = self.client.get("search/nurses?q=") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nurses_endpoint_gets_nurses(self): + response = self.client.get("search/nurses?q=Marie") + self.assertIn(b"OK", response.data) + + def test_nurses_endpoint_can_retrieve_cached_result(self): + # call once + self.client.get("search/nurses?q=Marie") + # second time should retrieve cached result + response = self.client.get("search/nurses?q=Marie") + self.assertIn(b"X-Retrieved-From-Cache", response.headers.keys()) + + def test_nurses_endpoint_with_bad_endpoint(self): + """ + This tests running an endpoint with incorrect/unavailable doctype + """ + response = self.client.get("search/nurse?q=Marie") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nurses_endpoint_with_unavailable_query(self): + """ + This tests running nurses endpoint with correct doctype but unavailable query + """ + response = self.client.get("search/nurses?q=1234") + self.assertIn(b'"status": "FAILED"', response.data) + +class TestNursesAPIWithoutDoctypes(TestSetup): + """ + This tests nurses search api without doctype, keywords are used instead + """ + def test_nurses_endpoint_endpoint_without_keyword_in_query(self): + response = self.client.get("search?q=Marie") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nurses_endpoint_gets_nurses(self): + response = self.client.get("search?q=nurse Marie") + self.assertIn(b"OK", response.data) + self.assertIn(b"MARIE WANJUGU MURIGO", response.data) + + def test_nurses_endpoint_with_unavailable_query(self): + """ + This tests running nurses endpoint with correct available keyword but unavailable query + """ + response = self.client.get("search?q=Registered Nurse 1234") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nurses_cs_endpoint_with_keyword_only(self): + """ + This tests running nurses endpoint with correct available keyword only + """ + response = self.client.get("search?q=nursing officer") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nurses_endpoint_without_query(self): + """ + This tests running nurses endpoint without query + """ + response = self.client.get("search?q=") + self.assertIn(b'"status": "FAILED"', response.data) + + def test_nurses_endpoint_with_nonkeyword(self): + """ + This tests running nurses endpoint with a keyword that is unavailable. + """ + response = self.client.get("search?q=kijana Marie") + self.assertIn(b'"status": "FAILED"', response.data) + +