55
66from tests .model_serving .maas_billing .maas_subscription .utils import (
77 assert_api_key_created_ok ,
8+ assert_api_key_get_ok ,
89 create_api_key ,
910 get_api_key ,
11+ revoke_api_key ,
1012)
1113from utilities .general import generate_random_name
1214from utilities .opendatahub_logger import get_logger
@@ -44,11 +46,17 @@ def test_create_key_within_expiration_limit(
4446 expires_in = f"{ expires_in_hours } h" ,
4547 raise_on_error = False ,
4648 )
47- assert_api_key_created_ok (create_resp , create_body , required_fields = ("key" , "expiresAt" ))
49+ assert_api_key_created_ok (resp = create_resp , body = create_body , required_fields = ("key" , "expiresAt" ))
4850 LOGGER .info (
4951 f"[expiration] Created key within limit: expires_in={ expires_in_hours } h, "
5052 f"expiresAt={ create_body .get ('expiresAt' )} "
5153 )
54+ revoke_api_key (
55+ request_session_http = request_session_http ,
56+ base_url = base_url ,
57+ key_id = create_body ["id" ],
58+ ocp_user_token = ocp_token_for_actor ,
59+ )
5260
5361 @pytest .mark .tier1
5462 def test_create_key_at_expiration_limit (
@@ -69,11 +77,17 @@ def test_create_key_at_expiration_limit(
6977 expires_in = f"{ expires_in_hours } h" ,
7078 raise_on_error = False ,
7179 )
72- assert_api_key_created_ok (create_resp , create_body , required_fields = ("key" , "expiresAt" ))
80+ assert_api_key_created_ok (resp = create_resp , body = create_body , required_fields = ("key" , "expiresAt" ))
7381 LOGGER .info (
7482 f"[expiration] Created key at limit: expires_in={ expires_in_hours } h "
7583 f"({ MAAS_API_KEY_MAX_EXPIRATION_DAYS } days)"
7684 )
85+ revoke_api_key (
86+ request_session_http = request_session_http ,
87+ base_url = base_url ,
88+ key_id = create_body ["id" ],
89+ ocp_user_token = ocp_token_for_actor ,
90+ )
7791
7892 @pytest .mark .tier1
7993 def test_create_key_exceeds_expiration_limit (
@@ -122,10 +136,9 @@ def test_create_key_without_expiration(
122136 key_id = active_api_key_id ,
123137 ocp_user_token = ocp_token_for_actor ,
124138 )
125- assert get_resp .status_code == 200 , (
126- f"Expected 200 on GET /v1/api-keys/{ active_api_key_id } , got { get_resp .status_code } : { get_resp .text [:200 ]} "
127- )
139+ assert_api_key_get_ok (resp = get_resp , body = get_body , key_id = active_api_key_id )
128140 expires_at = get_body .get ("expiresAt" )
141+ assert expires_at is None , f"Expected no 'expiresAt' for key created without expiration, got: { expires_at !r} "
129142 LOGGER .info (f"[expiration] Key without expiration field: expiresAt={ expires_at !r} " )
130143
131144 @pytest .mark .tier2
@@ -136,17 +149,14 @@ def test_create_key_with_short_expiration(
136149 ocp_token_for_actor : str ,
137150 short_expiration_api_key_id : str ,
138151 ) -> None :
139- """Verify a key created with a 1-hour expiration has a non-null expiresAt value."""
152+ """Verify a key created with a 1-hour expiration has a non-null expirationDate value."""
140153 get_resp , get_body = get_api_key (
141154 request_session_http = request_session_http ,
142155 base_url = base_url ,
143156 key_id = short_expiration_api_key_id ,
144157 ocp_user_token = ocp_token_for_actor ,
145158 )
146- assert get_resp .status_code == 200 , (
147- f"Expected 200 on GET /v1/api-keys/{ short_expiration_api_key_id } , "
148- f"got { get_resp .status_code } : { get_resp .text [:200 ]} "
149- )
159+ assert_api_key_get_ok (resp = get_resp , body = get_body , key_id = short_expiration_api_key_id )
150160 assert get_body .get ("expirationDate" ), (
151161 f"Expected non-null 'expirationDate' for 1h key, got: { get_body .get ('expirationDate' )!r} "
152162 )
0 commit comments