mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-18 09:49:47 +00:00
Renamed and addressed PR comments
This commit is contained in:
parent
815b5c7279
commit
17f488036f
2 changed files with 31 additions and 43 deletions
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from llama_stack.core.datatypes import CORSSpec, process_cors_config
|
||||
from llama_stack.core.datatypes import CORSConfig, process_cors_config
|
||||
|
||||
|
||||
def test_cors_spec_defaults():
|
||||
config = CORSSpec()
|
||||
def test_cors_config_defaults():
|
||||
config = CORSConfig()
|
||||
|
||||
assert config.allow_origins == []
|
||||
assert config.allow_origin_regex is None
|
||||
|
|
@ -21,8 +21,8 @@ def test_cors_spec_defaults():
|
|||
assert config.max_age == 600
|
||||
|
||||
|
||||
def test_cors_spec_explicit_config():
|
||||
config = CORSSpec(
|
||||
def test_cors_config_explicit_config():
|
||||
config = CORSConfig(
|
||||
allow_origins=["https://example.com"], allow_credentials=True, max_age=3600, allow_methods=["GET", "POST"]
|
||||
)
|
||||
|
||||
|
|
@ -32,19 +32,19 @@ def test_cors_spec_explicit_config():
|
|||
assert config.allow_methods == ["GET", "POST"]
|
||||
|
||||
|
||||
def test_cors_spec_regex():
|
||||
config = CORSSpec(allow_origins=[], allow_origin_regex=r"https?://localhost:\d+")
|
||||
def test_cors_config_regex():
|
||||
config = CORSConfig(allow_origins=[], allow_origin_regex=r"https?://localhost:\d+")
|
||||
|
||||
assert config.allow_origins == []
|
||||
assert config.allow_origin_regex == r"https?://localhost:\d+"
|
||||
|
||||
|
||||
def test_cors_spec_wildcard_credentials_error():
|
||||
with pytest.raises(ValueError, match="CORS: allow_credentials=True requires explicit origins"):
|
||||
CORSSpec(allow_origins=["*"], allow_credentials=True)
|
||||
def test_cors_config_wildcard_credentials_error():
|
||||
with pytest.raises(ValueError, match="Cannot use wildcard origins with credentials enabled"):
|
||||
CORSConfig(allow_origins=["*"], allow_credentials=True)
|
||||
|
||||
with pytest.raises(ValueError, match="CORS: allow_credentials=True requires explicit origins"):
|
||||
CORSSpec(allow_origins=["https://example.com", "*"], allow_credentials=True)
|
||||
with pytest.raises(ValueError, match="Cannot use wildcard origins with credentials enabled"):
|
||||
CORSConfig(allow_origins=["https://example.com", "*"], allow_credentials=True)
|
||||
|
||||
|
||||
def test_process_cors_config_false():
|
||||
|
|
@ -55,29 +55,29 @@ def test_process_cors_config_false():
|
|||
def test_process_cors_config_true():
|
||||
result = process_cors_config(True)
|
||||
|
||||
assert isinstance(result, CORSSpec)
|
||||
assert isinstance(result, CORSConfig)
|
||||
assert result.allow_origins == []
|
||||
assert result.allow_origin_regex == r"https?://localhost:\d+"
|
||||
assert result.allow_credentials is False
|
||||
assert "GET" in result.allow_methods
|
||||
assert "POST" in result.allow_methods
|
||||
assert "OPTIONS" in result.allow_methods
|
||||
expected_methods = ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
|
||||
for method in expected_methods:
|
||||
assert method in result.allow_methods
|
||||
|
||||
|
||||
def test_process_cors_config_passthrough():
|
||||
original = CORSSpec(allow_origins=["https://example.com"], allow_methods=["GET"])
|
||||
original = CORSConfig(allow_origins=["https://example.com"], allow_methods=["GET"])
|
||||
result = process_cors_config(original)
|
||||
|
||||
assert result is original
|
||||
|
||||
|
||||
def test_process_cors_config_invalid_type():
|
||||
with pytest.raises(ValueError, match="Invalid CORS configuration type"):
|
||||
with pytest.raises(ValueError, match="Expected bool or CORSConfig, got str"):
|
||||
process_cors_config("invalid")
|
||||
|
||||
|
||||
def test_cors_spec_model_dump():
|
||||
cors_spec = CORSSpec(
|
||||
def test_cors_config_model_dump():
|
||||
cors_config = CORSConfig(
|
||||
allow_origins=["https://example.com"],
|
||||
allow_methods=["GET", "POST"],
|
||||
allow_headers=["Content-Type"],
|
||||
|
|
@ -85,7 +85,7 @@ def test_cors_spec_model_dump():
|
|||
max_age=3600,
|
||||
)
|
||||
|
||||
config_dict = cors_spec.model_dump()
|
||||
config_dict = cors_config.model_dump()
|
||||
|
||||
assert config_dict["allow_origins"] == ["https://example.com"]
|
||||
assert config_dict["allow_methods"] == ["GET", "POST"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue