Skip to content

Commit 098a418

Browse files
committed
fix unit test and type hint
1 parent 63102f0 commit 098a418

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

_test_unstructured_client/unit/test_request_utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from __future__ import annotations
22

3+
import json
4+
import pytest
5+
36
from unstructured_client._hooks.custom.request_utils import create_response
47

58

@@ -14,10 +17,12 @@ def test_create_response_for_json():
1417
assert response.headers["Content-Type"] == "application/json"
1518

1619
def test_create_response_for_csv():
17-
elements = 'type,element_id,text,languages,page_number,filename,filetype,parent_id' \
18-
'\nTitle,f73329878fbbb0bb131a83e7b6daacbe,Module One - Introduction to Product' \
19-
' Development and Quality Assurance,[\'eng\'],1,list-item-example-1.pdf,application/pdf,'
20+
elements = [
21+
b'type,element_id,text,languages,page_number,filename,filetype,parent_id' \
22+
b'\nTitle,f73329878fbbb0bb131a83e7b6daacbe,Module One - Introduction to Product' \
23+
b' Development and Quality Assurance,[\'eng\'],1,list-item-example-1.pdf,application/pdf,'
24+
]
2025
response = create_response(elements)
2126
assert response.status_code == 200
22-
assert response.json() == None
23-
assert response.headers["Content-Type"] == "text/csv"
27+
pytest.raises(json.decoder.JSONDecodeError, response.json)
28+
assert response.headers["Content-Type"] == "text/csv; charset=utf-8"

src/unstructured_client/_hooks/custom/request_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import io
66
import json
77
import logging
8-
from typing import Tuple, Any
8+
from typing import Sequence, Tuple, Any
99

1010
import httpx
1111
from requests_toolbelt.multipart.encoder import MultipartEncoder # type: ignore
@@ -139,7 +139,7 @@ def prepare_request_payload(form_data: FormData) -> FormData:
139139
return payload
140140

141141

142-
def create_response(elements: list[dict[str, Any] | bytes]) -> httpx.Response:
142+
def create_response(elements: Sequence[dict[str, Any] | bytes]) -> httpx.Response:
143143
"""
144144
Creates a modified response object with updated content.
145145

0 commit comments

Comments
 (0)