Files
manual_slop/tests/test_api_hook_client.py

93 lines
3.2 KiB
Python

import pytest
from unittest.mock import patch
import sys
import os
# Ensure project root is in path for imports
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
from api_hook_client import ApiHookClient
def test_get_status_success(live_gui: tuple) -> None:
"""
Test that get_status successfully retrieves the server status
when the live GUI is running.
"""
client = ApiHookClient()
status = client.get_status()
assert status == {'status': 'ok'}
def test_get_project_success(live_gui: tuple) -> None:
"""
Test successful retrieval of project data from the live GUI.
"""
client = ApiHookClient()
response = client.get_project()
assert 'project' in response
# We don't assert specific content as it depends on the environment's active project
def test_get_session_success(live_gui: tuple) -> None:
"""
Test successful retrieval of session data.
"""
client = ApiHookClient()
response = client.get_session()
assert 'session' in response
assert 'entries' in response['session']
def test_post_gui_success(live_gui: tuple) -> None:
"""
Test successful posting of GUI data.
"""
client = ApiHookClient()
gui_data = {'command': 'set_text', 'id': 'some_item', 'value': 'new_text'}
response = client.post_gui(gui_data)
assert response == {'status': 'queued'}
def test_get_performance_success(live_gui: tuple) -> None:
"""
Test successful retrieval of performance metrics.
"""
client = ApiHookClient()
response = client.get_performance()
assert "performance" in response
def test_unsupported_method_error() -> None:
"""
Test that calling an unsupported HTTP method raises a ValueError.
"""
client = ApiHookClient()
with pytest.raises(ValueError, match="Unsupported HTTP method"):
client._make_request('PUT', '/some_endpoint', data={'key': 'value'})
def test_get_text_value() -> None:
"""
Test retrieval of string representation using get_text_value.
"""
client = ApiHookClient()
with patch.object(client, 'get_value', return_value=123):
assert client.get_text_value("dummy_tag") == "123"
with patch.object(client, 'get_value', return_value=None):
assert client.get_text_value("dummy_tag") is None
def test_get_node_status() -> None:
"""
Test retrieval of DAG node status using get_node_status.
"""
client = ApiHookClient()
# When get_value returns a status directly
with patch.object(client, 'get_value', return_value="running"):
assert client.get_node_status("my_node") == "running"
# When get_value returns None and diagnostics provides a nodes dict
with patch.object(client, 'get_value', return_value=None):
with patch.object(client, '_make_request', return_value={'nodes': {'my_node': 'completed'}}):
assert client.get_node_status("my_node") == "completed"
# When get_value returns None and diagnostics provides a direct key
with patch.object(client, 'get_value', return_value=None):
with patch.object(client, '_make_request', return_value={'my_node': 'failed'}):
assert client.get_node_status("my_node") == "failed"
# When neither works
with patch.object(client, 'get_value', return_value=None):
with patch.object(client, '_make_request', return_value={}):
assert client.get_node_status("my_node") is None