Skip to content

Commit ee892c6

Browse files
committed
update
1 parent fe66c7f commit ee892c6

2 files changed

Lines changed: 97 additions & 60 deletions

File tree

packages/http-client-python/tests/mock_api/azure/asynctests/test_azure_client_generator_core_alternate_type_async.py

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,71 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6-
import geojson
76
import pytest
8-
import pytest_asyncio
9-
from specs.azure.clientgenerator.core.alternatetype import aio, models
7+
import geojson
8+
from specs.azure.clientgenerator.core.alternatetype.aio import AlternateTypeClient
9+
from specs.azure.clientgenerator.core.alternatetype import models
10+
11+
# Shared test data
12+
PROPERTIES = {"name": "A single point of interest", "category": "landmark", "elevation": 100}
1013

11-
FEATURE = geojson.Feature(
12-
geometry=geojson.Point((-122.25, 37.87)),
13-
properties={
14-
"name": "A single point of interest",
15-
"category": "landmark",
16-
"elevation": 100,
17-
},
18-
id="feature-1",
19-
)
14+
GEOMETRY = geojson.Point((-122.25, 37.87))
2015

16+
FEATURE_ID = "feature-1"
2117

22-
@pytest_asyncio.fixture
18+
19+
@pytest.fixture
2320
async def client():
24-
async with aio.AlternateTypeClient() as client:
21+
async with AlternateTypeClient(endpoint="http://localhost:3000") as client:
2522
yield client
2623

2724

25+
@pytest.fixture
26+
def feature_geojson():
27+
"""Shared GeoJSON Feature for tests."""
28+
return geojson.Feature(type="Feature", geometry=GEOMETRY, properties=PROPERTIES, id=FEATURE_ID)
29+
30+
2831
@pytest.mark.asyncio
29-
async def test_get_model(client: aio.AlternateTypeClient):
32+
async def test_external_type_get_model(client: AlternateTypeClient):
33+
"""Test getting a Feature object with geometry, properties, and optional id fields."""
3034
result = await client.external_type.get_model()
31-
assert result == FEATURE
35+
36+
# Validate the response structure based on the TypeSpec example
37+
assert result.type == "Feature"
38+
assert result.geometry.type == "Point"
39+
assert result.geometry.coordinates == [-122.25, 37.87]
40+
assert result.properties == PROPERTIES
41+
assert result.id == FEATURE_ID
3242

3343

3444
@pytest.mark.asyncio
35-
async def test_put_model(client: aio.AlternateTypeClient):
36-
await client.external_type.put_model(FEATURE)
45+
async def test_external_type_put_model(client: AlternateTypeClient, feature_geojson):
46+
"""Test putting a Feature object in request body."""
47+
# Should return None (204/empty response)
48+
result = await client.external_type.put_model(body=feature_geojson)
49+
assert result is None
3750

3851

3952
@pytest.mark.asyncio
40-
async def test_get_property(client: aio.AlternateTypeClient):
53+
async def test_external_type_get_property(client: AlternateTypeClient):
54+
"""Test getting a ModelWithFeatureProperty object with feature and additionalProperty fields."""
4155
result = await client.external_type.get_property()
42-
assert result == models.ModelWithFeatureProperty(
43-
feature=FEATURE,
44-
additional_property="extra",
45-
)
56+
57+
# Validate the response structure based on the TypeSpec example
58+
assert result.feature.type == "Feature"
59+
assert result.feature.geometry.type == "Point"
60+
assert result.feature.geometry.coordinates == [-122.25, 37.87]
61+
assert result.feature.properties == PROPERTIES
62+
assert result.feature.id == FEATURE_ID
63+
assert result.additional_property == "extra"
4664

4765

4866
@pytest.mark.asyncio
49-
async def test_put_property(client: aio.AlternateTypeClient):
50-
await client.external_type.put_property(
51-
models.ModelWithFeatureProperty(
52-
feature=FEATURE,
53-
additional_property="extra",
54-
)
55-
)
67+
async def test_external_type_put_property(client: AlternateTypeClient, feature_geojson):
68+
"""Test putting a ModelWithFeatureProperty object in request body."""
69+
model_with_feature = models.ModelWithFeatureProperty(feature=feature_geojson, additional_property="extra")
70+
71+
# Should return None (204/empty response)
72+
result = await client.external_type.put_property(body=model_with_feature)
73+
assert result is None

