-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconftest.py
More file actions
144 lines (109 loc) · 5.07 KB
/
conftest.py
File metadata and controls
144 lines (109 loc) · 5.07 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
143
144
"""Shared fixtures for Talk Python CLI tests."""
from __future__ import annotations
import json
from collections.abc import Generator
import httpx
import pytest
from pytest_httpx import HTTPXMock
from talk_python_cli.client import DEFAULT_URL, MCPClient
def request_json(req: httpx.Request) -> dict:
"""Parse the JSON body from a captured httpx request."""
return json.loads(req.content)
# ── MCP JSON-RPC response helpers ────────────────────────────────────────────
def jsonrpc_result(id: int, result: dict) -> dict:
"""Build a JSON-RPC 2.0 success response."""
return {'jsonrpc': '2.0', 'id': id, 'result': result}
def jsonrpc_error(id: int, code: int, message: str) -> dict:
"""Build a JSON-RPC 2.0 error response."""
return {'jsonrpc': '2.0', 'id': id, 'error': {'code': code, 'message': message}}
def tool_result(id: int, text: str) -> dict:
"""Build a tools/call result with a single text content block."""
return jsonrpc_result(id, {'content': [{'type': 'text', 'text': text}]})
def add_init_responses(httpx_mock: HTTPXMock, session_id: str = 'test-session') -> None:
"""Register the two responses required for the MCP initialize handshake.
1. ``initialize`` request → JSON-RPC result with server capabilities
2. ``notifications/initialized`` notification → 202 Accepted (no body)
"""
# Response to "initialize" (id=1)
httpx_mock.add_response(
method='POST',
url=DEFAULT_URL,
json=jsonrpc_result(
1,
{
'protocolVersion': '2025-03-26',
'capabilities': {'tools': {}},
'serverInfo': {'name': 'talkpython-mcp', 'version': '1.3.0'},
},
),
headers={'mcp-session-id': session_id},
)
# Response to "notifications/initialized" (no id → 202)
httpx_mock.add_response(
method='POST',
url=DEFAULT_URL,
status_code=202,
headers={'mcp-session-id': session_id},
)
# ── Fixtures ─────────────────────────────────────────────────────────────────
@pytest.fixture
def mcp_client() -> Generator[MCPClient]:
"""Return a fresh MCPClient pointing at the default URL."""
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
yield client
client.close()
# ── Sample response data ─────────────────────────────────────────────────────
RECENT_EPISODES_TEXT = (
'Recent Episodes (3 shown):\n\n'
'535. PyView: Real-time Python Web Apps\n'
' Published: Jan 23, 2026\n'
' URL: https://talkpython.fm/episodes/show/535\n\n'
'534. diskcache: Your secret Python perf weapon\n'
' Published: Jan 12, 2026\n'
' URL: https://talkpython.fm/episodes/show/534\n\n'
'533. Web Frameworks in Prod by Their Creators\n'
' Published: Jan 05, 2026\n'
' URL: https://talkpython.fm/episodes/show/533'
)
SEARCH_EPISODES_TEXT = (
'Found 2 episode(s) matching "FastAPI":\n\n'
'- Episode 535: PyView: Real-time Python Web Apps\n'
' URL: https://talkpython.fm/episodes/show/535\n\n'
'- Episode 533: Web Frameworks in Prod by Their Creators\n'
' URL: https://talkpython.fm/episodes/show/533'
)
EPISODE_DETAIL_TEXT = (
'Episode 535: PyView: Real-time Python Web Apps\n\n'
'Published: January 23, 2026\n'
'Duration: 01:07:56\n'
'URL: https://talkpython.fm/episodes/show/535\n\n'
'Description:\nBuilding on the web is like working with the perfect clay.'
)
EPISODES_LIST_TEXT = (
'All Episodes:\n'
'535 - PyView: Real-time Python Web Apps\n'
'534 - diskcache: Your secret Python perf weapon\n'
'533 - Web Frameworks in Prod by Their Creators'
)
TRANSCRIPT_TEXT = 'Hello and welcome to Talk Python To Me, a weekly podcast on Python and related technologies.'
TRANSCRIPT_VTT_TEXT = 'WEBVTT\n\n00:00:00.000 --> 00:00:05.000\nHello and welcome to Talk Python To Me.'
SEARCH_GUESTS_TEXT = 'Found 1 guest(s) matching "Hynek":\n\n- Hynek Schlawack (ID: 312)'
GUEST_DETAIL_TEXT = 'Hynek Schlawack\nGuest ID: 312\n\nBio:\nInfrastructure and software engineer from Berlin.'
GUESTS_LIST_TEXT = 'All Guests:\nHynek Schlawack (ID: 312) — 5 appearances\nGuido van Rossum (ID: 1) — 4 appearances'
SEARCH_COURSES_TEXT = (
'Found 2 course(s) matching "Python":\n\n'
'- Course 57: Just Enough Python for Data Scientists\n'
'- Course 58: Agentic AI Programming for Python'
)
COURSE_DETAIL_TEXT = (
'Course 57: Just Enough Python for Data Scientists\n\n'
'Price: $29\nPublished: 2025-08-08\n'
'URL: https://training.talkpython.fm/courses/just-enough-python'
)
COURSES_LIST_TEXT = (
'Talk Python Training Courses (52 total):\n\n'
'## Just Enough Python for Data Scientists\n'
' ID: 57 | Price: $29\n\n'
'## Agentic AI Programming for Python\n'
' ID: 58 | Price: $39'
)