<s> from datetime import datetime <EOL> from django . test import TestCase <EOL> from casexml . apps . stock . models import DocDomainMapping , StockReport , StockTransaction <EOL> from corehq . apps . domain . models import Domain <EOL> from corehq . apps . locations . models import Location , LocationType , SQLLocation <EOL> from corehq . apps . products . models import Product , SQLProduct <EOL> class TestDeleteDomain ( TestCase ) : <EOL> def _create_data ( self , domain_name , i ) : <EOL> product = Product ( domain = domain_name , name = '<STR_LIT>' . format ( i ) ) <EOL> product . save ( ) <EOL> location = Location ( <EOL> domain = domain_name , <EOL> site_code = '<STR_LIT>' . format ( i ) , <EOL> name = '<STR_LIT>' . format ( i ) , <EOL> location_type = '<STR_LIT>' <EOL> ) <EOL> location . save ( ) <EOL> report = StockReport . objects . create ( <EOL> type = '<STR_LIT>' , <EOL> domain = domain_name , <EOL> form_id = '<STR_LIT>' , <EOL> date = datetime . utcnow ( ) <EOL> ) <EOL> StockTransaction . objects . create ( <EOL> report = report , <EOL> product_id = product . get_id , <EOL> sql_product = SQLProduct . objects . get ( product_id = product . get_id ) , <EOL> section_id = '<STR_LIT>' , <EOL> type = '<STR_LIT>' , <EOL> case_id = location . linked_supply_point ( ) . get_id , <EOL> stock_on_hand = <NUM_LIT:100> <EOL> ) <EOL> def setUp ( self ) : <EOL> self . domain = Domain ( name = "<STR_LIT:test>" , is_active = True ) <EOL> self . domain . save ( ) <EOL> self . domain . convert_to_commtrack ( ) <EOL> self . domain2 = Domain ( name = "<STR_LIT>" , is_active = True ) <EOL> self . domain2 . save ( ) <EOL> self . domain2 . convert_to_commtrack ( ) <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> 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> for i in xrange ( <NUM_LIT:2> ) : <EOL> self . _create_data ( '<STR_LIT:test>' , i ) <EOL> self . _create_data ( '<STR_LIT>' , i ) <EOL> def _assert_sql_counts ( self , domain , number ) : <EOL> self . assertEqual ( StockTransaction . objects . filter ( report__domain = domain ) . count ( ) , number ) <EOL> self . assertEqual ( StockReport . objects . filter ( domain = domain ) . count ( ) , number ) <EOL> self . assertEqual ( SQLLocation . objects . filter ( domain = domain ) . count ( ) , number ) <EOL> self . assertEqual ( SQLProduct . objects . filter ( domain = domain ) . count ( ) , number ) <EOL> self . assertEqual ( DocDomainMapping . objects . filter ( domain_name = domain ) . count ( ) , number ) <EOL> self . assertEqual ( LocationType . objects . filter ( domain = domain ) . count ( ) , number ) <EOL> def test_sql_objects_deletion ( self ) : <EOL> self . _assert_sql_counts ( '<STR_LIT:test>' , <NUM_LIT:2> ) <EOL> self . domain . delete ( ) <EOL> self . _assert_sql_counts ( '<STR_LIT:test>' , <NUM_LIT:0> ) <EOL> self . _assert_sql_counts ( '<STR_LIT>' , <NUM_LIT:2> ) <EOL> def tearDown ( self ) : <EOL> self . domain2 . delete ( ) </s>
