1import unittest 2 3from devtools_testutils import AzureMgmtTestCase, ResourceGroupPreparer 4from azure.mgmt.botservice import AzureBotService 5from azure.mgmt.botservice.models import ( 6 Bot, 7 BotProperties, 8 BotChannel, 9 ErrorException, 10 Sku 11) 12 13class BotServiceChannelsTestCase(AzureMgmtTestCase): 14 def setUp(self): 15 super(BotServiceChannelsTestCase, self).setUp() 16 #create a bot here 17 self.client = self.create_mgmt_client(AzureBotService) 18 self.resource_name = self.get_resource_name('azurebotservice') 19 20 def createBot(self): 21 location = 'global' 22 sku_name = 'Free' 23 kind= 'Bot' 24 display_name = "this is a test bot" 25 description= "this is a description for a test bot" 26 endpoint = "https://bing.com/messages/" 27 msa_app_id = "056d9ad9-17a9-4cc7-aebb-43bf6f293a08" 28 developer_app_insight_key = '59513bad-10a7-4d41-b4d0-b1c34c6af511' 29 developer_app_insights_api_key = 'w24iw5ocbhcig71su7ibaj63hey5ieaozeuwdv11' 30 developer_app_insights_application_id = 'cf03484e-3fdb-4b5e-9ad7-94bde32e5a19' 31 bot = self.client.bots.create( 32 resource_group_name = self.resource_group_name, 33 resource_name = self.resource_name, 34 parameters = Bot( 35 location= location, 36 sku = Sku(name=sku_name), 37 kind= kind, 38 properties= BotProperties( 39 display_name = display_name, 40 description= description, 41 endpoint = endpoint, 42 msa_app_id = msa_app_id, 43 developer_app_insight_key = developer_app_insight_key, 44 developer_app_insights_api_key = developer_app_insights_api_key, 45 developer_app_insights_application_id = developer_app_insights_application_id, 46 ) 47 ) 48 ) 49 50 def tearDown(self): 51 super(BotServiceChannelsTestCase, self).tearDown() 52 self.client.bots.delete( 53 resource_group_name = self.resource_group_name, 54 resource_name = self.resource_name 55 ) 56 57 def validateCreateGetAndDeleteChannel(self, channel_name, channel_properties, run_exist_check=True, validate=None): 58 self.createBot() 59 60 botChannel = BotChannel( 61 location = 'global', 62 properties = channel_properties 63 ) 64 65 self.client.channels.create( 66 resource_group_name = self.resource_group_name, 67 resource_name = self.resource_name, 68 channel_name = channel_name, 69 parameters = botChannel 70 ) 71 72 channel = self.client.channels.get( 73 resource_group_name = self.resource_group_name, 74 resource_name = self.resource_name, 75 channel_name = channel_name 76 ) 77 78 self.assertIsNotNone(channel) 79 #is_enabled being true means that the service has managed to get the channel working. 80 if channel_name == 'DirectLineChannel': 81 self.assertTrue(channel.properties.properties.sites[0].is_enabled) 82 else: 83 self.assertTrue(channel.properties.properties.is_enabled) 84 85 if validate: 86 validate( 87 resource_group_name=self.resource_group_name, 88 resource_name=self.resource_name, 89 assertIsNotNone=self.assertIsNotNone 90 ) 91 92 channel = self.client.channels.delete( 93 resource_group_name = self.resource_group_name, 94 resource_name = self.resource_name, 95 channel_name = channel_name 96 ) 97 if run_exist_check: 98 with self.assertRaises(ErrorException): 99 channel = self.client.channels.get( 100 resource_group_name = self.resource_group_name, 101 resource_name = self.resource_name, 102 channel_name = channel_name 103 ) 104 105 @ResourceGroupPreparer(name_prefix='pythonsdkbot') 106 def test_email_channel(self, resource_group): 107 self.resource_group_name = resource_group.name 108 from azure.mgmt.botservice.models import EmailChannel,EmailChannelProperties 109 channel = EmailChannel( 110 properties = EmailChannelProperties( 111 email_address = 'swagatm2@outlook.com', 112 password = 'Botuser123@', 113 is_enabled = True 114 ) 115 ) 116 117 self.validateCreateGetAndDeleteChannel( 118 channel_name = 'EmailChannel', 119 channel_properties = channel 120 ) 121 122 123 @unittest.skip("skip") 124 @ResourceGroupPreparer(name_prefix='pythonsdkbot') 125 def test_telegram_channel(self, resource_group): 126 from azure.mgmt.botservice.models import TelegramChannel,TelegramChannelProperties 127 self.resource_group_name = resource_group.name 128 channel = TelegramChannel( 129 properties = TelegramChannelProperties( 130 access_token = '520413022:AAF12lBf6s4tSqntaXEZnvrn6XOVrjQ6YN4', 131 is_enabled = True, 132 ) 133 ) 134 135 self.validateCreateGetAndDeleteChannel( 136 channel_name = 'TelegramChannel', 137 channel_properties = channel 138 ) 139 140 @unittest.skip("skip") 141 @ResourceGroupPreparer(name_prefix='pythonsdkbot') 142 def test_sms_channel(self, resource_group): 143 from azure.mgmt.botservice.models import SmsChannel,SmsChannelProperties 144 self.resource_group_name = resource_group.name 145 channel = SmsChannel( 146 properties = SmsChannelProperties( 147 phone = '+15153258725', 148 account_sid = 'AC421cab6999e0c8c0d1a90c6643db8f05', 149 auth_token = '507d2f4f9a832fdd042d05c500b3a88f', 150 is_enabled = True, 151 is_validated = False 152 ) 153 ) 154 155 self.validateCreateGetAndDeleteChannel( 156 channel_name = 'SmsChannel', 157 channel_properties = channel 158 ) 159 160 @ResourceGroupPreparer(name_prefix='pythonsdkbot') 161 def test_msteams_channel(self, resource_group): 162 from azure.mgmt.botservice.models import MsTeamsChannel,MsTeamsChannelProperties 163 self.resource_group_name = resource_group.name 164 channel = MsTeamsChannel( 165 properties = MsTeamsChannelProperties( 166 is_enabled = True, 167 ) 168 ) 169 170 self.validateCreateGetAndDeleteChannel( 171 channel_name = 'MsTeamsChannel', 172 channel_properties = channel, 173 run_exist_check=False 174 ) 175 176 @ResourceGroupPreparer(name_prefix='pythonsdkbot') 177 def test_skype_channel(self, resource_group): 178 from azure.mgmt.botservice.models import SkypeChannel,SkypeChannelProperties 179 self.resource_group_name = resource_group.name 180 channel = SkypeChannel( 181 properties = SkypeChannelProperties( 182 is_enabled = True, 183 enable_messaging = True, 184 ) 185 ) 186 187 self.validateCreateGetAndDeleteChannel( 188 channel_name = 'SkypeChannel', 189 channel_properties = channel, 190 run_exist_check=False 191 ) 192 193 194 @ResourceGroupPreparer(name_prefix='pythonsdkbot') 195 def test_directline_channel(self, resource_group): 196 # also test secrets api 197 def validate_directline(resource_group_name, resource_name, assertIsNotNone): 198 settings = self.client.channels.list_with_keys( 199 resource_group_name=resource_group_name, 200 resource_name=resource_name, 201 channel_name='DirectLineChannel', 202 ) 203 assertIsNotNone(settings) 204 assertIsNotNone(settings.properties.properties.sites[0].key) 205 206 207 from azure.mgmt.botservice.models import DirectLineChannel,DirectLineChannelProperties,DirectLineSite 208 self.resource_group_name = resource_group.name 209 channel = DirectLineChannel( 210 properties=DirectLineChannelProperties( 211 sites=[DirectLineSite( 212 site_name='default', 213 is_enabled=True, 214 is_v1_enabled=False, 215 is_v3_enabled=True)] 216 ) 217 ) 218 219 self.validateCreateGetAndDeleteChannel( 220 channel_name = 'DirectLineChannel', 221 channel_properties = channel, 222 validate=validate_directline 223 )