def _setup_users(self): hsa = create_hsa(self, "16175551000", "wendy", products="la lb zi") ic = create_manager(self, "16175551001", "sally") sh = create_manager(self, "16175551004", "robert", config.Roles.HSA_SUPERVISOR) im = create_manager(self, "16175551002", "peter", config.Roles.IMCI_COORDINATOR, "26") dp = create_manager(self, "16175551003", "ruth", config.Roles.DISTRICT_PHARMACIST, "26") return (hsa, ic, sh, im, dp)
def testRolesAndOperations(self): create_hsa(self, "5551111", "hsa") create_manager(self, "5551112", "charles") # in charge! create_manager(self, "5551113", "pill pusher", "dp", facility_code="26") a = """ 5551111 > ready 100100 5551111 < %(bad_perms)s 5551111 > os 100100 5551111 < %(bad_perms)s 5551112 > soh la 200 5551112 < %(bad_perms)s 5551112 > eo la 200 5551112 < %(bad_perms)s 5551112 > add zi 5551112 < %(bad_perms)s 5551112 > remove zi 5551112 < %(bad_perms)s 5551112 > rec la 200 5551112 < %(bad_perms)s 5551112 > give 100101 la 200 5551112 < %(bad_perms)s 5551112 > confirm 5551112 < %(bad_perms)s """ % {"bad_perms": config.Messages.UNSUPPORTED_OPERATION} self.runScript(a)
def testReportEmergencyForAnotherHSA(self): create_manager(self, "16175551234", "charles", role="ic") create_hsa(self, "16175551000", "joe") create_hsa(self, "16175551001", "phoneless", "2") a = """ 16175551000 > report 261602 eo zi 40 la 200 16175551000 < %(response)s 16175551234 < %(super)s """ % {"response": config.Messages.EMERGENCY_SOH % \ {"products": "zi la"}, "super": config.Messages.SUPERVISOR_EMERGENCY_SOH_NOTIFICATION % \ {"hsa": "phoneless", "emergency_products": "zi 160", "normal_products": "la 160", "hsa_id": "261602"}} self.runScript(a) hsa_sp = SupplyPoint.objects.get(code="261602") self.assertEqual(40, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="zi").quantity) self.assertEqual(200, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="la").quantity) self.assertEqual(2, StockRequest.objects.count()) for req in StockRequest.objects.all(): self.assertEqual(hsa_sp, req.supply_point) self.assertEqual(StockRequestStatus.REQUESTED, req.status) self.assertTrue(req.is_pending()) if req.is_emergency: self.assertTrue(Product.by_code("zi"), req.product) else: self.assertTrue(Product.by_code("la"), req.product)
def testRolesAndOperations(self): create_hsa(self, "5551111", "hsa") create_manager(self, "5551112", "charles") # in charge! create_manager(self, "5551113", "pill pusher", "dp", facility_code="26") a = """ 5551111 > ready 100100 5551111 < %(bad_perms)s 5551111 > os 100100 5551111 < %(bad_perms)s 5551112 > soh la 200 5551112 < %(bad_perms)s 5551112 > eo la 200 5551112 < %(bad_perms)s 5551112 > add zi 5551112 < %(bad_perms)s 5551112 > remove zi 5551112 < %(bad_perms)s 5551112 > rec la 200 5551112 < %(bad_perms)s 5551112 > give 100101 la 200 5551112 < %(bad_perms)s 5551112 > confirm 5551112 < %(bad_perms)s """ % { "bad_perms": config.Messages.UNSUPPORTED_OPERATION } self.runScript(a)
def testReportForAnotherHSA(self): create_manager(self, "16175551234", "charles", role="ic") create_hsa(self, "16175551000", "joe") create_hsa(self, "16175551001", "phoneless", "2") a = """ 16175551000 > report 261602 soh zi 40 la 200 16175551000 < %(response)s 16175551234 < %(super)s """ % {"response": config.Messages.SOH_ORDER_CONFIRM % \ {"contact": "joe", "products": "zi la"}, "super": config.Messages.SUPERVISOR_SOH_NOTIFICATION % \ {"hsa": "phoneless", "products": "zi 160, la 160", "hsa_id": "261602"}} self.runScript(a) hsa_sp = SupplyPoint.objects.get(code="261602") self.assertEqual( 40, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="zi").quantity) self.assertEqual( 200, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="la").quantity) self.assertEqual(2, StockRequest.objects.count()) for req in StockRequest.objects.all(): self.assertEqual(hsa_sp, req.supply_point) self.assertEqual(StockRequestStatus.REQUESTED, req.status) self.assertTrue(req.is_pending()) self.assertFalse(req.is_emergency)
def testSohAndReceiptReporting(self): create_manager(self, "16175551234", "charles", role="ic") create_hsa(self, "16175551000", "joe") a = """ 16175551234 > report 261601 soh zi 40 la 200 16175551234 < joe needs the following products: zi 160, la 160. Type 'report 261601 rec [prod code] [amount]' to report receipts for the HSA. """ self.runScript(a) hsa_sp = SupplyPoint.objects.get(code=261601) self.assertEqual(40, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="zi").quantity) self.assertEqual(200, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="la").quantity) self.assertEqual(2, StockRequest.objects.count()) for req in StockRequest.objects.all(): self.assertEqual(hsa_sp, req.supply_point) self.assertEqual(StockRequestStatus.REQUESTED, req.status) self.assertTrue(req.is_pending()) b = """ 16175551234 > report 261601 rec zi 160 la 160 16175551234 < Thank you charles. You reported the following receipts for joe: zi la """ self.runScript(b) self.assertEqual(200, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="zi").quantity) self.assertEqual(360, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="la").quantity) self.assertEqual(2, StockRequest.objects.count()) for req in StockRequest.objects.all(): self.assertEqual(hsa_sp, req.supply_point) self.assertEqual(StockRequestStatus.RECEIVED, req.status) self.assertFalse(req.is_pending())
def testBadHsaId(self): create_manager(self, "16175551234", "charles", role="ic") a = """ 16175551234 > report 261601 soh zi 40 la 200 16175551234 < %(bad_hsa)s """ % {"bad_hsa": config.Messages.UNKNOWN_HSA % {"hsa_id": 261601}} self.runScript(a)
def testBadRoles(self): create_manager(self, "16175551234", "cindy") create_hsa(self, "16175551235", "alex", products="zi") a = """ 16175551234 > give 261601 zi 20 16175551234 < %(bad_role)s 16175551235 > give 2616 zi 20 16175551235 < Cannot find hsa with id 2616. Please double check the id and try again. """ % {"bad_role": config.Messages.UNSUPPORTED_OPERATION} self.runScript(a)
def testReceiptReporting(self): create_manager(self, "16175551234", "charles", role="ic") create_hsa(self, "16175551000", "joe") a = """ 16175551234 > report 261601 rec zi 100 la 400 16175551234 < Thank you charles. You reported the following receipts for joe: zi la """ self.runScript(a) hsa_sp = SupplyPoint.objects.get(code="261601") self.assertEqual(100, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="zi").quantity) self.assertEqual(400, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="la").quantity)
def testBadRoles(self): create_manager(self, "16175551234", "cindy") create_hsa(self, "16175551235", "alex", products="zi") a = """ 16175551234 > give 261601 zi 20 16175551234 < %(bad_role)s 16175551235 > give 2616 zi 20 16175551235 < Cannot find hsa with id 2616. Please double check the id and try again. """ % { "bad_role": config.Messages.UNSUPPORTED_OPERATION } self.runScript(a)
def testBadHsaId(self): create_manager(self, "16175551234", "charles", role="ic") a = """ 16175551234 > report 261601 soh zi 40 la 200 16175551234 < %(bad_hsa)s """ % { "bad_hsa": config.Messages.UNKNOWN_HSA % { "hsa_id": 261601 } } self.runScript(a)
def testNoProductsAdded(self): hsa = create_hsa(self, "16175551000", "wendy", products="") ic = create_manager(self, "16175551001", "sally") a = """ 16175551000 > soh zi 10 16175551000 < %(no_products)s """ % {"no_products": config.Messages.NO_PRODUCTS_MANAGED} self.runScript(a)
def testReceiptReporting(self): create_manager(self, "16175551234", "charles", role="ic") create_hsa(self, "16175551000", "joe") a = """ 16175551234 > report 261601 rec zi 100 la 400 16175551234 < Thank you charles. You reported the following receipts for joe: zi la """ self.runScript(a) hsa_sp = SupplyPoint.objects.get(code="261601") self.assertEqual( 100, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="zi").quantity) self.assertEqual( 400, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="la").quantity)
def testManagerLeave(self): hsa = create_hsa(self, "555555", "somehsa", products="la zi") ic = create_manager(self, "666666", "somemanager") super = create_manager(self, "777777", "somesuper", config.Roles.HSA_SUPERVISOR) report_stock(self, hsa, "zi 10 la 15", [ic, super], "zi 190, la 345") b = """ 666666 > leave 666666 < %(left)s """ % {"left": config.Messages.LEAVE_CONFIRM} self.runScript(b) failed = False try: report_stock(self, hsa, "zi 10 la 15", [ic, super], "zi 190, la 345") except Exception: # this is expected failed = True if not failed: self.fail("Reporting stock should not have notified the supervisor") report_stock(self, hsa, "zi 10 la 15", [super], "zi 190, la 345")
def testSohAndReceiptReporting(self): create_manager(self, "16175551234", "charles", role="ic") create_hsa(self, "16175551000", "joe") a = """ 16175551234 > report 261601 soh zi 40 la 200 16175551234 < joe needs the following products: zi 160, la 160. Type 'report 261601 rec [prod code] [amount]' to report receipts for the HSA. """ self.runScript(a) hsa_sp = SupplyPoint.objects.get(code=261601) self.assertEqual( 40, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="zi").quantity) self.assertEqual( 200, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="la").quantity) self.assertEqual(2, StockRequest.objects.count()) for req in StockRequest.objects.all(): self.assertEqual(hsa_sp, req.supply_point) self.assertEqual(StockRequestStatus.REQUESTED, req.status) self.assertTrue(req.is_pending()) b = """ 16175551234 > report 261601 rec zi 160 la 160 16175551234 < Thank you charles. You reported the following receipts for joe: zi la """ self.runScript(b) self.assertEqual( 200, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="zi").quantity) self.assertEqual( 360, ProductStock.objects.get(supply_point=hsa_sp, product__sms_code="la").quantity) self.assertEqual(2, StockRequest.objects.count()) for req in StockRequest.objects.all(): self.assertEqual(hsa_sp, req.supply_point) self.assertEqual(StockRequestStatus.RECEIVED, req.status) self.assertFalse(req.is_pending())
def testManagerLeave(self): hsa = create_hsa(self, "555555", "somehsa", products="la zi") ic = create_manager(self, "666666", "somemanager") super = create_manager(self, "777777", "somesuper", config.Roles.HSA_SUPERVISOR) report_stock(self, hsa, "zi 10 la 15", [ic, super], "zi 190, la 345") b = """ 666666 > leave 666666 < %(left)s """ % { "left": config.Messages.LEAVE_CONFIRM } self.runScript(b) failed = False try: report_stock(self, hsa, "zi 10 la 15", [ic, super], "zi 190, la 345") except Exception: # this is expected failed = True if not failed: self.fail( "Reporting stock should not have notified the supervisor") report_stock(self, hsa, "zi 10 la 15", [super], "zi 190, la 345")