15
15
LinkupSourcedAnswer ,
16
16
LinkupUnknownError ,
17
17
)
18
- from linkup .errors import LinkupInsufficientCreditError , LinkupNoResultError
18
+ from linkup .errors import (
19
+ LinkupInsufficientCreditError ,
20
+ LinkupNoResultError ,
21
+ LinkupTooManyRequestsError ,
22
+ )
19
23
from linkup .types import LinkupSearchImageResult , LinkupSearchTextResult
20
24
21
25
@@ -221,7 +225,7 @@ def test_search_insufficient_credit_error(mocker: MockerFixture, client: LinkupC
221
225
mock_response .json .return_value = {
222
226
"statusCode" : 429 ,
223
227
"error" : {
224
- "code" : "INSUFFICIENT_CREDITS " ,
228
+ "code" : "INSUFFICIENT_FUNDS_CREDITS " ,
225
229
"message" : "You do not have enough credits to perform this request." ,
226
230
"details" : [],
227
231
},
@@ -236,6 +240,48 @@ def test_search_insufficient_credit_error(mocker: MockerFixture, client: LinkupC
236
240
client .search (query = "foo" , depth = "standard" , output_type = "searchResults" )
237
241
238
242
243
+ def test_search_too_many_requests_error (mocker : MockerFixture , client : LinkupClient ) -> None :
244
+ mock_response = mocker .Mock ()
245
+ mock_response .status_code = 429
246
+ mock_response .json .return_value = {
247
+ "statusCode" : 429 ,
248
+ "error" : {
249
+ "code" : "TOO_MANY_REQUESTS" ,
250
+ "message" : "Too many requests." ,
251
+ "details" : [],
252
+ },
253
+ }
254
+
255
+ mocker .patch (
256
+ "linkup.client.LinkupClient._request" ,
257
+ return_value = mock_response ,
258
+ )
259
+
260
+ with pytest .raises (LinkupTooManyRequestsError ):
261
+ client .search (query = "foo" , depth = "standard" , output_type = "searchResults" )
262
+
263
+
264
+ def test_search_error_429_unknown_code (mocker : MockerFixture , client : LinkupClient ) -> None :
265
+ mock_response = mocker .Mock ()
266
+ mock_response .status_code = 429
267
+ mock_response .json .return_value = {
268
+ "statusCode" : 429 ,
269
+ "error" : {
270
+ "code" : "FOOBAR" ,
271
+ "message" : "Foobar" ,
272
+ "details" : [],
273
+ },
274
+ }
275
+
276
+ mocker .patch (
277
+ "linkup.client.LinkupClient._request" ,
278
+ return_value = mock_response ,
279
+ )
280
+
281
+ with pytest .raises (LinkupUnknownError ):
282
+ client .search (query = "foo" , depth = "standard" , output_type = "searchResults" )
283
+
284
+
239
285
def test_search_structured_search_invalid_request (
240
286
mocker : MockerFixture ,
241
287
client : LinkupClient ,
@@ -543,7 +589,7 @@ async def test_async_search_insufficient_credit_error(
543
589
mock_response .json .return_value = {
544
590
"statusCode" : 429 ,
545
591
"error" : {
546
- "code" : "INSUFFICIENT_CREDITS " ,
592
+ "code" : "INSUFFICIENT_FUNDS_CREDITS " ,
547
593
"message" : "You do not have enough credits to perform this request." ,
548
594
"details" : [],
549
595
},
@@ -557,6 +603,52 @@ async def test_async_search_insufficient_credit_error(
557
603
await client .async_search (query = "foo" , depth = "standard" , output_type = "searchResults" )
558
604
559
605
606
+ @pytest .mark .asyncio
607
+ async def test_async_search_too_many_requests_error (
608
+ mocker : MockerFixture , client : LinkupClient
609
+ ) -> None :
610
+ mock_response = mocker .Mock ()
611
+ mock_response .status_code = 429
612
+ mock_response .json .return_value = {
613
+ "statusCode" : 429 ,
614
+ "error" : {
615
+ "code" : "TOO_MANY_REQUESTS" ,
616
+ "message" : "Too many requests." ,
617
+ "details" : [],
618
+ },
619
+ }
620
+
621
+ mocker .patch (
622
+ "linkup.client.LinkupClient._async_request" ,
623
+ return_value = mock_response ,
624
+ )
625
+ with pytest .raises (LinkupTooManyRequestsError ):
626
+ await client .async_search (query = "foo" , depth = "standard" , output_type = "searchResults" )
627
+
628
+
629
+ @pytest .mark .asyncio
630
+ async def test_async_search_error_429_unknown_code (
631
+ mocker : MockerFixture , client : LinkupClient
632
+ ) -> None :
633
+ mock_response = mocker .Mock ()
634
+ mock_response .status_code = 429
635
+ mock_response .json .return_value = {
636
+ "statusCode" : 429 ,
637
+ "error" : {
638
+ "code" : "FOOBAR" ,
639
+ "message" : "Foobar" ,
640
+ "details" : [],
641
+ },
642
+ }
643
+
644
+ mocker .patch (
645
+ "linkup.client.LinkupClient._async_request" ,
646
+ return_value = mock_response ,
647
+ )
648
+ with pytest .raises (LinkupUnknownError ):
649
+ await client .async_search (query = "foo" , depth = "standard" , output_type = "searchResults" )
650
+
651
+
560
652
@pytest .mark .asyncio
561
653
async def test_async_search_structured_search_invalid_request (
562
654
mocker : MockerFixture ,
0 commit comments