26
26
from firebase_admin import _user_mgt
27
27
from tests import testutils
28
28
29
+ from six .moves import urllib
30
+
29
31
30
32
INVALID_STRINGS = [None , '' , 0 , 1 , True , False , list (), tuple (), dict ()]
31
33
INVALID_DICTS = [None , 'foo' , 0 , 1 , True , False , list (), tuple ()]
@@ -87,6 +89,14 @@ def _check_user_record(user, expected_uid='testuser'):
87
89
assert provider .provider_id == 'phone'
88
90
89
91
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
+
90
100
class TestUserRecord (object ):
91
101
92
102
# 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):
511
521
assert page .next_page_token == ''
512
522
assert page .has_next_page is False
513
523
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' })
515
525
516
526
def test_list_users_paged_iteration (self , user_mgt_app ):
517
527
# Page 1
@@ -537,7 +547,7 @@ def test_list_users_paged_iteration(self, user_mgt_app):
537
547
assert user .uid == 'user4'
538
548
with pytest .raises (StopIteration ):
539
549
next (iterator )
540
- self ._check_rpc_calls (recorder , {'maxResults' : 1000 , 'nextPageToken' : 'token' })
550
+ self ._check_rpc_calls (recorder , {'maxResults' : ' 1000' , 'nextPageToken' : 'token' })
541
551
542
552
def test_list_users_iterator_state (self , user_mgt_app ):
543
553
response = {
@@ -590,13 +600,13 @@ def test_list_users_with_max_results(self, user_mgt_app):
590
600
_ , recorder = _instrument_user_manager (user_mgt_app , 200 , MOCK_LIST_USERS_RESPONSE )
591
601
page = auth .list_users (max_results = 500 , app = user_mgt_app )
592
602
self ._check_page (page )
593
- self ._check_rpc_calls (recorder , {'maxResults' : 500 })
603
+ self ._check_rpc_calls (recorder , {'maxResults' : ' 500' })
594
604
595
605
def test_list_users_with_all_args (self , user_mgt_app ):
596
606
_ , recorder = _instrument_user_manager (user_mgt_app , 200 , MOCK_LIST_USERS_RESPONSE )
597
607
page = auth .list_users (page_token = 'foo' , max_results = 500 , app = user_mgt_app )
598
608
self ._check_page (page )
599
- self ._check_rpc_calls (recorder , {'nextPageToken' : 'foo' , 'maxResults' : 500 })
609
+ self ._check_rpc_calls (recorder , {'nextPageToken' : 'foo' , 'maxResults' : ' 500' })
600
610
601
611
def test_list_users_error (self , user_mgt_app ):
602
612
_instrument_user_manager (user_mgt_app , 500 , '{"error":"test"}' )
@@ -618,9 +628,9 @@ def _check_page(self, page):
618
628
619
629
def _check_rpc_calls (self , recorder , expected = None ):
620
630
if expected is None :
621
- expected = {'maxResults' : 1000 }
631
+ expected = {'maxResults' : ' 1000' }
622
632
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 ))
624
634
assert request == expected
625
635
626
636
0 commit comments