3
3
# Authors: Bernhard Mallinger <bernhard.mallinger@eox.at>
4
4
#
5
5
# Copyright (c) 2024 Bernhard Mallinger
6
+ # Copyright (c) 2025 Francesco Bartoli
6
7
#
7
8
# Permission is hereby granted, free of charge, to any person
8
9
# obtaining a copy of this software and associated documentation
26
27
# OTHER DEALINGS IN THE SOFTWARE.
27
28
#
28
29
# =================================================================
30
+ import io
31
+ import json
32
+ import sys
29
33
30
34
import pytest
31
35
32
36
from pygeoapi .api import API
37
+ from pygeoapi .provider .base import BaseProvider , ProviderItemNotFoundError
33
38
from pygeoapi .util import yaml_load
34
39
35
40
from tests .util import get_test_file_path
@@ -50,3 +55,99 @@ def openapi():
50
55
@pytest .fixture ()
51
56
def api_ (config , openapi ):
52
57
return API (config , openapi )
58
+
59
+
60
+ @pytest .fixture
61
+ def basic_provider_def ():
62
+ """Basic provider definition for testing."""
63
+ return {
64
+ "name" : "test_provider" ,
65
+ "type" : "feature" ,
66
+ "data" : "/path/to/data.geojson"
67
+ }
68
+
69
+
70
+ @pytest .fixture
71
+ def extended_provider_def ():
72
+ """Extended provider definition with all optional fields."""
73
+ return {
74
+ "name" : "test_provider" ,
75
+ "type" : "feature" ,
76
+ "data" : "/path/to/data.geojson" ,
77
+ "editable" : True ,
78
+ "options" : {"some_option" : "value" },
79
+ "id_field" : "feature_id" ,
80
+ "uri_field" : "uri" ,
81
+ "x_field" : "longitude" ,
82
+ "y_field" : "latitude" ,
83
+ "time_field" : "timestamp" ,
84
+ "title_field" : "title" ,
85
+ "properties" : ["prop1" , "prop2" ],
86
+ "file_types" : [".geojson" , ".json" ]
87
+ }
88
+
89
+
90
+ @pytest .fixture
91
+ def basic_provider (basic_provider_def ):
92
+ """Basic BaseProvider instance."""
93
+ return BaseProvider (basic_provider_def )
94
+
95
+
96
+ @pytest .fixture
97
+ def extended_provider (extended_provider_def ):
98
+ """Extended BaseProvider instance."""
99
+ return BaseProvider (extended_provider_def )
100
+
101
+
102
+ @pytest .fixture
103
+ def mock_provider_with_get ():
104
+ """Mock provider that implements get() method."""
105
+ class MockProvider (BaseProvider ):
106
+ def get (self , identifier , ** kwargs ):
107
+ if identifier == "mock_id" :
108
+ return {"type" : "Feature" , "id" : identifier }
109
+ else :
110
+ raise ProviderItemNotFoundError ("Not found" )
111
+
112
+ provider_def = {
113
+ "name" : "mock_provider" ,
114
+ "type" : "feature" ,
115
+ "data" : "/path/to/data.geojson"
116
+ }
117
+ return MockProvider (provider_def )
118
+
119
+
120
+ @pytest .fixture
121
+ def valid_geojson_item ():
122
+ """Valid GeoJSON item for testing."""
123
+ return json .dumps ({
124
+ "type" : "Feature" ,
125
+ "id" : "test_id" ,
126
+ "geometry" : {"type" : "Point" , "coordinates" : [0 , 0 ]},
127
+ "properties" : {"name" : "Test Feature" }
128
+ })
129
+
130
+
131
+ @pytest .fixture
132
+ def geojson_item_with_props_id ():
133
+ """GeoJSON item with identifier in properties."""
134
+ return json .dumps ({
135
+ "type" : "Feature" ,
136
+ "geometry" : {"type" : "Point" , "coordinates" : [0 , 0 ]},
137
+ "properties" : {"identifier" : "props_id" , "name" : "Test" }
138
+ })
139
+
140
+
141
+ @pytest .fixture
142
+ def remove_stdout ():
143
+ """Fixture to remove standard output during tests."""
144
+ class RemoveStdout :
145
+ def __enter__ (self ):
146
+ self .original_stdout = sys .stdout
147
+ sys .stdout = io .StringIO ()
148
+ return self
149
+
150
+ def __exit__ (self , exc_type , exc_val , exc_tb ):
151
+ sys .stdout = self .original_stdout
152
+
153
+ return RemoveStdout
0 commit comments