File: test_event_routes_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 (57 lines) | stat: -rw-r--r-- 2,544 bytes parent folder | download | duplicates (2)
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
# -------------------------------------------------------------------------
# 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.core.exceptions import  ResourceNotFoundError, HttpResponseError
from azure.digitaltwins.core.aio import DigitalTwinsClient
from azure.digitaltwins.core import DigitalTwinsEventRoute
from devtools_testutils import AzureRecordedTestCase


class TestDigitalTwinsEventRouteAsync(AzureRecordedTestCase):

    def _get_client(self, endpoint, **kwargs):
        credential = self.get_credential(DigitalTwinsClient, is_async=True)
        return self.create_client_from_credential(
            DigitalTwinsClient,
            credential,
            endpoint=endpoint,
            **kwargs)

    @pytest.mark.asyncio
    async def test_create_event_route_no_endpoint(self, recorded_test, digitaltwin):
        event_route_id = self.create_random_name('eventRoute-')
        event_filter = "$eventType = 'DigitalTwinTelemetryMessages' or $eventType = 'DigitalTwinLifecycleNotification'"
        endpoint = self.create_random_name('endpoint-')
        route = DigitalTwinsEventRoute(
            endpoint_name=endpoint,
            filter=event_filter
        )
        client = self._get_client(digitaltwin["endpoint"])
        with pytest.raises(HttpResponseError):
            await client.upsert_event_route(event_route_id, route)

    @pytest.mark.asyncio
    async def test_get_event_route_not_existing(self, recorded_test, digitaltwin):
        event_route_id = self.create_random_name('eventRoute-')
        client = self._get_client(digitaltwin["endpoint"])
        with pytest.raises(ResourceNotFoundError):
            await client.get_event_route(event_route_id)

    @pytest.mark.asyncio
    async def test_list_event_routes(self, recorded_test, digitaltwin):
        client = self._get_client(digitaltwin["endpoint"])
        all_routes = []
        async for r in client.list_event_routes():
            all_routes.append(r)
        assert all_routes == []

    @pytest.mark.asyncio
    async def test_delete_event_route_not_existing(self, recorded_test, digitaltwin):
        event_route_id = self.create_random_name('eventRoute-')
        client = self._get_client(digitaltwin["endpoint"])
        with pytest.raises(ResourceNotFoundError):
            await client.delete_event_route(event_route_id)