fix: validate date format in create_schedule with clear error message
This commit is contained in:
48
tests/test_customer.py
Normal file
48
tests/test_customer.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import pytest
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
from tryton_mcp.server import create_customer
|
||||
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent / "src"))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
class TestParty:
|
||||
|
||||
async def test_create_new_customer(self, mcp_client, mock_settings):
|
||||
mock_client = mock_settings.get_client.return_value
|
||||
mock_client.call.return_value = [1]
|
||||
|
||||
result = await mcp_client.call_tool(
|
||||
"create_customer",
|
||||
{
|
||||
"name": "Alejandro Zapata",
|
||||
"identifiers": [["create", [{"type": "mobile", "code": "310659595"}]]],
|
||||
},
|
||||
)
|
||||
|
||||
assert result.content is not None
|
||||
assert len(result.content) == 1
|
||||
assert result.content[0].text == "[1]"
|
||||
|
||||
async def test_find_customer(self, mcp_client, mock_settings):
|
||||
|
||||
expected_return = [
|
||||
{'id': 19, 'party': 44, 'party.': {'name': 'Alejandro Zapata', 'id': 44}}
|
||||
]
|
||||
|
||||
mock_client = mock_settings.get_client.return_value
|
||||
mock_client.call.return_value = expected_return
|
||||
|
||||
result = await mcp_client.call_tool(
|
||||
"find_customer_by_identifier",
|
||||
{
|
||||
"identifier": "310659595"
|
||||
})
|
||||
|
||||
assert result.content is not None
|
||||
assert len(result.content) == 1
|
||||
assert json.loads(result.content[0].text) == expected_return
|
||||
@@ -2,6 +2,7 @@ import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
import datetime
|
||||
import json
|
||||
from fastmcp.exceptions import ToolError
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@@ -78,6 +79,19 @@ class TestCreateSchedule:
|
||||
},
|
||||
)
|
||||
|
||||
async def test_create_schedule_invalid_date_format(self, mcp_client, mock_settings):
|
||||
with pytest.raises(ToolError, match="Invalid date format"):
|
||||
await mcp_client.call_tool(
|
||||
"create_schedule",
|
||||
{
|
||||
"professional": 6,
|
||||
"description": "Test appointment",
|
||||
"customer": 4,
|
||||
"date": "invalid-date",
|
||||
"service_center": 11,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
class TestFindServiceCenters:
|
||||
|
||||
Reference in New Issue
Block a user