File: test_reverse_proxy_async.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (61 lines) | stat: -rw-r--r-- 3,135 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
import pytest
from azure.messaging.webpubsubservice.aio import WebPubSubServiceClient
from azure.messaging.webpubsubservice._operations._operations import build_web_pub_sub_service_send_to_all_request
from azure.core.credentials import AzureKeyCredential

from testcase import WebpubsubPowerShellPreparer
from testcase_async import WebpubsubAsyncTest
from devtools_testutils.aio import recorded_by_proxy_async 

@pytest.mark.live_test_only
class TestWebpubsubReverseProxyAsync(WebpubsubAsyncTest):

    @pytest.mark.asyncio
    @recorded_by_proxy_async
    async def test_reverse_proxy_endpoint_redirection(self):
        def _callback(pipeline_request):
            assert pipeline_request.http_request.url.startswith("https://apim.contoso.com/")
            raise ValueError("Success!")
        wps_endpoint = "https://wps.contoso.com/"
        apim_endpoint = "https://apim.contoso.com/"
        credential = AzureKeyCredential("AzureKeyCredential")
        request = build_web_pub_sub_service_send_to_all_request("Hub", content='test_webpubsub_send_request', content_type='text/plain')
        async with WebPubSubServiceClient(wps_endpoint, "Hub", credential, reverse_proxy_endpoint=apim_endpoint) as client:
            with pytest.raises(ValueError) as ex:
                await client.send_request(request, raw_request_hook=_callback)
            assert "Success!" in str(ex.value)

    @pytest.mark.asyncio
    @recorded_by_proxy_async
    async def test_reverse_proxy_endpoint_redirection_identity(self):
        def _callback(pipeline_request):
            assert pipeline_request.http_request.url.startswith("https://apim.contoso.com/")
            raise ValueError("Success!")
        wps_endpoint = "https://wps.contoso.com/"
        apim_endpoint = "https://apim.contoso.com/"
        credential = self.get_credential(WebPubSubServiceClient, is_async=True)
        request = build_web_pub_sub_service_send_to_all_request('Hub', content='test_webpubsub_send_request', content_type='text/plain')
        async with WebPubSubServiceClient(wps_endpoint, "Hub", credential, reverse_proxy_endpoint=apim_endpoint) as client:
            with pytest.raises(ValueError) as ex:
                await client.send_request(request, raw_request_hook=_callback)
            assert "Success!" in str(ex.value)

    @pytest.mark.asyncio
    @WebpubsubPowerShellPreparer()
    @recorded_by_proxy_async
    async def test_reverse_proxy_call(self, webpubsub_connection_string, webpubsub_reverse_proxy_endpoint):
        client = self.create_client(
            connection_string=webpubsub_connection_string,
            hub='hub',
            logging_enable=True,
            reverse_proxy_endpoint=webpubsub_reverse_proxy_endpoint
        )

        await client.send_to_all({'Hello': 'reverse_proxy_endpoint!'})