packages/http-client-python/tests/mock_api/azure/test_azure_client_generator_core_alternate_type.py

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,67 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6-
import geojson
76
import pytest
8-
from specs.azure.clientgenerator.core.alternatetype import AlternateTypeClient, models
7+
import geojson
8+
from specs.azure.clientgenerator.core.alternatetype import AlternateTypeClient
9+
from specs.azure.clientgenerator.core.alternatetype import models
10+
11+
# Shared test data
12+
PROPERTIES = {"name": "A single point of interest", "category": "landmark", "elevation": 100}
913

10-
FEATURE = geojson.Feature(
11-
geometry=geojson.Point((-122.25, 37.87)),
12-
properties={
13-
"name": "A single point of interest",
14-
"category": "landmark",
15-
"elevation": 100,
16-
},
17-
id="feature-1",
18-
)
14+
GEOMETRY = geojson.Point((-122.25, 37.87))
15+
16+
FEATURE_ID = "feature-1"
1917

2018

2119
@pytest.fixture
2220
def client():
23-
with AlternateTypeClient() as client:
21+
with AlternateTypeClient(endpoint="http://localhost:3000") as client:
2422
yield client
2523

2624

27-
def test_get_model(client: AlternateTypeClient):
25+
@pytest.fixture
26+
def feature_geojson():
27+
"""Shared GeoJSON Feature for tests."""
28+
return geojson.Feature(type="Feature", geometry=GEOMETRY, properties=PROPERTIES, id=FEATURE_ID)
29+
30+
31+
def test_external_type_get_model(client: AlternateTypeClient):
32+
"""Test getting a Feature object with geometry, properties, and optional id fields."""
2833
result = client.external_type.get_model()
29-
assert result == FEATURE
34+
35+
# Validate the response structure based on the TypeSpec example
36+
assert result.type == "Feature"
37+
assert result.geometry.type == "Point"
38+
assert result.geometry.coordinates == [-122.25, 37.87]
39+
assert result.properties == PROPERTIES
40+
assert result.id == FEATURE_ID
3041

3142

32-
def test_put_model(client: AlternateTypeClient):
33-
client.external_type.put_model(FEATURE)
43+
def test_external_type_put_model(client: AlternateTypeClient, feature_geojson):
44+
"""Test putting a Feature object in request body."""
45+
# Should return None (204/empty response)
46+
result = client.external_type.put_model(body=feature_geojson)
47+
assert result is None
3448

3549

36-
def test_get_property(client: AlternateTypeClient):
50+
def test_external_type_get_property(client: AlternateTypeClient):
51+
"""Test getting a ModelWithFeatureProperty object with feature and additionalProperty fields."""
3752
result = client.external_type.get_property()
38-
assert result == models.ModelWithFeatureProperty(
39-
feature=FEATURE,
40-
additional_property="extra",
41-
)
42-
43-
44-
def test_put_property(client: AlternateTypeClient):
45-
client.external_type.put_property(
46-
models.ModelWithFeatureProperty(
47-
feature=FEATURE,
48-
additional_property="extra",
49-
)
50-
)
53+
54+
# Validate the response structure based on the TypeSpec example
55+
assert result.feature.type == "Feature"
56+
assert result.feature.geometry.type == "Point"
57+
assert result.feature.geometry.coordinates == [-122.25, 37.87]
58+
assert result.feature.properties == PROPERTIES
59+
assert result.feature.id == FEATURE_ID
60+
assert result.additional_property == "extra"
61+
62+
63+
def test_external_type_put_property(client: AlternateTypeClient, feature_geojson):
64+
"""Test putting a ModelWithFeatureProperty object in request body."""
65+
model_with_feature = models.ModelWithFeatureProperty(feature=feature_geojson, additional_property="extra")
66+
67+
# Should return None (204/empty response)
68+
result = client.external_type.put_property(body=model_with_feature)
69+
assert result is None

0 commit comments

Comments
 (0)