File: test_client.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 (79 lines) | stat: -rw-r--r-- 3,260 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -------------------------------------------------------------------------
# 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 devtools_testutils import AzureRecordedTestCase

from azure.mixedreality.authentication import MixedRealityStsClient
from azure.mixedreality.authentication._shared.mixedreality_account_key_credential import MixedRealityAccountKeyCredential

class TestClient(AzureRecordedTestCase):

    def test_create_client(self, account_info):
        client = MixedRealityStsClient(
            account_id=account_info["account_id"],
            account_domain=account_info["account_domain"],
            credential=account_info["key_credential"])

        assert client is not None

    def test_create_client_custom_with_endpoint(self, account_info):
        custom_endpoint_url = "https://my.custom.endpoint"
        client = MixedRealityStsClient(
            account_id=account_info["account_id"],
            account_domain=account_info["account_domain"],
            credential=account_info["key_credential"],
            custom_endpoint_url=custom_endpoint_url)

        assert client._endpoint_url == custom_endpoint_url

    def test_create_client_with_credential(self, account_info):
        token_credential = MixedRealityAccountKeyCredential(
            account_info["account_id"], account_info["key_credential"])
        client = MixedRealityStsClient(
            account_id=account_info["account_id"],
            account_domain=account_info["account_domain"],
            credential=token_credential)

        assert client._credential == token_credential

    def test_create_client_with_invalid_arguments(self, account_info):
        with pytest.raises(ValueError):
            MixedRealityStsClient(
                account_id=None,
                account_domain=account_info["account_domain"],
                credential=account_info["key_credential"])

        with pytest.raises(ValueError):
            MixedRealityStsClient(
                account_id=account_info["account_id"],
                account_domain=None,
                credential=account_info["key_credential"])

        with pytest.raises(ValueError):
            MixedRealityStsClient(
                account_id=account_info["account_id"],
                account_domain=account_info["account_domain"],
                credential=None)

        with pytest.raises(ValueError):
            MixedRealityStsClient(
                account_id=account_info["account_id"],
                account_domain=account_info["account_domain"],
                credential=account_info["key_credential"],
                custom_endpoint_url="#")

    def test_get_token(self, recorded_test, account_info):
        client = MixedRealityStsClient(
            account_id=account_info["account_id"],
            account_domain=account_info["account_domain"],
            credential=account_info["key_credential"])

        token = client.get_token()

        assert token is not None
        assert token.token is not None
        assert token.expires_on is not None