Skip to content

Commit 2359c2e

Browse files
committed
Add a basic test for the formatter
1 parent b25dc27 commit 2359c2e

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

pygeoapi/api/itemtypes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,6 @@ def get_collection_items(
710710

711711
try:
712712
content = formatter.write(
713-
api=api,
714713
data=content,
715714
dataset=dataset,
716715
id_field=(p.uri_field or 'id'),
@@ -1025,7 +1024,6 @@ def get_collection_item(api: API, request: APIRequest,
10251024

10261025
try:
10271026
content = formatter.write(
1028-
api=api,
10291027
data=content,
10301028
dataset=dataset,
10311029
id_field=(p.uri_field or 'id'),

pygeoapi/formatter/jsonfg.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ def __init__(self, formatter_def: dict):
6363
self.mimetype = "application/geo+json"
6464

6565
def write(
66-
self, api: APIRequest, data: dict,
67-
dataset: str, id_field: str, options: dict = {}
66+
self, data: dict, dataset: str, id_field: str, options: dict = {}
6867
) -> dict:
6968
"""
7069
Generate data in JSON-FG format
@@ -108,8 +107,10 @@ def geojson2jsonfg(
108107
"""
109108
Return JSON-FG from a GeoJSON content.
110109
111-
:param cls: API object
112-
:param data: dict of data:
110+
:param data: dict of data
111+
:param dataset: dataset name
112+
:param identifier: identifier field name
113+
:param id_field: id field name
113114
114115
:returns: dict of converted GeoJSON (JSON-FG)
115116
"""

tests/formatter/test_jsonfg__formatter.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,52 @@
3030
import pytest
3131

3232
from pygeoapi.formatter.jsonfg import JSONFGFormatter
33+
34+
35+
@pytest.fixture()
36+
def fixture():
37+
data = {
38+
'type': 'FeatureCollection',
39+
'features': [{
40+
'type': 'Feature',
41+
'id': '123-456',
42+
'geometry': {
43+
'type': 'Point',
44+
'coordinates': [125.6, 10.1]},
45+
'properties': {
46+
'name': 'Dinagat Islands',
47+
'foo': 'bar'
48+
}}
49+
],
50+
'links': [{
51+
'rel': 'self',
52+
'type': 'application/geo+json',
53+
'title': 'GeoJSON',
54+
'href': 'http://example.com'
55+
}]
56+
}
57+
58+
return data
59+
60+
61+
def test_jsonfg__formatter(fixture):
62+
f = JSONFGFormatter({'geom': True})
63+
f_jsonfg = f.write(data=fixture, dataset='test', id_field='id', options={})
64+
65+
assert f.mimetype == "application/geo+json"
66+
67+
assert f_jsonfg['type'] == 'FeatureCollection'
68+
assert f_jsonfg['features'][0]['type'] == 'Feature'
69+
assert f_jsonfg['features'][0]['geometry']['type'] == 'Point'
70+
assert f_jsonfg['features'][0]['geometry']['coordinates'] == [125.6, 10.1]
71+
assert f_jsonfg['features'][0]['properties']['id'] == '123-456'
72+
assert f_jsonfg['features'][0]['properties']['name'] == 'Dinagat Islands'
73+
assert f_jsonfg['features'][0]['properties']['foo'] == 'bar'
74+
75+
assert f_jsonfg['featureType'] == 'OGRGeoJSON'
76+
assert f_jsonfg['conformsTo']
77+
assert f_jsonfg['coordRefSys'] == '[EPSG:4326]'
78+
assert f_jsonfg['features'][0]['place'] is None
79+
assert f_jsonfg['features'][0]['time'] is None
80+
81+
assert len(f_jsonfg['links']) == 1

0 commit comments

Comments
 (0)