Skip to content
This repository was archived by the owner on May 22, 2026. It is now read-only.

Commit af22aff

Browse files
author
iscai-msft
committed
fix placement of generated tests in tsp
1 parent fb0797d commit af22aff

25 files changed

Lines changed: 322 additions & 65 deletions

File tree

packages/typespec-python/test/azure/generated/authentication-api-key-subdir/authentication/api/key/subdir/_generated/generated_tests/conftest.py renamed to packages/typespec-python/test/azure/generated/authentication-api-key-subdir/authentication/api/key/subdir/generated_tests/conftest.py

File renamed without changes.

packages/typespec-python/test/azure/generated/authentication-api-key-subdir/authentication/api/key/subdir/_generated/generated_tests/test_api_key.py renamed to packages/typespec-python/test/azure/generated/authentication-api-key-subdir/authentication/api/key/subdir/generated_tests/test_api_key.py

File renamed without changes.

packages/typespec-python/test/azure/generated/authentication-api-key-subdir/authentication/api/key/subdir/_generated/generated_tests/test_api_key_async.py renamed to packages/typespec-python/test/azure/generated/authentication-api-key-subdir/authentication/api/key/subdir/generated_tests/test_api_key_async.py

File renamed without changes.

packages/typespec-python/test/azure/generated/authentication-api-key-subdir/authentication/api/key/subdir/_generated/generated_tests/testpreparer.py renamed to packages/typespec-python/test/azure/generated/authentication-api-key-subdir/authentication/api/key/subdir/generated_tests/testpreparer.py

File renamed without changes.

packages/typespec-python/test/azure/generated/authentication-api-key-subdir/authentication/api/key/subdir/_generated/generated_tests/testpreparer_async.py renamed to packages/typespec-python/test/azure/generated/authentication-api-key-subdir/authentication/api/key/subdir/generated_tests/testpreparer_async.py

File renamed without changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
import os
9+
import pytest
10+
from dotenv import load_dotenv
11+
from devtools_testutils import (
12+
test_proxy,
13+
add_general_regex_sanitizer,
14+
add_body_key_sanitizer,
15+
add_header_regex_sanitizer,
16+
)
17+
18+
load_dotenv()
19+
20+
21+
# For security, please avoid record sensitive identity information in recordings
22+
@pytest.fixture(scope="session", autouse=True)
23+
def add_sanitizers(test_proxy):
24+
apikey_subscription_id = os.environ.get("APIKEY_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000")
25+
apikey_tenant_id = os.environ.get("APIKEY_TENANT_ID", "00000000-0000-0000-0000-000000000000")
26+
apikey_client_id = os.environ.get("APIKEY_CLIENT_ID", "00000000-0000-0000-0000-000000000000")
27+
apikey_client_secret = os.environ.get("APIKEY_CLIENT_SECRET", "00000000-0000-0000-0000-000000000000")
28+
add_general_regex_sanitizer(regex=apikey_subscription_id, value="00000000-0000-0000-0000-000000000000")
29+
add_general_regex_sanitizer(regex=apikey_tenant_id, value="00000000-0000-0000-0000-000000000000")
30+
add_general_regex_sanitizer(regex=apikey_client_id, value="00000000-0000-0000-0000-000000000000")
31+
add_general_regex_sanitizer(regex=apikey_client_secret, value="00000000-0000-0000-0000-000000000000")
32+
33+
add_header_regex_sanitizer(key="Set-Cookie", value="[set-cookie;]")
34+
add_header_regex_sanitizer(key="Cookie", value="cookie;")
35+
add_body_key_sanitizer(json_path="$..access_token", value="access_token")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
import pytest
9+
from devtools_testutils import recorded_by_proxy
10+
from testpreparer import ApiKeyClientTestBase, ApiKeyPreparer
11+
12+
13+
@pytest.mark.skip("you may need to update the auto-generated test case before run it")
14+
class TestApiKey(ApiKeyClientTestBase):
15+
@ApiKeyPreparer()
16+
@recorded_by_proxy
17+
def test_valid(self, apikey_endpoint):
18+
client = self.create_client(endpoint=apikey_endpoint)
19+
response = client.valid()
20+
21+
# please add some check logic here by yourself
22+
# ...
23+
24+
@ApiKeyPreparer()
25+
@recorded_by_proxy
26+
def test_invalid(self, apikey_endpoint):
27+
client = self.create_client(endpoint=apikey_endpoint)
28+
response = client.invalid()
29+
30+
# please add some check logic here by yourself
31+
# ...
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
import pytest
9+
from devtools_testutils.aio import recorded_by_proxy_async
10+
from testpreparer import ApiKeyPreparer
11+
from testpreparer_async import ApiKeyClientTestBaseAsync
12+
13+
14+
@pytest.mark.skip("you may need to update the auto-generated test case before run it")
15+
class TestApiKeyAsync(ApiKeyClientTestBaseAsync):
16+
@ApiKeyPreparer()
17+
@recorded_by_proxy_async
18+
async def test_valid(self, apikey_endpoint):
19+
client = self.create_async_client(endpoint=apikey_endpoint)
20+
response = await client.valid()
21+
22+
# please add some check logic here by yourself
23+
# ...
24+
25+
@ApiKeyPreparer()
26+
@recorded_by_proxy_async
27+
async def test_invalid(self, apikey_endpoint):
28+
client = self.create_async_client(endpoint=apikey_endpoint)
29+
response = await client.invalid()
30+
31+
# please add some check logic here by yourself
32+
# ...
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
from authentication.api.key.subdir import ApiKeyClient
9+
from devtools_testutils import AzureRecordedTestCase, PowerShellPreparer
10+
import functools
11+
12+
13+
class ApiKeyClientTestBase(AzureRecordedTestCase):
14+
15+
def create_client(self, endpoint):
16+
credential = self.get_credential(ApiKeyClient)
17+
return self.create_client_from_credential(
18+
ApiKeyClient,
19+
credential=credential,
20+
endpoint=endpoint,
21+
)
22+
23+
24+
ApiKeyPreparer = functools.partial(PowerShellPreparer, "apikey", apikey_endpoint="https://fake_apikey_endpoint.com")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
from authentication.api.key.subdir.aio import ApiKeyClient
9+
from devtools_testutils import AzureRecordedTestCase
10+
11+
12+
class ApiKeyClientTestBaseAsync(AzureRecordedTestCase):
13+
14+
def create_async_client(self, endpoint):
15+
credential = self.get_credential(ApiKeyClient, is_async=True)
16+
return self.create_client_from_credential(
17+
ApiKeyClient,
18+
credential=credential,
19+
endpoint=endpoint,
20+
)

0 commit comments

Comments
 (0)