<s> from datetime import datetime <EOL> from casexml . apps . stock . models import StockTransaction <EOL> from corehq . apps . commtrack . models import StockState <EOL> from corehq . util . translation import localize <EOL> from custom . ilsgateway . tanzania . reminders import SOH_CONFIRM , STOCKOUT_CONFIRM , STOCKOUT_HELP <EOL> from custom . ilsgateway . tests . handlers . utils import ILSTestScript <EOL> class TestStockout ( ILSTestScript ) : <EOL> def test_stockout ( self ) : <EOL> with localize ( '<STR_LIT>' ) : <EOL> response1 = unicode ( SOH_CONFIRM ) <EOL> response2 = unicode ( STOCKOUT_CONFIRM ) <EOL> response3 = unicode ( STOCKOUT_HELP ) <EOL> supply_point_id = self . loc1 . sql_location . supply_point_id <EOL> script = """<STR_LIT>""" % { "<STR_LIT>" : response1 } <EOL> self . run_script ( script ) <EOL> self . assertEqual ( StockTransaction . objects . filter ( case_id = self . facility_sp_id ) . count ( ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( StockState . objects . filter ( case_id = self . facility_sp_id ) . count ( ) , <NUM_LIT:3> ) <EOL> script = """<STR_LIT>""" . format ( response3 ) <EOL> self . run_script ( script ) <EOL> quantities = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> for ( idx , stock_transaction ) in enumerate ( StockTransaction . objects . all ( ) . order_by ( '<STR_LIT>' ) ) : <EOL> self . assertEqual ( stock_transaction . case_id , supply_point_id ) <EOL> self . assertEqual ( stock_transaction . stock_on_hand , quantities [ idx ] ) <EOL> now = datetime . utcnow ( ) <EOL> script = """<STR_LIT>""" . format ( response2 % { <EOL> "<STR_LIT>" : self . user1 . full_name , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : self . loc1 . name <EOL> } ) <EOL> self . run_script ( script ) <EOL> for stock_transaction in StockTransaction . objects . filter ( report__date__gte = now ) : <EOL> self . assertEqual ( stock_transaction . case_id , supply_point_id ) <EOL> self . assertEqual ( stock_transaction . stock_on_hand , <NUM_LIT:0> ) </s>
