示例#1
0
    async def test_get_relay_configuration_with_route_type_nearest(
            self, communication_livetest_dynamic_connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_livetest_dynamic_connection_string,
            http_logging_policy=get_http_logging_policy())

        async with identity_client:
            user = await identity_client.create_user()

        networkTraversalClient = CommunicationRelayClient.from_connection_string(
            communication_livetest_dynamic_connection_string,
            http_logging_policy=get_http_logging_policy())

        async with networkTraversalClient:
            print('Getting relay config with nearest type:\n')
            config = await networkTraversalClient.get_relay_configuration(
                user=user, route_type=RouteType.NEAREST)

        print('Ice Servers Async:\n')
        for iceServer in config.ice_servers:
            assert iceServer.username is not None
            print('Username: '******'Credential: ' + iceServer.credential)

            assert iceServer.urls is not None
            for url in iceServer.urls:
                print('Url:' + url)

            assert iceServer.route_type == RouteType.NEAREST

        assert config is not None
示例#2
0
    def test_get_relay_configuration_with_route_type_nearest(self, communication_livetest_dynamic_connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_livetest_dynamic_connection_string,
            http_logging_policy=get_http_logging_policy()
        )
        user = identity_client.create_user()

        relay_client = CommunicationRelayClient.from_connection_string(
            communication_livetest_dynamic_connection_string,
            http_logging_policy=get_http_logging_policy()
        )

        print('Getting relay config with route type nearest:\n')
        config = relay_client.get_relay_configuration(user, RouteType.NEAREST)

        for iceServer in config.ice_servers:
            assert iceServer.username is not None
            print('Username: '******'Credential: ' + iceServer.credential)
            
            assert iceServer.urls is not None
            for url in iceServer.urls:
                print('Url: ' + url)

            print(iceServer.route_type)
            assert iceServer.route_type == RouteType.NEAREST

        assert config is not None
示例#3
0
    def test_get_relay_configuration(self, communication_livetest_dynamic_connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_livetest_dynamic_connection_string,
            http_logging_policy=get_http_logging_policy()
        )
        user = identity_client.create_user()

        relay_client = CommunicationRelayClient.from_connection_string(
            communication_livetest_dynamic_connection_string,
            http_logging_policy=get_http_logging_policy()
        )

        print('Getting relay config:\n')
        config = relay_client.get_relay_configuration(user)
        
        print('Ice Servers: \n')
        for iceServer in config.ice_servers:
            assert iceServer.username is not None
            print('Username: '******'Credential: ' + iceServer.credential)
            
            assert iceServer.urls is not None
            for url in iceServer.urls:
                print('Url: ' + url)

        assert config is not None
        
示例#4
0
    async def test_get_relay_configuration(
            self, communication_livetest_dynamic_connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_livetest_dynamic_connection_string,
            api_version=ApiVersion.V2021_03_07,
            http_logging_policy=get_http_logging_policy())

        async with identity_client:
            user = await identity_client.create_user()

        networkTraversalClient = CommunicationRelayClient.from_connection_string(
            communication_livetest_dynamic_connection_string,
            http_logging_policy=get_http_logging_policy())

        async with networkTraversalClient:
            print('Getting relay config:\n')
            config = await networkTraversalClient.get_relay_configuration(user)

        print('Ice Servers Async:\n')
        for iceServer in config.ice_servers:
            assert iceServer.username is not None
            print('Username: '******'Credential: ' + iceServer.credential)

            assert iceServer.urls is not None
            for url in iceServer.urls:
                print('Url:' + url)

        assert config is not None
示例#5
0
    def test_revoke_tokens_with_no_user(self, communication_connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_connection_string,
            http_logging_policy=get_http_logging_policy())

        with pytest.raises(Exception) as ex:
            identity_client.revoke_tokens(user=None)
