Skip to content

Commit c6de5b3

Browse files
committed
Minor test updates
1 parent 638bee7 commit c6de5b3

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

_test_contract/platform_api/test_destinations.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def test_list_destinations_5xx_code(
108108

109109

110110
def test_get_destination(httpx_mock, client: UnstructuredClient, platform_api_url: str):
111-
url = f"{platform_api_url}/api/v1/destinations/0c363dec-3c70-45ee-8041-481044a6e1cc"
111+
dest_id = "0c363dec-3c70-45ee-8041-481044a6e1cc"
112+
url = f"{platform_api_url}/api/v1/destinations/{dest_id}"
112113

113114
httpx_mock.add_response(
114115
method="GET",
@@ -124,7 +125,7 @@ def test_get_destination(httpx_mock, client: UnstructuredClient, platform_api_ur
124125
)
125126

126127
destination_response = client.destinations.get_destination(
127-
request=operations.GetDestinationRequest(destination_id="1")
128+
request=operations.GetDestinationRequest(destination_id=dest_id)
128129
)
129130
assert destination_response.status_code == 200
130131

@@ -147,7 +148,8 @@ def test_get_destination(httpx_mock, client: UnstructuredClient, platform_api_ur
147148
def test_get_destination_not_found(
148149
httpx_mock, client: UnstructuredClient, platform_api_url: str
149150
):
150-
url = f"{platform_api_url}/api/v1/destinations/0c363dec-3c70-45ee-8041-481044a6e1cc"
151+
dest_id = "0c363dec-3c70-45ee-8041-481044a6e1cc"
152+
url = f"{platform_api_url}/api/v1/destinations/{dest_id}"
151153

152154
httpx_mock.add_response(
153155
method="GET",
@@ -158,7 +160,7 @@ def test_get_destination_not_found(
158160

159161
with pytest.raises(SDKError) as excinfo:
160162
client.destinations.get_destination(
161-
request=operations.GetDestinationRequest(destination_id="1")
163+
request=operations.GetDestinationRequest(destination_id=dest_id)
162164
)
163165

164166
requests = httpx_mock.get_requests()
@@ -215,7 +217,8 @@ def test_create_destination(
215217
def test_update_destination(
216218
httpx_mock, client: UnstructuredClient, platform_api_url: str
217219
):
218-
url = f"{platform_api_url}/api/v1/destinations/b25d4161-77a0-4e08-b65e-86f398ce15ad"
220+
dest_id = "b25d4161-77a0-4e08-b65e-86f398ce15ad"
221+
url = f"{platform_api_url}/api/v1/destinations/{dest_id}"
219222

220223
httpx_mock.add_response(
221224
method="PUT",
@@ -232,7 +235,7 @@ def test_update_destination(
232235

233236
destination_update_response = client.destinations.update_destination(
234237
request=operations.UpdateDestinationRequest(
235-
destination_id="1",
238+
destination_id=dest_id,
236239
update_destination_connector=shared.UpdateDestinationConnector(
237240
config={}
238241
),
@@ -260,7 +263,8 @@ def test_update_destination(
260263
def test_delete_destination(
261264
httpx_mock, client: UnstructuredClient, platform_api_url: str
262265
):
263-
url = f"{platform_api_url}/api/v1/destinations/b25d4161-77a0-4e08-b65e-86f398ce15ad"
266+
dest_id = "b25d4161-77a0-4e08-b65e-86f398ce15ad"
267+
url = f"{platform_api_url}/api/v1/destinations/{dest_id}"
264268

265269
httpx_mock.add_response(
266270
method="DELETE",
@@ -271,7 +275,7 @@ def test_delete_destination(
271275
)
272276

273277
response = client.destinations.delete_destination(
274-
request=operations.DeleteDestinationRequest(destination_id="1")
278+
request=operations.DeleteDestinationRequest(destination_id=dest_id)
275279
)
276280
assert response.status_code == 200
277281

_test_contract/platform_api/test_sources.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def test_list_sources_5xx_code(
107107

108108

109109
def test_get_source(httpx_mock, client: UnstructuredClient, platform_api_url: str):
110-
url = f"{platform_api_url}/api/v1/sources/a15d4161-77a0-4e08-b65e-86f398ce15ad"
110+
dest_id = "a15d4161-77a0-4e08-b65e-86f398ce15ad"
111+
url = f"{platform_api_url}/api/v1/sources/{dest_id}"
111112

112113
httpx_mock.add_response(
113114
method="GET",
@@ -123,7 +124,7 @@ def test_get_source(httpx_mock, client: UnstructuredClient, platform_api_url: st
123124
)
124125

125126
source_response = client.sources.get_source(
126-
request=operations.GetSourceRequest(source_id="1")
127+
request=operations.GetSourceRequest(source_id=dest_id)
127128
)
128129
assert source_response.status_code == 200
129130

@@ -144,7 +145,8 @@ def test_get_source(httpx_mock, client: UnstructuredClient, platform_api_url: st
144145
def test_get_source_not_found(
145146
httpx_mock, client: UnstructuredClient, platform_api_url: str
146147
):
147-
url = f"{platform_api_url}/api/v1/sources/a15d4161-77a0-4e08-b65e-86f398ce15ad"
148+
dest_id = "a15d4161-77a0-4e08-b65e-86f398ce15ad"
149+
url = f"{platform_api_url}/api/v1/sources/{dest_id}"
148150

149151
httpx_mock.add_response(
150152
method="GET",
@@ -154,7 +156,7 @@ def test_get_source_not_found(
154156
)
155157

156158
with pytest.raises(SDKError) as excinfo:
157-
client.sources.get_source(request=operations.GetSourceRequest(source_id="1"))
159+
client.sources.get_source(request=operations.GetSourceRequest(source_id=dest_id))
158160

159161
requests = httpx_mock.get_requests()
160162
assert len(requests) == 1
@@ -204,7 +206,8 @@ def test_create_source(httpx_mock, client: UnstructuredClient, platform_api_url:
204206

205207

206208
def test_update_source(httpx_mock, client: UnstructuredClient, platform_api_url: str):
207-
url = f"{platform_api_url}/api/v1/sources/a15d4161-77a0-4e08-b65e-86f398ce15ad"
209+
dest_id = "a15d4161-77a0-4e08-b65e-86f398ce15ad"
210+
url = f"{platform_api_url}/api/v1/sources/{dest_id}"
208211

209212
httpx_mock.add_response(
210213
method="PUT",
@@ -222,7 +225,7 @@ def test_update_source(httpx_mock, client: UnstructuredClient, platform_api_url:
222225

223226
source_update_response = client.sources.update_source(
224227
request=operations.UpdateSourceRequest(
225-
source_id="1",
228+
source_id=dest_id,
226229
update_source_connector=shared.UpdateSourceConnector(
227230
config={}
228231
),
@@ -248,7 +251,8 @@ def test_update_source(httpx_mock, client: UnstructuredClient, platform_api_url:
248251

249252

250253
def test_delete_source(httpx_mock, client: UnstructuredClient, platform_api_url: str):
251-
url = f"{platform_api_url}/api/v1/sources/a15d4161-77a0-4e08-b65e-86f398ce15ad"
254+
dest_id = "a15d4161-77a0-4e08-b65e-86f398ce15ad"
255+
url = f"{platform_api_url}/api/v1/sources/{dest_id}"
252256

253257
httpx_mock.add_response(
254258
method="DELETE",
@@ -259,7 +263,7 @@ def test_delete_source(httpx_mock, client: UnstructuredClient, platform_api_url:
259263
)
260264

261265
response = client.sources.delete_source(
262-
request=operations.DeleteSourceRequest(source_id="1")
266+
request=operations.DeleteSourceRequest(source_id=dest_id)
263267
)
264268
assert response.status_code == 200
265269

_test_unstructured_client/unit/test_custom_hooks.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,6 @@ def test_unit_clean_server_url_fixes_malformed_localhost_url(server_url: str):
210210
assert client.general.sdk_configuration.server_url == "http://localhost:8000"
211211

212212

213-
def test_unit_clean_server_url_returns_empty_string_given_empty_string():
214-
client = UnstructuredClient(server_url="", api_key_auth=FAKE_KEY)
215-
assert client.general.sdk_configuration.server_url == ""
216-
217213

218214
def test_unit_clean_server_url_returns_None_given_no_server_url():
219215
client = UnstructuredClient(api_key_auth=FAKE_KEY)
@@ -230,7 +226,7 @@ def test_unit_clean_server_url_returns_None_given_no_server_url():
230226
],
231227
)
232228
def test_unit_clean_server_url_fixes_malformed_urls_with_positional_arguments(server_url: str):
233-
client = UnstructuredClient(FAKE_KEY, "", server_url)
229+
client = UnstructuredClient(FAKE_KEY, server_url=server_url)
234230
assert (
235231
client.general.sdk_configuration.server_url
236232
== "https://unstructured-000mock.api.unstructuredapp.io"

src/unstructured_client/_hooks/custom/clean_server_url_hook.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class CleanServerUrlSDKInitHook(SDKInitHook):
1313
def clean_server_url(self, base_url) -> str:
1414
"""Fix url scheme and remove the '/general/v0/general' path."""
1515

16+
if not base_url:
17+
return None
1618
# -- add a url scheme if not present (urllib.parse does not work reliably without it)
1719
if "http" not in base_url:
1820
base_url = "http://" + base_url

0 commit comments

Comments
 (0)