File: test_communication_identity_client_async.py

package info (click to toggle)
python-azure 20201208%2Bgit-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,437,920 kB
  • sloc: python: 4,287,452; javascript: 269; makefile: 198; sh: 187; xml: 106
file content (71 lines) | stat: -rw-r--r-- 3,329 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
62
63
64
65
66
67
68
69
70
71
# 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.communication.administration.aio import CommunicationIdentityClient
from azure_devtools.scenario_tests import RecordingProcessor
from devtools_testutils import ResourceGroupPreparer
from _shared.helper import URIIdentityReplacer
from _shared.asynctestcase  import AsyncCommunicationTestCase
from _shared.testcase import BodyReplacerProcessor
from _shared.communication_service_preparer import CommunicationServicePreparer

class CommunicationIdentityClientTestAsync(AsyncCommunicationTestCase):
    def setUp(self):
        super(CommunicationIdentityClientTestAsync, self).setUp()
        self.recording_processors.extend([
            BodyReplacerProcessor(keys=["id", "token"]),
            URIIdentityReplacer()])

    @ResourceGroupPreparer(random_name_enabled=True, use_cache=True)
    @CommunicationServicePreparer()
    @pytest.mark.asyncio
    @AsyncCommunicationTestCase.await_prepared_test
    async def test_create_user(self, connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(connection_string)
        async with identity_client:
            user = await identity_client.create_user()

        assert user.identifier is not None

    @ResourceGroupPreparer(random_name_enabled=True, use_cache=True)
    @CommunicationServicePreparer()
    @pytest.mark.asyncio
    @AsyncCommunicationTestCase.await_prepared_test
    async def test_issue_token(self, connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(connection_string)
        async with identity_client:
            user = await identity_client.create_user()
            token_response = await identity_client.issue_token(user, scopes=["chat"])

        assert user.identifier is not None
        assert token_response.token is not None

    @ResourceGroupPreparer(random_name_enabled=True, use_cache=True)
    @CommunicationServicePreparer()
    @pytest.mark.asyncio
    @AsyncCommunicationTestCase.await_prepared_test
    async def test_revoke_tokens(self, connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(connection_string)
        async with identity_client:
            user = await identity_client.create_user()
            token_response = await identity_client.issue_token(user, scopes=["chat"])
            await identity_client.revoke_tokens(user)

        assert user.identifier is not None
        assert token_response.token is not None

    @ResourceGroupPreparer(random_name_enabled=True, use_cache=True)
    @CommunicationServicePreparer()
    @pytest.mark.asyncio
    @AsyncCommunicationTestCase.await_prepared_test
    async def test_delete_user(self, connection_string):
        identity_client = CommunicationIdentityClient.from_connection_string(connection_string)
        async with identity_client:
            user = await identity_client.create_user()
            await identity_client.delete_user(user)

        assert user.identifier is not None