generated from coulomb/repo-seed
First implementation
This commit is contained in:
64
tests/test_sdk_wrapper.py
Normal file
64
tests/test_sdk_wrapper.py
Normal file
@@ -0,0 +1,64 @@
|
||||
"""
|
||||
Basic tests for feature-control-sdk wrapper + local provider.
|
||||
|
||||
Run with: pytest tests/test_sdk_wrapper.py
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from feature_control_sdk import FeatureControlClient, LocalProvider
|
||||
|
||||
|
||||
def test_local_provider_boolean():
|
||||
provider = LocalProvider({"test.feature": True})
|
||||
client = FeatureControlClient()
|
||||
client.set_provider(provider)
|
||||
|
||||
assert client.get_boolean_value("test.feature", False) is True
|
||||
assert client.get_boolean_value("missing.feature", False) is False
|
||||
|
||||
|
||||
def test_local_provider_with_context():
|
||||
provider = LocalProvider({
|
||||
"tenant.feature": False,
|
||||
"agent.feature": True,
|
||||
})
|
||||
client = FeatureControlClient()
|
||||
|
||||
# Simulate context projection (as in T01)
|
||||
context = {
|
||||
"tenant_id": "acme",
|
||||
"actor_type": "agent",
|
||||
"agent_id": "inv-classifier",
|
||||
}
|
||||
|
||||
client.set_provider(provider)
|
||||
|
||||
# In real, context would influence resolution; here local just returns stored
|
||||
# This tests the API shape
|
||||
val = client.get_boolean_value("agent.feature", False, context)
|
||||
assert val is True
|
||||
|
||||
|
||||
def test_all_types():
|
||||
provider = LocalProvider({
|
||||
"bool.f": True,
|
||||
"str.f": "hello",
|
||||
"num.f": 42,
|
||||
"obj.f": {"a": 1},
|
||||
})
|
||||
client = FeatureControlClient()
|
||||
client.set_provider(provider)
|
||||
|
||||
assert client.get_boolean_value("bool.f", False) is True
|
||||
assert client.get_string_value("str.f", "x") == "hello"
|
||||
assert client.get_number_value("num.f", 0) == 42
|
||||
assert client.get_object_value("obj.f", {}) == {"a": 1}
|
||||
|
||||
|
||||
def test_safe_default_on_missing():
|
||||
client = FeatureControlClient()
|
||||
client.set_provider(LocalProvider({}))
|
||||
|
||||
assert client.get_boolean_value("no.such", False) is False
|
||||
assert client.get_string_value("no.such", "def") == "def"
|
||||
Reference in New Issue
Block a user