@@ -114,14 +114,25 @@ def test_query_all_aggregated_http_error(self, _):
114114
115115 # region test query
116116 @params (
117- ("osdu:wks:dataset--File.Generic:1.0.0" , None , None ),
118- ("*:*:*:*" , None , None ),
119- (None , None , None ),
120- (None , "opendes:reference-data--ResourceSecurityClassification:RESTRICTED" , None ),
121- (None , "opendes:reference-data--ResourceSecurityClassification:RESTRICTED" , 20 ),
122- ("*:*:*:*" , "opendes:reference-data--ResourceSecurityClassification:RESTRICTED" , None ),
117+ ("osdu:wks:dataset--File.Generic:1.0.0" , None , None , None ),
118+ ("*:*:*:*" , None , None , None ),
119+ (None , None , None , None ),
120+ (None , "opendes:reference-data--ResourceSecurityClassification:RESTRICTED" , None , None ),
121+ (None , "opendes:reference-data--ResourceSecurityClassification:RESTRICTED" , None , 20 ),
122+ (
123+ None ,
124+ None ,
125+ 'data.WellboreID:("opendes:master-data--Wellbore:ad215042-05db-2b7e-e053-c818a488c79a")' ,
126+ None ,
127+ ),
128+ (
129+ "*:*:*:*" ,
130+ "opendes:reference-data--ResourceSecurityClassification:RESTRICTED" ,
131+ None ,
132+ None ,
133+ ),
123134 )
124- def test_query (self , kind , identifier , limit ):
135+ def test_query (self , kind , identifier , query , limit ):
125136 """Test the query function"""
126137 request_data = {}
127138
@@ -133,6 +144,9 @@ def test_query(self, kind, identifier, limit):
133144 if identifier is not None :
134145 request_data ["query" ] = f'id:("{ identifier } ")'
135146
147+ if query is not None :
148+ request_data ["query" ] = query
149+
136150 if limit is not None :
137151 request_data ["limit" ] = limit
138152
@@ -150,14 +164,22 @@ def test_query(self, kind, identifier, limit):
150164 client = create_dummy_client ()
151165 search_client = SearchClient (client )
152166
153- response_data = search_client .query (kind , identifier , limit )
167+ response_data = search_client .query (kind , identifier , query , limit )
154168
155169 mock_post_returning_json .assert_called_once ()
156170 mock_post_returning_json .assert_called_with (
157171 "http://www.test.com/api/search/v2/query" , request_data
158172 )
159173 self .assertEqual (expected_response_data , response_data )
160174
175+ def test_query_cant_pass_id_and_query (self ):
176+ """Test query with id and query faile"""
177+ with self .assertRaises (ValueError ):
178+ client = create_dummy_client ()
179+ search_client = SearchClient (client )
180+
181+ _ = search_client .query (identifier = "id" , query = "query" )
182+
161183 @mock .patch .object (OsduClient , "post_returning_json" , side_effect = HTTPError (1 ))
162184 def test_query_http_error (self , _ ):
163185 """Test query http errors are propogated"""
@@ -170,13 +192,47 @@ def test_query_http_error(self, _):
170192 # endregion test query
171193
172194 # region test query_by_id
195+ @params (
196+ ("id1" , None ),
197+ ("id1" , 2 ),
198+ ("id" , None ),
199+ ("id" , 2 ),
200+ )
201+ def test_query_by_id (self , identifier , limit ):
202+ """Test the query_by_id function"""
203+ request_data = {
204+ "kind" : "*:*:*:*" ,
205+ "query" : f'id:("{ identifier } ")' ,
206+ }
207+ if limit is not None :
208+ request_data ["limit" ] = limit
209+
210+ expected_response_data = {
211+ "results" : [],
212+ "totalCount" : 1 ,
213+ }
214+ with mock .patch (
215+ "osdu.client.OsduClient.post_returning_json" , return_value = expected_response_data
216+ ) as mock_post_returning_json :
217+ client = create_dummy_client ()
218+ search_client = SearchClient (client )
219+
220+ response_data = search_client .query_by_id (identifier , limit )
221+
222+ mock_post_returning_json .assert_called_once ()
223+ mock_post_returning_json .assert_called_with (
224+ "http://www.test.com/api/search/v2/query" , request_data
225+ )
226+ self .assertEqual (expected_response_data , response_data )
227+
173228 @params ("id1" , "id" )
174- def test_query_by_id (self , identifier ):
229+ def test_query_by_id_defaults (self , identifier ):
175230 """Test the query_by_id function"""
176231 request_data = {
177232 "kind" : "*:*:*:*" ,
178233 "query" : f'id:("{ identifier } ")' ,
179234 }
235+
180236 expected_response_data = {
181237 "results" : [],
182238 "totalCount" : 1 ,
@@ -206,6 +262,75 @@ def test_query_by_id_http_error(self, _):
206262
207263 # endregion test query_by_id
208264
265+ # region test query_by_kind
266+ @params (
267+ ("kind1" , None ),
268+ ("kind1" , 2 ),
269+ ("kind" , None ),
270+ ("kind" , 2 ),
271+ )
272+ def test_query_by_kind (self , kind , limit ):
273+ """Test the query_by_kind function"""
274+ request_data = {
275+ "kind" : kind ,
276+ }
277+ if limit is not None :
278+ request_data ["limit" ] = limit
279+
280+ expected_response_data = {
281+ "results" : [],
282+ "totalCount" : 1 ,
283+ }
284+ with mock .patch (
285+ "osdu.client.OsduClient.post_returning_json" , return_value = expected_response_data
286+ ) as mock_post_returning_json :
287+ client = create_dummy_client ()
288+ search_client = SearchClient (client )
289+
290+ response_data = search_client .query_by_kind (kind , limit )
291+
292+ mock_post_returning_json .assert_called_once ()
293+ mock_post_returning_json .assert_called_with (
294+ "http://www.test.com/api/search/v2/query" , request_data
295+ )
296+ self .assertEqual (expected_response_data , response_data )
297+
298+ @params ("kind1" , "kind" )
299+ def test_query_by_kind_defaults (self , kind ):
300+ """Test the query_by_kind function"""
301+ request_data = {
302+ "kind" : kind ,
303+ }
304+
305+ expected_response_data = {
306+ "results" : [],
307+ "totalCount" : 1 ,
308+ }
309+ with mock .patch (
310+ "osdu.client.OsduClient.post_returning_json" , return_value = expected_response_data
311+ ) as mock_post_returning_json :
312+ client = create_dummy_client ()
313+ search_client = SearchClient (client )
314+
315+ response_data = search_client .query_by_kind (kind )
316+
317+ mock_post_returning_json .assert_called_once ()
318+ mock_post_returning_json .assert_called_with (
319+ "http://www.test.com/api/search/v2/query" , request_data
320+ )
321+ self .assertEqual (expected_response_data , response_data )
322+
323+ @mock .patch .object (OsduClient , "post_returning_json" , side_effect = HTTPError (1 ))
324+ def test_query_by_kind_http_error (self , _ ):
325+ """Test query_by_kind http errors are propogated"""
326+ with self .assertRaises (HTTPError ):
327+ client = create_dummy_client ()
328+ search_client = SearchClient (client )
329+
330+ _ = search_client .query_by_kind ("kind" )
331+
332+ # endregion test query_by_kind
333+
209334
210335if __name__ == "__main__" :
211336 import nose2
0 commit comments