Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing properties attribute to Feature model #33

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Contributors Guide

# Contributing to pydantic-geojson
Sven Varkel <[email protected]>
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ from pydantic_geojson import FeatureModel
data = {
"type": "Feature",
"properties":{
"a_property": "a_value"
},
"geometry": {
"type": "Polygon",
"coordinates": [
Expand Down Expand Up @@ -366,3 +369,10 @@ data = {
>>> type='FeatureCollection' features=[FeatureModel(type='Feature', geometry=PointModel(type='Point', coordinates=Coordinates(lon=-80.870885, lat=35.215151))), FeatureModel(type='Feature', geometry=PolygonModel(type='Polygon', coordinates=[[Coordinates(lon=-80.724878, lat=35.265454), Coordinates(lon=-80.722646, lat=35.260338), Coordinates(lon=-80.720329, lat=35.260618), Coordinates(lon=-80.704793, lat=35.268397), Coordinates(lon=-80.724878, lat=35.265454)]]))]
```

Testing
------------

```bash
poetry run pytest
```
3 changes: 2 additions & 1 deletion pydantic_geojson/feature.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union
from typing import Union, Any

from pydantic import BaseModel

Expand All @@ -13,6 +13,7 @@

class FeatureModel(BaseModel):
type: str = FeatureFieldType
properties: dict[str, Any]
geometry: Union[
PointModel,
MultiPointModel,
Expand Down
30 changes: 25 additions & 5 deletions tests/test_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,41 @@
[-80.704793, 35.268397],
[-82.715179, 35.267696],
[-80.721359, 35.267276],
[-80.724878, 35.265454]
[-80.724878, 35.265454],
]
]
],
},
"properties": {
"property1": "a string value",
"property2": 0.666,
"property3": 1,
"property4": True,
"property5": True,
"property6": None,
},
"properties": {}
}


class TestFeatureModel:

def test_geometry_model_type(self):
f_model = FeatureModel(**data)
assert f_model.geometry.type == data['geometry']['type']
assert f_model.type == data['type']
assert f_model.geometry.type == data["geometry"]["type"]
assert f_model.type == data["type"]

def test_model_type(self):
f_model = FeatureModel(**data)
assert f_model.type == FEATURE

def test_model_properties(self):
f_model = FeatureModel(**data)
assert f_model.type == FEATURE
assert isinstance(f_model.properties, dict)
assert f_model.properties == data["properties"]

assert f_model.type == FEATURE

def test_model_properties_with_validate(self):
f_model = FeatureModel.model_validate(data)
assert isinstance(f_model.properties, dict)
assert f_model.properties == data["properties"]
Loading