From 78c6baf244f5f70cf9d179886e743e10f4e88fa4 Mon Sep 17 00:00:00 2001 From: Tobias Wochinger Date: Tue, 7 Nov 2023 10:54:18 +0100 Subject: [PATCH 1/6] tests: upload more files --- tests/conftest.py | 19 ++++++++++--------- .../integration/api/test_integration_files.py | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index f6d4f961..2ca4d19b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -119,15 +119,16 @@ def workspace_name(integration_config: CommonConfig) -> str: if len(_get_file_names(integration_config=integration_config, workspace_name=workspace_name)) == 0: with open("tests/data/example.txt", "rb") as example_file_txt: - response = httpx.post( - f"{integration_config.api_url}/workspaces/{workspace_name}/files", - files={ - "file": ("example.txt", example_file_txt, "text/plain"), - "meta": (None, json.dumps({"find": "me"}).encode("utf-8")), - }, - headers={"Authorization": f"Bearer {integration_config.api_key}"}, - ) - assert response.status_code == HTTPStatus.CREATED + for i in range(15): + response = httpx.post( + f"{integration_config.api_url}/workspaces/{workspace_name}/files", + files={ + "file": (f"example{i}.txt", example_file_txt, "text/plain"), + "meta": (None, json.dumps({"find": "me"}).encode("utf-8")), + }, + headers={"Authorization": f"Bearer {integration_config.api_key}"}, + ) + assert response.status_code == HTTPStatus.CREATED _wait_for_file_to_be_available(integration_config, workspace_name) diff --git a/tests/integration/api/test_integration_files.py b/tests/integration/api/test_integration_files.py index 0cf58a27..69358196 100644 --- a/tests/integration/api/test_integration_files.py +++ b/tests/integration/api/test_integration_files.py @@ -11,7 +11,7 @@ async def test_list_paginated(self, integration_config: CommonConfig, workspace_ async with DeepsetCloudAPI.factory(integration_config) as deepset_cloud_api: files_api = FilesAPI(deepset_cloud_api) result = await files_api.list_paginated( - workspace_name=workspace_name, limit=10, name="example", content="text", odata_filter="find eq 'me'" + workspace_name=workspace_name, limit=10, name="example0", content="text", odata_filter="find eq 'me'" ) assert result.total == 1 From da53ba1a7be91f198cb0c8aa29ed78b15449f16b Mon Sep 17 00:00:00 2001 From: Tobias Wochinger Date: Tue, 7 Nov 2023 11:22:59 +0100 Subject: [PATCH 2/6] chore: open new file everytime --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 2ca4d19b..60ea8d06 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -118,8 +118,8 @@ def workspace_name(integration_config: CommonConfig) -> str: assert response.status_code in (HTTPStatus.CREATED, HTTPStatus.CONFLICT) if len(_get_file_names(integration_config=integration_config, workspace_name=workspace_name)) == 0: - with open("tests/data/example.txt", "rb") as example_file_txt: - for i in range(15): + for i in range(15): + with open("tests/data/example.txt", "rb") as example_file_txt: response = httpx.post( f"{integration_config.api_url}/workspaces/{workspace_name}/files", files={ From d3b7761e5b1ca32b2123f7ef4f8d7a2417764413 Mon Sep 17 00:00:00 2001 From: Tobias Wochinger Date: Tue, 7 Nov 2023 11:26:18 +0100 Subject: [PATCH 3/6] chor: add log statement --- tests/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/conftest.py b/tests/conftest.py index 60ea8d06..e8b0ece7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -35,6 +35,7 @@ def _get_file_names(integration_config: CommonConfig, workspace_name: str) -> Li ) assert list_response.status_code == HTTPStatus.OK file_names: List[str] = list_response.json()["data"] + logger.info("Found files", file_names=file_names) return file_names From 055e1ee5bb81584fe483f896bb5f38f0bcc881a4 Mon Sep 17 00:00:00 2001 From: Kristof Herrmann Date: Tue, 7 Nov 2023 11:36:19 +0100 Subject: [PATCH 4/6] fix: upload files --- tests/conftest.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index e8b0ece7..23a3380b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,4 @@ import datetime -import json import os from http import HTTPStatus from typing import List @@ -120,16 +119,13 @@ def workspace_name(integration_config: CommonConfig) -> str: if len(_get_file_names(integration_config=integration_config, workspace_name=workspace_name)) == 0: for i in range(15): - with open("tests/data/example.txt", "rb") as example_file_txt: - response = httpx.post( - f"{integration_config.api_url}/workspaces/{workspace_name}/files", - files={ - "file": (f"example{i}.txt", example_file_txt, "text/plain"), - "meta": (None, json.dumps({"find": "me"}).encode("utf-8")), - }, - headers={"Authorization": f"Bearer {integration_config.api_key}"}, - ) - assert response.status_code == HTTPStatus.CREATED + response = httpx.post( + f"{integration_config.api_url}/workspaces/{workspace_name}/files", + data={"text": "This is text", "meta": {"find": "me"}}, + params={"file_name": f"example{i}.txt"}, + headers={"Authorization": f"Bearer {integration_config.api_key}"}, + ) + assert response.status_code == HTTPStatus.CREATED _wait_for_file_to_be_available(integration_config, workspace_name) From 65c67c55ca526c34a34ba03013482866a241557d Mon Sep 17 00:00:00 2001 From: Kristof Herrmann Date: Tue, 7 Nov 2023 11:51:38 +0100 Subject: [PATCH 5/6] fix --- tests/conftest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 23a3380b..946c624c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import datetime +import json import os from http import HTTPStatus from typing import List @@ -121,7 +122,10 @@ def workspace_name(integration_config: CommonConfig) -> str: for i in range(15): response = httpx.post( f"{integration_config.api_url}/workspaces/{workspace_name}/files", - data={"text": "This is text", "meta": {"find": "me"}}, + data={"text": "This is text"}, + files={ + "meta": (None, json.dumps({"find": "me"}).encode("utf-8")), + }, params={"file_name": f"example{i}.txt"}, headers={"Authorization": f"Bearer {integration_config.api_key}"}, ) From dee6161f10019bf54f4112fc682fa87d7a11d89e Mon Sep 17 00:00:00 2001 From: Kristof Herrmann Date: Tue, 7 Nov 2023 11:54:37 +0100 Subject: [PATCH 6/6] fix --- tests/integration/api/test_integration_files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/api/test_integration_files.py b/tests/integration/api/test_integration_files.py index 69358196..08de89e5 100644 --- a/tests/integration/api/test_integration_files.py +++ b/tests/integration/api/test_integration_files.py @@ -18,6 +18,6 @@ async def test_list_paginated(self, integration_config: CommonConfig, workspace_ assert result.has_more is False assert len(result.data) == 1 found_file = result.data[0] - assert found_file.name == "example.txt" + assert found_file.name == "example0.txt" assert found_file.size > 0 assert found_file.meta == {"find": "me"}