diff --git a/packages/http-client-python/emitter/src/code-model.ts b/packages/http-client-python/emitter/src/code-model.ts index 398fdc8f4e..6da74f43d8 100644 --- a/packages/http-client-python/emitter/src/code-model.ts +++ b/packages/http-client-python/emitter/src/code-model.ts @@ -32,12 +32,7 @@ import { simpleTypesMap, typesMap, } from "./types.js"; -import { - emitParamBase, - getClientNamespace, - getImplementation, - removeUnderscoresFromNamespace, -} from "./utils.js"; +import { emitParamBase, getClientNamespace, getImplementation, getRootNamespace } from "./utils.js"; function emitBasicMethod( context: PythonSdkContext, @@ -281,7 +276,7 @@ export function emitCodeModel( // Get types const sdkPackage = sdkContext.sdkPackage; const codeModel: Record = { - namespace: removeUnderscoresFromNamespace(sdkPackage.rootNamespace).toLowerCase(), + namespace: getRootNamespace(sdkContext), clients: [], }; for (const client of sdkPackage.clients) { diff --git a/packages/http-client-python/emitter/src/utils.ts b/packages/http-client-python/emitter/src/utils.ts index 4028a421fe..6dcd8289f9 100644 --- a/packages/http-client-python/emitter/src/utils.ts +++ b/packages/http-client-python/emitter/src/utils.ts @@ -200,26 +200,50 @@ export function capitalize(name: string): string { return name[0].toUpperCase() + name.slice(1); } +const LIB_NAMESPACE = [ + "azure.core", + "azure.resourcemanager", + "azure.clientgenerator.core", + "typespec.rest", + "typespec.http", + "typespec.versioning", +]; + +function getRootTypespecNamespace(context: PythonSdkContext): string { + if (context.sdkPackage.clients.length > 0) { + return context.sdkPackage.clients[0].clientNamespace; + } + if (context.sdkPackage.models.length > 0) { + const result = context.sdkPackage.models + .map((model) => model.clientNamespace) + .filter((namespace) => !LIB_NAMESPACE.includes(namespace)); + if (result.length > 0) { + result.sort(); + return result[0]; + } + } + if (context.sdkPackage.namespaces.length > 0) { + return context.sdkPackage.namespaces[0].fullName; + } + return ""; +} + +export function getRootNamespace(context: PythonSdkContext): string { + const rootNamespace = context.emitContext.options["enable-typespec-namespace"] + ? getRootTypespecNamespace(context) + : context.sdkPackage.rootNamespace; + return removeUnderscoresFromNamespace(rootNamespace).toLowerCase(); +} + export function getClientNamespace( context: PythonSdkContext, clientNamespace: string, ) { - const rootNamespace = removeUnderscoresFromNamespace( - context.sdkPackage.rootNamespace, - ).toLowerCase(); + const rootNamespace = getRootNamespace(context); if (!context.emitContext.options["enable-typespec-namespace"]) { return rootNamespace; } - if ( - [ - "azure.core", - "azure.resourcemanager", - "azure.clientgenerator.core", - "typespec.rest", - "typespec.http", - "typespec.versioning", - ].some((item) => clientNamespace.toLowerCase().startsWith(item)) - ) { + if (LIB_NAMESPACE.some((item) => clientNamespace.toLowerCase().startsWith(item))) { return rootNamespace; } return clientNamespace === "" diff --git a/packages/http-client-python/eng/scripts/ci/regenerate.ts b/packages/http-client-python/eng/scripts/ci/regenerate.ts index b54b0492ce..9bff24fb0c 100644 --- a/packages/http-client-python/eng/scripts/ci/regenerate.ts +++ b/packages/http-client-python/eng/scripts/ci/regenerate.ts @@ -90,8 +90,16 @@ const EMITTER_OPTIONS: Record | Record | Record[ ? relativeSpec : dirname(relativeSpec); const emitter_options = EMITTER_OPTIONS[key] || [{}]; - const result = Array.isArray(emitter_options) ? emitter_options : [emitter_options]; - - function updateOptions(options: Record): void { - if (options["package-name"] && options["enable-typespec-namespace"] === undefined) { - options["enable-typespec-namespace"] = "false"; - } - } - - // when package name is different with typespec namespace, disable typespec namespace - if (flavor !== "azure") { - for (const options of result) { - if (Array.isArray(options)) { - for (const option of options) { - updateOptions(option); - } - } else { - updateOptions(options); - } - } - } - - return result; + return Array.isArray(emitter_options) ? emitter_options : [emitter_options]; } // Function to execute CLI commands asynchronously diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py index 2ec9c2f49d..58c6dd1d90 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py @@ -197,6 +197,8 @@ def _serialize_and_write_package_files(self, client_namespace: str) -> None: env = Environment( loader=PackageLoader("pygen.codegen", "templates/packaging_templates"), undefined=StrictUndefined, + trim_blocks=True, + lstrip_blocks=True, ) package_files = _PACKAGE_FILES @@ -465,7 +467,10 @@ def _namespace_from_package_name(self) -> str: return get_namespace_from_package_name(self.code_model.options["package_name"]) def _name_space(self) -> str: - if self.code_model.namespace.count(".") >= self._namespace_from_package_name.count("."): + if ( + self.code_model.namespace.count(".") >= self._namespace_from_package_name.count(".") + or self.code_model.options["enable_typespec_namespace"] + ): return self.code_model.namespace return self._namespace_from_package_name diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 index 45239f0dac..6a1d6e5101 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 @@ -2,19 +2,28 @@ {{ license_header }} # coding: utf-8 {% if package_mode %} + import os import re -{% endif -%} +{% endif %} from setuptools import setup, find_packages {% set package_name = package_name or code_model.clients[0].name %} PACKAGE_NAME = "{{ package_name|lower }}" -{% if package_mode -%} +{% if code_model.options["enable_typespec_namespace"] %} +PACKAGE_NAMESPACE = "{{ code_model.namespace|lower }}" +{% endif %} +{% if package_mode %} PACKAGE_PPRINT_NAME = "{{ package_pprint_name }}" +{% if code_model.options["enable_typespec_namespace"] %} +# a.b.c => a/b/c +package_folder_path = PACKAGE_NAMESPACE.replace(".", "/") +{% else %} # a-b-c => a/b/c package_folder_path = PACKAGE_NAME.replace("-", "/") +{% endif %} # Version extraction inspired from 'requests' with open(os.path.join(package_folder_path, "_version.py"), "r") as fd: @@ -33,7 +42,8 @@ version = "{{ package_version }}" {% set long_description = code_model.description %} {% set author_email = "" %} {% set url = "" %} -{% endif -%} +{% endif %} + setup( name=PACKAGE_NAME, @@ -70,9 +80,9 @@ setup( {% if pkgutil_names %} # Exclude packages that will be covered by PEP420 or nspkg {% endif %} - {%- for pkgutil_name in pkgutil_names %} + {% for pkgutil_name in pkgutil_names %} "{{ pkgutil_name }}", - {%- endfor %} + {% endfor %} ] ), include_package_data=True, diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_array_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_array_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_array_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_array_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_dictionary_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_dictionary_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_dictionary_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_dictionary_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_extensible_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_extensible_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_extensible_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_extensible_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_fixed_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py similarity index 84% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_fixed_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py index de17f194b6..c8f132319c 100644 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_fixed_async.py +++ b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py @@ -5,6 +5,7 @@ # -------------------------------------------------------------------------- import pytest from typetest.enum.fixed import aio, models +from azure.core.exceptions import HttpResponseError @pytest.fixture @@ -20,8 +21,8 @@ async def test_known_value(client): @pytest.mark.asyncio -async def test_unknown_value(client: aio.FixedClient, core_library): +async def test_unknown_value(client: aio.FixedClient): try: await client.string.put_unknown_value("Weekend") - except core_library.exceptions.HttpResponseError as err: + except HttpResponseError as err: assert err.status_code == 500 diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_empty_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_empty_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_empty_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_empty_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_usage_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_usage_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_usage_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_usage_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_visibility_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_visibility_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_visibility_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_visibility_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_nullable_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_nullable_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_nullable_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_nullable_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_optional_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_optional_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_optional_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_optional_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_scalar_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_scalar_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_scalar_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_scalar_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_union_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_union_async.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_union_async.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_union_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_array.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_array.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_array.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_array.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_dictionary.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_dictionary.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_dictionary.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_dictionary.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_enum_extensible.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_enum_extensible.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_enum_extensible.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_enum_extensible.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_enum_fixed.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_enum_fixed.py similarity index 84% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_enum_fixed.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_enum_fixed.py index 0d085d0200..a2a7ca11a6 100644 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_enum_fixed.py +++ b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_enum_fixed.py @@ -5,6 +5,7 @@ # -------------------------------------------------------------------------- import pytest from typetest.enum.fixed import FixedClient, models +from azure.core.exceptions import HttpResponseError @pytest.fixture @@ -18,8 +19,8 @@ def test_known_value(client): client.string.put_known_value(models.DaysOfWeekEnum.MONDAY) -def test_unknown_value(client: FixedClient, core_library): +def test_unknown_value(client: FixedClient): try: client.string.put_unknown_value("Weekend") - except core_library.exceptions.HttpResponseError as err: + except HttpResponseError as err: assert err.status_code == 500 diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_empty.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_empty.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_empty.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_empty.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_not_discriminated.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_not_discriminated.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_recursive.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_recursive.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_recursive.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_recursive.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_single_discriminator.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_single_discriminator.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_usage.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_usage.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_usage.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_usage.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_visibility.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_visibility.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_visibility.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_visibility.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_additionalproperties.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_additionalproperties.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_additionalproperties.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_additionalproperties.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_nullable.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_nullable.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_nullable.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_nullable.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_optional.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_optional.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_optional.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_optional.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_valuetypes.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_valuetypes.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_valuetypes.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_valuetypes.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_scalar.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_scalar.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_scalar.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_scalar.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_union.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_union.py similarity index 100% rename from packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_union.py rename to packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_union.py diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_array_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_array_async.py new file mode 100644 index 0000000000..7eef272805 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_array_async.py @@ -0,0 +1,118 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +import pytest +import isodate +from type.array.aio import ArrayClient +from type.array import models + + +@pytest.fixture +async def client(): + async with ArrayClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_boolean_value(client: ArrayClient): + assert await client.boolean_value.get() == [True, False] + await client.boolean_value.put([True, False]) + + +@pytest.mark.asyncio +async def test_datetime_value(client: ArrayClient): + assert await client.datetime_value.get() == [isodate.parse_datetime("2022-08-26T18:38:00Z")] + await client.datetime_value.put([isodate.parse_datetime("2022-08-26T18:38:00Z")]) + + +@pytest.mark.asyncio +async def test_duration_value(client: ArrayClient): + assert await client.duration_value.get() == [isodate.parse_duration("P123DT22H14M12.011S")] + await client.duration_value.put([isodate.parse_duration("P123DT22H14M12.011S")]) + + +@pytest.mark.asyncio +async def test_float32_value(client: ArrayClient): + assert await client.float32_value.get() == [43.125] + await client.float32_value.put([43.125]) + + +@pytest.mark.asyncio +async def test_int32_value(client: ArrayClient): + assert await client.int32_value.get() == [1, 2] + await client.int32_value.put([1, 2]) + + +@pytest.mark.asyncio +async def test_int64_value(client: ArrayClient): + assert await client.int64_value.get() == [2**53 - 1, -(2**53 - 1)] + await client.int64_value.put([2**53 - 1, -(2**53 - 1)]) + + +@pytest.mark.asyncio +async def test_model_value(client: ArrayClient): + assert await client.model_value.get() == [ + models.InnerModel(property="hello"), + models.InnerModel(property="world"), + ] + await client.model_value.put( + [ + models.InnerModel(property="hello"), + models.InnerModel(property="world"), + ] + ) + + +@pytest.mark.asyncio +async def test_nullable_boolean_value(client: ArrayClient): + assert await client.nullable_boolean_value.get() == [True, None, False] + await client.nullable_boolean_value.put([True, None, False]) + + +@pytest.mark.asyncio +async def test_nullable_float_value(client: ArrayClient): + assert await client.nullable_float_value.get() == [1.25, None, 3.0] + await client.nullable_float_value.put([1.25, None, 3.0]) + + +@pytest.mark.asyncio +async def test_nullable_int32_value(client: ArrayClient): + assert await client.nullable_int32_value.get() == [1, None, 3] + await client.nullable_int32_value.put([1, None, 3]) + + +@pytest.mark.asyncio +async def test_nullable_model_value(client: ArrayClient): + assert await client.nullable_model_value.get() == [ + models.InnerModel(property="hello"), + None, + models.InnerModel(property="world"), + ] + await client.nullable_model_value.put( + [ + models.InnerModel(property="hello"), + None, + models.InnerModel(property="world"), + ] + ) + + +@pytest.mark.asyncio +async def test_nullable_string_value(client: ArrayClient): + assert await client.nullable_string_value.get() == ["hello", None, "world"] + await client.nullable_string_value.put(["hello", None, "world"]) + + +@pytest.mark.asyncio +async def test_string_value(client: ArrayClient): + assert await client.string_value.get() == ["hello", ""] + await client.string_value.put(["hello", ""]) + + +@pytest.mark.asyncio +async def test_unknown_value(client: ArrayClient): + assert await client.unknown_value.get() == [1, "hello", None] + await client.unknown_value.put([1, "hello", None]) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_dictionary_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_dictionary_async.py new file mode 100644 index 0000000000..337334315b --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_dictionary_async.py @@ -0,0 +1,98 @@ +# ------------------------------------------------------------------------- +# 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 type.dictionary import models +from type.dictionary.aio import DictionaryClient +import isodate + + +@pytest.fixture +async def client(): + async with DictionaryClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_boolean_value(client: DictionaryClient): + value = {"k1": True, "k2": False} + assert await client.boolean_value.get() == value + await client.boolean_value.put(value) + + +@pytest.mark.asyncio +async def test_datetime_value(client: DictionaryClient): + value = {"k1": isodate.parse_datetime("2022-08-26T18:38:00Z")} + assert await client.datetime_value.get() == value + await client.datetime_value.put(value) + + +@pytest.mark.asyncio +async def test_duration_value(client: DictionaryClient): + value = {"k1": isodate.parse_duration("P123DT22H14M12.011S")} + assert await client.duration_value.get() == value + await client.duration_value.put(value) + + +@pytest.mark.asyncio +async def test_float32_value(client: DictionaryClient): + value = {"k1": 43.125} + assert await client.float32_value.get() == value + await client.float32_value.put(value) + + +@pytest.mark.asyncio +async def test_int32_value(client: DictionaryClient): + value = {"k1": 1, "k2": 2} + assert await client.int32_value.get() == value + await client.int32_value.put(value) + + +@pytest.mark.asyncio +async def test_int64_value(client: DictionaryClient): + value = {"k1": 2**53 - 1, "k2": -(2**53 - 1)} + assert await client.int64_value.get() == value + await client.int64_value.put(value) + + +@pytest.mark.asyncio +async def test_model_value(client: DictionaryClient): + value = { + "k1": models.InnerModel(property="hello"), + "k2": models.InnerModel(property="world"), + } + assert await client.model_value.get() == value + await client.model_value.put(value) + + +@pytest.mark.asyncio +async def test_nullable_float_value(client: DictionaryClient): + value = {"k1": 1.25, "k2": 0.5, "k3": None} + assert await client.nullable_float_value.get() == value + await client.nullable_float_value.put(value) + + +@pytest.mark.asyncio +async def test_recursive_model_value(client: DictionaryClient): + value = { + "k1": models.InnerModel(property="hello", children={}), + "k2": models.InnerModel(property="world", children={"k2.1": models.InnerModel(property="inner world")}), + } + assert await client.recursive_model_value.get() == value + await client.recursive_model_value.put(value) + + +@pytest.mark.asyncio +async def test_string_value(client: DictionaryClient): + value = {"k1": "hello", "k2": ""} + assert await client.string_value.get() == value + await client.string_value.put(value) + + +@pytest.mark.asyncio +async def test_unknown_value(client: DictionaryClient): + value = {"k1": 1, "k2": "hello", "k3": None} + assert await client.unknown_value.get() == value + await client.unknown_value.put(value) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_extensible_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_extensible_async.py new file mode 100644 index 0000000000..7fdbb6794d --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_extensible_async.py @@ -0,0 +1,25 @@ +# ------------------------------------------------------------------------- +# 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 type.enum.extensible import models, aio + + +@pytest.fixture +async def client(): + async with aio.ExtensibleClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_known_value(client): + assert await client.string.get_known_value() == models.DaysOfWeekExtensibleEnum.MONDAY + await client.string.put_known_value(models.DaysOfWeekExtensibleEnum.MONDAY) + + +@pytest.mark.asyncio +async def test_unknown_value(client): + assert await client.string.get_unknown_value() == "Weekend" + await client.string.put_unknown_value("Weekend") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py new file mode 100644 index 0000000000..2669fbf488 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py @@ -0,0 +1,28 @@ +# ------------------------------------------------------------------------- +# 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 type.enum.fixed import aio, models +from corehttp.exceptions import HttpResponseError + + +@pytest.fixture +async def client(): + async with aio.FixedClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_known_value(client): + assert await client.string.get_known_value() == models.DaysOfWeekEnum.MONDAY + await client.string.put_known_value(models.DaysOfWeekEnum.MONDAY) + + +@pytest.mark.asyncio +async def test_unknown_value(client: aio.FixedClient): + try: + await client.string.put_unknown_value("Weekend") + except HttpResponseError as err: + assert err.status_code == 500 diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_empty_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_empty_async.py new file mode 100644 index 0000000000..f954d70fe8 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_empty_async.py @@ -0,0 +1,32 @@ +# ------------------------------------------------------------------------- +# 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 type.model.empty.aio import EmptyClient +from type.model.empty.models import EmptyInput, EmptyOutput, EmptyInputOutput + + +@pytest.fixture +async def client(): + async with EmptyClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_put(client: EmptyClient): + await client.put_empty(EmptyInput()) + await client.put_empty({}) + + +@pytest.mark.asyncio +async def test_get(client: EmptyClient): + assert await client.get_empty() == EmptyOutput() + assert await client.get_empty() == {} + + +@pytest.mark.asyncio +async def test_post_round(client: EmptyClient): + assert await client.post_round_trip_empty(EmptyInputOutput()) == EmptyInputOutput() + assert await client.post_round_trip_empty({}) == {} diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py new file mode 100644 index 0000000000..6c24c89f1f --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py @@ -0,0 +1,70 @@ +# ------------------------------------------------------------------------- +# 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 type.model.inheritance.enumdiscriminator.aio import EnumDiscriminatorClient +from type.model.inheritance.enumdiscriminator import models + + +@pytest.fixture +async def client(): + async with EnumDiscriminatorClient() as client: + yield client + + +@pytest.fixture +def valid_body(): + return models.Golden(weight=10) + + +@pytest.fixture +def valid_fixed_body(): + return models.Cobra(length=10) + + +@pytest.mark.asyncio +async def test_get_extensible_model(client: EnumDiscriminatorClient, valid_body: models.Dog): + assert await client.get_extensible_model() == valid_body + assert isinstance(await client.get_extensible_model(), models.Golden) + + +@pytest.mark.asyncio +async def test_put_extensible_model(client: EnumDiscriminatorClient, valid_body: models.Dog): + await client.put_extensible_model(valid_body) + + +@pytest.mark.asyncio +async def test_get_extensible_model_missing_discriminator( + client: EnumDiscriminatorClient, +): + assert await client.get_extensible_model_missing_discriminator() == models.Dog(weight=10) + + +@pytest.mark.asyncio +async def test_get_extensible_model_wrong_discriminator( + client: EnumDiscriminatorClient, +): + assert await client.get_extensible_model_wrong_discriminator() == models.Dog(weight=8, kind="wrongKind") + + +@pytest.mark.asyncio +async def test_get_fixed_model(client: EnumDiscriminatorClient, valid_fixed_body: models.Snake): + assert await client.get_fixed_model() == valid_fixed_body + assert isinstance(await client.get_fixed_model(), models.Cobra) + + +@pytest.mark.asyncio +async def test_put_fixed_model(client: EnumDiscriminatorClient, valid_fixed_body: models.Snake): + await client.put_fixed_model(valid_fixed_body) + + +@pytest.mark.asyncio +async def test_get_fixed_model_missing_discriminator(client: EnumDiscriminatorClient): + assert await client.get_fixed_model_missing_discriminator() == models.Snake(length=10) + + +@pytest.mark.asyncio +async def test_get_fixed_model_wrong_discriminator(client: EnumDiscriminatorClient): + assert await client.get_fixed_model_wrong_discriminator() == models.Snake(length=8, kind="wrongKind") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py new file mode 100644 index 0000000000..a308164bc1 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py @@ -0,0 +1,85 @@ +# ------------------------------------------------------------------------- +# 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 type.model.inheritance.nesteddiscriminator.aio import NestedDiscriminatorClient +from type.model.inheritance.nesteddiscriminator.models import GoblinShark, Salmon, Fish + + +@pytest.fixture +async def client(): + async with NestedDiscriminatorClient() as client: + yield client + + +@pytest.fixture +async def valid_body(): + return GoblinShark(age=1) + + +@pytest.mark.asyncio +async def test_get_model(client, valid_body): + assert await client.get_model() == valid_body + assert isinstance(await client.get_model(), GoblinShark) + + +@pytest.mark.asyncio +async def test_put_model(client, valid_body): + await client.put_model(valid_body) + + +@pytest.fixture +async def valid_recursive_body(): + return Salmon( + { + "age": 1, + "kind": "salmon", + "partner": {"age": 2, "kind": "shark", "sharktype": "saw"}, + "friends": [ + { + "age": 2, + "kind": "salmon", + "partner": {"age": 3, "kind": "salmon"}, + "hate": { + "key1": {"age": 4, "kind": "salmon"}, + "key2": {"age": 2, "kind": "shark", "sharktype": "goblin"}, + }, + }, + {"age": 3, "kind": "shark", "sharktype": "goblin"}, + ], + "hate": { + "key3": {"age": 3, "kind": "shark", "sharktype": "saw"}, + "key4": { + "age": 2, + "kind": "salmon", + "friends": [ + {"age": 1, "kind": "salmon"}, + {"age": 4, "kind": "shark", "sharktype": "goblin"}, + ], + }, + }, + } + ) + + +@pytest.mark.asyncio +async def test_get_recursive_model(client, valid_recursive_body): + assert valid_recursive_body == await client.get_recursive_model() + assert isinstance(await client.get_recursive_model(), Salmon) + + +@pytest.mark.asyncio +async def test_put_recursive_model(client, valid_recursive_body): + await client.put_recursive_model(valid_recursive_body) + + +@pytest.mark.asyncio +async def test_get_missing_discriminator(client): + assert await client.get_missing_discriminator() == Fish(age=1) + + +@pytest.mark.asyncio +async def test_get_wrong_discriminator(client): + assert await client.get_wrong_discriminator() == Fish(age=1, kind="wrongKind") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py new file mode 100644 index 0000000000..bcb16b645c --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py @@ -0,0 +1,34 @@ +# ------------------------------------------------------------------------- +# 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 type.model.inheritance.notdiscriminated.aio import NotDiscriminatedClient +from type.model.inheritance.notdiscriminated.models import Siamese + + +@pytest.fixture +async def client(): + async with NotDiscriminatedClient() as client: + yield client + + +@pytest.fixture +async def valid_body(): + return Siamese(name="abc", age=32, smart=True) + + +@pytest.mark.asyncio +async def test_get_valid(client, valid_body): + assert await client.get_valid() == valid_body + + +@pytest.mark.asyncio +async def test_post_valid(client, valid_body): + await client.post_valid(valid_body) + + +@pytest.mark.asyncio +async def test_put_valid(client, valid_body): + assert valid_body == await client.put_valid(valid_body) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py new file mode 100644 index 0000000000..0f8192ac76 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py @@ -0,0 +1,34 @@ +# ------------------------------------------------------------------------- +# 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 type.model.inheritance.recursive.aio import RecursiveClient +from type.model.inheritance.recursive.models import Extension + + +@pytest.fixture +async def client(): + async with RecursiveClient() as client: + yield client + + +@pytest.fixture +async def expected(): + return Extension( + { + "level": 0, + "extension": [{"level": 1, "extension": [{"level": 2}]}, {"level": 1}], + } + ) + + +@pytest.mark.asyncio +async def test_put(client: RecursiveClient, expected: Extension): + await client.put(expected) + + +@pytest.mark.asyncio +async def test_get(client: RecursiveClient, expected: Extension): + assert await client.get() == expected diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py new file mode 100644 index 0000000000..9e6767e861 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py @@ -0,0 +1,67 @@ +# ------------------------------------------------------------------------- +# 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 type.model.inheritance.singlediscriminator.aio import SingleDiscriminatorClient +from type.model.inheritance.singlediscriminator.models import Sparrow, Eagle, Bird, Dinosaur + + +@pytest.fixture +async def client(): + async with SingleDiscriminatorClient() as client: + yield client + + +@pytest.fixture +async def valid_body(): + return Sparrow(wingspan=1) + + +@pytest.mark.asyncio +async def test_get_model(client, valid_body): + assert await client.get_model() == valid_body + + +@pytest.mark.asyncio +async def test_put_model(client, valid_body): + await client.put_model(valid_body) + + +@pytest.fixture +async def recursive_body(): + return Eagle( + { + "wingspan": 5, + "kind": "eagle", + "partner": {"wingspan": 2, "kind": "goose"}, + "friends": [{"wingspan": 2, "kind": "seagull"}], + "hate": {"key3": {"wingspan": 1, "kind": "sparrow"}}, + } + ) + + +@pytest.mark.asyncio +async def test_get_recursive_model(client, recursive_body): + assert await client.get_recursive_model() == recursive_body + + +@pytest.mark.asyncio +async def test_put_recursive_model(client, recursive_body): + await client.put_recursive_model(recursive_body) + + +@pytest.mark.asyncio +async def test_get_missing_discriminator(client): + assert await client.get_missing_discriminator() == Bird(wingspan=1) + + +@pytest.mark.asyncio +async def test_get_wrong_discriminator(client): + assert await client.get_wrong_discriminator() == Bird(wingspan=1, kind="wrongKind") + + +@pytest.mark.asyncio +async def test_get_legacy_model(client): + assert await client.get_legacy_model() == Dinosaur(size=20, kind="t-rex") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_usage_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_usage_async.py new file mode 100644 index 0000000000..342dea20f2 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_usage_async.py @@ -0,0 +1,32 @@ +# ------------------------------------------------------------------------- +# 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 type.model.usage import models +from type.model.usage.aio import UsageClient + + +@pytest.fixture +async def client(): + async with UsageClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_input(client: UsageClient): + input = models.InputRecord(required_prop="example-value") + assert await client.input(input) is None + + +@pytest.mark.asyncio +async def test_output(client: UsageClient): + output = models.OutputRecord(required_prop="example-value") + assert output == await client.output() + + +@pytest.mark.asyncio +async def test_input_and_output(client: UsageClient): + input_output = models.InputOutputRecord(required_prop="example-value") + assert input_output == await client.input_and_output(input_output) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_visibility_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_visibility_async.py new file mode 100644 index 0000000000..5d5162b806 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_visibility_async.py @@ -0,0 +1,47 @@ +# ------------------------------------------------------------------------- +# 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 type.model.visibility.aio import VisibilityClient +from type.model.visibility import models + + +@pytest.fixture +async def client(): + async with VisibilityClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_get_model(client): + result = await client.get_model(models.VisibilityModel(query_prop=123)) + assert result == models.VisibilityModel(read_prop="abc") + + +@pytest.mark.asyncio +async def test_put_model(client): + await client.put_model(models.VisibilityModel(create_prop=["foo", "bar"], update_prop=[1, 2])) + + +@pytest.mark.asyncio +async def test_patch_model(client): + await client.patch_model(models.VisibilityModel(update_prop=[1, 2])) + + +@pytest.mark.asyncio +async def test_post_model(client): + await client.post_model(models.VisibilityModel(create_prop=["foo", "bar"])) + + +@pytest.mark.asyncio +async def test_delete_model(client): + await client.delete_model(models.VisibilityModel(delete_prop=True)) + + +@pytest.mark.asyncio +async def test_put_read_only_model(client): + await client.put_read_only_model( + models.ReadOnlyModel(optional_nullable_int_list=[1, 2], optional_string_record={"foo", "bar"}) + ) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py new file mode 100644 index 0000000000..3c8638c0a1 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py @@ -0,0 +1,352 @@ +# ------------------------------------------------------------------------- +# 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 type.property.additionalproperties import models +from type.property.additionalproperties.aio import AdditionalPropertiesClient + + +@pytest.fixture +async def client(): + async with AdditionalPropertiesClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_extends_different_spread_float(client: AdditionalPropertiesClient): + body = models.DifferentSpreadFloatDerived({"name": "abc", "prop": 43.125, "derivedProp": 43.125}) + assert await client.extends_different_spread_float.get() == body + await client.extends_different_spread_float.put(body) + + +@pytest.mark.asyncio +async def test_extends_different_spread_model(client: AdditionalPropertiesClient): + body = models.DifferentSpreadModelDerived( + {"knownProp": "abc", "prop": {"state": "ok"}, "derivedProp": {"state": "ok"}} + ) + assert await client.extends_different_spread_model.get() == body + await client.extends_different_spread_model.put(body) + + +@pytest.mark.asyncio +async def test_extends_different_spread_model_array(client: AdditionalPropertiesClient): + body = models.DifferentSpreadModelArrayDerived( + { + "knownProp": "abc", + "prop": [{"state": "ok"}, {"state": "ok"}], + "derivedProp": [{"state": "ok"}, {"state": "ok"}], + } + ) + assert await client.extends_different_spread_model_array.get() == body + await client.extends_different_spread_model_array.put(body) + + +@pytest.mark.asyncio +async def test_extends_different_spread_string(client: AdditionalPropertiesClient): + body = models.DifferentSpreadStringDerived({"id": 43.125, "prop": "abc", "derivedProp": "abc"}) + assert await client.extends_different_spread_string.get() == body + await client.extends_different_spread_string.put(body) + + +@pytest.mark.asyncio +async def test_extends_float(client: AdditionalPropertiesClient): + body = models.ExtendsFloatAdditionalProperties({"id": 43.125, "prop": 43.125}) + assert await client.extends_float.get() == body + await client.extends_float.put(body) + + +@pytest.mark.asyncio +async def test_extends_model(client: AdditionalPropertiesClient): + body = models.ExtendsModelAdditionalProperties({"knownProp": {"state": "ok"}, "prop": {"state": "ok"}}) + assert await client.extends_model.get() == body + await client.extends_model.put(body) + + +@pytest.mark.asyncio +async def test_extends_model_array(client: AdditionalPropertiesClient): + body = models.ExtendsModelArrayAdditionalProperties( + { + "knownProp": [{"state": "ok"}, {"state": "ok"}], + "prop": [{"state": "ok"}, {"state": "ok"}], + } + ) + assert await client.extends_model_array.get() == body + await client.extends_model_array.put(body) + + +@pytest.mark.asyncio +async def test_extends_string(client: AdditionalPropertiesClient): + body = models.ExtendsStringAdditionalProperties({"name": "ExtendsStringAdditionalProperties", "prop": "abc"}) + assert await client.extends_string.get() == body + await client.extends_string.put(body) + + +@pytest.mark.asyncio +async def test_extends_unknown(client: AdditionalPropertiesClient): + body = models.ExtendsUnknownAdditionalProperties( + { + "name": "ExtendsUnknownAdditionalProperties", + "prop1": 32, + "prop2": True, + "prop3": "abc", + } + ) + assert await client.extends_unknown.get() == body + await client.extends_unknown.put(body) + + +@pytest.mark.asyncio +async def test_extends_unknown_derived(client: AdditionalPropertiesClient): + body = models.ExtendsUnknownAdditionalPropertiesDerived( + { + "name": "ExtendsUnknownAdditionalProperties", + "index": 314, + "age": 2.71875, + "prop1": 32, + "prop2": True, + "prop3": "abc", + } + ) + assert await client.extends_unknown_derived.get() == body + await client.extends_unknown_derived.put(body) + + +@pytest.mark.asyncio +async def test_extends_unknown_discriminated(client: AdditionalPropertiesClient): + body = models.ExtendsUnknownAdditionalPropertiesDiscriminatedDerived( + { + "kind": "derived", + "name": "Derived", + "index": 314, + "age": 2.71875, + "prop1": 32, + "prop2": True, + "prop3": "abc", + } + ) + assert await client.extends_unknown_discriminated.get() == body + await client.extends_unknown_discriminated.put(body) + + +@pytest.mark.asyncio +async def test_is_float(client: AdditionalPropertiesClient): + body = models.IsFloatAdditionalProperties({"id": 43.125, "prop": 43.125}) + assert await client.is_float.get() == body + await client.is_float.put(body) + + +@pytest.mark.asyncio +async def test_is_model(client: AdditionalPropertiesClient): + body = models.IsModelAdditionalProperties({"knownProp": {"state": "ok"}, "prop": {"state": "ok"}}) + assert await client.is_model.get() == body + await client.is_model.put(body) + + +@pytest.mark.asyncio +async def test_is_model_array(client: AdditionalPropertiesClient): + body = models.IsModelArrayAdditionalProperties( + { + "knownProp": [{"state": "ok"}, {"state": "ok"}], + "prop": [{"state": "ok"}, {"state": "ok"}], + } + ) + assert await client.is_model_array.get() == body + await client.is_model_array.put(body) + + +@pytest.mark.asyncio +async def test_is_string(client: AdditionalPropertiesClient): + body = models.IsStringAdditionalProperties({"name": "IsStringAdditionalProperties", "prop": "abc"}) + assert await client.is_string.get() == body + await client.is_string.put(body) + + +@pytest.mark.asyncio +async def test_is_unknown(client: AdditionalPropertiesClient): + body = models.IsUnknownAdditionalProperties( + { + "name": "IsUnknownAdditionalProperties", + "prop1": 32, + "prop2": True, + "prop3": "abc", + } + ) + assert await client.is_unknown.get() == body + await client.is_unknown.put(body) + + +@pytest.mark.asyncio +async def test_is_unknown_derived(client: AdditionalPropertiesClient): + body = models.IsUnknownAdditionalPropertiesDerived( + { + "name": "IsUnknownAdditionalProperties", + "index": 314, + "age": 2.71875, + "prop1": 32, + "prop2": True, + "prop3": "abc", + } + ) + assert await client.is_unknown_derived.get() == body + await client.is_unknown_derived.put(body) + + +@pytest.mark.asyncio +async def test_is_unknown_discriminated(client: AdditionalPropertiesClient): + body = models.IsUnknownAdditionalPropertiesDiscriminatedDerived( + { + "kind": "derived", + "name": "Derived", + "index": 314, + "age": 2.71875, + "prop1": 32, + "prop2": True, + "prop3": "abc", + } + ) + assert await client.is_unknown_discriminated.get() == body + await client.is_unknown_discriminated.put(body) + + +@pytest.mark.asyncio +async def test_multiple_spread(client: AdditionalPropertiesClient): + body = {"flag": True, "prop1": "abc", "prop2": 43.125} + assert await client.multiple_spread.get() == body + await client.multiple_spread.put(body) + + +@pytest.mark.asyncio +async def test_spread_different_float(client: AdditionalPropertiesClient): + body = {"name": "abc", "prop": 43.125} + assert await client.spread_different_float.get() == body + await client.spread_different_float.put(body) + + +@pytest.mark.asyncio +async def test_spread_different_model(client: AdditionalPropertiesClient): + body = {"knownProp": "abc", "prop": {"state": "ok"}} + assert await client.spread_different_model.get() == body + await client.spread_different_model.put(body) + + +@pytest.mark.asyncio +async def test_spread_different_model_array(client: AdditionalPropertiesClient): + body = {"knownProp": "abc", "prop": [{"state": "ok"}, {"state": "ok"}]} + assert await client.spread_different_model_array.get() == body + await client.spread_different_model_array.put(body) + + +@pytest.mark.asyncio +async def test_spread_different_string(client: AdditionalPropertiesClient): + body = {"id": 43.125, "prop": "abc"} + assert await client.spread_different_string.get() == body + await client.spread_different_string.put(body) + + +@pytest.mark.asyncio +async def test_spread_model(client: AdditionalPropertiesClient): + body = {"knownProp": {"state": "ok"}, "prop": {"state": "ok"}} + assert await client.spread_model.get() == body + await client.spread_model.put(body) + + +@pytest.mark.asyncio +async def test_spread_model_array(client: AdditionalPropertiesClient): + body = { + "knownProp": [{"state": "ok"}, {"state": "ok"}], + "prop": [{"state": "ok"}, {"state": "ok"}], + } + assert await client.spread_model_array.get() == body + await client.spread_model_array.put(body) + + +@pytest.mark.asyncio +async def test_spread_record_discriminated_union(client: AdditionalPropertiesClient): + body = { + "name": "abc", + "prop1": {"fooProp": "abc", "kind": "kind0"}, + "prop2": { + "end": "2021-01-02T00:00:00Z", + "kind": "kind1", + "start": "2021-01-01T00:00:00Z", + }, + } + assert await client.spread_record_discriminated_union.get() == body + await client.spread_record_discriminated_union.put(body) + + +@pytest.mark.asyncio +async def test_spread_record_non_discriminated_union( + client: AdditionalPropertiesClient, +): + body = { + "name": "abc", + "prop1": {"kind": "kind0", "fooProp": "abc"}, + "prop2": { + "kind": "kind1", + "start": "2021-01-01T00:00:00Z", + "end": "2021-01-02T00:00:00Z", + }, + } + assert await client.spread_record_non_discriminated_union.get() == body + await client.spread_record_non_discriminated_union.put(body) + + +@pytest.mark.asyncio +async def test_spread_record_non_discriminated_union2( + client: AdditionalPropertiesClient, +): + body = { + "name": "abc", + "prop1": {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, + "prop2": { + "kind": "kind1", + "start": "2021-01-01T00:00:00Z", + "end": "2021-01-02T00:00:00Z", + }, + } + assert await client.spread_record_non_discriminated_union2.get() == body + await client.spread_record_non_discriminated_union2.put(body) + + +@pytest.mark.asyncio +async def test_spread_record_non_discriminated_union3( + client: AdditionalPropertiesClient, +): + body = { + "name": "abc", + "prop1": [ + {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, + {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, + ], + "prop2": { + "kind": "kind1", + "start": "2021-01-01T00:00:00Z", + "end": "2021-01-02T00:00:00Z", + }, + } + assert await client.spread_record_non_discriminated_union3.get() == body + await client.spread_record_non_discriminated_union3.put(body) + + +@pytest.mark.asyncio +async def test_spread_record_union(client: AdditionalPropertiesClient): + body = {"flag": True, "prop1": "abc", "prop2": 43.125} + assert await client.spread_record_union.get() == body + await client.spread_record_union.put(body) + + +@pytest.mark.asyncio +async def test_spread_string(client: AdditionalPropertiesClient): + body = {"name": "SpreadSpringRecord", "prop": "abc"} + assert await client.spread_string.get() == body + await client.spread_string.put(body) + + +@pytest.mark.asyncio +async def test_spread_float(client: AdditionalPropertiesClient): + body = {"id": 43.125, "prop": 43.125} + assert await client.spread_float.get() == body + await client.spread_float.put(body) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_nullable_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_nullable_async.py new file mode 100644 index 0000000000..70eeaf4e61 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_nullable_async.py @@ -0,0 +1,110 @@ +# cspell: ignore Hdvcmxk +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +import json +import pytest +from type.property.nullable import models +from type.property.nullable.aio import NullableClient +from type.property.nullable._model_base import ( # pylint: disable=protected-access + SdkJSONEncoder, +) + +try: + from corehttp.serialization import NULL +except ImportError: + from azure.core.serialization import NULL + + +@pytest.fixture +async def client(): + async with NullableClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_bytes(client: NullableClient): + non_null_model = models.BytesProperty(required_property="foo", nullable_property="aGVsbG8sIHdvcmxkIQ==") + non_model = models.BytesProperty(required_property="foo", nullable_property=NULL) + assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) + assert await client.bytes.get_non_null() == non_null_model + assert (await client.bytes.get_null())["nullableProperty"] is None + await client.bytes.patch_non_null(body=non_null_model) + await client.bytes.patch_null(body=non_model) + + +@pytest.mark.asyncio +async def test_collections_byte(client: NullableClient): + non_null_model = models.CollectionsByteProperty( + required_property="foo", + nullable_property=["aGVsbG8sIHdvcmxkIQ==", "aGVsbG8sIHdvcmxkIQ=="], + ) + non_model = models.CollectionsByteProperty(required_property="foo", nullable_property=NULL) + assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) + assert await client.collections_byte.get_non_null() == non_null_model + assert (await client.collections_byte.get_null())["nullableProperty"] is None + await client.collections_byte.patch_non_null(body=non_null_model) + await client.collections_byte.patch_null(body=non_model) + + +@pytest.mark.asyncio +async def test_collections_model(client: NullableClient): + non_null_model = models.CollectionsModelProperty( + required_property="foo", + nullable_property=[ + models.InnerModel(property="hello"), + models.InnerModel(property="world"), + ], + ) + non_model = models.CollectionsModelProperty(required_property="foo", nullable_property=NULL) + assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) + assert await client.collections_model.get_non_null() == non_null_model + assert (await client.collections_model.get_null())["nullableProperty"] is None + await client.collections_model.patch_non_null(body=non_null_model) + await client.collections_model.patch_null(body=non_model) + + +@pytest.mark.asyncio +async def test_collections_string(client: NullableClient): + non_null_model = models.CollectionsStringProperty(required_property="foo", nullable_property=["hello", "world"]) + non_model = models.CollectionsStringProperty(required_property="foo", nullable_property=NULL) + assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) + assert await client.collections_string.get_non_null() == non_null_model + assert (await client.collections_string.get_null())["nullableProperty"] is None + await client.collections_string.patch_non_null(body=non_null_model) + await client.collections_string.patch_null(body=non_model) + + +@pytest.mark.asyncio +async def test_datetime(client: NullableClient): + non_null_model = models.DatetimeProperty(required_property="foo", nullable_property="2022-08-26T18:38:00Z") + non_model = models.DatetimeProperty(required_property="foo", nullable_property=NULL) + assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) + assert await client.datetime.get_non_null() == non_null_model + assert (await client.datetime.get_null())["nullableProperty"] is None + await client.datetime.patch_non_null(body=non_null_model) + await client.datetime.patch_null(body=non_model) + + +@pytest.mark.asyncio +async def test_duration(client: NullableClient): + non_null_model = models.DurationProperty(required_property="foo", nullable_property="P123DT22H14M12.011S") + non_model = models.DurationProperty(required_property="foo", nullable_property=NULL) + assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) + assert await client.duration.get_non_null() == non_null_model + assert (await client.duration.get_null())["nullableProperty"] is None + await client.duration.patch_non_null(body=non_null_model) + await client.duration.patch_null(body=non_model) + + +@pytest.mark.asyncio +async def test_string(client: NullableClient): + non_null_model = models.StringProperty(required_property="foo", nullable_property="hello") + non_model = models.StringProperty(required_property="foo", nullable_property=NULL) + assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) + assert await client.string.get_non_null() == non_null_model + assert (await client.string.get_null())["nullableProperty"] is None + await client.string.patch_non_null(body=non_null_model) + await client.string.patch_null(body=non_model) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_optional_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_optional_async.py new file mode 100644 index 0000000000..bfa3dc80f1 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_optional_async.py @@ -0,0 +1,197 @@ +# cspell: ignore Hdvcmxk +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from typing import Any +import pytest +from type.property.optional import models +from type.property.optional.aio import OptionalClient + + +@pytest.fixture +async def client(): + async with OptionalClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_boolean_literal(client): + body = models.BooleanLiteralProperty(property=True) + assert await client.boolean_literal.get_all() == body + assert await client.boolean_literal.get_default() == models.BooleanLiteralProperty() + await client.boolean_literal.put_all(body) + await client.boolean_literal.put_default(models.BooleanLiteralProperty()) + + +@pytest.mark.asyncio +async def test_bytes(client): + body = models.BytesProperty(property="aGVsbG8sIHdvcmxkIQ==") + assert await client.bytes.get_all() == body + assert await client.bytes.get_default() == models.BytesProperty() + await client.bytes.put_all(body) + await client.bytes.put_default(models.BytesProperty()) + + +@pytest.mark.asyncio +async def test_collections_byte(client): + body = models.CollectionsByteProperty(property=["aGVsbG8sIHdvcmxkIQ==", "aGVsbG8sIHdvcmxkIQ=="]) + assert await client.collections_byte.get_all() == body + assert await client.collections_byte.get_default() == models.CollectionsByteProperty() + await client.collections_byte.put_all(body) + await client.collections_byte.put_default(models.CollectionsByteProperty()) + + +@pytest.mark.asyncio +async def test_collections_model(client): + body = models.CollectionsModelProperty( + property=[ + models.StringProperty(property="hello"), + models.StringProperty(property="world"), + ] + ) + assert await client.collections_model.get_all() == body + assert await client.collections_model.get_default() == models.CollectionsModelProperty() + await client.collections_model.put_all(body) + await client.collections_model.put_default(models.CollectionsModelProperty()) + + +@pytest.mark.asyncio +async def test_datetime(client): + body = models.DatetimeProperty(property="2022-08-26T18:38:00Z") + assert await client.datetime.get_all() == body + assert await client.datetime.get_default() == models.DatetimeProperty() + await client.datetime.put_all(body) + await client.datetime.put_default(models.DatetimeProperty()) + + +@pytest.mark.asyncio +async def test_duration(client): + body = models.DurationProperty(property="P123DT22H14M12.011S") + assert await client.duration.get_all() == body + assert await client.duration.get_default() == models.DurationProperty() + await client.duration.put_all(body) + await client.duration.put_default(models.DurationProperty()) + + +@pytest.mark.asyncio +async def test_float_literal(client): + body = models.FloatLiteralProperty(property=1.25) + assert await client.float_literal.get_all() == body + assert await client.float_literal.get_default() == models.FloatLiteralProperty() + await client.float_literal.put_all(body) + await client.float_literal.put_default(models.FloatLiteralProperty()) + + +@pytest.mark.asyncio +async def test_int_literal(client): + body = models.IntLiteralProperty(property=1) + assert await client.int_literal.get_all() == body + assert await client.int_literal.get_default() == models.IntLiteralProperty() + await client.int_literal.put_all(body) + await client.int_literal.put_default(models.IntLiteralProperty()) + + +@pytest.mark.asyncio +async def test_plaindate(client): + body = models.PlainDateProperty(property="2022-12-12") + assert await client.plain_date.get_all() == body + + +@pytest.mark.asyncio +async def test_plaindate(client): + assert await client.plain_date.get_default() == models.PlainDateProperty() + + +@pytest.mark.asyncio +async def test_plaindate(client): + body = models.PlainDateProperty(property="2022-12-12") + await client.plain_date.put_all(body) + + +@pytest.mark.asyncio +async def test_plaindate(client): + await client.plain_date.put_default(models.PlainDateProperty()) + + +@pytest.mark.asyncio +async def test_plaintime(client): + body = models.PlainTimeProperty(property="13:06:12") + assert await client.plain_time.get_all() == body + + +@pytest.mark.asyncio +async def test_plaintime(client): + assert await client.plain_time.get_default() == models.PlainTimeProperty() + + +@pytest.mark.asyncio +async def test_plaintime(client): + body = models.PlainTimeProperty(property="13:06:12") + await client.plain_time.put_all(body) + + +@pytest.mark.asyncio +async def test_plaintime(client): + await client.plain_time.put_default(models.PlainTimeProperty()) + + +@pytest.mark.asyncio +async def test_required_and_optional(client): + all_body = { + "optionalProperty": "hello", + "requiredProperty": 42, + } + required_only_body = { + "requiredProperty": 42, + } + assert await client.required_and_optional.get_all() == all_body + assert await client.required_and_optional.get_required_only() == required_only_body + await client.required_and_optional.put_all(all_body) + await client.required_and_optional.put_required_only(required_only_body) + + +@pytest.mark.asyncio +async def test_string(client): + body = models.StringProperty(property="hello") + assert await client.string.get_all() == body + assert await client.string.get_default() == models.StringProperty() + await client.string.put_all(body) + await client.string.put_default(models.StringProperty()) + + +@pytest.mark.asyncio +async def test_string_literal(client): + body = models.StringLiteralProperty(property="hello") + assert await client.string_literal.get_all() == body + assert await client.string_literal.get_default() == models.StringLiteralProperty() + await client.string_literal.put_all(body) + await client.string_literal.put_default(models.StringLiteralProperty()) + + +@pytest.mark.asyncio +async def test_union_float_literal(client): + body = models.UnionFloatLiteralProperty(property=2.375) + assert await client.union_float_literal.get_all() == body + assert await client.union_float_literal.get_default() == models.UnionFloatLiteralProperty() + await client.union_float_literal.put_all(body) + await client.union_float_literal.put_default(models.UnionFloatLiteralProperty()) + + +@pytest.mark.asyncio +async def test_union_int_literal(client): + body = models.UnionIntLiteralProperty(property=2) + assert await client.union_int_literal.get_all() == body + assert await client.union_int_literal.get_default() == models.UnionIntLiteralProperty() + await client.union_int_literal.put_all(body) + await client.union_int_literal.put_default(models.UnionIntLiteralProperty()) + + +@pytest.mark.asyncio +async def test_union_string_literal(client): + body = models.UnionStringLiteralProperty(property="world") + assert await client.union_string_literal.get_all() == body + assert await client.union_string_literal.get_default() == models.UnionStringLiteralProperty() + await client.union_string_literal.put_all(body) + await client.union_string_literal.put_default(models.UnionStringLiteralProperty()) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py new file mode 100644 index 0000000000..97f5260f77 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py @@ -0,0 +1,315 @@ +# cspell: ignore Hdvcmxk +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +import decimal + +import pytest +import datetime +from type.property.valuetypes import models +from type.property.valuetypes.aio import ValueTypesClient + + +@pytest.fixture +async def client(): + async with ValueTypesClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_boolean(client: ValueTypesClient): + body = models.BooleanProperty(property=True) + assert body.property == body["property"] + await client.boolean.put(body) + + resp = await client.boolean.get() + assert resp.property == resp["property"] == True + + +@pytest.mark.asyncio +async def test_boolean_literal(client: ValueTypesClient): + body = models.BooleanLiteralProperty(property=True) + assert body.property == body["property"] + await client.boolean_literal.put(body) + + resp = await client.boolean_literal.get() + assert resp.property == resp["property"] == True + + +@pytest.mark.asyncio +async def test_bytes(client: ValueTypesClient): + body = models.BytesProperty(property=b"hello, world!") + assert body.property == b"hello, world!" + assert body["property"] == "aGVsbG8sIHdvcmxkIQ==" + await client.bytes.put(body) + + resp = await client.bytes.get() + assert resp.property == b"hello, world!" + assert resp["property"] == "aGVsbG8sIHdvcmxkIQ==" + + +@pytest.mark.asyncio +async def test_collections_int(client: ValueTypesClient): + body = models.CollectionsIntProperty(property=[1, 2]) + assert body.property == body["property"] + await client.collections_int.put(body) + + resp = await client.collections_int.get() + assert resp.property == resp["property"] == [1, 2] + + +@pytest.mark.asyncio +async def test_collections_model(client: ValueTypesClient): + body = models.CollectionsModelProperty(property=[{"property": "hello"}, {"property": "world"}]) + assert body.property[0].property == body["property"][0]["property"] + await client.collections_model.put(body) + + resp = await client.collections_model.get() + assert resp.property[1].property == resp["property"][1]["property"] + + +@pytest.mark.asyncio +async def test_collections_string(client: ValueTypesClient): + body = models.CollectionsStringProperty(property=["hello", "world"]) + assert body.property == body["property"] + await client.collections_string.put(body) + + resp = await client.collections_string.get() + assert resp.property == resp["property"] == ["hello", "world"] + + +@pytest.mark.asyncio +async def test_datetime(client): + received_body = await client.datetime.get() + assert received_body == {"property": "2022-08-26T18:38:00Z"} + assert received_body.property.year == 2022 + assert received_body.property.month == 8 + assert received_body.property.day == 26 + assert received_body.property.hour == 18 + assert received_body.property.minute == 38 + + await client.datetime.put(models.DatetimeProperty(property=datetime.datetime(2022, 8, 26, hour=18, minute=38))) + + +@pytest.mark.asyncio +async def test_decimal(client: ValueTypesClient): + body = models.DecimalProperty(property=decimal.Decimal("0.33333")) + assert body.property == decimal.Decimal("0.33333") + assert body["property"] == 0.33333 + await client.decimal.put(body) + + resp = await client.decimal.get() + assert resp.property == decimal.Decimal("0.33333") + assert resp["property"] == 0.33333 + + +@pytest.mark.asyncio +async def test_decimal128(client: ValueTypesClient): + body = models.Decimal128Property(property=decimal.Decimal("0.33333")) + assert body.property == decimal.Decimal("0.33333") + assert body["property"] == 0.33333 + await client.decimal128.put(body) + + resp = await client.decimal128.get() + assert resp.property == decimal.Decimal("0.33333") + assert resp["property"] == 0.33333 + + +@pytest.mark.asyncio +async def test_dictionary_string(client: ValueTypesClient): + body = models.DictionaryStringProperty(property={"k1": "hello", "k2": "world"}) + assert body.property == body["property"] + await client.dictionary_string.put(body) + + resp = await client.dictionary_string.get() + assert resp.property == resp["property"] == {"k1": "hello", "k2": "world"} + + +@pytest.mark.asyncio +async def test_duration(client: ValueTypesClient): + body = models.DurationProperty(property="P123DT22H14M12.011S") + assert body.property == datetime.timedelta(days=123, seconds=80052, microseconds=11000) + assert body["property"] == "P123DT22H14M12.011S" + await client.duration.put(body) + + resp = await client.duration.get() + assert resp.property == datetime.timedelta(days=123, seconds=80052, microseconds=11000) + assert resp["property"] == "P123DT22H14M12.011S" + + +@pytest.mark.asyncio +async def test_enum(client: ValueTypesClient): + body = models.EnumProperty(property=models.InnerEnum.VALUE_ONE) + assert body.property == body["property"] + await client.enum.put(body) + + resp = await client.enum.get() + assert resp.property == resp["property"] == "ValueOne" + + +@pytest.mark.asyncio +async def test_extensible_enum(client: ValueTypesClient): + body = models.ExtensibleEnumProperty(property="UnknownValue") + assert body.property == body["property"] + await client.extensible_enum.put(body) + + resp = await client.extensible_enum.get() + assert resp.property == resp["property"] == "UnknownValue" + + +@pytest.mark.asyncio +async def test_float(client: ValueTypesClient): + body = models.FloatProperty(property=43.125) + assert body.property == body["property"] + await client.float.put(body) + + resp = await client.float.get() + assert resp.property == resp["property"] == 43.125 + + +@pytest.mark.asyncio +async def test_float_literal(client: ValueTypesClient): + body = models.FloatLiteralProperty(property=43.125) + assert body.property == body["property"] + await client.float_literal.put(body) + + resp = await client.float_literal.get() + assert resp.property == resp["property"] == 43.125 + + +@pytest.mark.asyncio +async def test_int(client: ValueTypesClient): + body = models.IntProperty(property=42) + assert body.property == body["property"] + await client.int_operations.put(body) + + resp = await client.int_operations.get() + assert resp.property == resp["property"] == 42 + + +@pytest.mark.asyncio +async def test_int_literal(client: ValueTypesClient): + body = models.IntLiteralProperty(property=42) + assert body.property == body["property"] + await client.int_literal.put(body) + + resp = await client.int_literal.get() + assert resp.property == resp["property"] == 42 + + +@pytest.mark.asyncio +async def test_model(client: ValueTypesClient): + body = models.ModelProperty(property={"property": "hello"}) + assert body.property.property == body["property"]["property"] + await client.model.put(body) + + resp = await client.model.get() + assert resp.property.property == resp["property"]["property"] + + +@pytest.mark.asyncio +async def test_never(client: ValueTypesClient): + assert await client.never.get() == models.NeverProperty() + await client.never.put(models.NeverProperty()) + + +@pytest.mark.asyncio +async def test_string(client: ValueTypesClient): + body = models.StringProperty(property="hello") + assert body.property == body["property"] + await client.string.put(body) + + resp = await client.string.get() + assert resp.property == resp["property"] == "hello" + + +@pytest.mark.asyncio +async def test_string_literal(client: ValueTypesClient): + body = models.StringLiteralProperty(property="hello") + assert body.property == body["property"] + await client.string_literal.put(body) + + resp = await client.string_literal.get() + assert resp.property == resp["property"] == "hello" + + +@pytest.mark.asyncio +async def test_union_enum_value(client: ValueTypesClient): + body = models.UnionEnumValueProperty(property=models.ExtendedEnum.ENUM_VALUE2) + assert body.property == body["property"] + await client.union_enum_value.put(body) + + resp = await client.union_enum_value.get() + assert resp.property == resp["property"] == "value2" + + +@pytest.mark.asyncio +async def test_union_float_literal(client: ValueTypesClient): + body = models.UnionFloatLiteralProperty(property=46.875) + assert body.property == body["property"] + await client.union_float_literal.put(body) + + resp = await client.union_float_literal.get() + assert resp.property == resp["property"] == 46.875 + + +@pytest.mark.asyncio +async def test_union_int_literal(client: ValueTypesClient): + body = models.UnionIntLiteralProperty(property=42) + assert body.property == body["property"] + await client.union_int_literal.put(body) + + resp = await client.union_int_literal.get() + assert resp.property == resp["property"] == 42 + + +@pytest.mark.asyncio +async def test_union_string_literal(client: ValueTypesClient): + body = models.UnionStringLiteralProperty(property="world") + assert body.property == body["property"] + await client.union_string_literal.put(body) + + resp = await client.union_string_literal.get() + assert resp.property == resp["property"] == "world" + + +@pytest.mark.asyncio +async def test_unknown_array(client: ValueTypesClient): + body = models.UnknownArrayProperty(property=["hello", "world"]) + assert body.property == body["property"] + await client.unknown_array.put(body) + + resp = await client.unknown_array.get() + assert resp.property == resp["property"] == ["hello", "world"] + + +@pytest.mark.asyncio +async def test_unknown_dict(client: ValueTypesClient): + body = models.UnknownDictProperty(property={"k1": "hello", "k2": 42}) + assert body.property == body["property"] + await client.unknown_dict.put(body) + + resp = await client.unknown_dict.get() + assert resp.property == resp["property"] == {"k1": "hello", "k2": 42} + + +@pytest.mark.asyncio +async def test_unknown_int(client: ValueTypesClient): + body = models.UnknownIntProperty(property=42) + assert body.property == body["property"] + await client.unknown_int.put(body) + + resp = await client.unknown_int.get() + assert resp.property == resp["property"] == 42 + + +@pytest.mark.asyncio +async def test_unknown_string(client: ValueTypesClient): + body = models.UnknownStringProperty(property="hello") + assert body.property == body["property"] + await client.unknown_string.put(body) + + resp = await client.unknown_string.get() + assert resp.property == resp["property"] == "hello" diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_scalar_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_scalar_async.py new file mode 100644 index 0000000000..c0ccb293d5 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_scalar_async.py @@ -0,0 +1,60 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +import decimal +from functools import reduce + +import pytest +from type.scalar.aio import ScalarClient + + +@pytest.fixture +async def client(): + async with ScalarClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_scalar_string(client: ScalarClient): + assert await client.string.get() == "test" + await client.string.put("test") + + +@pytest.mark.asyncio +async def test_scalar_boolean(client: ScalarClient): + assert await client.boolean.get() == True + await client.boolean.put(True) + + +@pytest.mark.asyncio +async def test_scalar_unknown(client: ScalarClient): + assert await client.unknown.get() == "test" + await client.unknown.put("test") + + +@pytest.mark.asyncio +async def test_decimal128_type(client: ScalarClient): + assert await client.decimal128_type.response_body() == decimal.Decimal("0.33333") + await client.decimal128_type.request_body(decimal.Decimal("0.33333")) + await client.decimal128_type.request_parameter(value=decimal.Decimal("0.33333")) + + +@pytest.mark.asyncio +async def test_decimal_type(client: ScalarClient): + assert await client.decimal_type.response_body() == decimal.Decimal("0.33333") + await client.decimal_type.request_body(decimal.Decimal("0.33333")) + await client.decimal_type.request_parameter(value=decimal.Decimal("0.33333")) + + +@pytest.mark.asyncio +async def test_decimal128_verify(client: ScalarClient): + prepare = await client.decimal128_verify.prepare_verify() + await client.decimal128_verify.verify(reduce(lambda x, y: x + y, prepare)) + + +@pytest.mark.asyncio +async def test_decimal_verify(client: ScalarClient): + prepare = await client.decimal_verify.prepare_verify() + await client.decimal_verify.verify(reduce(lambda x, y: x + y, prepare)) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_union_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_union_async.py new file mode 100644 index 0000000000..c85cf57407 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_union_async.py @@ -0,0 +1,90 @@ +# ------------------------------------------------------------------------- +# 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 type.union.aio import UnionClient +from type.union import models + + +@pytest.fixture +async def client(): + async with UnionClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_enums_only(client: UnionClient): + value = models.EnumsOnlyCases(lr="right", ud="up") + assert (await client.enums_only.get()) == {"prop": value} + await client.enums_only.send(prop=value) + + +@pytest.mark.asyncio +async def test_floats_only(client: UnionClient): + value = 2.2 + assert (await client.floats_only.get()) == {"prop": value} + await client.floats_only.send(prop=value) + + +@pytest.mark.asyncio +async def test_ints_only(client: UnionClient): + value = 2 + assert (await client.ints_only.get()) == {"prop": value} + await client.ints_only.send(prop=value) + + +@pytest.mark.asyncio +async def test_mixed_literals(client: UnionClient): + value = models.MixedLiteralsCases(string_literal="a", int_literal=2, float_literal=3.3, boolean_literal=True) + assert (await client.mixed_literals.get()) == {"prop": value} + await client.mixed_literals.send(prop=value) + + +@pytest.mark.asyncio +async def test_mixed_types(client: UnionClient): + value = models.MixedTypesCases( + model=models.Cat(name="test"), + literal="a", + int_property=2, + boolean=True, + array=[models.Cat(name="test"), "a", 2, True], + ) + assert (await client.mixed_types.get()) == {"prop": value} + await client.mixed_types.send(prop=value) + + +@pytest.mark.asyncio +async def test_models_only(client: UnionClient): + value = models.Cat(name="test") + assert (await client.models_only.get()) == {"prop": value} + await client.models_only.send(prop=value) + + +@pytest.mark.asyncio +async def test_string_and_array(client: UnionClient): + value = models.StringAndArrayCases(string="test", array=["test1", "test2"]) + assert (await client.string_and_array.get()) == {"prop": value} + await client.string_and_array.send(prop=value) + + +@pytest.mark.asyncio +async def test_string_extensible(client: UnionClient): + value = "custom" + assert (await client.string_extensible.get()) == {"prop": value} + await client.string_extensible.send(prop=value) + + +@pytest.mark.asyncio +async def test_string_extensible_named(client: UnionClient): + value = "custom" + assert (await client.string_extensible_named.get()) == {"prop": value} + await client.string_extensible_named.send(prop=value) + + +@pytest.mark.asyncio +async def test_strings_only(client: UnionClient): + value = "b" + assert (await client.strings_only.get()) == {"prop": value} + await client.strings_only.send(prop=value) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_unbranded_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_unbranded_async.py index 1ba8cc5750..c5dda175a7 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_unbranded_async.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_unbranded_async.py @@ -4,7 +4,7 @@ # ------------------------------------ import traceback import pytest -from typetest.scalar.aio import ScalarClient +from type.scalar.aio import ScalarClient from corehttp.exceptions import HttpResponseError diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_array.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_array.py new file mode 100644 index 0000000000..1af3bc8e46 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_array.py @@ -0,0 +1,103 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +import pytest +import isodate +from type.array import ArrayClient, models + + +@pytest.fixture +def client(): + with ArrayClient() as client: + yield client + + +def test_boolean_value(client: ArrayClient): + assert client.boolean_value.get() == [True, False] + client.boolean_value.put([True, False]) + + +def test_datetime_value(client: ArrayClient): + assert client.datetime_value.get() == [isodate.parse_datetime("2022-08-26T18:38:00Z")] + client.datetime_value.put([isodate.parse_datetime("2022-08-26T18:38:00Z")]) + + +def test_duration_value(client: ArrayClient): + assert client.duration_value.get() == [isodate.parse_duration("P123DT22H14M12.011S")] + client.duration_value.put([isodate.parse_duration("P123DT22H14M12.011S")]) + + +def test_float32_value(client: ArrayClient): + assert client.float32_value.get() == [43.125] + client.float32_value.put([43.125]) + + +def test_int32_value(client: ArrayClient): + assert client.int32_value.get() == [1, 2] + client.int32_value.put([1, 2]) + + +def test_int64_value(client: ArrayClient): + assert client.int64_value.get() == [2**53 - 1, -(2**53 - 1)] + client.int64_value.put([2**53 - 1, -(2**53 - 1)]) + + +def test_model_value(client: ArrayClient): + assert client.model_value.get() == [ + models.InnerModel(property="hello"), + models.InnerModel(property="world"), + ] + client.model_value.put( + [ + models.InnerModel(property="hello"), + models.InnerModel(property="world"), + ] + ) + + +def test_nullable_boolean_value(client: ArrayClient): + assert client.nullable_boolean_value.get() == [True, None, False] + client.nullable_boolean_value.put([True, None, False]) + + +def test_nullable_float_value(client: ArrayClient): + assert client.nullable_float_value.get() == [1.25, None, 3.0] + client.nullable_float_value.put([1.25, None, 3.0]) + + +def test_nullable_int32_value(client: ArrayClient): + assert client.nullable_int32_value.get() == [1, None, 3] + client.nullable_int32_value.put([1, None, 3]) + + +def test_nullable_model_value(client: ArrayClient): + assert client.nullable_model_value.get() == [ + models.InnerModel(property="hello"), + None, + models.InnerModel(property="world"), + ] + client.nullable_model_value.put( + [ + models.InnerModel(property="hello"), + None, + models.InnerModel(property="world"), + ] + ) + + +def test_nullable_string_value(client: ArrayClient): + assert client.nullable_string_value.get() == ["hello", None, "world"] + client.nullable_string_value.put(["hello", None, "world"]) + + +def test_string_value(client: ArrayClient): + assert client.string_value.get() == ["hello", ""] + client.string_value.put(["hello", ""]) + + +def test_unknown_value(client: ArrayClient): + assert client.unknown_value.get() == [1, "hello", None] + client.unknown_value.put([1, "hello", None]) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_dictionary.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_dictionary.py new file mode 100644 index 0000000000..5563a603fe --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_dictionary.py @@ -0,0 +1,86 @@ +# ------------------------------------------------------------------------- +# 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 type.dictionary import DictionaryClient, models +import isodate + + +@pytest.fixture +def client(): + with DictionaryClient() as client: + yield client + + +def test_boolean_value(client: DictionaryClient): + value = {"k1": True, "k2": False} + assert client.boolean_value.get() == value + client.boolean_value.put(value) + + +def test_datetime_value(client: DictionaryClient): + value = {"k1": isodate.parse_datetime("2022-08-26T18:38:00Z")} + assert client.datetime_value.get() == value + client.datetime_value.put(value) + + +def test_duration_value(client: DictionaryClient): + value = {"k1": isodate.parse_duration("P123DT22H14M12.011S")} + assert client.duration_value.get() == value + client.duration_value.put(value) + + +def test_float32_value(client: DictionaryClient): + value = {"k1": 43.125} + assert client.float32_value.get() == value + client.float32_value.put(value) + + +def test_int32_value(client: DictionaryClient): + value = {"k1": 1, "k2": 2} + assert client.int32_value.get() == value + client.int32_value.put(value) + + +def test_int64_value(client: DictionaryClient): + value = {"k1": 2**53 - 1, "k2": -(2**53 - 1)} + assert client.int64_value.get() == value + client.int64_value.put(value) + + +def test_model_value(client: DictionaryClient): + value = { + "k1": models.InnerModel(property="hello"), + "k2": models.InnerModel(property="world"), + } + assert client.model_value.get() == value + client.model_value.put(value) + + +def test_nullable_float_value(client: DictionaryClient): + value = {"k1": 1.25, "k2": 0.5, "k3": None} + assert client.nullable_float_value.get() == value + client.nullable_float_value.put(value) + + +def test_recursive_model_value(client: DictionaryClient): + value = { + "k1": models.InnerModel(property="hello", children={}), + "k2": models.InnerModel(property="world", children={"k2.1": models.InnerModel(property="inner world")}), + } + assert client.recursive_model_value.get() == value + client.recursive_model_value.put(value) + + +def test_string_value(client: DictionaryClient): + value = {"k1": "hello", "k2": ""} + assert client.string_value.get() == value + client.string_value.put(value) + + +def test_unknown_value(client: DictionaryClient): + value = {"k1": 1, "k2": "hello", "k3": None} + assert client.unknown_value.get() == value + client.unknown_value.put(value) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_extensible.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_extensible.py new file mode 100644 index 0000000000..d98cb59400 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_extensible.py @@ -0,0 +1,23 @@ +# ------------------------------------------------------------------------- +# 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 type.enum.extensible import ExtensibleClient, models + + +@pytest.fixture +def client(): + with ExtensibleClient() as client: + yield client + + +def test_known_value(client): + assert client.string.get_known_value() == models.DaysOfWeekExtensibleEnum.MONDAY + client.string.put_known_value(models.DaysOfWeekExtensibleEnum.MONDAY) + + +def test_unknown_value(client): + assert client.string.get_unknown_value() == "Weekend" + client.string.put_unknown_value("Weekend") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_fixed.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_fixed.py new file mode 100644 index 0000000000..720f61a766 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_fixed.py @@ -0,0 +1,26 @@ +# ------------------------------------------------------------------------- +# 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 type.enum.fixed import FixedClient, models +from corehttp.exceptions import HttpResponseError + + +@pytest.fixture +def client(): + with FixedClient() as client: + yield client + + +def test_known_value(client): + assert client.string.get_known_value() == models.DaysOfWeekEnum.MONDAY + client.string.put_known_value(models.DaysOfWeekEnum.MONDAY) + + +def test_unknown_value(client: FixedClient): + try: + client.string.put_unknown_value("Weekend") + except HttpResponseError as err: + assert err.status_code == 500 diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_empty.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_empty.py new file mode 100644 index 0000000000..38ad39e6b5 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_empty.py @@ -0,0 +1,29 @@ +# ------------------------------------------------------------------------- +# 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 type.model.empty import EmptyClient +from type.model.empty.models import EmptyInput, EmptyOutput, EmptyInputOutput + + +@pytest.fixture +def client(): + with EmptyClient() as client: + yield client + + +def test_put(client: EmptyClient): + client.put_empty(EmptyInput()) + client.put_empty({}) + + +def test_get(client: EmptyClient): + assert client.get_empty() == EmptyOutput() + assert client.get_empty() == {} + + +def test_post_round(client: EmptyClient): + assert client.post_round_trip_empty(EmptyInputOutput()) == EmptyInputOutput() + assert client.post_round_trip_empty({}) == {} diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py new file mode 100644 index 0000000000..837fe1b458 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py @@ -0,0 +1,58 @@ +# ------------------------------------------------------------------------- +# 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 type.model.inheritance.enumdiscriminator import EnumDiscriminatorClient +from type.model.inheritance.enumdiscriminator import models + + +@pytest.fixture +def client(): + with EnumDiscriminatorClient() as client: + yield client + + +@pytest.fixture +def valid_body(): + return models.Golden(weight=10) + + +@pytest.fixture +def valid_fixed_body(): + return models.Cobra(length=10) + + +def test_get_extensible_model(client: EnumDiscriminatorClient, valid_body: models.Dog): + assert client.get_extensible_model() == valid_body + assert isinstance(client.get_extensible_model(), models.Golden) + + +def test_put_extensible_model(client: EnumDiscriminatorClient, valid_body: models.Dog): + client.put_extensible_model(valid_body) + + +def test_get_extensible_model_missing_discriminator(client: EnumDiscriminatorClient): + assert client.get_extensible_model_missing_discriminator() == models.Dog(weight=10) + + +def test_get_extensible_model_wrong_discriminator(client: EnumDiscriminatorClient): + assert client.get_extensible_model_wrong_discriminator() == models.Dog(weight=8, kind="wrongKind") + + +def test_get_fixed_model(client: EnumDiscriminatorClient, valid_fixed_body: models.Snake): + assert client.get_fixed_model() == valid_fixed_body + assert isinstance(client.get_fixed_model(), models.Cobra) + + +def test_put_fixed_model(client: EnumDiscriminatorClient, valid_fixed_body: models.Snake): + client.put_fixed_model(valid_fixed_body) + + +def test_get_fixed_model_missing_discriminator(client: EnumDiscriminatorClient): + assert client.get_fixed_model_missing_discriminator() == models.Snake(length=10) + + +def test_get_fixed_model_wrong_discriminator(client: EnumDiscriminatorClient): + assert client.get_fixed_model_wrong_discriminator() == models.Snake(length=8, kind="wrongKind") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py new file mode 100644 index 0000000000..ba74713b7a --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py @@ -0,0 +1,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 type.model.inheritance.nesteddiscriminator import NestedDiscriminatorClient +from type.model.inheritance.nesteddiscriminator.models import GoblinShark, Salmon, Fish + + +@pytest.fixture +def client(): + with NestedDiscriminatorClient() as client: + yield client + + +@pytest.fixture +def valid_body(): + return GoblinShark(age=1) + + +def test_get_model(client, valid_body): + assert client.get_model() == valid_body + assert isinstance(client.get_model(), GoblinShark) + + +def test_put_model(client, valid_body): + client.put_model(valid_body) + + +@pytest.fixture +def valid_recursive_body(): + return Salmon( + { + "age": 1, + "kind": "salmon", + "partner": {"age": 2, "kind": "shark", "sharktype": "saw"}, + "friends": [ + { + "age": 2, + "kind": "salmon", + "partner": {"age": 3, "kind": "salmon"}, + "hate": { + "key1": {"age": 4, "kind": "salmon"}, + "key2": {"age": 2, "kind": "shark", "sharktype": "goblin"}, + }, + }, + {"age": 3, "kind": "shark", "sharktype": "goblin"}, + ], + "hate": { + "key3": {"age": 3, "kind": "shark", "sharktype": "saw"}, + "key4": { + "age": 2, + "kind": "salmon", + "friends": [ + {"age": 1, "kind": "salmon"}, + {"age": 4, "kind": "shark", "sharktype": "goblin"}, + ], + }, + }, + } + ) + + +def test_get_recursive_model(client, valid_recursive_body): + assert valid_recursive_body == client.get_recursive_model() + assert isinstance(client.get_recursive_model(), Salmon) + + +def test_put_recursive_model(client, valid_recursive_body): + client.put_recursive_model(valid_recursive_body) + + +def test_get_missing_discriminator(client): + assert client.get_missing_discriminator() == Fish(age=1) + + +def test_get_wrong_discriminator(client): + assert client.get_wrong_discriminator() == Fish(age=1, kind="wrongKind") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py new file mode 100644 index 0000000000..2bdbce464f --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py @@ -0,0 +1,31 @@ +# ------------------------------------------------------------------------- +# 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 type.model.inheritance.notdiscriminated import NotDiscriminatedClient +from type.model.inheritance.notdiscriminated.models import Siamese + + +@pytest.fixture +def client(): + with NotDiscriminatedClient() as client: + yield client + + +@pytest.fixture +def valid_body(): + return Siamese(name="abc", age=32, smart=True) + + +def test_get_valid(client, valid_body): + assert client.get_valid() == valid_body + + +def test_post_valid(client, valid_body): + client.post_valid(valid_body) + + +def test_put_valid(client, valid_body): + assert valid_body == client.put_valid(valid_body) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_recursive.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_recursive.py new file mode 100644 index 0000000000..f014b8d08e --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_recursive.py @@ -0,0 +1,32 @@ +# ------------------------------------------------------------------------- +# 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 type.model.inheritance.recursive import RecursiveClient +from type.model.inheritance.recursive.models import Extension + + +@pytest.fixture +def client(): + with RecursiveClient() as client: + yield client + + +@pytest.fixture +def expected(): + return Extension( + { + "level": 0, + "extension": [{"level": 1, "extension": [{"level": 2}]}, {"level": 1}], + } + ) + + +def test_put(client: RecursiveClient, expected: Extension): + client.put(expected) + + +def test_get(client: RecursiveClient, expected: Extension): + assert client.get() == expected diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py new file mode 100644 index 0000000000..d81729560c --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py @@ -0,0 +1,60 @@ +# ------------------------------------------------------------------------- +# 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 type.model.inheritance.singlediscriminator import SingleDiscriminatorClient +from type.model.inheritance.singlediscriminator.models import Sparrow, Eagle, Bird, Dinosaur + + +@pytest.fixture +def client(): + with SingleDiscriminatorClient() as client: + yield client + + +@pytest.fixture +def valid_body(): + return Sparrow(wingspan=1) + + +def test_get_model(client, valid_body): + assert client.get_model() == valid_body + + +def test_put_model(client, valid_body): + client.put_model(valid_body) + + +@pytest.fixture +def recursive_body(): + return Eagle( + { + "wingspan": 5, + "kind": "eagle", + "partner": {"wingspan": 2, "kind": "goose"}, + "friends": [{"wingspan": 2, "kind": "seagull"}], + "hate": {"key3": {"wingspan": 1, "kind": "sparrow"}}, + } + ) + + +def test_get_recursive_model(client, recursive_body): + assert client.get_recursive_model() == recursive_body + + +def test_put_recursive_model(client, recursive_body): + client.put_recursive_model(recursive_body) + + +def test_get_missing_discriminator(client): + assert client.get_missing_discriminator() == Bird(wingspan=1) + + +def test_get_wrong_discriminator(client): + assert client.get_wrong_discriminator() == Bird(wingspan=1, kind="wrongKind") + + +def test_get_legacy_model(client): + assert client.get_legacy_model() == Dinosaur(size=20, kind="t-rex") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_usage.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_usage.py new file mode 100644 index 0000000000..7541e8568e --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_usage.py @@ -0,0 +1,28 @@ +# ------------------------------------------------------------------------- +# 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 type.model.usage import UsageClient, models + + +@pytest.fixture +def client(): + with UsageClient() as client: + yield client + + +def test_input(client: UsageClient): + input = models.InputRecord(required_prop="example-value") + assert client.input(input) is None + + +def test_output(client: UsageClient): + output = models.OutputRecord(required_prop="example-value") + assert output == client.output() + + +def test_input_and_output(client: UsageClient): + input_output = models.InputOutputRecord(required_prop="example-value") + assert input_output == client.input_and_output(input_output) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_visibility.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_visibility.py new file mode 100644 index 0000000000..d7a56e5b3d --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_visibility.py @@ -0,0 +1,40 @@ +# ------------------------------------------------------------------------- +# 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 type.model.visibility import VisibilityClient, models + + +@pytest.fixture +def client(): + with VisibilityClient() as client: + yield client + + +def test_get_model(client): + result = client.get_model(models.VisibilityModel(query_prop=123)) + assert result == models.VisibilityModel(read_prop="abc") + + +def test_put_model(client): + client.put_model(models.VisibilityModel(create_prop=["foo", "bar"], update_prop=[1, 2])) + + +def test_patch_model(client): + client.patch_model(models.VisibilityModel(update_prop=[1, 2])) + + +def test_post_model(client): + client.post_model(models.VisibilityModel(create_prop=["foo", "bar"])) + + +def test_delete_model(client): + client.delete_model(models.VisibilityModel(delete_prop=True)) + + +def test_put_read_only_model(client): + client.put_read_only_model( + models.ReadOnlyModel(optional_nullable_int_list=[1, 2], optional_string_record={"foo", "bar"}) + ) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_additionalproperties.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_additionalproperties.py new file mode 100644 index 0000000000..d3e48a9701 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_additionalproperties.py @@ -0,0 +1,313 @@ +# ------------------------------------------------------------------------- +# 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 type.property.additionalproperties import AdditionalPropertiesClient, models + + +@pytest.fixture +def client(): + with AdditionalPropertiesClient() as client: + yield client + + +def test_extends_different_spread_float(client: AdditionalPropertiesClient): + body = models.DifferentSpreadFloatDerived({"name": "abc", "prop": 43.125, "derivedProp": 43.125}) + assert client.extends_different_spread_float.get() == body + client.extends_different_spread_float.put(body) + + +def test_extends_different_spread_model(client: AdditionalPropertiesClient): + body = models.DifferentSpreadModelDerived( + {"knownProp": "abc", "prop": {"state": "ok"}, "derivedProp": {"state": "ok"}} + ) + assert client.extends_different_spread_model.get() == body + client.extends_different_spread_model.put(body) + + +def test_extends_different_spread_model_array(client: AdditionalPropertiesClient): + body = models.DifferentSpreadModelArrayDerived( + { + "knownProp": "abc", + "prop": [{"state": "ok"}, {"state": "ok"}], + "derivedProp": [{"state": "ok"}, {"state": "ok"}], + } + ) + assert client.extends_different_spread_model_array.get() == body + client.extends_different_spread_model_array.put(body) + + +def test_extends_different_spread_string(client: AdditionalPropertiesClient): + body = models.DifferentSpreadStringDerived({"id": 43.125, "prop": "abc", "derivedProp": "abc"}) + assert client.extends_different_spread_string.get() == body + client.extends_different_spread_string.put(body) + + +def test_extends_float(client: AdditionalPropertiesClient): + body = models.ExtendsFloatAdditionalProperties({"id": 43.125, "prop": 43.125}) + assert client.extends_float.get() == body + client.extends_float.put(body) + + +def test_extends_model(client: AdditionalPropertiesClient): + body = models.ExtendsModelAdditionalProperties({"knownProp": {"state": "ok"}, "prop": {"state": "ok"}}) + assert client.extends_model.get() == body + client.extends_model.put(body) + + +def test_extends_model_array(client: AdditionalPropertiesClient): + body = models.ExtendsModelArrayAdditionalProperties( + { + "knownProp": [{"state": "ok"}, {"state": "ok"}], + "prop": [{"state": "ok"}, {"state": "ok"}], + } + ) + assert client.extends_model_array.get() == body + client.extends_model_array.put(body) + + +def test_extends_string(client: AdditionalPropertiesClient): + body = models.ExtendsStringAdditionalProperties({"name": "ExtendsStringAdditionalProperties", "prop": "abc"}) + assert client.extends_string.get() == body + client.extends_string.put(body) + + +def test_extends_unknown(client: AdditionalPropertiesClient): + body = models.ExtendsUnknownAdditionalProperties( + { + "name": "ExtendsUnknownAdditionalProperties", + "prop1": 32, + "prop2": True, + "prop3": "abc", + } + ) + assert client.extends_unknown.get() == body + client.extends_unknown.put(body) + + +def test_extends_unknown_derived(client: AdditionalPropertiesClient): + body = models.ExtendsUnknownAdditionalPropertiesDerived( + { + "name": "ExtendsUnknownAdditionalProperties", + "index": 314, + "age": 2.71875, + "prop1": 32, + "prop2": True, + "prop3": "abc", + } + ) + assert client.extends_unknown_derived.get() == body + client.extends_unknown_derived.put(body) + + +def test_extends_unknown_discriminated(client: AdditionalPropertiesClient): + body = models.ExtendsUnknownAdditionalPropertiesDiscriminatedDerived( + { + "kind": "derived", + "name": "Derived", + "index": 314, + "age": 2.71875, + "prop1": 32, + "prop2": True, + "prop3": "abc", + } + ) + assert client.extends_unknown_discriminated.get() == body + client.extends_unknown_discriminated.put(body) + + +def test_is_float(client: AdditionalPropertiesClient): + body = models.IsFloatAdditionalProperties({"id": 43.125, "prop": 43.125}) + assert client.is_float.get() == body + client.is_float.put(body) + + +def test_is_model(client: AdditionalPropertiesClient): + body = models.IsModelAdditionalProperties({"knownProp": {"state": "ok"}, "prop": {"state": "ok"}}) + assert client.is_model.get() == body + client.is_model.put(body) + + +def test_is_model_array(client: AdditionalPropertiesClient): + body = models.IsModelArrayAdditionalProperties( + { + "knownProp": [{"state": "ok"}, {"state": "ok"}], + "prop": [{"state": "ok"}, {"state": "ok"}], + } + ) + assert client.is_model_array.get() == body + client.is_model_array.put(body) + + +def test_is_string(client: AdditionalPropertiesClient): + body = models.IsStringAdditionalProperties({"name": "IsStringAdditionalProperties", "prop": "abc"}) + assert client.is_string.get() == body + client.is_string.put(body) + + +def test_is_unknown(client: AdditionalPropertiesClient): + body = models.IsUnknownAdditionalProperties( + { + "name": "IsUnknownAdditionalProperties", + "prop1": 32, + "prop2": True, + "prop3": "abc", + } + ) + assert client.is_unknown.get() == body + client.is_unknown.put(body) + + +def test_is_unknown_derived(client: AdditionalPropertiesClient): + body = models.IsUnknownAdditionalPropertiesDerived( + { + "name": "IsUnknownAdditionalProperties", + "index": 314, + "age": 2.71875, + "prop1": 32, + "prop2": True, + "prop3": "abc", + } + ) + assert client.is_unknown_derived.get() == body + client.is_unknown_derived.put(body) + + +def test_is_unknown_discriminated(client: AdditionalPropertiesClient): + body = models.IsUnknownAdditionalPropertiesDiscriminatedDerived( + { + "kind": "derived", + "name": "Derived", + "index": 314, + "age": 2.71875, + "prop1": 32, + "prop2": True, + "prop3": "abc", + } + ) + assert client.is_unknown_discriminated.get() == body + client.is_unknown_discriminated.put(body) + + +def test_multiple_spread(client: AdditionalPropertiesClient): + body = {"flag": True, "prop1": "abc", "prop2": 43.125} + assert client.multiple_spread.get() == body + client.multiple_spread.put(body) + + +def test_spread_different_float(client: AdditionalPropertiesClient): + body = {"name": "abc", "prop": 43.125} + assert client.spread_different_float.get() == body + client.spread_different_float.put(body) + + +def test_spread_different_model(client: AdditionalPropertiesClient): + body = {"knownProp": "abc", "prop": {"state": "ok"}} + assert client.spread_different_model.get() == body + client.spread_different_model.put(body) + + +def test_spread_different_model_array(client: AdditionalPropertiesClient): + body = {"knownProp": "abc", "prop": [{"state": "ok"}, {"state": "ok"}]} + assert client.spread_different_model_array.get() == body + client.spread_different_model_array.put(body) + + +def test_spread_different_string(client: AdditionalPropertiesClient): + body = {"id": 43.125, "prop": "abc"} + assert client.spread_different_string.get() == body + client.spread_different_string.put(body) + + +def test_spread_model(client: AdditionalPropertiesClient): + body = {"knownProp": {"state": "ok"}, "prop": {"state": "ok"}} + assert client.spread_model.get() == body + client.spread_model.put(body) + + +def test_spread_model_array(client: AdditionalPropertiesClient): + body = { + "knownProp": [{"state": "ok"}, {"state": "ok"}], + "prop": [{"state": "ok"}, {"state": "ok"}], + } + assert client.spread_model_array.get() == body + client.spread_model_array.put(body) + + +def test_spread_record_discriminated_union(client: AdditionalPropertiesClient): + body = { + "name": "abc", + "prop1": {"fooProp": "abc", "kind": "kind0"}, + "prop2": { + "end": "2021-01-02T00:00:00Z", + "kind": "kind1", + "start": "2021-01-01T00:00:00Z", + }, + } + assert client.spread_record_discriminated_union.get() == body + client.spread_record_discriminated_union.put(body) + + +def test_spread_record_non_discriminated_union(client: AdditionalPropertiesClient): + body = { + "name": "abc", + "prop1": {"kind": "kind0", "fooProp": "abc"}, + "prop2": { + "kind": "kind1", + "start": "2021-01-01T00:00:00Z", + "end": "2021-01-02T00:00:00Z", + }, + } + assert client.spread_record_non_discriminated_union.get() == body + client.spread_record_non_discriminated_union.put(body) + + +def test_spread_record_non_discriminated_union2(client: AdditionalPropertiesClient): + body = { + "name": "abc", + "prop1": {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, + "prop2": { + "kind": "kind1", + "start": "2021-01-01T00:00:00Z", + "end": "2021-01-02T00:00:00Z", + }, + } + assert client.spread_record_non_discriminated_union2.get() == body + client.spread_record_non_discriminated_union2.put(body) + + +def test_spread_record_non_discriminated_union3(client: AdditionalPropertiesClient): + body = { + "name": "abc", + "prop1": [ + {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, + {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, + ], + "prop2": { + "kind": "kind1", + "start": "2021-01-01T00:00:00Z", + "end": "2021-01-02T00:00:00Z", + }, + } + assert client.spread_record_non_discriminated_union3.get() == body + client.spread_record_non_discriminated_union3.put(body) + + +def test_spread_record_union(client: AdditionalPropertiesClient): + body = {"flag": True, "prop1": "abc", "prop2": 43.125} + assert client.spread_record_union.get() == body + client.spread_record_union.put(body) + + +def test_spread_string(client: AdditionalPropertiesClient): + body = {"name": "SpreadSpringRecord", "prop": "abc"} + assert client.spread_string.get() == body + client.spread_string.put(body) + + +def test_spread_float(client: AdditionalPropertiesClient): + body = {"id": 43.125, "prop": 43.125} + assert client.spread_float.get() == body + client.spread_float.put(body) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_nullable.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_nullable.py new file mode 100644 index 0000000000..528965447f --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_nullable.py @@ -0,0 +1,102 @@ +# cspell: ignore Hdvcmxk +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +import json +import pytest +from type.property.nullable import NullableClient, models +from type.property.nullable._model_base import ( # pylint: disable=protected-access + SdkJSONEncoder, +) + +try: + from corehttp.serialization import NULL +except ImportError: + from azure.core.serialization import NULL + + +@pytest.fixture +def client(): + with NullableClient() as client: + yield client + + +def test_bytes(client: NullableClient): + non_null_model = models.BytesProperty(required_property="foo", nullable_property="aGVsbG8sIHdvcmxkIQ==") + non_model = models.BytesProperty(required_property="foo", nullable_property=NULL) + assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) + assert client.bytes.get_non_null() == non_null_model + assert client.bytes.get_null()["nullableProperty"] is None + client.bytes.patch_non_null(body=non_null_model) + client.bytes.patch_null(body=non_model) + + +def test_collections_byte(client: NullableClient): + non_null_model = models.CollectionsByteProperty( + required_property="foo", + nullable_property=["aGVsbG8sIHdvcmxkIQ==", "aGVsbG8sIHdvcmxkIQ=="], + ) + non_model = models.CollectionsByteProperty(required_property="foo", nullable_property=NULL) + assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) + assert client.collections_byte.get_non_null() == non_null_model + assert client.collections_byte.get_null()["nullableProperty"] is None + client.collections_byte.patch_non_null(body=non_null_model) + client.collections_byte.patch_null(body=non_model) + + +def test_collections_model(client: NullableClient): + non_null_model = models.CollectionsModelProperty( + required_property="foo", + nullable_property=[ + models.InnerModel(property="hello"), + models.InnerModel(property="world"), + ], + ) + non_model = models.CollectionsModelProperty(required_property="foo", nullable_property=NULL) + assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) + assert client.collections_model.get_non_null() == non_null_model + assert client.collections_model.get_null()["nullableProperty"] is None + client.collections_model.patch_non_null(body=non_null_model) + client.collections_model.patch_null(body=non_model) + + +def test_collections_string(client: NullableClient): + non_null_model = models.CollectionsStringProperty(required_property="foo", nullable_property=["hello", "world"]) + non_model = models.CollectionsStringProperty(required_property="foo", nullable_property=NULL) + assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) + assert client.collections_string.get_non_null() == non_null_model + assert client.collections_string.get_null()["nullableProperty"] is None + client.collections_string.patch_non_null(body=non_null_model) + client.collections_string.patch_null(body=non_model) + + +def test_datetime(client: NullableClient): + non_null_model = models.DatetimeProperty(required_property="foo", nullable_property="2022-08-26T18:38:00Z") + non_model = models.DatetimeProperty(required_property="foo", nullable_property=NULL) + assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) + assert client.datetime.get_non_null() == non_null_model + assert client.datetime.get_null()["nullableProperty"] is None + client.datetime.patch_non_null(body=non_null_model) + client.datetime.patch_null(body=non_model) + + +def test_duration(client: NullableClient): + non_null_model = models.DurationProperty(required_property="foo", nullable_property="P123DT22H14M12.011S") + non_model = models.DurationProperty(required_property="foo", nullable_property=NULL) + assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) + assert client.duration.get_non_null() == non_null_model + assert client.duration.get_null()["nullableProperty"] is None + client.duration.patch_non_null(body=non_null_model) + client.duration.patch_null(body=non_model) + + +def test_string(client: NullableClient): + non_null_model = models.StringProperty(required_property="foo", nullable_property="hello") + non_model = models.StringProperty(required_property="foo", nullable_property=NULL) + assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) + assert client.string.get_non_null() == non_null_model + assert client.string.get_null()["nullableProperty"] is None + client.string.patch_non_null(body=non_null_model) + client.string.patch_null(body=non_model) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_optional.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_optional.py new file mode 100644 index 0000000000..7f2d0d75aa --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_optional.py @@ -0,0 +1,174 @@ +# cspell: ignore Hdvcmxk +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from typing import Any +import pytest +from type.property.optional import OptionalClient, models + + +@pytest.fixture +def client(): + with OptionalClient() as client: + yield client + + +def test_boolean_literal(client): + body = models.BooleanLiteralProperty(property=True) + assert client.boolean_literal.get_all() == body + assert client.boolean_literal.get_default() == models.BooleanLiteralProperty() + client.boolean_literal.put_all(body) + client.boolean_literal.put_default(models.BooleanLiteralProperty()) + + +def test_bytes(client): + body = models.BytesProperty(property="aGVsbG8sIHdvcmxkIQ==") + assert client.bytes.get_all() == body + assert client.bytes.get_default() == models.BytesProperty() + client.bytes.put_all(body) + client.bytes.put_default(models.BytesProperty()) + + +def test_collections_byte(client): + body = models.CollectionsByteProperty(property=["aGVsbG8sIHdvcmxkIQ==", "aGVsbG8sIHdvcmxkIQ=="]) + assert client.collections_byte.get_all() == body + assert client.collections_byte.get_default() == models.CollectionsByteProperty() + client.collections_byte.put_all(body) + client.collections_byte.put_default(models.CollectionsByteProperty()) + + +def test_collections_model(client): + body = models.CollectionsModelProperty( + property=[ + models.StringProperty(property="hello"), + models.StringProperty(property="world"), + ] + ) + assert client.collections_model.get_all() == body + assert client.collections_model.get_default() == models.CollectionsModelProperty() + client.collections_model.put_all(body) + client.collections_model.put_default(models.CollectionsModelProperty()) + + +def test_datetime(client): + body = models.DatetimeProperty(property="2022-08-26T18:38:00Z") + assert client.datetime.get_all() == body + assert client.datetime.get_default() == models.DatetimeProperty() + client.datetime.put_all(body) + client.datetime.put_default(models.DatetimeProperty()) + + +def test_duration(client): + body = models.DurationProperty(property="P123DT22H14M12.011S") + assert client.duration.get_all() == body + assert client.duration.get_default() == models.DurationProperty() + client.duration.put_all(body) + client.duration.put_default(models.DurationProperty()) + + +def test_float_literal(client): + body = models.FloatLiteralProperty(property=1.25) + assert client.float_literal.get_all() == body + assert client.float_literal.get_default() == models.FloatLiteralProperty() + client.float_literal.put_all(body) + client.float_literal.put_default(models.FloatLiteralProperty()) + + +def test_int_literal(client): + body = models.IntLiteralProperty(property=1) + assert client.int_literal.get_all() == body + assert client.int_literal.get_default() == models.IntLiteralProperty() + client.int_literal.put_all(body) + client.int_literal.put_default(models.IntLiteralProperty()) + + +def test_plaindate_get_all(client): + body = models.PlainDateProperty(property="2022-12-12") + assert client.plain_date.get_all() == body + + +def test_plaindate_get_default(client): + assert client.plain_date.get_default() == models.PlainDateProperty() + + +def test_plaindate_put_all(client): + body = models.PlainDateProperty(property="2022-12-12") + client.plain_date.put_all(body) + + +def test_plaindate_put_default(client): + client.plain_date.put_default(models.PlainDateProperty()) + + +def test_plaintime_get_all(client): + body = models.PlainTimeProperty(property="13:06:12") + assert client.plain_time.get_all() == body + + +def test_plaintime_get_default(client): + assert client.plain_time.get_default() == models.PlainTimeProperty() + + +def test_plaintime_put_all(client): + body = models.PlainTimeProperty(property="13:06:12") + client.plain_time.put_all(body) + + +def test_plaintime_put_default(client): + client.plain_time.put_default(models.PlainTimeProperty()) + + +def test_required_and_optional(client): + all_body = { + "optionalProperty": "hello", + "requiredProperty": 42, + } + required_only_body = { + "requiredProperty": 42, + } + assert client.required_and_optional.get_all() == all_body + assert client.required_and_optional.get_required_only() == required_only_body + client.required_and_optional.put_all(all_body) + client.required_and_optional.put_required_only(required_only_body) + + +def test_string(client): + body = models.StringProperty(property="hello") + assert client.string.get_all() == body + assert client.string.get_default() == models.StringProperty() + client.string.put_all(body) + client.string.put_default(models.StringProperty()) + + +def test_string_literal(client): + body = models.StringLiteralProperty(property="hello") + assert client.string_literal.get_all() == body + assert client.string_literal.get_default() == models.StringLiteralProperty() + client.string_literal.put_all(body) + client.string_literal.put_default(models.StringLiteralProperty()) + + +def test_union_float_literal(client): + body = models.UnionFloatLiteralProperty(property=2.375) + assert client.union_float_literal.get_all() == body + assert client.union_float_literal.get_default() == models.UnionFloatLiteralProperty() + client.union_float_literal.put_all(body) + client.union_float_literal.put_default(models.UnionFloatLiteralProperty()) + + +def test_union_int_literal(client): + body = models.UnionIntLiteralProperty(property=2) + assert client.union_int_literal.get_all() == body + assert client.union_int_literal.get_default() == models.UnionIntLiteralProperty() + client.union_int_literal.put_all(body) + client.union_int_literal.put_default(models.UnionIntLiteralProperty()) + + +def test_union_string_literal(client): + body = models.UnionStringLiteralProperty(property="world") + assert client.union_string_literal.get_all() == body + assert client.union_string_literal.get_default() == models.UnionStringLiteralProperty() + client.union_string_literal.put_all(body) + client.union_string_literal.put_default(models.UnionStringLiteralProperty()) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_valuetypes.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_valuetypes.py new file mode 100644 index 0000000000..8171a944d1 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_valuetypes.py @@ -0,0 +1,286 @@ +# cspell: ignore Hdvcmxk +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from calendar import c +import decimal + +import pytest +import datetime +from type.property.valuetypes import ValueTypesClient, models + + +@pytest.fixture +def client(): + with ValueTypesClient() as client: + yield client + + +def test_boolean(client: ValueTypesClient): + body = models.BooleanProperty(property=True) + assert body.property == body["property"] + client.boolean.put(body) + + resp = client.boolean.get() + assert resp.property == resp["property"] == True + + +def test_boolean_literal(client: ValueTypesClient): + body = models.BooleanLiteralProperty(property=True) + assert body.property == body["property"] + client.boolean_literal.put(body) + + resp = client.boolean_literal.get() + assert resp.property == resp["property"] == True + + +def test_bytes(client: ValueTypesClient): + body = models.BytesProperty(property=b"hello, world!") + assert body.property == b"hello, world!" + assert body["property"] == "aGVsbG8sIHdvcmxkIQ==" + client.bytes.put(body) + + resp = client.bytes.get() + assert resp.property == b"hello, world!" + assert resp["property"] == "aGVsbG8sIHdvcmxkIQ==" + + +def test_collections_int(client: ValueTypesClient): + body = models.CollectionsIntProperty(property=[1, 2]) + assert body.property == body["property"] + client.collections_int.put(body) + + resp = client.collections_int.get() + assert resp.property == resp["property"] == [1, 2] + + +def test_collections_model(client: ValueTypesClient): + body = models.CollectionsModelProperty(property=[{"property": "hello"}, {"property": "world"}]) + assert body.property[0].property == body["property"][0]["property"] + client.collections_model.put(body) + + resp = client.collections_model.get() + assert resp.property[1].property == resp["property"][1]["property"] + + +def test_collections_string(client: ValueTypesClient): + body = models.CollectionsStringProperty(property=["hello", "world"]) + assert body.property == body["property"] + client.collections_string.put(body) + + resp = client.collections_string.get() + assert resp.property == resp["property"] == ["hello", "world"] + + +def test_datetime(client): + received_body = client.datetime.get() + assert received_body == {"property": "2022-08-26T18:38:00Z"} + assert received_body.property.year == 2022 + assert received_body.property.month == 8 + assert received_body.property.day == 26 + assert received_body.property.hour == 18 + assert received_body.property.minute == 38 + + client.datetime.put(models.DatetimeProperty(property=datetime.datetime(2022, 8, 26, hour=18, minute=38))) + + +def test_decimal(client: ValueTypesClient): + body = models.DecimalProperty(property=decimal.Decimal("0.33333")) + assert body.property == decimal.Decimal("0.33333") + assert body["property"] == 0.33333 + client.decimal.put(body) + + resp = client.decimal.get() + assert resp.property == decimal.Decimal("0.33333") + assert resp["property"] == 0.33333 + + +def test_decimal128(client: ValueTypesClient): + body = models.Decimal128Property(property=decimal.Decimal("0.33333")) + assert body.property == decimal.Decimal("0.33333") + assert body["property"] == 0.33333 + client.decimal128.put(body) + + resp = client.decimal128.get() + assert resp.property == decimal.Decimal("0.33333") + assert resp["property"] == 0.33333 + + +def test_dictionary_string(client: ValueTypesClient): + body = models.DictionaryStringProperty(property={"k1": "hello", "k2": "world"}) + assert body.property == body["property"] + client.dictionary_string.put(body) + + resp = client.dictionary_string.get() + assert resp.property == resp["property"] == {"k1": "hello", "k2": "world"} + + +def test_duration(client: ValueTypesClient): + body = models.DurationProperty(property="P123DT22H14M12.011S") + assert body.property == datetime.timedelta(days=123, seconds=80052, microseconds=11000) + assert body["property"] == "P123DT22H14M12.011S" + client.duration.put(body) + + resp = client.duration.get() + assert resp.property == datetime.timedelta(days=123, seconds=80052, microseconds=11000) + assert resp["property"] == "P123DT22H14M12.011S" + + +def test_enum(client: ValueTypesClient): + body = models.EnumProperty(property=models.InnerEnum.VALUE_ONE) + assert body.property == body["property"] + client.enum.put(body) + + resp = client.enum.get() + assert resp.property == resp["property"] == "ValueOne" + + +def test_extensible_enum(client: ValueTypesClient): + body = models.ExtensibleEnumProperty(property="UnknownValue") + assert body.property == body["property"] + client.extensible_enum.put(body) + + resp = client.extensible_enum.get() + assert resp.property == resp["property"] == "UnknownValue" + + +def test_float(client: ValueTypesClient): + body = models.FloatProperty(property=43.125) + assert body.property == body["property"] + client.float.put(body) + + resp = client.float.get() + assert resp.property == resp["property"] == 43.125 + + +def test_float_literal(client: ValueTypesClient): + body = models.FloatLiteralProperty(property=43.125) + assert body.property == body["property"] + client.float_literal.put(body) + + resp = client.float_literal.get() + assert resp.property == resp["property"] == 43.125 + + +def test_int(client: ValueTypesClient): + body = models.IntProperty(property=42) + assert body.property == body["property"] + client.int_operations.put(body) + + resp = client.int_operations.get() + assert resp.property == resp["property"] == 42 + + +def test_int_literal(client: ValueTypesClient): + body = models.IntLiteralProperty(property=42) + assert body.property == body["property"] + client.int_literal.put(body) + + resp = client.int_literal.get() + assert resp.property == resp["property"] == 42 + + +def test_model(client: ValueTypesClient): + body = models.ModelProperty(property={"property": "hello"}) + assert body.property.property == body["property"]["property"] + client.model.put(body) + + resp = client.model.get() + assert resp.property.property == resp["property"]["property"] + + +def test_never(client: ValueTypesClient): + assert client.never.get() == models.NeverProperty() + client.never.put(models.NeverProperty()) + + +def test_string(client: ValueTypesClient): + body = models.StringProperty(property="hello") + assert body.property == body["property"] + client.string.put(body) + + resp = client.string.get() + assert resp.property == resp["property"] == "hello" + + +def test_string_literal(client: ValueTypesClient): + body = models.StringLiteralProperty(property="hello") + assert body.property == body["property"] + client.string_literal.put(body) + + resp = client.string_literal.get() + assert resp.property == resp["property"] == "hello" + + +def test_union_enum_value(client: ValueTypesClient): + body = models.UnionEnumValueProperty(property=models.ExtendedEnum.ENUM_VALUE2) + assert body.property == body["property"] + client.union_enum_value.put(body) + + resp = client.union_enum_value.get() + assert resp.property == resp["property"] == "value2" + + +def test_union_float_literal(client: ValueTypesClient): + body = models.UnionFloatLiteralProperty(property=46.875) + assert body.property == body["property"] + client.union_float_literal.put(body) + + resp = client.union_float_literal.get() + assert resp.property == resp["property"] == 46.875 + + +def test_union_int_literal(client: ValueTypesClient): + body = models.UnionIntLiteralProperty(property=42) + assert body.property == body["property"] + client.union_int_literal.put(body) + + resp = client.union_int_literal.get() + assert resp.property == resp["property"] == 42 + + +def test_union_string_literal(client: ValueTypesClient): + body = models.UnionStringLiteralProperty(property="world") + assert body.property == body["property"] + client.union_string_literal.put(body) + + resp = client.union_string_literal.get() + assert resp.property == resp["property"] == "world" + + +def test_unknown_array(client: ValueTypesClient): + body = models.UnknownArrayProperty(property=["hello", "world"]) + assert body.property == body["property"] + client.unknown_array.put(body) + + resp = client.unknown_array.get() + assert resp.property == resp["property"] == ["hello", "world"] + + +def test_unknown_dict(client: ValueTypesClient): + body = models.UnknownDictProperty(property={"k1": "hello", "k2": 42}) + assert body.property == body["property"] + client.unknown_dict.put(body) + + resp = client.unknown_dict.get() + assert resp.property == resp["property"] == {"k1": "hello", "k2": 42} + + +def test_unknown_int(client: ValueTypesClient): + body = models.UnknownIntProperty(property=42) + assert body.property == body["property"] + client.unknown_int.put(body) + + resp = client.unknown_int.get() + assert resp.property == resp["property"] == 42 + + +def test_unknown_string(client: ValueTypesClient): + body = models.UnknownStringProperty(property="hello") + assert body.property == body["property"] + client.unknown_string.put(body) + + resp = client.unknown_string.get() + assert resp.property == resp["property"] == "hello" diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_scalar.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_scalar.py new file mode 100644 index 0000000000..2dadfe8429 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_scalar.py @@ -0,0 +1,53 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +import decimal +from functools import reduce + +import pytest +from type.scalar import ScalarClient + + +@pytest.fixture +def client(): + with ScalarClient() as client: + yield client + + +def test_scalar_string(client: ScalarClient): + assert client.string.get() == "test" + client.string.put("test") + + +def test_scalar_boolean(client: ScalarClient): + assert client.boolean.get() == True + client.boolean.put(True) + + +def test_scalar_unknown(client: ScalarClient): + assert client.unknown.get() == "test" + client.unknown.put("test") + + +def test_decimal128_type(client: ScalarClient): + assert client.decimal128_type.response_body() == decimal.Decimal("0.33333") + client.decimal128_type.request_body(decimal.Decimal("0.33333")) + client.decimal128_type.request_parameter(value=decimal.Decimal("0.33333")) + + +def test_decimal_type(client: ScalarClient): + assert client.decimal_type.response_body() == decimal.Decimal("0.33333") + client.decimal_type.request_body(decimal.Decimal("0.33333")) + client.decimal_type.request_parameter(value=decimal.Decimal("0.33333")) + + +def test_decimal128_verify(client: ScalarClient): + prepare = client.decimal128_verify.prepare_verify() + client.decimal128_verify.verify(reduce(lambda x, y: x + y, prepare)) + + +def test_decimal_verify(client: ScalarClient): + prepare = client.decimal_verify.prepare_verify() + client.decimal_verify.verify(reduce(lambda x, y: x + y, prepare)) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_union.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_union.py new file mode 100644 index 0000000000..18c3f1b4c4 --- /dev/null +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_union.py @@ -0,0 +1,80 @@ +# ------------------------------------------------------------------------- +# 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 type.union import UnionClient +from type.union import models + + +@pytest.fixture +def client(): + with UnionClient() as client: + yield client + + +def test_enums_only(client: UnionClient): + value = models.EnumsOnlyCases(lr="right", ud="up") + assert client.enums_only.get() == {"prop": value} + client.enums_only.send(prop=value) + + +def test_floats_only(client: UnionClient): + value = 2.2 + assert client.floats_only.get() == {"prop": value} + client.floats_only.send(prop=value) + + +def test_ints_only(client: UnionClient): + value = 2 + assert client.ints_only.get() == {"prop": value} + client.ints_only.send(prop=value) + + +def test_mixed_literals(client: UnionClient): + value = models.MixedLiteralsCases(string_literal="a", int_literal=2, float_literal=3.3, boolean_literal=True) + assert client.mixed_literals.get() == {"prop": value} + client.mixed_literals.send(prop=value) + + +def test_mixed_types(client: UnionClient): + value = models.MixedTypesCases( + model=models.Cat(name="test"), + literal="a", + int_property=2, + boolean=True, + array=[models.Cat(name="test"), "a", 2, True], + ) + assert client.mixed_types.get() == {"prop": value} + client.mixed_types.send(prop=value) + + +def test_models_only(client: UnionClient): + value = models.Cat(name="test") + assert client.models_only.get() == {"prop": value} + client.models_only.send(prop=value) + + +def test_string_and_array(client: UnionClient): + value = models.StringAndArrayCases(string="test", array=["test1", "test2"]) + assert client.string_and_array.get() == {"prop": value} + client.string_and_array.send(prop=value) + + +def test_string_extensible(client: UnionClient): + value = "custom" + assert client.string_extensible.get() == {"prop": value} + client.string_extensible.send(prop=value) + + +def test_string_extensible_named(client: UnionClient): + value = "custom" + assert client.string_extensible_named.get() == {"prop": value} + client.string_extensible_named.send(prop=value) + + +def test_strings_only(client: UnionClient): + value = "b" + assert client.strings_only.get() == {"prop": value} + client.strings_only.send(prop=value) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_unbranded.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_unbranded.py index 1f52da5d0f..b4115b0211 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_unbranded.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_unbranded.py @@ -9,7 +9,7 @@ import traceback from importlib import import_module import pytest -from typetest.scalar import ScalarClient +from type.scalar import ScalarClient from corehttp.exceptions import HttpResponseError