|
| 1 | +import json |
| 2 | + |
1 | 3 | import pytest |
2 | 4 |
|
3 | 5 | from tests.integration.helpers import ( |
@@ -202,14 +204,77 @@ def test_account_login_view(get_login_id): |
202 | 204 | assert_headers_in_lines(headers, lines) |
203 | 205 |
|
204 | 206 |
|
| 207 | +@pytest.fixture |
205 | 208 | def test_account_setting_view(): |
206 | | - res = exec_test_command( |
| 209 | + expected_headers = [ |
| 210 | + "longview_subscription", |
| 211 | + "network_helper", |
| 212 | + "interfaces_for_new_linodes", |
| 213 | + ] |
| 214 | + |
| 215 | + settings_text = exec_test_command( |
207 | 216 | BASE_CMDS["account"] + ["settings", "--text", "--delimiter=,"] |
208 | 217 | ) |
209 | | - lines = res.splitlines() |
| 218 | + lines = settings_text.splitlines() |
| 219 | + headers = lines[0].split(",") |
210 | 220 |
|
211 | | - headers = ["longview_subscription", "network_helper"] |
212 | | - assert_headers_in_lines(headers, lines) |
| 221 | + for expected in expected_headers: |
| 222 | + assert ( |
| 223 | + expected in headers |
| 224 | + ), f"Expected header '{expected}' not found in CLI output" |
| 225 | + |
| 226 | + # Fetch current interfaces setting |
| 227 | + settings_json = exec_test_command( |
| 228 | + BASE_CMDS["account"] + ["settings", "--json"] |
| 229 | + ) |
| 230 | + original_value = json.loads(settings_json)[0]["interfaces_for_new_linodes"] |
| 231 | + |
| 232 | + yield original_value |
| 233 | + |
| 234 | + # Restore original setting after test |
| 235 | + exec_test_command( |
| 236 | + BASE_CMDS["account"] |
| 237 | + + [ |
| 238 | + "settings-update", |
| 239 | + "--interfaces_for_new_linodes", |
| 240 | + original_value, |
| 241 | + ] |
| 242 | + ) |
| 243 | + |
| 244 | + |
| 245 | +def test_update_interfaces_setting(test_account_setting_view): |
| 246 | + original_value = test_account_setting_view |
| 247 | + |
| 248 | + # Define valid values different from the original |
| 249 | + valid_options = [ |
| 250 | + "legacy_config_only", |
| 251 | + "legacy_config_default_but_linode_allowed", |
| 252 | + "linode_default_but_legacy_config_allowed", |
| 253 | + "linode_only", |
| 254 | + ] |
| 255 | + |
| 256 | + # Select a different value for testing |
| 257 | + new_value = next(val for val in valid_options if val != original_value) |
| 258 | + |
| 259 | + # Update the setting |
| 260 | + exec_test_command( |
| 261 | + BASE_CMDS["account"] |
| 262 | + + [ |
| 263 | + "settings-update", |
| 264 | + "--interfaces_for_new_linodes", |
| 265 | + new_value, |
| 266 | + ] |
| 267 | + ) |
| 268 | + |
| 269 | + # Verify the setting was updated |
| 270 | + updated_json = exec_test_command( |
| 271 | + BASE_CMDS["account"] + ["settings", "--json"] |
| 272 | + ) |
| 273 | + updated_value = json.loads(updated_json)[0]["interfaces_for_new_linodes"] |
| 274 | + |
| 275 | + assert ( |
| 276 | + updated_value == new_value |
| 277 | + ), f"Expected {new_value}, got {updated_value}" |
213 | 278 |
|
214 | 279 |
|
215 | 280 | def test_user_list(): |
|
0 commit comments