@@ -180,7 +180,7 @@ def test_create_test_user(self):
180180 user = resp ["user" ]
181181 self .assertEqual (user ["id" ], "u1" )
182182 mock_post .assert_called_with (
183- f"{ common .DEFAULT_BASE_URL } { MgmtV1 .user_create_path } " ,
183+ f"{ common .DEFAULT_BASE_URL } { MgmtV1 .test_user_create_path } " ,
184184 headers = {
185185 ** common .default_headers ,
186186 "Authorization" : f"Bearer { self .dummy_project_id } :{ self .dummy_management_key } " ,
@@ -964,6 +964,167 @@ def test_search_all(self):
964964 timeout = DEFAULT_TIMEOUT_SECONDS ,
965965 )
966966
967+ def test_search_all_test_users (self ):
968+ # Test failed flows
969+ with patch ("requests.post" ) as mock_post :
970+ mock_post .return_value .ok = False
971+ self .assertRaises (
972+ AuthException ,
973+ self .client .mgmt .user .search_all_test_users ,
974+ ["t1, t2" ],
975+ ["r1" , "r2" ],
976+ )
977+
978+ with patch ("requests.post" ) as mock_post :
979+ mock_post .return_value .ok = True
980+ self .assertRaises (
981+ AuthException ,
982+ self .client .mgmt .user .search_all_test_users ,
983+ [],
984+ [],
985+ - 1 ,
986+ 0 ,
987+ )
988+
989+ self .assertRaises (
990+ AuthException ,
991+ self .client .mgmt .user .search_all_test_users ,
992+ [],
993+ [],
994+ 0 ,
995+ - 1 ,
996+ )
997+
998+ # Test success flow
999+ with patch ("requests.post" ) as mock_post :
1000+ network_resp = mock .Mock ()
1001+ network_resp .ok = True
1002+ network_resp .json .return_value = json .loads (
1003+ """{"users": [{"id": "u1"}, {"id": "u2"}]}"""
1004+ )
1005+ mock_post .return_value = network_resp
1006+ resp = self .client .mgmt .user .search_all_test_users (
1007+ ["t1, t2" ],
1008+ ["r1" , "r2" ],
1009+ sso_app_ids = ["app1" ],
1010+ login_ids = ["l1" ],
1011+ )
1012+ users = resp ["users" ]
1013+ self .assertEqual (len (users ), 2 )
1014+ self .assertEqual (users [0 ]["id" ], "u1" )
1015+ self .assertEqual (users [1 ]["id" ], "u2" )
1016+ mock_post .assert_called_with (
1017+ f"{ common .DEFAULT_BASE_URL } { MgmtV1 .test_users_search_path } " ,
1018+ headers = {
1019+ ** common .default_headers ,
1020+ "Authorization" : f"Bearer { self .dummy_project_id } :{ self .dummy_management_key } " ,
1021+ },
1022+ params = None ,
1023+ json = {
1024+ "tenantIds" : ["t1, t2" ],
1025+ "roleNames" : ["r1" , "r2" ],
1026+ "limit" : 0 ,
1027+ "page" : 0 ,
1028+ "testUsersOnly" : True ,
1029+ "withTestUser" : True ,
1030+ "ssoAppIds" : ["app1" ],
1031+ "loginIds" : ["l1" ],
1032+ },
1033+ allow_redirects = False ,
1034+ verify = True ,
1035+ timeout = DEFAULT_TIMEOUT_SECONDS ,
1036+ )
1037+
1038+ # Test success flow with text and sort
1039+ with patch ("requests.post" ) as mock_post :
1040+ network_resp = mock .Mock ()
1041+ network_resp .ok = True
1042+ network_resp .json .return_value = json .loads (
1043+ """{"users": [{"id": "u1"}, {"id": "u2"}]}"""
1044+ )
1045+ mock_post .return_value = network_resp
1046+ sort = [Sort (field = "kuku" , desc = True ), Sort (field = "bubu" )]
1047+ resp = self .client .mgmt .user .search_all_test_users (
1048+ ["t1, t2" ],
1049+ ["r1" , "r2" ],
1050+ sso_app_ids = ["app1" ],
1051+ text = "blue" ,
1052+ sort = sort ,
1053+ )
1054+ users = resp ["users" ]
1055+ self .assertEqual (len (users ), 2 )
1056+ self .assertEqual (users [0 ]["id" ], "u1" )
1057+ self .assertEqual (users [1 ]["id" ], "u2" )
1058+ mock_post .assert_called_with (
1059+ f"{ common .DEFAULT_BASE_URL } { MgmtV1 .test_users_search_path } " ,
1060+ headers = {
1061+ ** common .default_headers ,
1062+ "Authorization" : f"Bearer { self .dummy_project_id } :{ self .dummy_management_key } " ,
1063+ },
1064+ params = None ,
1065+ json = {
1066+ "tenantIds" : ["t1, t2" ],
1067+ "roleNames" : ["r1" , "r2" ],
1068+ "limit" : 0 ,
1069+ "page" : 0 ,
1070+ "testUsersOnly" : True ,
1071+ "withTestUser" : True ,
1072+ "ssoAppIds" : ["app1" ],
1073+ "text" : "blue" ,
1074+ "sort" : [
1075+ {"desc" : True , "field" : "kuku" },
1076+ {"desc" : False , "field" : "bubu" },
1077+ ],
1078+ },
1079+ allow_redirects = False ,
1080+ verify = True ,
1081+ timeout = DEFAULT_TIMEOUT_SECONDS ,
1082+ )
1083+
1084+ # Test success flow with custom attributes
1085+ with patch ("requests.post" ) as mock_post :
1086+ network_resp = mock .Mock ()
1087+ network_resp .ok = True
1088+ network_resp .json .return_value = json .loads (
1089+ """{"users": [{"id": "u1"}, {"id": "u2"}]}"""
1090+ )
1091+ mock_post .return_value = network_resp
1092+ resp = self .client .mgmt .user .search_all_test_users (
1093+ ["t1, t2" ],
1094+ ["r1" , "r2" ],
1095+ custom_attributes = {"ak" : "av" },
1096+ statuses = ["invited" ],
1097+ phones = ["+111111" ],
1098+ 1099+ )
1100+ users = resp ["users" ]
1101+ self .assertEqual (len (users ), 2 )
1102+ self .assertEqual (users [0 ]["id" ], "u1" )
1103+ self .assertEqual (users [1 ]["id" ], "u2" )
1104+ mock_post .assert_called_with (
1105+ f"{ common .DEFAULT_BASE_URL } { MgmtV1 .test_users_search_path } " ,
1106+ headers = {
1107+ ** common .default_headers ,
1108+ "Authorization" : f"Bearer { self .dummy_project_id } :{ self .dummy_management_key } " ,
1109+ },
1110+ params = None ,
1111+ json = {
1112+ "tenantIds" : ["t1, t2" ],
1113+ "roleNames" : ["r1" , "r2" ],
1114+ "limit" : 0 ,
1115+ "page" : 0 ,
1116+ "testUsersOnly" : True ,
1117+ "withTestUser" : True ,
1118+ "customAttributes" : {"ak" : "av" },
1119+ "statuses" : ["invited" ],
1120+ 1121+ "phones" : ["+111111" ],
1122+ },
1123+ allow_redirects = False ,
1124+ verify = True ,
1125+ timeout = DEFAULT_TIMEOUT_SECONDS ,
1126+ )
1127+
9671128 def test_get_provider_token (self ):
9681129 # Test failed flows
9691130 with patch ("requests.get" ) as mock_post :
0 commit comments