<s> from corehq . apps . commtrack . models import StockState <EOL> from corehq . util . translation import localize <EOL> from custom . ilsgateway . models import SupplyPointStatus , SupplyPointStatusValues , SupplyPointStatusTypes <EOL> from custom . ilsgateway . tanzania . reminders import DELIVERY_PARTIAL_CONFIRM , NOT_DELIVERED_CONFIRM , DELIVERY_CONFIRM_DISTRICT , DELIVERY_CONFIRM_CHILDREN , INVALID_PRODUCT_CODE , DELIVERED_CONFIRM <EOL> from custom . ilsgateway . tests . handlers . utils import ILSTestScript <EOL> class ILSDeliveredTest ( ILSTestScript ) : <EOL> def setUp ( self ) : <EOL> super ( ILSDeliveredTest , self ) . setUp ( ) <EOL> def test_delivery_facility_received_no_quantities_reported ( self ) : <EOL> with localize ( '<STR_LIT>' ) : <EOL> response = unicode ( DELIVERY_PARTIAL_CONFIRM ) <EOL> script = """<STR_LIT>""" . format ( response ) <EOL> self . run_script ( script ) <EOL> sps = SupplyPointStatus . objects . filter ( location_id = self . loc1 . get_id , <EOL> status_type = "<STR_LIT>" ) . order_by ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( SupplyPointStatusValues . RECEIVED , sps . status_value ) <EOL> self . assertEqual ( SupplyPointStatusTypes . DELIVERY_FACILITY , sps . status_type ) <EOL> def test_delivery_facility_received_quantities_reported ( self ) : <EOL> with localize ( '<STR_LIT>' ) : <EOL> response = unicode ( DELIVERED_CONFIRM ) <EOL> sohs = { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> <EOL> } <EOL> script = """<STR_LIT>""" . format ( response % { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . run_script ( script ) <EOL> self . assertEqual ( <NUM_LIT:2> , StockState . objects . count ( ) ) <EOL> for ps in StockState . objects . all ( ) . order_by ( '<STR_LIT>' ) : <EOL> self . assertEqual ( self . loc1 . linked_supply_point ( ) . get_id , ps . case_id ) <EOL> self . assertEqual ( ps . stock_on_hand , sohs [ ps . sql_product . code ] ) <EOL> def test_delivery_facility_not_received ( self ) : <EOL> with localize ( '<STR_LIT>' ) : <EOL> response = unicode ( NOT_DELIVERED_CONFIRM ) <EOL> script = """<STR_LIT>""" . format ( response ) <EOL> self . run_script ( script ) <EOL> sps = SupplyPointStatus . objects . filter ( location_id = self . loc1 . get_id , <EOL> status_type = "<STR_LIT>" ) . order_by ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( SupplyPointStatusValues . NOT_RECEIVED , sps . status_value ) <EOL> self . assertEqual ( SupplyPointStatusTypes . DELIVERY_FACILITY , sps . status_type ) <EOL> def test_delivery_facility_report_product_error ( self ) : <EOL> with localize ( '<STR_LIT>' ) : <EOL> response = unicode ( INVALID_PRODUCT_CODE ) <EOL> script = """<STR_LIT>""" % { '<STR_LIT>' : response % { "<STR_LIT>" : "<STR_LIT>" } } <EOL> self . run_script ( script ) <EOL> def test_delivery_district_received ( self ) : <EOL> with localize ( '<STR_LIT>' ) : <EOL> response = unicode ( DELIVERY_CONFIRM_DISTRICT ) <EOL> response2 = unicode ( DELIVERY_CONFIRM_CHILDREN ) <EOL> script = """<STR_LIT>""" . format ( <EOL> response % dict ( contact_name = "<STR_LIT>" . format ( <EOL> self . user_dis . first_name , <EOL> self . user_dis . last_name <EOL> ) , facility_name = self . dis . name ) , <EOL> response2 % dict ( district_name = self . dis . name ) <EOL> ) <EOL> self . run_script ( script ) <EOL> sps = SupplyPointStatus . objects . filter ( location_id = self . dis . get_id , <EOL> status_type = "<STR_LIT>" ) . order_by ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( SupplyPointStatusValues . RECEIVED , sps . status_value ) <EOL> self . assertEqual ( SupplyPointStatusTypes . DELIVERY_DISTRICT , sps . status_type ) <EOL> def test_delivery_district_not_received ( self ) : <EOL> with localize ( '<STR_LIT>' ) : <EOL> response = unicode ( NOT_DELIVERED_CONFIRM ) <EOL> script = """<STR_LIT>""" . format ( response ) <EOL> self . run_script ( script ) <EOL> sps = SupplyPointStatus . objects . filter ( location_id = self . dis . get_id , <EOL> status_type = "<STR_LIT>" ) . order_by ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( SupplyPointStatusValues . NOT_RECEIVED , sps . status_value ) <EOL> self . assertEqual ( SupplyPointStatusTypes . DELIVERY_DISTRICT , sps . status_type ) </s>