示例#6
0
    def setUp(self):
        super(ChatClientTest, self).setUp()

        self.recording_processors.extend([
            BodyReplacerProcessor(keys=["id", "token", "createdBy", "participants", "multipleStatus", "value"]),
            URIIdentityReplacer(),
            ChatURIReplacer()])

        self.identity_client = CommunicationIdentityClient.from_connection_string(
            self.connection_str)

        endpoint, _ = parse_connection_str(self.connection_str)
        self.endpoint = endpoint

        # create user and issue token
        self.user = self.identity_client.create_user()
        tokenresponse = self.identity_client.get_token(self.user, scopes=["chat"])
        self.token = tokenresponse.token

        # create ChatClient
        self.chat_client = ChatClient(
            self.endpoint, 
            CommunicationTokenCredential(self.token), 
            http_logging_policy=get_http_logging_policy()
        )
 async def test_purchase_phone_numbers_from_managed_identity(self):
     endpoint, access_key = parse_connection_str(self.connection_str)
     credential = create_token_credential()
     phone_number_client = PhoneNumbersClient(
         endpoint,
         credential,
         http_logging_policy=get_http_logging_policy())
     capabilities = PhoneNumberCapabilities(
         calling=PhoneNumberCapabilityType.INBOUND,
         sms=PhoneNumberCapabilityType.INBOUND_OUTBOUND)
     async with phone_number_client:
         search_poller = await phone_number_client.begin_search_available_phone_numbers(
             self.country_code,
             PhoneNumberType.TOLL_FREE,
             PhoneNumberAssignmentType.APPLICATION,
             capabilities,
             polling=True)
         phone_number_to_buy = await search_poller.result()
         purchase_poller = await phone_number_client.begin_purchase_phone_numbers(
             phone_number_to_buy.search_id, polling=True)
         await purchase_poller.result()
         release_poller = await phone_number_client.begin_release_phone_number(
             phone_number_to_buy.phone_numbers[0])
     assert release_poller.status(
     ) == PhoneNumberOperationStatus.SUCCEEDED.value
示例#8
0
    def test_access_token_validation(self):
        """
        This is to make sure that consecutive calls made using the same chat_client or chat_thread_client
        does not throw an exception due to mismatch in the generation of azure.core.credentials.AccessToken
        """

        # create ChatClient
        chat_client = ChatClient(
            self.endpoint, 
            CommunicationTokenCredential(self.token),
            http_logging_policy=get_http_logging_policy()
        )
        raised = False
        try:
            # create chat thread
            topic1 = "test topic1"
            create_chat_thread1_result = chat_client.create_chat_thread(topic1)
            self.thread_id = create_chat_thread1_result.chat_thread.id

            # get chat thread client
            chat_thread1_client = chat_client.get_chat_thread_client(self.thread_id)

            # list all chat threads
            chat_thead_infos = chat_client.list_chat_threads()
            for chat_threads_info_page in chat_thead_infos.by_page():
                for chat_thread_info in chat_threads_info_page:
                    print("ChatThreadInfo: ", chat_thread_info)
        except:
           raised = True

        assert raised is False
    def test_delete_user_with_no_user(self, communication_livetest_dynamic_connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_livetest_dynamic_connection_string,
            http_logging_policy=get_http_logging_policy()
        )

        with pytest.raises(Exception) as ex:
            identity_client.delete_user(user=None)
    def test_create_user_and_token_with_no_scopes(self, communication_livetest_dynamic_connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_livetest_dynamic_connection_string,
            http_logging_policy=get_http_logging_policy()
        )

        with pytest.raises(Exception) as ex:
            user, token_response = identity_client.create_user_and_token(scopes=None)
 def _get_managed_identity_phone_number_client(self):
     endpoint, access_key = parse_connection_str(self.connection_str)
     credential = async_create_token_credential()
     return PhoneNumbersClient(
         endpoint,
         credential,
         http_logging_policy=get_http_logging_policy(),
         headers_policy=get_header_policy())
示例#12
0
    def test_get_token_with_no_scopes(self, communication_connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_connection_string,
            http_logging_policy=get_http_logging_policy())
        user = identity_client.create_user()

        with pytest.raises(Exception) as ex:
            token_response = identity_client.get_token(user, scopes=None)
    def test_get_token_with_no_user(self, communication_livetest_dynamic_connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_livetest_dynamic_connection_string,
            http_logging_policy=get_http_logging_policy()
        )

        with pytest.raises(Exception) as ex:
            token_response = identity_client.get_token(user=None, scopes=[CommunicationTokenScope.CHAT])
    async def test_create_user(self, communication_connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_connection_string,
            http_logging_policy=get_http_logging_policy())
        async with identity_client:
            user = await identity_client.create_user()

        assert user.properties.get('id') is not None
    def test_create_user_and_token(self, communication_livetest_dynamic_connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_livetest_dynamic_connection_string,
            http_logging_policy=get_http_logging_policy()
        )
        user, token_response = identity_client.create_user_and_token(scopes=[CommunicationTokenScope.CHAT])

        assert user.properties.get('id') is not None
        assert token_response.token is not None
