|
13 | 13 | from syrupy.extensions.json import JSONSnapshotExtension |
14 | 14 | from typing import Generator |
15 | 15 |
|
| 16 | + |
| 17 | +def pytest_configure(config): |
| 18 | + config.addinivalue_line( |
| 19 | + 'markers', |
| 20 | + 'needs_large_license: test requires a license with 10+ user slots (sys-admin/team-admin tests)', |
| 21 | + ) |
| 22 | + |
16 | 23 | # Patterns for volatile values that change between test runs |
17 | 24 | _TIMESTAMP_RE = re.compile(r'\d{4}-\d{2}-\d{2}T\d{2}:\d{2}') |
18 | 25 | _AUTH_LOCAL_RE = re.compile(r'^[0-9a-f]+@auth\.local$') |
@@ -349,17 +356,35 @@ def delete_group(account_token: Secret, group_id: int): |
349 | 356 |
|
350 | 357 | MIN_LICENSE_USERS = 10 |
351 | 358 |
|
352 | | -@pytest.fixture(scope='session', autouse=True) |
353 | | -def check_license(system_admin_account_token: Secret): |
354 | | - """Verify the test license has enough user slots before running any tests.""" |
355 | | - headers = {'Authorization': f'Bearer {system_admin_account_token.value}'} |
356 | | - case: Case = system_admin_account_operations.find_operation_by_id('getSystemInformation').Case() |
357 | | - response = case.call(headers=headers) |
358 | | - assert response.status_code == 200 |
359 | | - |
360 | | - data = response.json() |
361 | | - max_users = data.get('license_maxusers', 0) |
362 | | - assert max_users >= MIN_LICENSE_USERS, ( |
363 | | - f'Test license allows only {max_users} users, but at least {MIN_LICENSE_USERS} are required. ' |
364 | | - f'Please update the license in version-compare/seatable-license.txt and in the CI secrets.' |
| 359 | +def _get_license_maxusers() -> int: |
| 360 | + """Query the SeaTable API for the license user limit.""" |
| 361 | + import requests as req |
| 362 | + resp = req.post(f'{BASE_URL}/api2/auth-token/', |
| 363 | + data={'username': ADMIN_USERNAME, 'password': ADMIN_PASSWORD}) |
| 364 | + if resp.status_code != 200: |
| 365 | + return 0 |
| 366 | + token = resp.json()['token'] |
| 367 | + |
| 368 | + resp = req.get(f'{BASE_URL}/api/v2.1/admin/sysinfo/', |
| 369 | + headers={'Authorization': f'Bearer {token}'}) |
| 370 | + if resp.status_code != 200: |
| 371 | + return 0 |
| 372 | + return resp.json().get('license_maxusers', 0) |
| 373 | + |
| 374 | +def pytest_collection_modifyitems(items): |
| 375 | + """Skip tests marked with needs_large_license when the license is too small.""" |
| 376 | + has_advanced = any(item.get_closest_marker('needs_large_license') for item in items) |
| 377 | + if not has_advanced: |
| 378 | + return |
| 379 | + |
| 380 | + maxusers = _get_license_maxusers() |
| 381 | + if maxusers >= MIN_LICENSE_USERS: |
| 382 | + return |
| 383 | + |
| 384 | + skip_marker = pytest.mark.skip( |
| 385 | + reason=f'License has {maxusers} user slots, ' |
| 386 | + f'but {MIN_LICENSE_USERS}+ are required for admin tests' |
365 | 387 | ) |
| 388 | + for item in items: |
| 389 | + if item.get_closest_marker('needs_large_license'): |
| 390 | + item.add_marker(skip_marker) |
0 commit comments