File tree Expand file tree Collapse file tree 2 files changed +34
-5
lines changed
Expand file tree Collapse file tree 2 files changed +34
-5
lines changed Original file line number Diff line number Diff line change 77import certifi
88import json
99import logging
10+ import os
1011import requests
1112
1213logger = logging .getLogger ('intercom.request' )
1314
1415
16+ def configure_timeout ():
17+ """Configure the request timeout."""
18+ timeout = os .getenv ('INTERCOM_REQUEST_TIMEOUT' , '90' )
19+ try :
20+ return int (timeout )
21+ except ValueError :
22+ logger .warning ('%s is not a valid timeout value.' , timeout )
23+ return 90
24+
25+
1526class Request (object ):
1627
17- timeout = 10
28+ timeout = configure_timeout ()
1829
1930def __init__ (self , http_method , path , http_session = None ):
2031self .http_method = http_method
2132self .path = path
2233self .http_session = http_session
2334
24-
2535def execute (self , base_url , auth , params ):
2636return self .send_request_to_path (base_url , auth , params )
2737
Original file line number Diff line number Diff line change @@ -332,6 +332,25 @@ def it_needs_encoding_or_apparent_encoding(self):
332332@istest
333333def it_allows_the_timeout_to_be_changed (self ):
334334from intercom .request import Request
335- eq_ (10 , Request .timeout )
336- Request .timeout = 3
337- eq_ (3 , Request .timeout )
335+ try :
336+ eq_ (90 , Request .timeout )
337+ Request .timeout = 3
338+ eq_ (3 , Request .timeout )
339+ finally :
340+ Request .timeout = 90
341+
342+ @istest
343+ def it_allows_the_timeout_to_be_configured (self ):
344+ import os
345+ from intercom .request import configure_timeout
346+
347+ # check the default
348+ eq_ (90 , configure_timeout ())
349+
350+ # override the default
351+ os .environ ['INTERCOM_REQUEST_TIMEOUT' ] = '20'
352+ eq_ (20 , configure_timeout ())
353+
354+ # ignore bad timeouts, reset to default 90
355+ os .environ ['INTERCOM_REQUEST_TIMEOUT' ] = 'abc'
356+ eq_ (90 , configure_timeout ())
You can’t perform that action at this time.
0 commit comments