2323import firebase_admin
2424from firebase_admin import db
2525from firebase_admin import exceptions
26+ from firebase_admin import _http_client
2627from firebase_admin import _sseclient
2728from tests import testutils
2829
@@ -731,15 +732,8 @@ def test_parse_db_url_errors(self, url, emulator_host):
731732 def test_valid_db_url (self , url ):
732733 firebase_admin .initialize_app (testutils .MockCredential (), {'databaseURL' : url })
733734 ref = db .reference ()
734- recorder = []
735- adapter = MockAdapter ('{}' , 200 , recorder )
736- ref ._client .session .mount (url , adapter )
737735 assert ref ._client .base_url == 'https://test.firebaseio.com'
738736 assert 'auth_variable_override' not in ref ._client .params
739- assert ref ._client .timeout is None
740- assert ref .get () == {}
741- assert len (recorder ) == 1
742- assert recorder [0 ]._extra_kwargs .get ('timeout' ) is None
743737
744738 @pytest .mark .parametrize ('url' , [
745739 None , '' , 'foo' , 'http://test.firebaseio.com' , 'https://google.com' ,
@@ -761,15 +755,13 @@ def test_multi_db_support(self):
761755 ref = db .reference ()
762756 assert ref ._client .base_url == default_url
763757 assert 'auth_variable_override' not in ref ._client .params
764- assert ref ._client .timeout is None
765758 assert ref ._client is db .reference ()._client
766759 assert ref ._client is db .reference (url = default_url )._client
767760
768761 other_url = 'https://other.firebaseio.com'
769762 other_ref = db .reference (url = other_url )
770763 assert other_ref ._client .base_url == other_url
771764 assert 'auth_variable_override' not in ref ._client .params
772- assert other_ref ._client .timeout is None
773765 assert other_ref ._client is db .reference (url = other_url )._client
774766 assert other_ref ._client is db .reference (url = other_url + '/' )._client
775767
@@ -782,7 +774,6 @@ def test_valid_auth_override(self, override):
782774 default_ref = db .reference ()
783775 other_ref = db .reference (url = 'https://other.firebaseio.com' )
784776 for ref in [default_ref , other_ref ]:
785- assert ref ._client .timeout is None
786777 if override == {}:
787778 assert 'auth_variable_override' not in ref ._client .params
788779 else :
@@ -804,22 +795,22 @@ def test_invalid_auth_override(self, override):
804795 with pytest .raises (ValueError ):
805796 db .reference (app = other_app , url = 'https://other.firebaseio.com' )
806797
807- def test_http_timeout (self ):
798+ @pytest .mark .parametrize ('options, timeout' , [
799+ ({'httpTimeout' : 4 }, 4 ),
800+ ({'httpTimeout' : None }, None ),
801+ ({}, _http_client .DEFAULT_TIMEOUT_SECONDS ),
802+ ])
803+ def test_http_timeout (self , options , timeout ):
808804 test_url = 'https://test.firebaseio.com'
809- firebase_admin . initialize_app ( testutils . MockCredential (), {
805+ all_options = {
810806 'databaseURL' : test_url ,
811- 'httpTimeout' : 60
812- })
807+ }
808+ all_options .update (options )
809+ firebase_admin .initialize_app (testutils .MockCredential (), all_options )
813810 default_ref = db .reference ()
814811 other_ref = db .reference (url = 'https://other.firebaseio.com' )
815812 for ref in [default_ref , other_ref ]:
816- recorder = []
817- adapter = MockAdapter ('{}' , 200 , recorder )
818- ref ._client .session .mount (ref ._client .base_url , adapter )
819- assert ref ._client .timeout == 60
820- assert ref .get () == {}
821- assert len (recorder ) == 1
822- assert recorder [0 ]._extra_kwargs ['timeout' ] == pytest .approx (60 , 0.001 )
813+ self ._check_timeout (ref , timeout )
823814
824815 def test_app_delete (self ):
825816 app = firebase_admin .initialize_app (
@@ -841,6 +832,18 @@ def test_user_agent_format(self):
841832 firebase_admin .__version__ , sys .version_info .major , sys .version_info .minor )
842833 assert db ._USER_AGENT == expected
843834
835+ def _check_timeout (self , ref , timeout ):
836+ assert ref ._client .timeout == timeout
837+ recorder = []
838+ adapter = MockAdapter ('{}' , 200 , recorder )
839+ ref ._client .session .mount (ref ._client .base_url , adapter )
840+ assert ref .get () == {}
841+ assert len (recorder ) == 1
842+ if timeout is None :
843+ assert recorder [0 ]._extra_kwargs ['timeout' ] is None
844+ else :
845+ assert recorder [0 ]._extra_kwargs ['timeout' ] == pytest .approx (timeout , 0.001 )
846+
844847
845848@pytest .fixture (params = ['foo' , '$key' , '$value' ])
846849def initquery (request ):
0 commit comments