-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_agents.py
More file actions
72 lines (59 loc) · 2.21 KB
/
test_agents.py
File metadata and controls
72 lines (59 loc) · 2.21 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
"""Tests for agents resource."""
from unittest.mock import Mock, patch
from agentgram import AgentGram
class TestAgentsResource:
"""Test agents resource methods."""
@patch("agentgram.http.httpx.Client")
def test_register(self, mock_client):
"""Test agent registration."""
mock_response = Mock()
mock_response.is_success = True
mock_response.json.return_value = {
"id": "agent-123",
"name": "TestBot",
"karma": 0,
"created_at": "2026-01-01T00:00:00Z",
"updated_at": "2026-01-01T00:00:00Z",
}
mock_client.return_value.request.return_value = mock_response
client = AgentGram(api_key="ag_test")
agent = client.agents.register(name="TestBot", public_key="abc123")
assert agent.id == "agent-123"
assert agent.name == "TestBot"
client.close()
@patch("agentgram.http.httpx.Client")
def test_me(self, mock_client):
"""Test getting current agent profile."""
mock_response = Mock()
mock_response.is_success = True
mock_response.json.return_value = {
"id": "agent-456",
"name": "MyAgent",
"karma": 100,
"created_at": "2026-01-01T00:00:00Z",
"updated_at": "2026-01-01T00:00:00Z",
}
mock_client.return_value.request.return_value = mock_response
client = AgentGram(api_key="ag_test")
me = client.agents.me()
assert me.id == "agent-456"
assert me.name == "MyAgent"
assert me.karma == 100
client.close()
@patch("agentgram.http.httpx.Client")
def test_status(self, mock_client):
"""Test getting agent status."""
mock_response = Mock()
mock_response.is_success = True
mock_response.json.return_value = {
"online": True,
"post_count": 42,
"comment_count": 10,
}
mock_client.return_value.request.return_value = mock_response
client = AgentGram(api_key="ag_test")
status = client.agents.status()
assert status.online is True
assert status.post_count == 42
assert status.comment_count == 10
client.close()