mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
feat: add .opencode to gitignore and refactor lora routes
- Add .opencode directory to gitignore for agent-related files - Refactor lora_routes.py with consistent string formatting and improved route registration - Add DualRangeSlider Vue component for enhanced UI controls
This commit is contained in:
@@ -37,155 +37,167 @@ async def test_get_random_loras_success(routes):
|
||||
"""Test successful random LoRA generation"""
|
||||
routes.service.random_loras = [
|
||||
{
|
||||
'name': 'test_lora_1',
|
||||
'strength': 0.8,
|
||||
'clipStrength': 0.8,
|
||||
'active': True,
|
||||
'expanded': False,
|
||||
'locked': False
|
||||
"name": "test_lora_1",
|
||||
"strength": 0.8,
|
||||
"clipStrength": 0.8,
|
||||
"active": True,
|
||||
"expanded": False,
|
||||
"locked": False,
|
||||
},
|
||||
{
|
||||
'name': 'test_lora_2',
|
||||
'strength': 0.6,
|
||||
'clipStrength': 0.6,
|
||||
'active': True,
|
||||
'expanded': False,
|
||||
'locked': False
|
||||
}
|
||||
"name": "test_lora_2",
|
||||
"strength": 0.6,
|
||||
"clipStrength": 0.6,
|
||||
"active": True,
|
||||
"expanded": False,
|
||||
"locked": False,
|
||||
},
|
||||
]
|
||||
|
||||
request = DummyRequest(json_data={
|
||||
'count': 5,
|
||||
'model_strength_min': 0.5,
|
||||
'model_strength_max': 1.0,
|
||||
'use_same_clip_strength': True,
|
||||
'locked_loras': []
|
||||
})
|
||||
request = DummyRequest(
|
||||
json_data={
|
||||
"count": 5,
|
||||
"model_strength_min": 0.5,
|
||||
"model_strength_max": 1.0,
|
||||
"use_same_clip_strength": True,
|
||||
"locked_loras": [],
|
||||
}
|
||||
)
|
||||
|
||||
response = await routes.get_random_loras(request)
|
||||
payload = json.loads(response.text)
|
||||
|
||||
assert response.status == 200
|
||||
assert payload['success'] is True
|
||||
assert 'loras' in payload
|
||||
assert payload['count'] == 2
|
||||
assert payload["success"] is True
|
||||
assert "loras" in payload
|
||||
assert payload["count"] == 2
|
||||
|
||||
|
||||
async def test_get_random_loras_with_range(routes):
|
||||
"""Test random LoRAs with count range"""
|
||||
routes.service.random_loras = [
|
||||
{
|
||||
'name': 'test_lora_1',
|
||||
'strength': 0.8,
|
||||
'clipStrength': 0.8,
|
||||
'active': True,
|
||||
'expanded': False,
|
||||
'locked': False
|
||||
"name": "test_lora_1",
|
||||
"strength": 0.8,
|
||||
"clipStrength": 0.8,
|
||||
"active": True,
|
||||
"expanded": False,
|
||||
"locked": False,
|
||||
}
|
||||
]
|
||||
|
||||
request = DummyRequest(json_data={
|
||||
'count_min': 3,
|
||||
'count_max': 7,
|
||||
'model_strength_min': 0.0,
|
||||
'model_strength_max': 1.0,
|
||||
'use_same_clip_strength': True
|
||||
})
|
||||
request = DummyRequest(
|
||||
json_data={
|
||||
"count_min": 3,
|
||||
"count_max": 7,
|
||||
"model_strength_min": 0.0,
|
||||
"model_strength_max": 1.0,
|
||||
"use_same_clip_strength": True,
|
||||
}
|
||||
)
|
||||
|
||||
response = await routes.get_random_loras(request)
|
||||
payload = json.loads(response.text)
|
||||
|
||||
assert response.status == 200
|
||||
assert payload['success'] is True
|
||||
assert payload["success"] is True
|
||||
|
||||
|
||||
async def test_get_random_loras_invalid_count(routes):
|
||||
"""Test invalid count parameter"""
|
||||
request = DummyRequest(json_data={
|
||||
'count': 150, # Over limit
|
||||
'model_strength_min': 0.0,
|
||||
'model_strength_max': 1.0
|
||||
})
|
||||
request = DummyRequest(
|
||||
json_data={
|
||||
"count": 150, # Over limit
|
||||
"model_strength_min": 0.0,
|
||||
"model_strength_max": 1.0,
|
||||
}
|
||||
)
|
||||
|
||||
response = await routes.get_random_loras(request)
|
||||
payload = json.loads(response.text)
|
||||
|
||||
assert response.status == 400
|
||||
assert payload['success'] is False
|
||||
assert 'Count must be between 1 and 100' in payload['error']
|
||||
assert payload["success"] is False
|
||||
assert "Count must be between 1 and 100" in payload["error"]
|
||||
|
||||
|
||||
async def test_get_random_loras_invalid_strength(routes):
|
||||
"""Test invalid strength range"""
|
||||
request = DummyRequest(json_data={
|
||||
'count': 5,
|
||||
'model_strength_min': -0.5, # Invalid
|
||||
'model_strength_max': 1.0
|
||||
})
|
||||
request = DummyRequest(
|
||||
json_data={
|
||||
"count": 5,
|
||||
"model_strength_min": -11, # Invalid (below -10)
|
||||
"model_strength_max": 1.0,
|
||||
}
|
||||
)
|
||||
|
||||
response = await routes.get_random_loras(request)
|
||||
payload = json.loads(response.text)
|
||||
|
||||
assert response.status == 400
|
||||
assert payload['success'] is False
|
||||
assert payload["success"] is False
|
||||
assert "Model strength must be between -10 and 10" in payload["error"]
|
||||
|
||||
|
||||
async def test_get_random_loras_with_locked(routes):
|
||||
"""Test random LoRAs with locked items"""
|
||||
routes.service.random_loras = [
|
||||
{
|
||||
'name': 'new_lora',
|
||||
'strength': 0.7,
|
||||
'clipStrength': 0.7,
|
||||
'active': True,
|
||||
'expanded': False,
|
||||
'locked': False
|
||||
"name": "new_lora",
|
||||
"strength": 0.7,
|
||||
"clipStrength": 0.7,
|
||||
"active": True,
|
||||
"expanded": False,
|
||||
"locked": False,
|
||||
},
|
||||
{
|
||||
'name': 'locked_lora',
|
||||
'strength': 0.9,
|
||||
'clipStrength': 0.9,
|
||||
'active': True,
|
||||
'expanded': False,
|
||||
'locked': True
|
||||
}
|
||||
"name": "locked_lora",
|
||||
"strength": 0.9,
|
||||
"clipStrength": 0.9,
|
||||
"active": True,
|
||||
"expanded": False,
|
||||
"locked": True,
|
||||
},
|
||||
]
|
||||
|
||||
request = DummyRequest(json_data={
|
||||
'count': 5,
|
||||
'model_strength_min': 0.5,
|
||||
'model_strength_max': 1.0,
|
||||
'use_same_clip_strength': True,
|
||||
'locked_loras': [
|
||||
{
|
||||
'name': 'locked_lora',
|
||||
'strength': 0.9,
|
||||
'clipStrength': 0.9,
|
||||
'active': True,
|
||||
'expanded': False,
|
||||
'locked': True
|
||||
}
|
||||
]
|
||||
})
|
||||
request = DummyRequest(
|
||||
json_data={
|
||||
"count": 5,
|
||||
"model_strength_min": 0.5,
|
||||
"model_strength_max": 1.0,
|
||||
"use_same_clip_strength": True,
|
||||
"locked_loras": [
|
||||
{
|
||||
"name": "locked_lora",
|
||||
"strength": 0.9,
|
||||
"clipStrength": 0.9,
|
||||
"active": True,
|
||||
"expanded": False,
|
||||
"locked": True,
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
response = await routes.get_random_loras(request)
|
||||
payload = json.loads(response.text)
|
||||
|
||||
assert response.status == 200
|
||||
assert payload['success'] is True
|
||||
assert payload["success"] is True
|
||||
|
||||
|
||||
async def test_get_random_loras_error(routes, monkeypatch):
|
||||
"""Test error handling"""
|
||||
|
||||
async def failing(*_args, **_kwargs):
|
||||
raise RuntimeError("Service error")
|
||||
|
||||
routes.service.get_random_loras = failing
|
||||
request = DummyRequest(json_data={'count': 5})
|
||||
request = DummyRequest(json_data={"count": 5})
|
||||
|
||||
response = await routes.get_random_loras(request)
|
||||
payload = json.loads(response.text)
|
||||
|
||||
assert response.status == 500
|
||||
assert payload['success'] is False
|
||||
assert 'error' in payload
|
||||
assert payload["success"] is False
|
||||
assert "error" in payload
|
||||
|
||||
Reference in New Issue
Block a user