@@ -1227,8 +1227,9 @@ def test_clients(admin: KeycloakAdmin, realm: str) -> None:
12271227
12281228 # Authz resources
12291229 res = admin .get_client_authz_resources (client_id = auth_client_id )
1230- assert len (res ) == 1
1231- assert res [0 ]["name" ] == "Default Resource"
1230+ assert len (res ) in [0 , 1 ]
1231+ if len (res ) == 1 :
1232+ assert res [0 ]["name" ] == "Default Resource"
12321233
12331234 with pytest .raises (KeycloakGetError ) as err :
12341235 admin .get_client_authz_resources (client_id = client_id )
@@ -1258,8 +1259,8 @@ def test_clients(admin: KeycloakAdmin, realm: str) -> None:
12581259 ) == {"msg" : "Already exists" }
12591260
12601261 res = admin .get_client_authz_resources (client_id = auth_client_id )
1261- assert len (res ) == 2
1262- assert {x ["name" ] for x in res } == {"Default Resource" , "test-resource" }
1262+ assert len (res ) in [ 1 , 2 ]
1263+ assert {x ["name" ] for x in res }. issubset ( {"Default Resource" , "test-resource" })
12631264
12641265 res = admin .create_client_authz_resource (
12651266 client_id = auth_client_id ,
@@ -1293,8 +1294,9 @@ def test_clients(admin: KeycloakAdmin, realm: str) -> None:
12931294
12941295 # Authz policies
12951296 res = admin .get_client_authz_policies (client_id = auth_client_id )
1296- assert len (res ) == 1 , res
1297- assert res [0 ]["name" ] == "Default Policy"
1297+ assert len (res ) in [0 , 1 ], res
1298+ if len (res ) == 1 :
1299+ assert res [0 ]["name" ] == "Default Policy"
12981300
12991301 with pytest .raises (KeycloakGetError ) as err :
13001302 admin .get_client_authz_policies (client_id = "does-not-exist" )
@@ -1320,7 +1322,7 @@ def test_clients(admin: KeycloakAdmin, realm: str) -> None:
13201322 payload = {"name" : "test-authz-rb-policy" , "roles" : [{"id" : role_id }]},
13211323 skip_exists = True ,
13221324 ) == {"msg" : "Already exists" }
1323- assert len (admin .get_client_authz_policies (client_id = auth_client_id )) == 2
1325+ assert len (admin .get_client_authz_policies (client_id = auth_client_id )) in [ 1 , 2 ]
13241326
13251327 res = admin .create_client_authz_role_based_policy (
13261328 client_id = auth_client_id ,
@@ -1363,12 +1365,13 @@ def test_clients(admin: KeycloakAdmin, realm: str) -> None:
13631365 },
13641366 skip_exists = True ,
13651367 ) == {"msg" : "Already exists" }
1366- assert len (admin .get_client_authz_policies (client_id = auth_client_id )) == 3
1368+ assert len (admin .get_client_authz_policies (client_id = auth_client_id )) in [ 2 , 3 ]
13671369
13681370 # Test authz permissions
13691371 res = admin .get_client_authz_permissions (client_id = auth_client_id )
1370- assert len (res ) == 1 , res
1371- assert res [0 ]["name" ] == "Default Permission"
1372+ assert len (res ) in [0 , 1 ], res
1373+ if len (res ) == 1 :
1374+ assert res [0 ]["name" ] == "Default Permission"
13721375
13731376 with pytest .raises (KeycloakGetError ) as err :
13741377 admin .get_client_authz_permissions (client_id = "does-not-exist" )
@@ -1395,7 +1398,7 @@ def test_clients(admin: KeycloakAdmin, realm: str) -> None:
13951398 payload = {"name" : "test-permission-rb" , "resources" : [test_resource_id ]},
13961399 skip_exists = True ,
13971400 ) == {"msg" : "Already exists" }
1398- assert len (admin .get_client_authz_permissions (client_id = auth_client_id )) == 2
1401+ assert len (admin .get_client_authz_permissions (client_id = auth_client_id )) in [ 1 , 2 ]
13991402
14001403 # Test associating client policy with resource based permission
14011404 res = admin .update_client_authz_resource_permission (
@@ -2681,10 +2684,10 @@ def test_auth_flows(admin: KeycloakAdmin, realm: str) -> None:
26812684 with pytest .raises (KeycloakPostError ) as err :
26822685 admin .create_authentication_flow (payload = {"alias" : "test-create" , "builtIn" : False })
26832686 assert err .match ('409: b\' {"errorMessage":"Flow test-create already exists"}\' ' )
2684- assert admin . create_authentication_flow (
2685- payload = {"alias" : "test-create" },
2686- skip_exists = True ,
2687- ) == { "msg" : "Already exists" }
2687+ assert (
2688+ admin . create_authentication_flow ( payload = {"alias" : "test-create" }, skip_exists = True )
2689+ == json . dumps ({ "msg" : "Already exists" }). encode ()
2690+ )
26882691
26892692 # Update
26902693 res = admin .get_authentication_flows ()
@@ -3080,7 +3083,7 @@ def test_components(admin: KeycloakAdmin, realm: str) -> None:
30803083
30813084 # Test get components
30823085 res = admin .get_components ()
3083- assert len (res ) == 12
3086+ assert len (res ) in [ 12 , 14 ]
30843087
30853088 with pytest .raises (KeycloakGetError ) as err :
30863089 admin .get_component (component_id = "does-not-exist" )
@@ -4920,8 +4923,9 @@ async def test_a_clients(admin: KeycloakAdmin, realm: str) -> None:
49204923
49214924 # Authz resources
49224925 res = await admin .a_get_client_authz_resources (client_id = auth_client_id )
4923- assert len (res ) == 1
4924- assert res [0 ]["name" ] == "Default Resource"
4926+ assert len (res ) in [0 , 1 ]
4927+ if len (res ) == 1 :
4928+ assert res [0 ]["name" ] == "Default Resource"
49254929
49264930 with pytest .raises (KeycloakGetError ) as err :
49274931 await admin .a_get_client_authz_resources (client_id = client_id )
@@ -4954,8 +4958,8 @@ async def test_a_clients(admin: KeycloakAdmin, realm: str) -> None:
49544958 ) == {"msg" : "Already exists" }
49554959
49564960 res = await admin .a_get_client_authz_resources (client_id = auth_client_id )
4957- assert len (res ) == 2
4958- assert {x ["name" ] for x in res } == {"Default Resource" , "test-resource" }
4961+ assert len (res ) in [ 1 , 2 ]
4962+ assert {x ["name" ] for x in res }. issubset ( {"Default Resource" , "test-resource" })
49594963
49604964 res = await admin .a_create_client_authz_resource (
49614965 client_id = auth_client_id ,
@@ -4996,8 +5000,9 @@ async def test_a_clients(admin: KeycloakAdmin, realm: str) -> None:
49965000
49975001 # Authz policies
49985002 res = await admin .a_get_client_authz_policies (client_id = auth_client_id )
4999- assert len (res ) == 1 , res
5000- assert res [0 ]["name" ] == "Default Policy"
5003+ assert len (res ) in [0 , 1 ], res
5004+ if len (res ) == 1 :
5005+ assert res [0 ]["name" ] == "Default Policy"
50015006
50025007 with pytest .raises (KeycloakGetError ) as err :
50035008 await admin .a_get_client_authz_policies (client_id = "does-not-exist" )
@@ -5021,7 +5026,7 @@ async def test_a_clients(admin: KeycloakAdmin, realm: str) -> None:
50215026 payload = {"name" : "test-authz-rb-policy" , "roles" : [{"id" : role_id }]},
50225027 skip_exists = True ,
50235028 ) == {"msg" : "Already exists" }
5024- assert len (await admin .a_get_client_authz_policies (client_id = auth_client_id )) == 2
5029+ assert len (await admin .a_get_client_authz_policies (client_id = auth_client_id )) in [ 1 , 2 ]
50255030 role_based_policy_id = res ["id" ]
50265031 role_based_policy_name = res ["name" ]
50275032
@@ -5066,12 +5071,13 @@ async def test_a_clients(admin: KeycloakAdmin, realm: str) -> None:
50665071 },
50675072 skip_exists = True ,
50685073 ) == {"msg" : "Already exists" }
5069- assert len (await admin .a_get_client_authz_policies (client_id = auth_client_id )) == 3
5074+ assert len (await admin .a_get_client_authz_policies (client_id = auth_client_id )) in [ 2 , 3 ]
50705075
50715076 # Test authz permissions
50725077 res = await admin .a_get_client_authz_permissions (client_id = auth_client_id )
5073- assert len (res ) == 1 , res
5074- assert res [0 ]["name" ] == "Default Permission"
5078+ assert len (res ) in [0 , 1 ], res
5079+ if len (res ) == 1 :
5080+ assert res [0 ]["name" ] == "Default Permission"
50755081
50765082 with pytest .raises (KeycloakGetError ) as err :
50775083 await admin .a_get_client_authz_permissions (client_id = "does-not-exist" )
@@ -5098,7 +5104,7 @@ async def test_a_clients(admin: KeycloakAdmin, realm: str) -> None:
50985104 payload = {"name" : "test-permission-rb" , "resources" : [test_resource_id ]},
50995105 skip_exists = True ,
51005106 ) == {"msg" : "Already exists" }
5101- assert len (await admin .a_get_client_authz_permissions (client_id = auth_client_id )) == 2
5107+ assert len (await admin .a_get_client_authz_permissions (client_id = auth_client_id )) in [ 1 , 2 ]
51025108
51035109 # Test associating client policy with resource based permission
51045110 res = await admin .a_update_client_authz_resource_permission (
@@ -6933,7 +6939,7 @@ async def test_a_components(admin: KeycloakAdmin, realm: str) -> None:
69336939
69346940 # Test get components
69356941 res = await admin .a_get_components ()
6936- assert len (res ) == 12
6942+ assert len (res ) in [ 12 , 14 ]
69376943
69386944 with pytest .raises (KeycloakGetError ) as err :
69396945 await admin .a_get_component (component_id = "does-not-exist" )
0 commit comments