Create Feishu sheets for spreadsheet files
This commit is contained in:
@@ -106,6 +106,67 @@ class FeishuIntegrationTests(unittest.TestCase):
|
||||
online_docs['files'][str(file_path)]['url'],
|
||||
'https://mi.feishu.cn/docx/example',
|
||||
)
|
||||
self.assertEqual(online_docs['files'][str(file_path)]['kind'], 'doc')
|
||||
|
||||
def test_create_online_doc_converts_csv_to_feishu_sheet(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
client, state = _build_client(Path(tmp_dir))
|
||||
file_path = _write_account_file(
|
||||
state,
|
||||
'alice',
|
||||
'records.csv',
|
||||
'query,label\n导航到公司,"Agent(tag=""地图导航"")"\n',
|
||||
)
|
||||
|
||||
with patch.object(
|
||||
gui_server,
|
||||
'_feishu_status_payload',
|
||||
return_value={'logged_in': True, 'status': 'logged_in'},
|
||||
), patch.object(
|
||||
gui_server.MCPRuntime,
|
||||
'call_tool',
|
||||
side_effect=[
|
||||
(
|
||||
'{"url":"https://mi.feishu.cn/sheets/shtcn123","spreadsheet_token":"shtcn123"}',
|
||||
{'server_name': 'feishu-mcp-pro', 'tool_name': 'sheet_ops'},
|
||||
),
|
||||
(
|
||||
'{"sheets":[{"sheet_id":"abc123","title":"Sheet1"}]}',
|
||||
{'server_name': 'feishu-mcp-pro', 'tool_name': 'sheet_ops'},
|
||||
),
|
||||
(
|
||||
'{"ok":true}',
|
||||
{'server_name': 'feishu-mcp-pro', 'tool_name': 'sheet_ops'},
|
||||
),
|
||||
],
|
||||
) as call_tool:
|
||||
response = client.post(
|
||||
'/api/files/online-doc',
|
||||
json={'account_id': 'alice', 'path': str(file_path)},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
payload = response.json()
|
||||
self.assertEqual(payload['kind'], 'sheet')
|
||||
self.assertEqual(payload['url'], 'https://mi.feishu.cn/sheets/shtcn123')
|
||||
self.assertEqual(call_tool.call_count, 3)
|
||||
self.assertEqual(call_tool.call_args_list[0].args[0], 'sheet_ops')
|
||||
self.assertEqual(call_tool.call_args_list[0].kwargs['arguments']['action'], 'create')
|
||||
self.assertEqual(call_tool.call_args_list[2].kwargs['arguments']['action'], 'write')
|
||||
write_params = call_tool.call_args_list[2].kwargs['arguments']['params']
|
||||
self.assertEqual(write_params['range'], 'abc123!A1:B2')
|
||||
self.assertEqual(
|
||||
json.loads(write_params['values']),
|
||||
[['query', 'label'], ['导航到公司', 'Agent(tag="地图导航")']],
|
||||
)
|
||||
map_path = (
|
||||
state.account_paths('alice')['base']
|
||||
/ 'integrations'
|
||||
/ 'feishu'
|
||||
/ 'online-docs.json'
|
||||
)
|
||||
online_docs = json.loads(map_path.read_text(encoding='utf-8'))
|
||||
self.assertEqual(online_docs['files'][str(file_path)]['kind'], 'sheet')
|
||||
|
||||
def test_extract_first_url_ignores_wrapping_quotes(self) -> None:
|
||||
url = gui_server._extract_first_url(
|
||||
|
||||
Reference in New Issue
Block a user