2626from firebase_admin import _user_mgt
2727from tests import testutils
2828
29+ from six .moves import urllib
30+
2931
3032INVALID_STRINGS = [None , '' , 0 , 1 , True , False , list (), tuple (), dict ()]
3133INVALID_DICTS = [None , 'foo' , 0 , 1 , True , False , list (), tuple ()]
@@ -87,6 +89,14 @@ def _check_user_record(user, expected_uid='testuser'):
8789 assert provider .provider_id == 'phone'
8890
8991
92+ class TestAuthServiceInitialization (object ):
93+
94+ def test_fail_on_no_project_id (self ):
95+ app = firebase_admin .initialize_app (testutils .MockCredential (), name = 'userMgt2' )
96+ with pytest .raises (ValueError ):
97+ auth ._get_auth_service (app )
98+ firebase_admin .delete_app (app )
99+
90100class TestUserRecord (object ):
91101
92102 # Input dict must be non-empty, and must not contain unsupported keys.
@@ -511,7 +521,7 @@ def test_list_multiple_pages(self, user_mgt_app):
511521 assert page .next_page_token == ''
512522 assert page .has_next_page is False
513523 assert page .get_next_page () is None
514- self ._check_rpc_calls (recorder , {'maxResults' : 1000 , 'nextPageToken' : 'token' })
524+ self ._check_rpc_calls (recorder , {'maxResults' : ' 1000' , 'nextPageToken' : 'token' })
515525
516526 def test_list_users_paged_iteration (self , user_mgt_app ):
517527 # Page 1
@@ -537,7 +547,7 @@ def test_list_users_paged_iteration(self, user_mgt_app):
537547 assert user .uid == 'user4'
538548 with pytest .raises (StopIteration ):
539549 next (iterator )
540- self ._check_rpc_calls (recorder , {'maxResults' : 1000 , 'nextPageToken' : 'token' })
550+ self ._check_rpc_calls (recorder , {'maxResults' : ' 1000' , 'nextPageToken' : 'token' })
541551
542552 def test_list_users_iterator_state (self , user_mgt_app ):
543553 response = {
@@ -590,13 +600,13 @@ def test_list_users_with_max_results(self, user_mgt_app):
590600 _ , recorder = _instrument_user_manager (user_mgt_app , 200 , MOCK_LIST_USERS_RESPONSE )
591601 page = auth .list_users (max_results = 500 , app = user_mgt_app )
592602 self ._check_page (page )
593- self ._check_rpc_calls (recorder , {'maxResults' : 500 })
603+ self ._check_rpc_calls (recorder , {'maxResults' : ' 500' })
594604
595605 def test_list_users_with_all_args (self , user_mgt_app ):
596606 _ , recorder = _instrument_user_manager (user_mgt_app , 200 , MOCK_LIST_USERS_RESPONSE )
597607 page = auth .list_users (page_token = 'foo' , max_results = 500 , app = user_mgt_app )
598608 self ._check_page (page )
599- self ._check_rpc_calls (recorder , {'nextPageToken' : 'foo' , 'maxResults' : 500 })
609+ self ._check_rpc_calls (recorder , {'nextPageToken' : 'foo' , 'maxResults' : ' 500' })
600610
601611 def test_list_users_error (self , user_mgt_app ):
602612 _instrument_user_manager (user_mgt_app , 500 , '{"error":"test"}' )
@@ -618,9 +628,9 @@ def _check_page(self, page):
618628
619629 def _check_rpc_calls (self , recorder , expected = None ):
620630 if expected is None :
621- expected = {'maxResults' : 1000 }
631+ expected = {'maxResults' : ' 1000' }
622632 assert len (recorder ) == 1
623- request = json . loads ( recorder [0 ].body . decode ( ))
633+ request = dict ( urllib . parse . parse_qsl ( urllib . parse . urlsplit ( recorder [0 ].url ). query ))
624634 assert request == expected
625635
626636
0 commit comments