<s> """<STR_LIT>""" <EOL> import datetime <EOL> from casexml . apps . stock . const import SECTION_TYPE_STOCK <EOL> from django . test import TestCase <EOL> from corehq . apps . commtrack . models import SupplyPointCase , StockState <EOL> from corehq . apps . commtrack . tests . util import bootstrap_domain <EOL> from corehq . apps . products . models import SQLProduct <EOL> from . . models import SQLLocation <EOL> from . util import setup_locations_and_types <EOL> class TestChangeStatus ( TestCase ) : <EOL> domain = '<STR_LIT>' <EOL> location_type_names = [ '<STR_LIT:state>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> stock_tracking_types = [ '<STR_LIT>' ] <EOL> location_structure = [ <EOL> ( '<STR_LIT>' , [ <EOL> ( '<STR_LIT>' , [ <EOL> ( '<STR_LIT>' , [ ] ) , <EOL> ( '<STR_LIT>' , [ ] ) , <EOL> ] ) , <EOL> ( '<STR_LIT>' , [ <EOL> ( '<STR_LIT>' , [ ] ) , <EOL> ] ) <EOL> ] ) <EOL> ] <EOL> def setUp ( self ) : <EOL> self . domain_obj = bootstrap_domain ( self . domain ) <EOL> self . location_types , self . locations = setup_locations_and_types ( <EOL> self . domain , <EOL> self . location_type_names , <EOL> self . stock_tracking_types , <EOL> self . location_structure , <EOL> ) <EOL> self . suffolk = self . locations [ '<STR_LIT>' ] <EOL> self . boston = self . locations [ '<STR_LIT>' ] <EOL> self . county_type = self . location_types [ '<STR_LIT>' ] <EOL> self . city_type = self . location_types [ '<STR_LIT>' ] <EOL> def tearDown ( self ) : <EOL> self . domain_obj . delete ( ) <EOL> def assertHasSupplyPoint ( self , location ) : <EOL> msg = "<STR_LIT>" . format ( location . name ) <EOL> loc = SQLLocation . objects . get ( location_id = location . location_id ) <EOL> self . assertIsNotNone ( loc . supply_point_id , msg ) <EOL> self . assertIsNotNone ( loc . linked_supply_point ( ) , msg ) <EOL> def assertHasNoSupplyPoint ( self , location ) : <EOL> msg = "<STR_LIT>" . format ( location . name ) <EOL> loc = SQLLocation . objects . get ( location_id = location . location_id ) <EOL> self . assertIsNone ( loc . supply_point_id , msg ) <EOL> def test_change_to_track_stock ( self ) : <EOL> self . assertHasNoSupplyPoint ( self . suffolk ) <EOL> self . county_type . administrative = False <EOL> self . county_type . save ( ) <EOL> self . assertHasSupplyPoint ( self . suffolk ) <EOL> def test_change_to_administrative_and_back ( self ) : <EOL> self . assertHasSupplyPoint ( self . boston ) <EOL> supply_point_id = self . boston . supply_point_id <EOL> self . city_type . administrative = True <EOL> self . city_type . save ( ) <EOL> self . assertHasNoSupplyPoint ( self . boston ) <EOL> self . assertTrue ( SupplyPointCase . get ( supply_point_id ) . closed ) <EOL> self . city_type . administrative = False <EOL> self . city_type . save ( ) <EOL> self . assertHasSupplyPoint ( self . boston ) <EOL> self . assertEqual ( self . boston . supply_point_id , supply_point_id ) <EOL> self . assertFalse ( SupplyPointCase . get ( supply_point_id ) . closed ) <EOL> def test_stock_states ( self ) : <EOL> def has_stock_states ( location ) : <EOL> return StockState . objects . filter ( sql_location = location ) . exists ( ) <EOL> product = SQLProduct . objects . create ( <EOL> domain = self . domain , product_id = '<STR_LIT:foo>' , name = '<STR_LIT:foo>' ) <EOL> StockState . objects . create ( <EOL> section_id = SECTION_TYPE_STOCK , <EOL> case_id = self . boston . supply_point_id , <EOL> product_id = '<STR_LIT:foo>' , <EOL> last_modified_date = datetime . datetime . now ( ) , <EOL> stock_on_hand = <NUM_LIT:10> , <EOL> sql_product = product , <EOL> sql_location = self . boston , <EOL> ) <EOL> self . assertTrue ( has_stock_states ( self . boston ) ) <EOL> self . city_type . administrative = True <EOL> self . city_type . save ( ) <EOL> self . assertFalse ( has_stock_states ( self . boston ) ) <EOL> self . city_type . administrative = False <EOL> self . city_type . save ( ) <EOL> self . assertTrue ( has_stock_states ( self . boston ) ) </s>
