Skip to content

Commit d14aa25

Browse files
christophdbclaude
andcommitted
Skip admin tests gracefully when license has too few user slots
Replace hard-failing license check with needs_large_license marker. Admin tests (sys-admin, team-admin) are skipped with a clear message when the license has fewer than 10 user slots, allowing basic tests to run with a 3-user license. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 454ba38 commit d14aa25

6 files changed

Lines changed: 53 additions & 13 deletions

File tree

tests/conftest.py

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
from syrupy.extensions.json import JSONSnapshotExtension
1414
from typing import Generator
1515

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+
1623
# Patterns for volatile values that change between test runs
1724
_TIMESTAMP_RE = re.compile(r'\d{4}-\d{2}-\d{2}T\d{2}:\d{2}')
1825
_AUTH_LOCAL_RE = re.compile(r'^[0-9a-f]+@auth\.local$')
@@ -349,17 +356,35 @@ def delete_group(account_token: Secret, group_id: int):
349356

350357
MIN_LICENSE_USERS = 10
351358

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'
365387
)
388+
for item in items:
389+
if item.get_closest_marker('needs_large_license'):
390+
item.add_marker(skip_marker)

tests/test_admin_bases.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import pytest
12
from conftest import (
23
Base, Secret, system_admin_account_operations, USERNAME,
34
user_account_operations, create_group, delete_group,
45
)
56
from schemathesis import Case
67

8+
pytestmark = pytest.mark.needs_large_license
9+
710

811
def test_listAllBases(system_admin_account_token: Secret, base: Base):
912
"""List all bases in the system, verify our test base appears."""

tests/test_admin_groups.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import pytest
12
from conftest import (
23
Secret, system_admin_account_operations, USERNAME, ADMIN_USERNAME,
34
create_group, delete_group,
45
)
56
from schemathesis import Case
67

8+
pytestmark = pytest.mark.needs_large_license
9+
710

811
def test_listGroups(system_admin_account_token: Secret, account_token: Secret):
912
"""List groups as admin, verify a known group appears."""

tests/test_admin_search_users.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import pytest
12
from conftest import Secret, system_admin_account_operations, USERNAME, ADMIN_USERNAME
23
from schemathesis import Case
34

5+
pytestmark = pytest.mark.needs_large_license
6+
47

58
def test_listAdminUsers(system_admin_account_token: Secret):
69
headers = {'Authorization': f'Bearer {system_admin_account_token.value}'}

tests/test_admin_users.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import pytest
12
from conftest import Secret, system_admin_account_operations
23
from schemathesis import Case
34

5+
pytestmark = pytest.mark.needs_large_license
6+
47

58
def test_admin_user_lifecycle(system_admin_account_token: Secret):
69
"""Tests addNewUser, updateUser, deleteUser."""

tests/test_system_admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import pytest
12
import schemathesis
23
from conftest import BASE_URL, Secret, system_admin_account_operations, USERNAME
34
from schemathesis import Case
45
from syrupy.assertion import SnapshotAssertion
56
from syrupy.filters import props
7+
8+
pytestmark = pytest.mark.needs_large_license
69
from syrupy.matchers import path_type
710

811

0 commit comments

Comments
 (0)