|
1 | | -from __future__ import annotations |
2 | | - |
3 | | -import os |
4 | | - |
5 | | -import httpx |
6 | | -import pytest |
7 | | -from respx import MockRouter |
8 | | - |
9 | | -from zhipuai import ZhipuAI |
10 | | -from zhipuai.api_resource import FilesWithRawResponse |
11 | | - |
12 | | -base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:2333") |
13 | | -api_key = "Key.secret" |
14 | | - |
15 | | - |
16 | | -class TestZhipuAIFile: |
17 | | - client = ZhipuAI(base_url=base_url, api_key=api_key) |
18 | | - |
19 | | - @pytest.mark.respx(base_url=base_url) |
20 | | - def test_file_download_jsonl_raises(self, test_file_path: str, respx_mock: MockRouter) -> None: |
21 | | - with open(os.path.join(test_file_path, "batchinput.jsonl"), "rb") as file: |
22 | | - respx_mock.get("/files/1/content").mock( |
23 | | - return_value=httpx.Response(200, content=file.read()) |
24 | | - ) |
25 | | - legacy = FilesWithRawResponse(self.client.files) |
26 | | - response = legacy.content("1") |
27 | | - files_content = response.parse() |
28 | | - |
29 | | - assert files_content.content == b'{"custom_id": "request-1", "method": "POST", "url": "/v4/chat/completions", "body": {"model": "glm-4", "messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Hello world!"}],"max_tokens": 1000}}' |
30 | | - with pytest.raises(NotImplementedError) as exc: |
31 | | - files_content.json() |
32 | | - assert exc.type == NotImplementedError |
33 | | - |
34 | | - @pytest.mark.respx(base_url=base_url) |
35 | | - def test_file_download_jsonl(self, test_file_path: str, respx_mock: MockRouter) -> None: |
36 | | - with open(os.path.join(test_file_path, "batchinput.jsonl"), "rb") as file: |
37 | | - respx_mock.get("/files/1/content").mock( |
38 | | - return_value=httpx.Response(200, content=file.read(), |
39 | | - headers={ |
40 | | - "Content-Type": "application/jsonl", |
41 | | - "Content-Disposition": "attachment; filename=batchinput.jsonl" |
42 | | - } |
43 | | - ) |
44 | | - ) |
45 | | - legacy = FilesWithRawResponse(self.client.files) |
46 | | - response = legacy.content("1") |
47 | | - files_content = response.parse() |
48 | | - |
49 | | - assert files_content.content == b'{"custom_id": "request-1", "method": "POST", "url": "/v4/chat/completions", "body": {"model": "glm-4", "messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Hello world!"}],"max_tokens": 1000}}' |
50 | | - |
51 | | - text = next(files_content.iter_text()) |
52 | | - assert text == '{"custom_id": "request-1", "method": "POST", "url": "/v4/chat/completions", "body": {"model": "glm-4", "messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Hello world!"}],"max_tokens": 1000}}' |
53 | | - |
54 | | - |
55 | | - def test_is_closed(self): |
56 | | - assert self.client.is_closed() is False |
57 | | - |
58 | | - def test_close(self): |
59 | | - self.client.close() |
60 | | - assert self.client.is_closed() is True |
| 1 | +# from __future__ import annotations |
| 2 | +# |
| 3 | +# import os |
| 4 | +# |
| 5 | +# import httpx |
| 6 | +# import pytest |
| 7 | +# from respx import MockRouter |
| 8 | +# |
| 9 | +# from zhipuai import ZhipuAI |
| 10 | +# from zhipuai.api_resource import FilesWithRawResponse |
| 11 | +# |
| 12 | +# base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:2333") |
| 13 | +# api_key = "Key.secret" |
| 14 | +# |
| 15 | +# |
| 16 | +# class TestZhipuAIFile: |
| 17 | +# client = ZhipuAI(base_url=base_url, api_key=api_key) |
| 18 | +# |
| 19 | +# @pytest.mark.respx(base_url=base_url) |
| 20 | +# def test_file_download_jsonl_raises(self, test_file_path: str, respx_mock: MockRouter) -> None: |
| 21 | +# with open(os.path.join(test_file_path, "batchinput.jsonl"), "rb") as file: |
| 22 | +# respx_mock.get("/files/1/content").mock( |
| 23 | +# return_value=httpx.Response(200, content=file.read()) |
| 24 | +# ) |
| 25 | +# legacy = FilesWithRawResponse(self.client.files) |
| 26 | +# response = legacy.content("1") |
| 27 | +# files_content = response.parse() |
| 28 | +# |
| 29 | +# assert files_content.content == b'{"custom_id": "request-1", "method": "POST", "url": "/v4/chat/completions", "body": {"model": "glm-4", "messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Hello world!"}],"max_tokens": 1000}}' |
| 30 | +# with pytest.raises(NotImplementedError) as exc: |
| 31 | +# files_content.json() |
| 32 | +# assert exc.type == NotImplementedError |
| 33 | +# |
| 34 | +# @pytest.mark.respx(base_url=base_url) |
| 35 | +# def test_file_download_jsonl(self, test_file_path: str, respx_mock: MockRouter) -> None: |
| 36 | +# with open(os.path.join(test_file_path, "batchinput.jsonl"), "rb") as file: |
| 37 | +# respx_mock.get("/files/1/content").mock( |
| 38 | +# return_value=httpx.Response(200, content=file.read(), |
| 39 | +# headers={ |
| 40 | +# "Content-Type": "application/jsonl", |
| 41 | +# "Content-Disposition": "attachment; filename=batchinput.jsonl" |
| 42 | +# } |
| 43 | +# ) |
| 44 | +# ) |
| 45 | +# legacy = FilesWithRawResponse(self.client.files) |
| 46 | +# response = legacy.content("1") |
| 47 | +# files_content = response.parse() |
| 48 | +# |
| 49 | +# assert files_content.content == b'{"custom_id": "request-1", "method": "POST", "url": "/v4/chat/completions", "body": {"model": "glm-4", "messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Hello world!"}],"max_tokens": 1000}}' |
| 50 | +# |
| 51 | +# text = next(files_content.iter_text()) |
| 52 | +# assert text == '{"custom_id": "request-1", "method": "POST", "url": "/v4/chat/completions", "body": {"model": "glm-4", "messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Hello world!"}],"max_tokens": 1000}}' |
| 53 | +# |
| 54 | +# |
| 55 | +# def test_is_closed(self): |
| 56 | +# assert self.client.is_closed() is False |
| 57 | +# |
| 58 | +# def test_close(self): |
| 59 | +# self.client.close() |
| 60 | +# assert self.client.is_closed() is True |
0 commit comments