-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
131 lines (110 loc) · 3.92 KB
/
conftest.py
File metadata and controls
131 lines (110 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"""
Pytest configuration and fixtures for S3 tests
Generated-by: Claude AI
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
"""
import pytest
import os
import json
from pathlib import Path
from tests.common.s3_client import S3Client
# Try to import SDK capabilities module
try:
from tests.common.sdk_capabilities import (
SDKSpec,
build_caps_document,
load_caps_for_tests,
)
SDK_CAPS_AVAILABLE = True
except ImportError:
SDK_CAPS_AVAILABLE = False
@pytest.fixture(scope="session")
def config():
"""
Test configuration fixture
Returns configuration for S3 testing
"""
return {
"s3_endpoint": os.getenv("S3_ENDPOINT", "http://localhost:9000"),
"s3_access_key": os.getenv("S3_ACCESS_KEY", "minioadmin"),
"s3_secret_key": os.getenv("S3_SECRET_KEY", "minioadmin"),
"s3_region": os.getenv("S3_REGION", "us-east-1"),
"s3_bucket_prefix": os.getenv("S3_BUCKET_PREFIX", "msst-test"),
"verify_ssl": os.getenv("S3_VERIFY_SSL", "false").lower() == "true",
"s3_sdk": os.getenv("S3_SDK", "boto3"),
"s3_sdk_version": os.getenv("S3_SDK_VERSION", "latest"),
}
@pytest.fixture(scope="session")
def sdk_capabilities(config):
"""
SDK capability profile fixture
Generates or loads SDK capability profile for the current SDK/version
"""
if not SDK_CAPS_AVAILABLE:
# Return default capabilities if module not available
return {
"sdk": config["s3_sdk"],
"version": config["s3_sdk_version"],
"profile": {
"sigv4_chunked": True,
"unsigned_payload_allowed": True,
"virtual_hosted_default": True,
"list_objects_v1": False,
"list_objects_url_plus_treated_as_space": False,
"retry_mode": "standard",
"follows_301_region_redirect": True,
"follows_307_on_put": True,
"crc32c_default": False,
},
"sources": ["defaults"],
}
# Check if capabilities were already generated
caps_path = Path(os.getenv("S3_CAPS_JSON_PATH", ".sdk_capabilities.json"))
if caps_path.exists():
try:
return load_caps_for_tests(str(caps_path))
except Exception:
pass # Fall through to generate new capabilities
# Generate capabilities
try:
spec = SDKSpec(name=config["s3_sdk"], version=config["s3_sdk_version"])
override_json = os.getenv("S3_CAP_PROFILE_JSON")
force_override = os.getenv("S3_CAP_PROFILE_OVERRIDE", "0") == "1"
endpoint_hint = config.get("s3_endpoint")
capabilities = build_caps_document(
spec=spec,
endpoint_hint=endpoint_hint,
override_json_path=override_json if force_override else None,
force_override=force_override,
)
# Save for future use
with open(caps_path, "w") as f:
json.dump(capabilities, f, indent=2)
return capabilities
except Exception as e:
# Return defaults on error
print(f"Warning: Failed to generate SDK capabilities: {e}")
return {
"sdk": config["s3_sdk"],
"version": config["s3_sdk_version"],
"profile": {},
"sources": ["error-fallback"],
}
@pytest.fixture(scope="function")
def s3_client(config, sdk_capabilities):
"""
S3 client fixture
Creates an S3Client instance configured for the test environment
with SDK capability awareness
"""
client = S3Client(
endpoint_url=config["s3_endpoint"],
access_key=config["s3_access_key"],
secret_key=config["s3_secret_key"],
region=config["s3_region"],
use_ssl=config["s3_endpoint"].startswith("https"),
verify_ssl=config["verify_ssl"],
capabilities=sdk_capabilities.get("profile"),
)
yield client
# Cleanup happens in test fixtures