<s> import unittest <EOL> from azure . servicemanagement import ( <EOL> AffinityGroups , <EOL> AffinityGroup , <EOL> Locations , <EOL> ServiceManagementService , <EOL> ) <EOL> from testutils . common_recordingtestcase import ( <EOL> TestMode , <EOL> record , <EOL> ) <EOL> from tests . legacy_mgmt_testcase import LegacyMgmtTestCase <EOL> class LegacyMgmtAffinityGroupTest ( LegacyMgmtTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( LegacyMgmtAffinityGroupTest , self ) . setUp ( ) <EOL> self . sms = self . create_service_management ( ServiceManagementService ) <EOL> self . affinity_group_name = self . get_resource_name ( '<STR_LIT>' ) <EOL> self . hosted_service_name = None <EOL> self . storage_account_name = None <EOL> def tearDown ( self ) : <EOL> if not self . is_playback ( ) : <EOL> try : <EOL> if self . hosted_service_name is not None : <EOL> self . sms . delete_hosted_service ( self . hosted_service_name ) <EOL> except : <EOL> pass <EOL> try : <EOL> if self . storage_account_name is not None : <EOL> self . sms . delete_storage_account ( self . storage_account_name ) <EOL> except : <EOL> pass <EOL> try : <EOL> self . sms . delete_affinity_group ( self . affinity_group_name ) <EOL> except : <EOL> pass <EOL> return super ( LegacyMgmtAffinityGroupTest , self ) . tearDown ( ) <EOL> def _create_affinity_group ( self , name ) : <EOL> result = self . sms . create_affinity_group ( <EOL> name , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertIsNone ( result ) <EOL> def _affinity_group_exists ( self , name ) : <EOL> try : <EOL> props = self . sms . get_affinity_group_properties ( name ) <EOL> return props is not None <EOL> except : <EOL> return False <EOL> @ record <EOL> def test_list_affinity_groups ( self ) : <EOL> self . _create_affinity_group ( self . affinity_group_name ) <EOL> result = self . sms . list_affinity_groups ( ) <EOL> self . assertIsNotNone ( result ) <EOL> self . assertTrue ( len ( result ) > <NUM_LIT:0> ) <EOL> group = None <EOL> for temp in result : <EOL> if temp . name == self . affinity_group_name : <EOL> group = temp <EOL> break <EOL> self . assertIsNotNone ( group ) <EOL> self . assertIsNotNone ( group . name ) <EOL> self . assertIsNotNone ( group . label ) <EOL> self . assertIsNotNone ( group . description ) <EOL> self . assertIsNotNone ( group . location ) <EOL> self . assertIsNotNone ( group . capabilities ) <EOL> self . assertTrue ( len ( group . capabilities ) > <NUM_LIT:0> ) <EOL> @ record <EOL> def test_get_affinity_group_properties ( self ) : <EOL> self . hosted_service_name = self . get_resource_name ( '<STR_LIT>' ) <EOL> self . storage_account_name = self . get_resource_name ( '<STR_LIT>' ) <EOL> self . _create_affinity_group ( self . affinity_group_name ) <EOL> self . sms . create_hosted_service ( <EOL> self . hosted_service_name , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> None , <EOL> self . affinity_group_name ) <EOL> self . sms . create_storage_account ( <EOL> self . storage_account_name , <EOL> self . storage_account_name + '<STR_LIT>' , <EOL> self . storage_account_name + '<STR_LIT:label>' , <EOL> self . affinity_group_name ) <EOL> result = self . sms . get_affinity_group_properties ( <EOL> self . affinity_group_name ) <EOL> self . assertIsNotNone ( result ) <EOL> self . assertEqual ( result . name , self . affinity_group_name ) <EOL> self . assertIsNotNone ( result . label ) <EOL> self . assertIsNotNone ( result . description ) <EOL> self . assertIsNotNone ( result . location ) <EOL> self . assertIsNotNone ( result . hosted_services [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( <EOL> result . hosted_services [ <NUM_LIT:0> ] . service_name , self . hosted_service_name ) <EOL> self . assertEqual ( <EOL> result . hosted_services [ <NUM_LIT:0> ] . hosted_service_properties . affinity_group , <EOL> self . affinity_group_name ) <EOL> self . assertTrue ( len ( result . capabilities ) > <NUM_LIT:0> ) <EOL> @ record <EOL> def test_create_affinity_group ( self ) : <EOL> label = '<STR_LIT>' <EOL> description = '<STR_LIT>' <EOL> result = self . sms . create_affinity_group ( <EOL> self . affinity_group_name , label , '<STR_LIT>' , description ) <EOL> self . assertIsNone ( result ) <EOL> self . assertTrue ( self . _affinity_group_exists ( self . affinity_group_name ) ) <EOL> @ record <EOL> def test_update_affinity_group ( self ) : <EOL> self . _create_affinity_group ( self . affinity_group_name ) <EOL> label = '<STR_LIT>' <EOL> description = '<STR_LIT>' <EOL> result = self . sms . update_affinity_group ( <EOL> self . affinity_group_name , label , description ) <EOL> self . assertIsNone ( result ) <EOL> props = self . sms . get_affinity_group_properties ( <EOL> self . affinity_group_name ) <EOL> self . assertEqual ( props . label , label ) <EOL> self . assertEqual ( props . description , description ) <EOL> @ record <EOL> def test_delete_affinity_group ( self ) : <EOL> self . _create_affinity_group ( self . affinity_group_name ) <EOL> result = self . sms . delete_affinity_group ( self . affinity_group_name ) <EOL> self . assertIsNone ( result ) <EOL> self . assertFalse ( self . _affinity_group_exists ( self . affinity_group_name ) ) <EOL> @ record <EOL> def test_list_locations ( self ) : <EOL> result = self . sms . list_locations ( ) <EOL> self . assertIsNotNone ( result ) <EOL> self . assertTrue ( len ( result ) > <NUM_LIT:0> ) <EOL> self . assertIsNotNone ( result [ <NUM_LIT:0> ] . name ) <EOL> self . assertIsNotNone ( result [ <NUM_LIT:0> ] . display_name ) <EOL> self . assertIsNotNone ( result [ <NUM_LIT:0> ] . available_services ) <EOL> self . assertTrue ( len ( result [ <NUM_LIT:0> ] . available_services ) > <NUM_LIT:0> ) <EOL> self . assertTrue ( len ( result [ <NUM_LIT:0> ] . compute_capabilities . web_worker_role_sizes ) > <NUM_LIT:0> ) <EOL> self . assertTrue ( len ( result [ <NUM_LIT:0> ] . compute_capabilities . virtual_machines_role_sizes ) > <NUM_LIT:0> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