示例#16
0
    def test_delete_user(self, communication_connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_connection_string,
            http_logging_policy=get_http_logging_policy())
        user = identity_client.create_user()

        identity_client.delete_user(user)

        assert user.properties.get('id') is not None
示例#17
0
 def test_list_purchased_phone_numbers_from_managed_identity(self):
     endpoint, access_key = parse_connection_str(self.connection_str)
     credential = create_token_credential()
     phone_number_client = PhoneNumbersClient(
         endpoint,
         credential,
         http_logging_policy=get_http_logging_policy())
     phone_numbers = phone_number_client.list_purchased_phone_numbers()
     assert phone_numbers.next()
示例#18
0
    def setUp(self):
        super(ChatThreadClientTestAsync, self).setUp()

        self.recording_processors.extend([
            BodyReplacerProcessor(keys=[
                "id", "token", "senderId", "chatMessageId", "nextLink",
                "participants", "multipleStatus", "value"
            ]),
            URIIdentityReplacer(),
            ResponseReplacerProcessor(keys=[self._resource_name]),
            ChatURIReplacer()
        ])

        endpoint, _ = parse_connection_str(self.connection_str)
        self.endpoint = endpoint

        self.identity_client = CommunicationIdentityClient.from_connection_string(
            self.connection_str)

        self.users = []
        self.user_tokens = []
        self.chat_clients = []

        # create user 1
        self.user = self.identity_client.create_user()
        token_response = self.identity_client.get_token(self.user,
                                                        scopes=["chat"])
        self.token = token_response.token

        # create user 2
        self.new_user = self.identity_client.create_user()
        token_response = self.identity_client.get_token(self.new_user,
                                                        scopes=["chat"])
        self.token_new_user = token_response.token

        # create ChatClient
        self.chat_client = ChatClient(
            self.endpoint,
            CommunicationTokenCredential(self.token),
            http_logging_policy=get_http_logging_policy())
        self.chat_client_new_user = ChatClient(
            self.endpoint,
            CommunicationTokenCredential(self.token_new_user),
            http_logging_policy=get_http_logging_policy())
 def test_get_token_for_teams_user_with_valid_token(
         self, communication_livetest_dynamic_connection_string):
     if (self.skip_get_token_for_teams_user_test()):
         return
     identity_client = CommunicationIdentityClient.from_connection_string(
         communication_livetest_dynamic_connection_string,
         http_logging_policy=get_http_logging_policy())
     add_token = self.generate_teams_user_aad_token()
     token_response = identity_client.get_token_for_teams_user(add_token)
     assert token_response.token is not None
示例#20
0
    async def test_get_token_with_no_scopes(self, communication_livetest_dynamic_connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_livetest_dynamic_connection_string,
            http_logging_policy=get_http_logging_policy()
        )

        async with identity_client:
            with pytest.raises(Exception) as ex:
                user = await identity_client.create_user()
                token_response = await identity_client.get_token(user, scopes=None)
    async def test_get_token(self, communication_connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_connection_string,
            http_logging_policy=get_http_logging_policy())
        async with identity_client:
            user = await identity_client.create_user()
            token_response = await identity_client.get_token(
                user, scopes=[CommunicationTokenScope.CHAT])

        assert user.properties.get('id') is not None
        assert token_response.token is not None
 async def test_get_purchased_phone_number_from_managed_identity(self):
     endpoint, access_key = parse_connection_str(self.connection_str)
     credential = create_token_credential()
     phone_number_client = PhoneNumbersClient(
         endpoint,
         credential,
         http_logging_policy=get_http_logging_policy())
     async with phone_number_client:
         phone_number = await phone_number_client.get_purchased_phone_number(
             self.phone_number)
     assert phone_number.phone_number == self.phone_number
    def test_get_token_for_teams_user_with_empty_token(
            self, communication_livetest_dynamic_connection_string):
        if (self.skip_get_token_for_teams_user_test()):
            return
        identity_client = CommunicationIdentityClient.from_connection_string(
            communication_livetest_dynamic_connection_string,
            http_logging_policy=get_http_logging_policy())

        with pytest.raises(Exception) as ex:
            token_response = identity_client.get_token_for_teams_user("")
        assert str(ex.value.status_code) == "401"
        assert ex.value.message is not None
 async def test_list_purchased_phone_numbers_from_managed_identity(self):
     endpoint, access_key = parse_connection_str(self.connection_str)
     credential = create_token_credential()
     phone_number_client = PhoneNumbersClient(
         endpoint,
         credential,
         http_logging_policy=get_http_logging_policy())
     async with phone_number_client:
         phone_numbers = phone_number_client.list_purchased_phone_numbers()
         items = []
         async for item in phone_numbers:
             items.append(item)
     assert len(items) > 0
