<s> from django . test import TestCase <EOL> from corehq . apps . domain . models import Domain <EOL> from corehq . apps . locations . models import LocationType , Location <EOL> from corehq . apps . products . models import Product <EOL> from corehq . apps . users . models import CommCareUser <EOL> from custom . ewsghana . models import FacilityInCharge <EOL> class TestDeleteDomain ( TestCase ) : <EOL> def _create_data ( self , domain_name ) : <EOL> product = Product ( domain = domain_name , name = '<STR_LIT>' ) <EOL> product . save ( ) <EOL> location = Location ( <EOL> domain = domain_name , <EOL> site_code = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> location_type = '<STR_LIT>' <EOL> ) <EOL> location . save ( ) <EOL> self . locations [ domain_name ] = location . sql_location <EOL> user = CommCareUser . create ( <EOL> domain = domain_name , <EOL> username = '<STR_LIT>' . format ( domain_name ) , <EOL> password = '<STR_LIT>' <EOL> ) <EOL> FacilityInCharge . objects . create ( <EOL> user_id = user . get_id , <EOL> location = location . sql_location <EOL> ) <EOL> def setUp ( self ) : <EOL> self . domain = Domain ( name = "<STR_LIT:test>" , is_active = True ) <EOL> self . domain . save ( ) <EOL> self . domain2 = Domain ( name = "<STR_LIT>" , is_active = True ) <EOL> self . domain2 . save ( ) <EOL> self . locations = { } <EOL> LocationType . objects . create ( <EOL> domain = '<STR_LIT:test>' , <EOL> name = '<STR_LIT>' , <EOL> ) <EOL> LocationType . objects . create ( <EOL> domain = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> ) <EOL> self . _create_data ( '<STR_LIT:test>' ) <EOL> self . _create_data ( '<STR_LIT>' ) <EOL> def test_pre_delete_signal_receiver ( self ) : <EOL> self . domain . delete ( ) <EOL> self . assertEqual ( FacilityInCharge . objects . filter ( location = self . locations [ '<STR_LIT:test>' ] ) . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( FacilityInCharge . objects . filter ( location = self . locations [ '<STR_LIT>' ] ) . count ( ) , <NUM_LIT:1> ) <EOL> def tearDown ( self ) : <EOL> FacilityInCharge . objects . all ( ) . delete ( ) <EOL> self . domain2 . delete ( ) </s>
