|
3 | 3 | # Licensed under the MIT License. See License.txt in the project root for |
4 | 4 | # license information. |
5 | 5 | # -------------------------------------------------------------------------- |
6 | | -import geojson |
7 | 6 | 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} |
10 | 13 |
|
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)) |
20 | 15 |
|
| 16 | +FEATURE_ID = "feature-1" |
21 | 17 |
|
22 | | -@pytest_asyncio.fixture |
| 18 | + |
| 19 | +@pytest.fixture |
23 | 20 | async def client(): |
24 | | - async with aio.AlternateTypeClient() as client: |
| 21 | + async with AlternateTypeClient(endpoint="http://localhost:3000") as client: |
25 | 22 | yield client |
26 | 23 |
|
27 | 24 |
|
| 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 | + |
28 | 31 | @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.""" |
30 | 34 | 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 |
32 | 42 |
|
33 | 43 |
|
34 | 44 | @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 |
37 | 50 |
|
38 | 51 |
|
39 | 52 | @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.""" |
41 | 55 | 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" |
46 | 64 |
|
47 | 65 |
|
48 | 66 | @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 |
0 commit comments