mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Test: Refactor test fixtures to use HttpApiAuth naming consistently (#8180)
### What problem does this PR solve? - Rename `api_key` fixture to `HttpApiAuth` across all test files - Update all dependent fixtures and test cases to use new naming - Maintain same functionality while improving naming clarity The rename better reflects the fixture's purpose as an HTTP API authentication helper rather than just an API key. ### Type of change - [x] Refactoring
This commit is contained in:
@ -18,24 +18,24 @@ from common import batch_add_sessions_with_chat_assistant, delete_session_with_c
|
||||
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
def add_sessions_with_chat_assistant(request, api_key, add_chat_assistants):
|
||||
def add_sessions_with_chat_assistant(request, HttpApiAuth, add_chat_assistants):
|
||||
def cleanup():
|
||||
for chat_assistant_id in chat_assistant_ids:
|
||||
delete_session_with_chat_assistants(api_key, chat_assistant_id)
|
||||
delete_session_with_chat_assistants(HttpApiAuth, chat_assistant_id)
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
|
||||
_, _, chat_assistant_ids = add_chat_assistants
|
||||
return chat_assistant_ids[0], batch_add_sessions_with_chat_assistant(api_key, chat_assistant_ids[0], 5)
|
||||
return chat_assistant_ids[0], batch_add_sessions_with_chat_assistant(HttpApiAuth, chat_assistant_ids[0], 5)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def add_sessions_with_chat_assistant_func(request, api_key, add_chat_assistants):
|
||||
def add_sessions_with_chat_assistant_func(request, HttpApiAuth, add_chat_assistants):
|
||||
def cleanup():
|
||||
for chat_assistant_id in chat_assistant_ids:
|
||||
delete_session_with_chat_assistants(api_key, chat_assistant_id)
|
||||
delete_session_with_chat_assistants(HttpApiAuth, chat_assistant_id)
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
|
||||
_, _, chat_assistant_ids = add_chat_assistants
|
||||
return chat_assistant_ids[0], batch_add_sessions_with_chat_assistant(api_key, chat_assistant_ids[0], 5)
|
||||
return chat_assistant_ids[0], batch_add_sessions_with_chat_assistant(HttpApiAuth, chat_assistant_ids[0], 5)
|
||||
|
||||
@ -53,14 +53,14 @@ class TestSessionWithChatAssistantCreate:
|
||||
({"name": "case insensitive"}, 0, ""),
|
||||
],
|
||||
)
|
||||
def test_name(self, api_key, add_chat_assistants, payload, expected_code, expected_message):
|
||||
def test_name(self, HttpApiAuth, add_chat_assistants, payload, expected_code, expected_message):
|
||||
_, _, chat_assistant_ids = add_chat_assistants
|
||||
if payload["name"] == "duplicated_name":
|
||||
create_session_with_chat_assistant(api_key, chat_assistant_ids[0], payload)
|
||||
create_session_with_chat_assistant(HttpApiAuth, chat_assistant_ids[0], payload)
|
||||
elif payload["name"] == "case insensitive":
|
||||
create_session_with_chat_assistant(api_key, chat_assistant_ids[0], {"name": payload["name"].upper()})
|
||||
create_session_with_chat_assistant(HttpApiAuth, chat_assistant_ids[0], {"name": payload["name"].upper()})
|
||||
|
||||
res = create_session_with_chat_assistant(api_key, chat_assistant_ids[0], payload)
|
||||
res = create_session_with_chat_assistant(HttpApiAuth, chat_assistant_ids[0], payload)
|
||||
assert res["code"] == expected_code, res
|
||||
if expected_code == 0:
|
||||
assert res["data"]["name"] == payload["name"]
|
||||
@ -76,16 +76,16 @@ class TestSessionWithChatAssistantCreate:
|
||||
("invalid_chat_assistant_id", 102, "You do not own the assistant."),
|
||||
],
|
||||
)
|
||||
def test_invalid_chat_assistant_id(self, api_key, chat_assistant_id, expected_code, expected_message):
|
||||
res = create_session_with_chat_assistant(api_key, chat_assistant_id, {"name": "valid_name"})
|
||||
def test_invalid_chat_assistant_id(self, HttpApiAuth, chat_assistant_id, expected_code, expected_message):
|
||||
res = create_session_with_chat_assistant(HttpApiAuth, chat_assistant_id, {"name": "valid_name"})
|
||||
assert res["code"] == expected_code
|
||||
assert res["message"] == expected_message
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_concurrent_create_session(self, api_key, add_chat_assistants):
|
||||
def test_concurrent_create_session(self, HttpApiAuth, add_chat_assistants):
|
||||
count = 1000
|
||||
_, _, chat_assistant_ids = add_chat_assistants
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_ids[0])
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_ids[0])
|
||||
if res["code"] != 0:
|
||||
assert False, res
|
||||
sessions_count = len(res["data"])
|
||||
@ -94,7 +94,7 @@ class TestSessionWithChatAssistantCreate:
|
||||
futures = [
|
||||
executor.submit(
|
||||
create_session_with_chat_assistant,
|
||||
api_key,
|
||||
HttpApiAuth,
|
||||
chat_assistant_ids[0],
|
||||
{"name": f"session with chat assistant test {i}"},
|
||||
)
|
||||
@ -103,16 +103,16 @@ class TestSessionWithChatAssistantCreate:
|
||||
responses = list(as_completed(futures))
|
||||
assert len(responses) == count, responses
|
||||
assert all(future.result()["code"] == 0 for future in futures)
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_ids[0], {"page_size": count * 2})
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_ids[0], {"page_size": count * 2})
|
||||
if res["code"] != 0:
|
||||
assert False, res
|
||||
assert len(res["data"]) == sessions_count + count
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_add_session_to_deleted_chat_assistant(self, api_key, add_chat_assistants):
|
||||
def test_add_session_to_deleted_chat_assistant(self, HttpApiAuth, add_chat_assistants):
|
||||
_, _, chat_assistant_ids = add_chat_assistants
|
||||
res = delete_chat_assistants(api_key, {"ids": [chat_assistant_ids[0]]})
|
||||
res = delete_chat_assistants(HttpApiAuth, {"ids": [chat_assistant_ids[0]]})
|
||||
assert res["code"] == 0
|
||||
res = create_session_with_chat_assistant(api_key, chat_assistant_ids[0], {"name": "valid_name"})
|
||||
res = create_session_with_chat_assistant(HttpApiAuth, chat_assistant_ids[0], {"name": "valid_name"})
|
||||
assert res["code"] == 102
|
||||
assert res["message"] == "You do not own the assistant."
|
||||
|
||||
@ -52,9 +52,9 @@ class TestSessionWithChatAssistantDelete:
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_invalid_chat_assistant_id(self, api_key, add_sessions_with_chat_assistant_func, chat_assistant_id, expected_code, expected_message):
|
||||
def test_invalid_chat_assistant_id(self, HttpApiAuth, add_sessions_with_chat_assistant_func, chat_assistant_id, expected_code, expected_message):
|
||||
_, session_ids = add_sessions_with_chat_assistant_func
|
||||
res = delete_session_with_chat_assistants(api_key, chat_assistant_id, {"ids": session_ids})
|
||||
res = delete_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, {"ids": session_ids})
|
||||
assert res["code"] == expected_code
|
||||
assert res["message"] == expected_message
|
||||
|
||||
@ -66,54 +66,54 @@ class TestSessionWithChatAssistantDelete:
|
||||
pytest.param(lambda r: {"ids": r + ["invalid_id"]}, marks=pytest.mark.p3),
|
||||
],
|
||||
)
|
||||
def test_delete_partial_invalid_id(self, api_key, add_sessions_with_chat_assistant_func, payload):
|
||||
def test_delete_partial_invalid_id(self, HttpApiAuth, add_sessions_with_chat_assistant_func, payload):
|
||||
chat_assistant_id, session_ids = add_sessions_with_chat_assistant_func
|
||||
if callable(payload):
|
||||
payload = payload(session_ids)
|
||||
res = delete_session_with_chat_assistants(api_key, chat_assistant_id, payload)
|
||||
res = delete_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, payload)
|
||||
assert res["code"] == 0
|
||||
assert res["data"]["errors"][0] == "The chat doesn't own the session invalid_id"
|
||||
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_id)
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_id)
|
||||
if res["code"] != 0:
|
||||
assert False, res
|
||||
assert len(res["data"]) == 0
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_repeated_deletion(self, api_key, add_sessions_with_chat_assistant_func):
|
||||
def test_repeated_deletion(self, HttpApiAuth, add_sessions_with_chat_assistant_func):
|
||||
chat_assistant_id, session_ids = add_sessions_with_chat_assistant_func
|
||||
payload = {"ids": session_ids}
|
||||
res = delete_session_with_chat_assistants(api_key, chat_assistant_id, payload)
|
||||
res = delete_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, payload)
|
||||
assert res["code"] == 0
|
||||
|
||||
res = delete_session_with_chat_assistants(api_key, chat_assistant_id, payload)
|
||||
res = delete_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, payload)
|
||||
assert res["code"] == 102
|
||||
assert "The chat doesn't own the session" in res["message"]
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_duplicate_deletion(self, api_key, add_sessions_with_chat_assistant_func):
|
||||
def test_duplicate_deletion(self, HttpApiAuth, add_sessions_with_chat_assistant_func):
|
||||
chat_assistant_id, session_ids = add_sessions_with_chat_assistant_func
|
||||
res = delete_session_with_chat_assistants(api_key, chat_assistant_id, {"ids": session_ids * 2})
|
||||
res = delete_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, {"ids": session_ids * 2})
|
||||
assert res["code"] == 0
|
||||
assert "Duplicate session ids" in res["data"]["errors"][0]
|
||||
assert res["data"]["success_count"] == 5
|
||||
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_id)
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_id)
|
||||
if res["code"] != 0:
|
||||
assert False, res
|
||||
assert len(res["data"]) == 0
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_concurrent_deletion(self, api_key, add_chat_assistants):
|
||||
def test_concurrent_deletion(self, HttpApiAuth, add_chat_assistants):
|
||||
count = 100
|
||||
_, _, chat_assistant_ids = add_chat_assistants
|
||||
session_ids = batch_add_sessions_with_chat_assistant(api_key, chat_assistant_ids[0], count)
|
||||
session_ids = batch_add_sessions_with_chat_assistant(HttpApiAuth, chat_assistant_ids[0], count)
|
||||
|
||||
with ThreadPoolExecutor(max_workers=5) as executor:
|
||||
futures = [
|
||||
executor.submit(
|
||||
delete_session_with_chat_assistants,
|
||||
api_key,
|
||||
HttpApiAuth,
|
||||
chat_assistant_ids[0],
|
||||
{"ids": session_ids[i : i + 1]},
|
||||
)
|
||||
@ -124,15 +124,15 @@ class TestSessionWithChatAssistantDelete:
|
||||
assert all(future.result()["code"] == 0 for future in futures)
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_delete_1k(self, api_key, add_chat_assistants):
|
||||
def test_delete_1k(self, HttpApiAuth, add_chat_assistants):
|
||||
sessions_num = 1_000
|
||||
_, _, chat_assistant_ids = add_chat_assistants
|
||||
session_ids = batch_add_sessions_with_chat_assistant(api_key, chat_assistant_ids[0], sessions_num)
|
||||
session_ids = batch_add_sessions_with_chat_assistant(HttpApiAuth, chat_assistant_ids[0], sessions_num)
|
||||
|
||||
res = delete_session_with_chat_assistants(api_key, chat_assistant_ids[0], {"ids": session_ids})
|
||||
res = delete_session_with_chat_assistants(HttpApiAuth, chat_assistant_ids[0], {"ids": session_ids})
|
||||
assert res["code"] == 0
|
||||
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_ids[0])
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_ids[0])
|
||||
if res["code"] != 0:
|
||||
assert False, res
|
||||
assert len(res["data"]) == 0
|
||||
@ -150,7 +150,7 @@ class TestSessionWithChatAssistantDelete:
|
||||
)
|
||||
def test_basic_scenarios(
|
||||
self,
|
||||
api_key,
|
||||
HttpApiAuth,
|
||||
add_sessions_with_chat_assistant_func,
|
||||
payload,
|
||||
expected_code,
|
||||
@ -160,12 +160,12 @@ class TestSessionWithChatAssistantDelete:
|
||||
chat_assistant_id, session_ids = add_sessions_with_chat_assistant_func
|
||||
if callable(payload):
|
||||
payload = payload(session_ids)
|
||||
res = delete_session_with_chat_assistants(api_key, chat_assistant_id, payload)
|
||||
res = delete_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, payload)
|
||||
assert res["code"] == expected_code
|
||||
if res["code"] != 0:
|
||||
assert res["message"] == expected_message
|
||||
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_id)
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_id)
|
||||
if res["code"] != 0:
|
||||
assert False, res
|
||||
assert len(res["data"]) == remaining
|
||||
|
||||
@ -54,9 +54,9 @@ class TestSessionsWithChatAssistantList:
|
||||
pytest.param({"page": "a", "page_size": 2}, 100, 0, """ValueError("invalid literal for int() with base 10: \'a\'")""", marks=pytest.mark.skip),
|
||||
],
|
||||
)
|
||||
def test_page(self, api_key, add_sessions_with_chat_assistant, params, expected_code, expected_page_size, expected_message):
|
||||
def test_page(self, HttpApiAuth, add_sessions_with_chat_assistant, params, expected_code, expected_page_size, expected_message):
|
||||
chat_assistant_id, _ = add_sessions_with_chat_assistant
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_id, params=params)
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, params=params)
|
||||
assert res["code"] == expected_code
|
||||
if expected_code == 0:
|
||||
assert len(res["data"]) == expected_page_size
|
||||
@ -76,9 +76,9 @@ class TestSessionsWithChatAssistantList:
|
||||
pytest.param({"page_size": "a"}, 100, 0, """ValueError("invalid literal for int() with base 10: \'a\'")""", marks=pytest.mark.skip),
|
||||
],
|
||||
)
|
||||
def test_page_size(self, api_key, add_sessions_with_chat_assistant, params, expected_code, expected_page_size, expected_message):
|
||||
def test_page_size(self, HttpApiAuth, add_sessions_with_chat_assistant, params, expected_code, expected_page_size, expected_message):
|
||||
chat_assistant_id, _ = add_sessions_with_chat_assistant
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_id, params=params)
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, params=params)
|
||||
assert res["code"] == expected_code
|
||||
if expected_code == 0:
|
||||
assert len(res["data"]) == expected_page_size
|
||||
@ -98,7 +98,7 @@ class TestSessionsWithChatAssistantList:
|
||||
)
|
||||
def test_orderby(
|
||||
self,
|
||||
api_key,
|
||||
HttpApiAuth,
|
||||
add_sessions_with_chat_assistant,
|
||||
params,
|
||||
expected_code,
|
||||
@ -106,7 +106,7 @@ class TestSessionsWithChatAssistantList:
|
||||
expected_message,
|
||||
):
|
||||
chat_assistant_id, _ = add_sessions_with_chat_assistant
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_id, params=params)
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, params=params)
|
||||
assert res["code"] == expected_code
|
||||
if expected_code == 0:
|
||||
if callable(assertions):
|
||||
@ -131,7 +131,7 @@ class TestSessionsWithChatAssistantList:
|
||||
)
|
||||
def test_desc(
|
||||
self,
|
||||
api_key,
|
||||
HttpApiAuth,
|
||||
add_sessions_with_chat_assistant,
|
||||
params,
|
||||
expected_code,
|
||||
@ -139,7 +139,7 @@ class TestSessionsWithChatAssistantList:
|
||||
expected_message,
|
||||
):
|
||||
chat_assistant_id, _ = add_sessions_with_chat_assistant
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_id, params=params)
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, params=params)
|
||||
assert res["code"] == expected_code
|
||||
if expected_code == 0:
|
||||
if callable(assertions):
|
||||
@ -157,9 +157,9 @@ class TestSessionsWithChatAssistantList:
|
||||
({"name": "unknown"}, 0, 0, ""),
|
||||
],
|
||||
)
|
||||
def test_name(self, api_key, add_sessions_with_chat_assistant, params, expected_code, expected_num, expected_message):
|
||||
def test_name(self, HttpApiAuth, add_sessions_with_chat_assistant, params, expected_code, expected_num, expected_message):
|
||||
chat_assistant_id, _ = add_sessions_with_chat_assistant
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_id, params=params)
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, params=params)
|
||||
assert res["code"] == expected_code
|
||||
if expected_code == 0:
|
||||
if params["name"] != "session_with_chat_assistant_1":
|
||||
@ -179,14 +179,14 @@ class TestSessionsWithChatAssistantList:
|
||||
("unknown", 0, 0, "The chat doesn't exist"),
|
||||
],
|
||||
)
|
||||
def test_id(self, api_key, add_sessions_with_chat_assistant, session_id, expected_code, expected_num, expected_message):
|
||||
def test_id(self, HttpApiAuth, add_sessions_with_chat_assistant, session_id, expected_code, expected_num, expected_message):
|
||||
chat_assistant_id, session_ids = add_sessions_with_chat_assistant
|
||||
if callable(session_id):
|
||||
params = {"id": session_id(session_ids)}
|
||||
else:
|
||||
params = {"id": session_id}
|
||||
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_id, params=params)
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, params=params)
|
||||
assert res["code"] == expected_code
|
||||
if expected_code == 0:
|
||||
if params["id"] != session_ids[0]:
|
||||
@ -206,14 +206,14 @@ class TestSessionsWithChatAssistantList:
|
||||
("id", "session_with_chat_assistant_0", 0, 0, ""),
|
||||
],
|
||||
)
|
||||
def test_name_and_id(self, api_key, add_sessions_with_chat_assistant, session_id, name, expected_code, expected_num, expected_message):
|
||||
def test_name_and_id(self, HttpApiAuth, add_sessions_with_chat_assistant, session_id, name, expected_code, expected_num, expected_message):
|
||||
chat_assistant_id, session_ids = add_sessions_with_chat_assistant
|
||||
if callable(session_id):
|
||||
params = {"id": session_id(session_ids), "name": name}
|
||||
else:
|
||||
params = {"id": session_id, "name": name}
|
||||
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_id, params=params)
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, params=params)
|
||||
assert res["code"] == expected_code
|
||||
if expected_code == 0:
|
||||
assert len(res["data"]) == expected_num
|
||||
@ -221,29 +221,29 @@ class TestSessionsWithChatAssistantList:
|
||||
assert res["message"] == expected_message
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_concurrent_list(self, api_key, add_sessions_with_chat_assistant):
|
||||
def test_concurrent_list(self, HttpApiAuth, add_sessions_with_chat_assistant):
|
||||
count = 100
|
||||
chat_assistant_id, _ = add_sessions_with_chat_assistant
|
||||
with ThreadPoolExecutor(max_workers=5) as executor:
|
||||
futures = [executor.submit(list_session_with_chat_assistants, api_key, chat_assistant_id) for i in range(count)]
|
||||
futures = [executor.submit(list_session_with_chat_assistants, HttpApiAuth, chat_assistant_id) for i in range(count)]
|
||||
responses = list(as_completed(futures))
|
||||
assert len(responses) == count, responses
|
||||
assert all(future.result()["code"] == 0 for future in futures)
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_invalid_params(self, api_key, add_sessions_with_chat_assistant):
|
||||
def test_invalid_params(self, HttpApiAuth, add_sessions_with_chat_assistant):
|
||||
chat_assistant_id, _ = add_sessions_with_chat_assistant
|
||||
params = {"a": "b"}
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_id, params=params)
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, params=params)
|
||||
assert res["code"] == 0
|
||||
assert len(res["data"]) == 5
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_list_chats_after_deleting_associated_chat_assistant(self, api_key, add_sessions_with_chat_assistant):
|
||||
def test_list_chats_after_deleting_associated_chat_assistant(self, HttpApiAuth, add_sessions_with_chat_assistant):
|
||||
chat_assistant_id, _ = add_sessions_with_chat_assistant
|
||||
res = delete_chat_assistants(api_key, {"ids": [chat_assistant_id]})
|
||||
res = delete_chat_assistants(HttpApiAuth, {"ids": [chat_assistant_id]})
|
||||
assert res["code"] == 0
|
||||
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_id)
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_id)
|
||||
assert res["code"] == 102
|
||||
assert "You don't own the assistant" in res["message"]
|
||||
|
||||
@ -52,17 +52,17 @@ class TestSessionWithChatAssistantUpdate:
|
||||
pytest.param({"name": "case insensitive"}, 0, "", marks=pytest.mark.p3),
|
||||
],
|
||||
)
|
||||
def test_name(self, api_key, add_sessions_with_chat_assistant_func, payload, expected_code, expected_message):
|
||||
def test_name(self, HttpApiAuth, add_sessions_with_chat_assistant_func, payload, expected_code, expected_message):
|
||||
chat_assistant_id, session_ids = add_sessions_with_chat_assistant_func
|
||||
if payload["name"] == "duplicated_name":
|
||||
update_session_with_chat_assistant(api_key, chat_assistant_id, session_ids[0], payload)
|
||||
update_session_with_chat_assistant(HttpApiAuth, chat_assistant_id, session_ids[0], payload)
|
||||
elif payload["name"] == "case insensitive":
|
||||
update_session_with_chat_assistant(api_key, chat_assistant_id, session_ids[0], {"name": payload["name"].upper()})
|
||||
update_session_with_chat_assistant(HttpApiAuth, chat_assistant_id, session_ids[0], {"name": payload["name"].upper()})
|
||||
|
||||
res = update_session_with_chat_assistant(api_key, chat_assistant_id, session_ids[0], payload)
|
||||
res = update_session_with_chat_assistant(HttpApiAuth, chat_assistant_id, session_ids[0], payload)
|
||||
assert res["code"] == expected_code, res
|
||||
if expected_code == 0:
|
||||
res = list_session_with_chat_assistants(api_key, chat_assistant_id, {"id": session_ids[0]})
|
||||
res = list_session_with_chat_assistants(HttpApiAuth, chat_assistant_id, {"id": session_ids[0]})
|
||||
assert res["data"][0]["name"] == payload["name"]
|
||||
else:
|
||||
assert res["message"] == expected_message
|
||||
@ -75,9 +75,9 @@ class TestSessionWithChatAssistantUpdate:
|
||||
pytest.param("invalid_chat_assistant_id", 102, "Session does not exist", marks=pytest.mark.skip(reason="issues/")),
|
||||
],
|
||||
)
|
||||
def test_invalid_chat_assistant_id(self, api_key, add_sessions_with_chat_assistant_func, chat_assistant_id, expected_code, expected_message):
|
||||
def test_invalid_chat_assistant_id(self, HttpApiAuth, add_sessions_with_chat_assistant_func, chat_assistant_id, expected_code, expected_message):
|
||||
_, session_ids = add_sessions_with_chat_assistant_func
|
||||
res = update_session_with_chat_assistant(api_key, chat_assistant_id, session_ids[0], {"name": "valid_name"})
|
||||
res = update_session_with_chat_assistant(HttpApiAuth, chat_assistant_id, session_ids[0], {"name": "valid_name"})
|
||||
assert res["code"] == expected_code
|
||||
assert res["message"] == expected_message
|
||||
|
||||
@ -89,19 +89,19 @@ class TestSessionWithChatAssistantUpdate:
|
||||
("invalid_session_id", 102, "Session does not exist"),
|
||||
],
|
||||
)
|
||||
def test_invalid_session_id(self, api_key, add_sessions_with_chat_assistant_func, session_id, expected_code, expected_message):
|
||||
def test_invalid_session_id(self, HttpApiAuth, add_sessions_with_chat_assistant_func, session_id, expected_code, expected_message):
|
||||
chat_assistant_id, _ = add_sessions_with_chat_assistant_func
|
||||
res = update_session_with_chat_assistant(api_key, chat_assistant_id, session_id, {"name": "valid_name"})
|
||||
res = update_session_with_chat_assistant(HttpApiAuth, chat_assistant_id, session_id, {"name": "valid_name"})
|
||||
assert res["code"] == expected_code
|
||||
assert res["message"] == expected_message
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_repeated_update_session(self, api_key, add_sessions_with_chat_assistant_func):
|
||||
def test_repeated_update_session(self, HttpApiAuth, add_sessions_with_chat_assistant_func):
|
||||
chat_assistant_id, session_ids = add_sessions_with_chat_assistant_func
|
||||
res = update_session_with_chat_assistant(api_key, chat_assistant_id, session_ids[0], {"name": "valid_name_1"})
|
||||
res = update_session_with_chat_assistant(HttpApiAuth, chat_assistant_id, session_ids[0], {"name": "valid_name_1"})
|
||||
assert res["code"] == 0
|
||||
|
||||
res = update_session_with_chat_assistant(api_key, chat_assistant_id, session_ids[0], {"name": "valid_name_2"})
|
||||
res = update_session_with_chat_assistant(HttpApiAuth, chat_assistant_id, session_ids[0], {"name": "valid_name_2"})
|
||||
assert res["code"] == 0
|
||||
|
||||
@pytest.mark.p3
|
||||
@ -113,15 +113,15 @@ class TestSessionWithChatAssistantUpdate:
|
||||
pytest.param(None, 100, "TypeError", marks=pytest.mark.skip),
|
||||
],
|
||||
)
|
||||
def test_invalid_params(self, api_key, add_sessions_with_chat_assistant_func, payload, expected_code, expected_message):
|
||||
def test_invalid_params(self, HttpApiAuth, add_sessions_with_chat_assistant_func, payload, expected_code, expected_message):
|
||||
chat_assistant_id, session_ids = add_sessions_with_chat_assistant_func
|
||||
res = update_session_with_chat_assistant(api_key, chat_assistant_id, session_ids[0], payload)
|
||||
res = update_session_with_chat_assistant(HttpApiAuth, chat_assistant_id, session_ids[0], payload)
|
||||
assert res["code"] == expected_code
|
||||
if expected_code != 0:
|
||||
assert expected_message in res["message"]
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_concurrent_update_session(self, api_key, add_sessions_with_chat_assistant_func):
|
||||
def test_concurrent_update_session(self, HttpApiAuth, add_sessions_with_chat_assistant_func):
|
||||
count = 50
|
||||
chat_assistant_id, session_ids = add_sessions_with_chat_assistant_func
|
||||
|
||||
@ -129,7 +129,7 @@ class TestSessionWithChatAssistantUpdate:
|
||||
futures = [
|
||||
executor.submit(
|
||||
update_session_with_chat_assistant,
|
||||
api_key,
|
||||
HttpApiAuth,
|
||||
chat_assistant_id,
|
||||
session_ids[randint(0, 4)],
|
||||
{"name": f"update session test {i}"},
|
||||
@ -141,9 +141,9 @@ class TestSessionWithChatAssistantUpdate:
|
||||
assert all(future.result()["code"] == 0 for future in futures)
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_update_session_to_deleted_chat_assistant(self, api_key, add_sessions_with_chat_assistant_func):
|
||||
def test_update_session_to_deleted_chat_assistant(self, HttpApiAuth, add_sessions_with_chat_assistant_func):
|
||||
chat_assistant_id, session_ids = add_sessions_with_chat_assistant_func
|
||||
delete_chat_assistants(api_key, {"ids": [chat_assistant_id]})
|
||||
res = update_session_with_chat_assistant(api_key, chat_assistant_id, session_ids[0], {"name": "valid_name"})
|
||||
delete_chat_assistants(HttpApiAuth, {"ids": [chat_assistant_id]})
|
||||
res = update_session_with_chat_assistant(HttpApiAuth, chat_assistant_id, session_ids[0], {"name": "valid_name"})
|
||||
assert res["code"] == 102
|
||||
assert res["message"] == "You do not own the session"
|
||||
|
||||
Reference in New Issue
Block a user