Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tadelesh committed Apr 7, 2024
1 parent 67bf2aa commit 350e89a
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -------------------------------------------------------------------------
# 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 specs.azure.core.scalar.aio import ScalarClient
from specs.azure.core.scalar import models


@pytest.fixture
async def client():
async with ScalarClient() as client:
yield client


async def test_azure_location_scalar_get(client: ScalarClient):
result = await client.azure_location_scalar.get()
assert result == "eastus"


async def test_azure_location_scalar_put(client: ScalarClient):
await client.azure_location_scalar.put("eastus")


async def test_azure_location_scalar_post(client: ScalarClient):
result = await client.azure_location_scalar.post(
models.AzureLocationModel(location="eastus")
)
assert result == models.AzureLocationModel(location="eastus")


async def test_azure_location_scalar_header(client: ScalarClient):
await client.azure_location_scalar.header(region="eastus")


async def test_azure_location_scalar_query(client: ScalarClient):
await client.azure_location_scalar.query(region="eastus")
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -------------------------------------------------------------------------
# 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 specs.azure.core.scalar import ScalarClient, models


@pytest.fixture
def client():
with ScalarClient() as client:
yield client


def test_azure_location_scalar_get(client: ScalarClient):
result = client.azure_location_scalar.get()
assert result == "eastus"


def test_azure_location_scalar_put(client: ScalarClient):
client.azure_location_scalar.put("eastus")


def test_azure_location_scalar_post(client: ScalarClient):
result = client.azure_location_scalar.post(
models.AzureLocationModel(location="eastus")
)
assert result == models.AzureLocationModel(location="eastus")


def test_azure_location_scalar_header(client: ScalarClient):
client.azure_location_scalar.header(region="eastus")


def test_azure_location_scalar_query(client: ScalarClient):
client.azure_location_scalar.query(region="eastus")
1 change: 1 addition & 0 deletions packages/typespec-python/test/azure/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ azure-core==1.30.0
-e ./generated/azure-client-generator-core-usage
-e ./generated/azure-client-generator-core-flatten
-e ./generated/azure-core-basic
-e ./generated/azure-core-scalar
-e ./generated/azurecore-lro-rpclegacy
-e ./generated/azurecore-lro-rpc
-e ./generated/azure-core-lro-standard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,13 @@ async def test_model_client(client: NamingClient):
@pytest.mark.asyncio
async def test_model_language(client: NamingClient):
await client.model.language(models.PythonModel(default_name=True))


@pytest.mark.asyncio
async def test_union_enum_member_name(client: NamingClient):
await client.union_enum.union_enum_member_name(models.ExtensibleEnum.CLIENT_ENUM_VALUE1)


