-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_episodes.py
More file actions
142 lines (100 loc) · 4.71 KB
/
test_episodes.py
File metadata and controls
142 lines (100 loc) · 4.71 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
"""Tests for episode commands."""
from __future__ import annotations
from pytest_httpx import HTTPXMock
from talk_python_cli.client import DEFAULT_URL
from tests.conftest import (
EPISODE_DETAIL_TEXT,
EPISODES_LIST_TEXT,
RECENT_EPISODES_TEXT,
SEARCH_EPISODES_TEXT,
TRANSCRIPT_TEXT,
TRANSCRIPT_VTT_TEXT,
add_init_responses,
request_json,
tool_result,
)
def _setup_tool_call(httpx_mock: HTTPXMock, text: str) -> None:
"""Register init + one tool-call response."""
add_init_responses(httpx_mock)
httpx_mock.add_response(
method='POST',
url=DEFAULT_URL,
json=tool_result(3, text),
)
class TestEpisodeSearch:
def test_search_sends_correct_tool_call(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, SEARCH_EPISODES_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
result = client.call_tool('search_episodes', {'query': 'FastAPI', 'limit': 5})
client.close()
body = request_json(httpx_mock.get_requests()[-1])
assert body['method'] == 'tools/call'
assert body['params']['name'] == 'search_episodes'
assert body['params']['arguments']['query'] == 'FastAPI'
assert body['params']['arguments']['limit'] == 5
assert 'FastAPI' in result
def test_search_returns_results(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, SEARCH_EPISODES_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
result = client.call_tool('search_episodes', {'query': 'FastAPI', 'limit': 10})
client.close()
assert 'Episode 535' in result
assert 'Episode 533' in result
class TestEpisodeGet:
def test_get_episode_sends_show_id(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, EPISODE_DETAIL_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
result = client.call_tool('get_episode', {'show_id': 535})
client.close()
body = request_json(httpx_mock.get_requests()[-1])
assert body['params']['arguments']['show_id'] == 535
assert 'Episode 535' in result
assert 'January 23, 2026' in result
def test_get_episode_includes_url(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, EPISODE_DETAIL_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
result = client.call_tool('get_episode', {'show_id': 535})
client.close()
assert 'https://talkpython.fm/episodes/show/535' in result
class TestEpisodeList:
def test_list_sends_no_arguments(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, EPISODES_LIST_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
result = client.call_tool('get_episodes')
client.close()
body = request_json(httpx_mock.get_requests()[-1])
assert body['params']['arguments'] == {}
assert '535 - PyView' in result
class TestRecentEpisodes:
def test_recent_sends_limit(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, RECENT_EPISODES_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
result = client.call_tool('get_recent_episodes', {'limit': 3})
client.close()
body = request_json(httpx_mock.get_requests()[-1])
assert body['params']['arguments']['limit'] == 3
assert '535.' in result
assert '534.' in result
assert '533.' in result
class TestTranscript:
def test_transcript_returns_text(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, TRANSCRIPT_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
result = client.call_tool('get_transcript_for_episode', {'show_id': 535})
client.close()
assert 'Hello and welcome to Talk Python To Me' in result
def test_transcript_vtt_returns_webvtt(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, TRANSCRIPT_VTT_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
result = client.call_tool('get_transcript_vtt', {'show_id': 535})
client.close()
assert result.startswith('WEBVTT')
assert '00:00:00.000' in result