示例#25
0
    def test_send_sms_unauthorized_from_phone_number(self):

        sms_client = SmsClient.from_connection_string(
            self.connection_str, http_logging_policy=get_http_logging_policy())

        with pytest.raises(HttpResponseError) as ex:
            # calling send() with sms values
            sms_client.send(from_="+14255550123",
                            to=[self.phone_number],
                            message="Hello World via SMS")

        assert str(ex.value.status_code) == "401"
        assert ex.value.message is not None
示例#26
0
    def test_send_sms_single(self):

        sms_client = SmsClient.from_connection_string(
            self.connection_str, http_logging_policy=get_http_logging_policy())

        # calling send() with sms values
        sms_responses = sms_client.send(from_=self.phone_number,
                                        to=self.phone_number,
                                        message="Hello World via SMS")

        assert len(sms_responses) == 1

        self.verify_successful_sms_response(sms_responses[0])
    async def test_send_sms_fake_from_phone_number_async(self):

        sms_client = SmsClient.from_connection_string(
            self.connection_str, http_logging_policy=get_http_logging_policy())

        with pytest.raises(HttpResponseError) as ex:
            async with sms_client:
                # calling send() with sms values
                await sms_client.send(from_="+15550000000",
                                      to=[self.phone_number],
                                      message="Hello World via SMS")

        assert str(ex.value.status_code) == "400"
        assert ex.value.message is not None
 async def test_update_phone_number_capabilities_from_managed_identity(
         self):
     endpoint, access_key = parse_connection_str(self.connection_str)
     credential = create_token_credential()
     phone_number_client = PhoneNumbersClient(
         endpoint,
         credential,
         http_logging_policy=get_http_logging_policy())
     async with phone_number_client:
         poller = await phone_number_client.begin_update_phone_number_capabilities(
             self.phone_number,
             PhoneNumberCapabilityType.INBOUND_OUTBOUND,
             PhoneNumberCapabilityType.INBOUND,
             polling=True)
     assert poller.result()
    def test_create_user_from_managed_identity(self, communication_livetest_dynamic_connection_string):
        endpoint, access_key = parse_connection_str(communication_livetest_dynamic_connection_string)
        from devtools_testutils import is_live
        if not is_live():
            credential = FakeTokenCredential()
        else:
            credential = DefaultAzureCredential()
        identity_client = CommunicationIdentityClient(
            endpoint, 
            credential,
            http_logging_policy=get_http_logging_policy()
        )
        user = identity_client.create_user()

        assert user.properties.get('id') is not None
 def test_update_phone_number_capabilities_from_managed_identity(self):
     endpoint, access_key = parse_connection_str(self.connection_str)
     credential = create_token_credential()
     phone_number_client = PhoneNumbersClient(
         endpoint, 
         credential, 
         http_logging_policy=get_http_logging_policy()
     )
     poller = phone_number_client.begin_update_phone_number_capabilities(
         self.phone_number,
         PhoneNumberCapabilityType.INBOUND_OUTBOUND,
         PhoneNumberCapabilityType.INBOUND,
         polling = True
     )
     poller.result()
     assert poller.status() == PhoneNumberOperationStatus.SUCCEEDED.value