Skip to content

Commit

Permalink
Merge pull request #33 from svenvarkel/master
Browse files Browse the repository at this point in the history
Added missing properties attribute to Feature model
  • Loading branch information
folt authored Dec 8, 2024
2 parents 06f0d56 + b362eb1 commit 5dea9b2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
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"]

0 comments on commit 5dea9b2

Please sign in to comment.