From e1f24cce090a1b97d6e4d936ded58f64ccffcf16 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 12 Sep 2025 15:12:28 +0800 Subject: [PATCH] add test case --- .../asynctests/test_payload_pageable_async.py | 75 +++++++++++++++++++ .../test_payload_pageable.py | 54 +++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_pageable_async.py create mode 100644 packages/typespec-python/test/generic_mock_api_tests/test_payload_pageable.py diff --git a/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_pageable_async.py b/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_pageable_async.py new file mode 100644 index 00000000000..8af75000c29 --- /dev/null +++ b/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_pageable_async.py @@ -0,0 +1,75 @@ +# ------------------------------------------------------------------------- +# 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 payload.pageable.aio import PageableClient + + +@pytest.fixture +async def client(): + async with PageableClient(endpoint="http://localhost:3000") as client: + yield client + + +def assert_result(result): + assert len(result) == 4 + assert result[0].id == "1" + assert result[1].id == "2" + assert result[2].id == "3" + assert result[3].id == "4" + assert result[0].name == "dog" + assert result[1].name == "cat" + assert result[2].name == "bird" + assert result[3].name == "fish" + + +@pytest.mark.asyncio +async def test_link(client: PageableClient): + result = [p async for p in client.server_driven_pagination.link()] + assert_result(result) + + +@pytest.mark.asyncio +async def test_request_query_response_body(client: PageableClient): + result = [ + p + async for p in client.server_driven_pagination.continuation_token.request_query_response_body( + foo="foo", bar="bar" + ) + ] + assert_result(result) + + +@pytest.mark.asyncio +async def test_request_header_response_body(client: PageableClient): + result = [ + p + async for p in client.server_driven_pagination.continuation_token.request_header_response_body( + foo="foo", bar="bar" + ) + ] + assert_result(result) + + +@pytest.mark.asyncio +async def test_request_query_response_header(client: PageableClient): + result = [ + p + async for p in client.server_driven_pagination.continuation_token.request_query_response_header( + foo="foo", bar="bar" + ) + ] + assert_result(result) + + +@pytest.mark.asyncio +async def test_request_header_response_header(client: PageableClient): + result = [ + p + async for p in client.server_driven_pagination.continuation_token.request_query_response_header( + foo="foo", bar="bar" + ) + ] + assert_result(result) diff --git a/packages/typespec-python/test/generic_mock_api_tests/test_payload_pageable.py b/packages/typespec-python/test/generic_mock_api_tests/test_payload_pageable.py new file mode 100644 index 00000000000..f98f6648751 --- /dev/null +++ b/packages/typespec-python/test/generic_mock_api_tests/test_payload_pageable.py @@ -0,0 +1,54 @@ +# ------------------------------------------------------------------------- +# 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 payload.pageable import PageableClient + + +@pytest.fixture +def client(): + with PageableClient(endpoint="http://localhost:3000") as client: + yield client + + +def assert_result(result): + assert len(result) == 4 + assert result[0].id == "1" + assert result[1].id == "2" + assert result[2].id == "3" + assert result[3].id == "4" + assert result[0].name == "dog" + assert result[1].name == "cat" + assert result[2].name == "bird" + assert result[3].name == "fish" + + +def test_link(client: PageableClient): + result = list(client.server_driven_pagination.link()) + assert_result(result) + + +def test_request_query_response_body(client: PageableClient): + result = list(client.server_driven_pagination.continuation_token.request_query_response_body(foo="foo", bar="bar")) + assert_result(result) + + +def test_request_header_response_body(client: PageableClient): + result = list(client.server_driven_pagination.continuation_token.request_header_response_body(foo="foo", bar="bar")) + assert_result(result) + + +def test_request_query_response_header(client: PageableClient): + result = list( + client.server_driven_pagination.continuation_token.request_query_response_header(foo="foo", bar="bar") + ) + assert_result(result) + + +def test_request_header_response_header(client: PageableClient): + result = list( + client.server_driven_pagination.continuation_token.request_header_response_header(foo="foo", bar="bar") + ) + assert_result(result)