@pytest.mark.asyncio
async def test_union_enum_member_name(client: NamingClient):
await client.union_enum.union_enum_name(models.ClientExtensibleEnum.ENUM_VALUE1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -------------------------------------------------------------------------
# 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 server.endpoint.notdefined.aio import NotDefinedClient


@pytest.fixture
async def client():
async with NotDefinedClient(endpoint="http://localhost:3000") as client:
yield client


@pytest.mark.asyncio
async def test_valid(client: NotDefinedClient):
assert await client.valid() is True
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ async def client():

@pytest.mark.asyncio
@pytest.mark.parametrize(
"og_name,val", [
"og_name,val",
[
("boolean", True),
("string", "hello"),
("bytes", "aGVsbG8sIHdvcmxkIQ=="),
Expand All @@ -31,23 +32,24 @@ async def client():
("duration", "P123DT22H14M12.011S"),
("enum", "ValueOne"),
("extensible_enum", "UnknownValue"),
("model", {'property': 'hello'}),
("collections_string", ['hello', 'world']),
("model", {"property": "hello"}),
("collections_string", ["hello", "world"]),
("collections_int", [1, 2]),
("collections_model", [{'property': 'hello'}, {'property': 'world'}]),
("dictionary_string", {'k1': 'hello', 'k2': 'world'}),
("collections_model", [{"property": "hello"}, {"property": "world"}]),
("dictionary_string", {"k1": "hello", "k2": "world"}),
("unknown_string", "hello"),
("unknown_int", 42),
("unknown_dict", {'k1': 'hello', 'k2': 42}),
("unknown_array", ['hello', 'world']),
("unknown_dict", {"k1": "hello", "k2": 42}),
("unknown_array", ["hello", "world"]),
("boolean_literal", True),
("int_literal", 42),
("string_literal", "hello"),
("float_literal", 43.125),
("union_string_literal", "world"),
("union_float_literal", 46.875),
("union_int_literal", 42),
]
("union_enum_value", "value2"),
],
)
async def test(client, og_name, val):
body = {"property": val}
Expand All @@ -57,36 +59,47 @@ async def test(client, og_name, val):


@pytest.mark.parametrize(
"og_name,model,val", [
"og_name,model,val",
[
("boolean", models.BooleanProperty, True),
("string", models.StringProperty, "hello"),
("bytes", models.BytesProperty, b'hello, world!'),
("bytes", models.BytesProperty, b"hello, world!"),
("int_operations", models.IntProperty, 42),
("float", models.FloatProperty, 43.125),
("decimal", models.DecimalProperty, decimal.Decimal("0.33333")),
("decimal128", models.Decimal128Property, decimal.Decimal("0.33333")),
("enum", models.EnumProperty, models.InnerEnum.VALUE_ONE),
("extensible_enum", models.ExtensibleEnumProperty, "UnknownValue"),
("model", models.ModelProperty, models.InnerModel(property="hello")),
("collections_string",
models.CollectionsStringProperty, ['hello', 'world']),
("collections_string", models.CollectionsStringProperty, ["hello", "world"]),
("collections_int", models.CollectionsIntProperty, [1, 2]),
("collections_model", models.CollectionsModelProperty,
[{'property': 'hello'}, {'property': 'world'}]),
("dictionary_string", models.DictionaryStringProperty,
{'k1': 'hello', 'k2': 'world'}),
(
"collections_model",
models.CollectionsModelProperty,
[{"property": "hello"}, {"property": "world"}],
),
(
"dictionary_string",
models.DictionaryStringProperty,
{"k1": "hello", "k2": "world"},
),
("unknown_string", models.UnknownStringProperty, "hello"),
("unknown_int", models.UnknownIntProperty, 42),
("unknown_dict", models.UnknownDictProperty, {'k1': 'hello', 'k2': 42}),
("unknown_array", models.UnknownArrayProperty, ['hello', 'world']),
("unknown_dict", models.UnknownDictProperty, {"k1": "hello", "k2": 42}),
("unknown_array", models.UnknownArrayProperty, ["hello", "world"]),
("boolean_literal", models.BooleanLiteralProperty, True),
("int_literal", models.IntLiteralProperty, 42),
("string_literal", models.StringLiteralProperty, "hello"),
("float_literal", models.FloatLiteralProperty, 43.125),
("union_string_literal", models.UnionStringLiteralProperty, "world"),
("union_float_literal", models.UnionFloatLiteralProperty, 46.875),
("union_int_literal", models.UnionIntLiteralProperty, 42),
]
(
"union_enum_value",
models.UnionEnumValueProperty,
models.ExtendedEnum.ENUM_VALUE2,
),
],
)
@pytest.mark.asyncio
async def test_model(client, og_name, model, val):
Expand All @@ -100,28 +113,35 @@ async def test_model(client, og_name, model, val):
@pytest.mark.asyncio
async def test_datetime_model(client):
received_body = await client.datetime.get()
assert received_body == {"property": '2022-08-26T18:38:00Z'}
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)))
await client.datetime.put(
models.DatetimeProperty(
property=datetime.datetime(2022, 8, 26, hour=18, minute=38)
)
)


@pytest.mark.asyncio
async def test_never_model(client: ValueTypesClient):
assert await client.never.get() == models.NeverProperty()
await client.never.put(models.NeverProperty())


@pytest.mark.asyncio
async def test_model_deserialization(client: ValueTypesClient):
body = models.ModelProperty(property={"property": "hello"})
assert body.property.property == body["property"]["property"]
resp = await client.model.get()
assert resp.property.property == resp["property"]["property"]

body = models.CollectionsModelProperty(property=[{'property': 'hello'}, {'property': 'world'}])
body = models.CollectionsModelProperty(
property=[{"property": "hello"}, {"property": "world"}]
)
assert body.property[0].property == body["property"][0]["property"]
resp = await client.collections_model.get()
assert resp.property[1].property == resp["property"][1]["property"]
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ def test_model_client(client: NamingClient):

def test_model_language(client: NamingClient):
client.model.language(models.PythonModel(default_name=True))


def test_union_enum_member_name(client: NamingClient):
client.union_enum.union_enum_member_name(models.ExtensibleEnum.CLIENT_ENUM_VALUE1)


def test_union_enum_member_name(client: NamingClient):
client.union_enum.union_enum_name(models.ClientExtensibleEnum.ENUM_VALUE1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -------------------------------------------------------------------------
# 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 server.endpoint.notdefined import NotDefinedClient


@pytest.fixture
def client():
with NotDefinedClient(endpoint="http://localhost:3000") as client:
yield client


def test_valid(client: NotDefinedClient):
assert client.valid() is True
Loading

0 comments on commit 350e89a

Please sign in to comment.