-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_courses.py
More file actions
120 lines (84 loc) · 3.88 KB
/
test_courses.py
File metadata and controls
120 lines (84 loc) · 3.88 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
"""Tests for course commands."""
from __future__ import annotations
from pytest_httpx import HTTPXMock
from talk_python_cli.client import DEFAULT_URL
from tests.conftest import (
COURSE_DETAIL_TEXT,
COURSES_LIST_TEXT,
SEARCH_COURSES_TEXT,
add_init_responses,
request_json,
tool_result,
)
def _setup_tool_call(httpx_mock: HTTPXMock, text: str) -> None:
add_init_responses(httpx_mock)
httpx_mock.add_response(
method='POST',
url=DEFAULT_URL,
json=tool_result(3, text),
)
class TestCourseSearch:
def test_search_sends_query(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, SEARCH_COURSES_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
client.call_tool('search_courses', {'query': 'Python'})
client.close()
body = request_json(httpx_mock.get_requests()[-1])
assert body['params']['name'] == 'search_courses'
assert body['params']['arguments']['query'] == 'Python'
def test_search_with_course_id(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, SEARCH_COURSES_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
client.call_tool('search_courses', {'query': 'Python', 'course_id': 57})
client.close()
body = request_json(httpx_mock.get_requests()[-1])
args = body['params']['arguments']
assert args['query'] == 'Python'
assert args['course_id'] == 57
def test_search_returns_results(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, SEARCH_COURSES_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
result = client.call_tool('search_courses', {'query': 'Python'})
client.close()
assert 'Course 57' in result
assert 'Course 58' in result
class TestCourseGet:
def test_get_sends_course_id(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, COURSE_DETAIL_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
result = client.call_tool('get_course_details', {'course_id': 57})
client.close()
body = request_json(httpx_mock.get_requests()[-1])
assert body['params']['arguments']['course_id'] == 57
assert 'Course 57' in result
def test_get_includes_details(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, COURSE_DETAIL_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
result = client.call_tool('get_course_details', {'course_id': 57})
client.close()
assert '$29' in result
assert '2025-08-08' in result
class TestCourseList:
def test_list_sends_no_arguments(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, COURSES_LIST_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
client.call_tool('get_courses')
client.close()
body = request_json(httpx_mock.get_requests()[-1])
assert body['params']['name'] == 'get_courses'
assert body['params']['arguments'] == {}
def test_list_returns_courses(self, httpx_mock: HTTPXMock) -> None:
_setup_tool_call(httpx_mock, COURSES_LIST_TEXT)
from talk_python_cli.client import MCPClient
client = MCPClient(base_url=DEFAULT_URL, output_format='text')
result = client.call_tool('get_courses')
client.close()
assert '52 total' in result
assert 'Just Enough Python' in result
assert 'Agentic AI' in result