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:
Liu An
2025-06-11 14:25:40 +08:00
committed by GitHub
parent f29d9fa3f9
commit 6aff3e052a
30 changed files with 756 additions and 756 deletions

View File

@ -20,20 +20,20 @@ from common import batch_create_datasets, delete_datasets
@pytest.fixture(scope="class")
def add_datasets(api_key, request):
def add_datasets(HttpApiAuth, request):
def cleanup():
delete_datasets(api_key, {"ids": None})
delete_datasets(HttpApiAuth, {"ids": None})
request.addfinalizer(cleanup)
return batch_create_datasets(api_key, 5)
return batch_create_datasets(HttpApiAuth, 5)
@pytest.fixture(scope="function")
def add_datasets_func(api_key, request):
def add_datasets_func(HttpApiAuth, request):
def cleanup():
delete_datasets(api_key, {"ids": None})
delete_datasets(HttpApiAuth, {"ids": None})
request.addfinalizer(cleanup)
return batch_create_datasets(api_key, 3)
return batch_create_datasets(HttpApiAuth, 3)

View File

@ -48,9 +48,9 @@ class TestAuthorization:
class TestRquest:
@pytest.mark.p3
def test_content_type_bad(self, api_key):
def test_content_type_bad(self, HttpApiAuth):
BAD_CONTENT_TYPE = "text/xml"
res = create_dataset(api_key, {"name": "bad_content_type"}, headers={"Content-Type": BAD_CONTENT_TYPE})
res = create_dataset(HttpApiAuth, {"name": "bad_content_type"}, headers={"Content-Type": BAD_CONTENT_TYPE})
assert res["code"] == 101, res
assert res["message"] == f"Unsupported content type: Expected application/json, got {BAD_CONTENT_TYPE}", res
@ -63,8 +63,8 @@ class TestRquest:
],
ids=["malformed_json_syntax", "invalid_request_payload_type"],
)
def test_payload_bad(self, api_key, payload, expected_message):
res = create_dataset(api_key, data=payload)
def test_payload_bad(self, HttpApiAuth, payload, expected_message):
res = create_dataset(HttpApiAuth, data=payload)
assert res["code"] == 101, res
assert res["message"] == expected_message, res
@ -72,17 +72,17 @@ class TestRquest:
@pytest.mark.usefixtures("clear_datasets")
class TestCapability:
@pytest.mark.p3
def test_create_dataset_1k(self, api_key):
def test_create_dataset_1k(self, HttpApiAuth):
for i in range(1_000):
payload = {"name": f"dataset_{i}"}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, f"Failed to create dataset {i}"
@pytest.mark.p3
def test_create_dataset_concurrent(self, api_key):
def test_create_dataset_concurrent(self, HttpApiAuth):
count = 100
with ThreadPoolExecutor(max_workers=5) as executor:
futures = [executor.submit(create_dataset, api_key, {"name": f"dataset_{i}"}) for i in range(count)]
futures = [executor.submit(create_dataset, HttpApiAuth, {"name": f"dataset_{i}"}) 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)
@ -94,8 +94,8 @@ class TestDatasetCreate:
@given(name=valid_names())
@example("a" * 128)
@settings(max_examples=20)
def test_name(self, api_key, name):
res = create_dataset(api_key, {"name": name})
def test_name(self, HttpApiAuth, name):
res = create_dataset(HttpApiAuth, {"name": name})
assert res["code"] == 0, res
assert res["data"]["name"] == name, res
@ -111,49 +111,49 @@ class TestDatasetCreate:
],
ids=["empty_name", "space_name", "too_long_name", "invalid_name", "None_name"],
)
def test_name_invalid(self, api_key, name, expected_message):
def test_name_invalid(self, HttpApiAuth, name, expected_message):
payload = {"name": name}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101, res
assert expected_message in res["message"], res
@pytest.mark.p3
def test_name_duplicated(self, api_key):
def test_name_duplicated(self, HttpApiAuth):
name = "duplicated_name"
payload = {"name": name}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 103, res
assert res["message"] == f"Dataset name '{name}' already exists", res
@pytest.mark.p3
def test_name_case_insensitive(self, api_key):
def test_name_case_insensitive(self, HttpApiAuth):
name = "CaseInsensitive"
payload = {"name": name.upper()}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
payload = {"name": name.lower()}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 103, res
assert res["message"] == f"Dataset name '{name.lower()}' already exists", res
@pytest.mark.p2
def test_avatar(self, api_key, tmp_path):
def test_avatar(self, HttpApiAuth, tmp_path):
fn = create_image_file(tmp_path / "ragflow_test.png")
payload = {
"name": "avatar",
"avatar": f"data:image/png;base64,{encode_avatar(fn)}",
}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
@pytest.mark.p2
def test_avatar_exceeds_limit_length(self, api_key):
def test_avatar_exceeds_limit_length(self, HttpApiAuth):
payload = {"name": "avatar_exceeds_limit_length", "avatar": "a" * 65536}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101, res
assert "String should have at most 65535 characters" in res["message"], res
@ -168,55 +168,55 @@ class TestDatasetCreate:
],
ids=["empty_prefix", "missing_comma", "unsupported_mine_type", "invalid_mine_type"],
)
def test_avatar_invalid_prefix(self, api_key, tmp_path, name, prefix, expected_message):
def test_avatar_invalid_prefix(self, HttpApiAuth, tmp_path, name, prefix, expected_message):
fn = create_image_file(tmp_path / "ragflow_test.png")
payload = {
"name": name,
"avatar": f"{prefix}{encode_avatar(fn)}",
}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101, res
assert expected_message in res["message"], res
@pytest.mark.p3
def test_avatar_unset(self, api_key):
def test_avatar_unset(self, HttpApiAuth):
payload = {"name": "avatar_unset"}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["avatar"] is None, res
@pytest.mark.p3
def test_avatar_none(self, api_key):
def test_avatar_none(self, HttpApiAuth):
payload = {"name": "avatar_none", "avatar": None}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["avatar"] is None, res
@pytest.mark.p2
def test_description(self, api_key):
def test_description(self, HttpApiAuth):
payload = {"name": "description", "description": "description"}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["description"] == "description", res
@pytest.mark.p2
def test_description_exceeds_limit_length(self, api_key):
def test_description_exceeds_limit_length(self, HttpApiAuth):
payload = {"name": "description_exceeds_limit_length", "description": "a" * 65536}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101, res
assert "String should have at most 65535 characters" in res["message"], res
@pytest.mark.p3
def test_description_unset(self, api_key):
def test_description_unset(self, HttpApiAuth):
payload = {"name": "description_unset"}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["description"] is None, res
@pytest.mark.p3
def test_description_none(self, api_key):
def test_description_none(self, HttpApiAuth):
payload = {"name": "description_none", "description": None}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["description"] is None, res
@ -230,9 +230,9 @@ class TestDatasetCreate:
],
ids=["builtin_baai", "builtin_youdao", "tenant_zhipu"],
)
def test_embedding_model(self, api_key, name, embedding_model):
def test_embedding_model(self, HttpApiAuth, name, embedding_model):
payload = {"name": name, "embedding_model": embedding_model}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["embedding_model"] == embedding_model, res
@ -247,9 +247,9 @@ class TestDatasetCreate:
],
ids=["unknown_llm_name", "unknown_llm_factory", "tenant_no_auth_default_tenant_llm", "tenant_no_auth"],
)
def test_embedding_model_invalid(self, api_key, name, embedding_model):
def test_embedding_model_invalid(self, HttpApiAuth, name, embedding_model):
payload = {"name": name, "embedding_model": embedding_model}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101, res
if "tenant_no_auth" in name:
assert res["message"] == f"Unauthorized model: <{embedding_model}>", res
@ -268,9 +268,9 @@ class TestDatasetCreate:
],
ids=["missing_at", "empty_model_name", "empty_provider", "whitespace_only_model_name", "whitespace_only_provider"],
)
def test_embedding_model_format(self, api_key, name, embedding_model):
def test_embedding_model_format(self, HttpApiAuth, name, embedding_model):
payload = {"name": name, "embedding_model": embedding_model}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101, res
if name == "missing_at":
assert "Embedding model identifier must follow <model_name>@<provider> format" in res["message"], res
@ -278,16 +278,16 @@ class TestDatasetCreate:
assert "Both model_name and provider must be non-empty strings" in res["message"], res
@pytest.mark.p2
def test_embedding_model_unset(self, api_key):
def test_embedding_model_unset(self, HttpApiAuth):
payload = {"name": "embedding_model_unset"}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["embedding_model"] == "BAAI/bge-large-zh-v1.5@BAAI", res
@pytest.mark.p2
def test_embedding_model_none(self, api_key):
def test_embedding_model_none(self, HttpApiAuth):
payload = {"name": "embedding_model_none", "embedding_model": None}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101, res
assert "Input should be a valid string" in res["message"], res
@ -303,9 +303,9 @@ class TestDatasetCreate:
],
ids=["me", "team", "me_upercase", "team_upercase", "whitespace"],
)
def test_permission(self, api_key, name, permission):
def test_permission(self, HttpApiAuth, name, permission):
payload = {"name": name, "permission": permission}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["permission"] == permission.lower().strip(), res
@ -319,23 +319,23 @@ class TestDatasetCreate:
],
ids=["empty", "unknown", "type_error"],
)
def test_permission_invalid(self, api_key, name, permission):
def test_permission_invalid(self, HttpApiAuth, name, permission):
payload = {"name": name, "permission": permission}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101
assert "Input should be 'me' or 'team'" in res["message"]
@pytest.mark.p2
def test_permission_unset(self, api_key):
def test_permission_unset(self, HttpApiAuth):
payload = {"name": "permission_unset"}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["permission"] == "me", res
@pytest.mark.p3
def test_permission_none(self, api_key):
def test_permission_none(self, HttpApiAuth):
payload = {"name": "permission_none", "permission": None}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101, res
assert "Input should be 'me' or 'team'" in res["message"], res
@ -358,9 +358,9 @@ class TestDatasetCreate:
],
ids=["naive", "book", "email", "laws", "manual", "one", "paper", "picture", "presentation", "qa", "table", "tag"],
)
def test_chunk_method(self, api_key, name, chunk_method):
def test_chunk_method(self, HttpApiAuth, name, chunk_method):
payload = {"name": name, "chunk_method": chunk_method}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["chunk_method"] == chunk_method, res
@ -374,23 +374,23 @@ class TestDatasetCreate:
],
ids=["empty", "unknown", "type_error"],
)
def test_chunk_method_invalid(self, api_key, name, chunk_method):
def test_chunk_method_invalid(self, HttpApiAuth, name, chunk_method):
payload = {"name": name, "chunk_method": chunk_method}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101, res
assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in res["message"], res
@pytest.mark.p2
def test_chunk_method_unset(self, api_key):
def test_chunk_method_unset(self, HttpApiAuth):
payload = {"name": "chunk_method_unset"}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["chunk_method"] == "naive", res
@pytest.mark.p3
def test_chunk_method_none(self, api_key):
def test_chunk_method_none(self, HttpApiAuth):
payload = {"name": "chunk_method_none", "chunk_method": None}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101, res
assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in res["message"], res
@ -404,9 +404,9 @@ class TestDatasetCreate:
],
ids=["min", "mid", "max"],
)
def test_pagerank(self, api_key, name, pagerank):
def test_pagerank(self, HttpApiAuth, name, pagerank):
payload = {"name": name, "pagerank": pagerank}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["pagerank"] == pagerank, res
@ -419,23 +419,23 @@ class TestDatasetCreate:
],
ids=["min_limit", "max_limit"],
)
def test_pagerank_invalid(self, api_key, name, pagerank, expected_message):
def test_pagerank_invalid(self, HttpApiAuth, name, pagerank, expected_message):
payload = {"name": name, "pagerank": pagerank}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101, res
assert expected_message in res["message"], res
@pytest.mark.p3
def test_pagerank_unset(self, api_key):
def test_pagerank_unset(self, HttpApiAuth):
payload = {"name": "pagerank_unset"}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["pagerank"] == 0, res
@pytest.mark.p3
def test_pagerank_none(self, api_key):
def test_pagerank_none(self, HttpApiAuth):
payload = {"name": "pagerank_unset", "pagerank": None}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101, res
assert "Input should be a valid integer" in res["message"], res
@ -543,9 +543,9 @@ class TestDatasetCreate:
"raptor_random_seed_min",
],
)
def test_parser_config(self, api_key, name, parser_config):
def test_parser_config(self, HttpApiAuth, name, parser_config):
payload = {"name": name, "parser_config": parser_config}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
for k, v in parser_config.items():
if isinstance(v, dict):
@ -670,16 +670,16 @@ class TestDatasetCreate:
"parser_config_type_invalid",
],
)
def test_parser_config_invalid(self, api_key, name, parser_config, expected_message):
def test_parser_config_invalid(self, HttpApiAuth, name, parser_config, expected_message):
payload = {"name": name, "parser_config": parser_config}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101, res
assert expected_message in res["message"], res
@pytest.mark.p2
def test_parser_config_empty(self, api_key):
def test_parser_config_empty(self, HttpApiAuth):
payload = {"name": "parser_config_empty", "parser_config": {}}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["parser_config"] == {
"chunk_token_num": 128,
@ -690,9 +690,9 @@ class TestDatasetCreate:
}, res
@pytest.mark.p2
def test_parser_config_unset(self, api_key):
def test_parser_config_unset(self, HttpApiAuth):
payload = {"name": "parser_config_unset"}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["parser_config"] == {
"chunk_token_num": 128,
@ -703,9 +703,9 @@ class TestDatasetCreate:
}, res
@pytest.mark.p3
def test_parser_config_none(self, api_key):
def test_parser_config_none(self, HttpApiAuth):
payload = {"name": "parser_config_none", "parser_config": None}
res = create_dataset(api_key, payload)
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 0, res
assert res["data"]["parser_config"] == {
"chunk_token_num": 128,
@ -733,7 +733,7 @@ class TestDatasetCreate:
{"name": "unknown_field", "unknown_field": "unknown_field"},
],
)
def test_unsupported_field(self, api_key, payload):
res = create_dataset(api_key, payload)
def test_unsupported_field(self, HttpApiAuth, payload):
res = create_dataset(HttpApiAuth, payload)
assert res["code"] == 101, res
assert "Extra inputs are not permitted" in res["message"], res

View File

@ -47,9 +47,9 @@ class TestAuthorization:
class TestRquest:
@pytest.mark.p3
def test_content_type_bad(self, api_key):
def test_content_type_bad(self, HttpApiAuth):
BAD_CONTENT_TYPE = "text/xml"
res = delete_datasets(api_key, headers={"Content-Type": BAD_CONTENT_TYPE})
res = delete_datasets(HttpApiAuth, headers={"Content-Type": BAD_CONTENT_TYPE})
assert res["code"] == 101, res
assert res["message"] == f"Unsupported content type: Expected application/json, got {BAD_CONTENT_TYPE}", res
@ -62,35 +62,35 @@ class TestRquest:
],
ids=["malformed_json_syntax", "invalid_request_payload_type"],
)
def test_payload_bad(self, api_key, payload, expected_message):
res = delete_datasets(api_key, data=payload)
def test_payload_bad(self, HttpApiAuth, payload, expected_message):
res = delete_datasets(HttpApiAuth, data=payload)
assert res["code"] == 101, res
assert res["message"] == expected_message, res
@pytest.mark.p3
def test_payload_unset(self, api_key):
res = delete_datasets(api_key, None)
def test_payload_unset(self, HttpApiAuth):
res = delete_datasets(HttpApiAuth, None)
assert res["code"] == 101, res
assert res["message"] == "Malformed JSON syntax: Missing commas/brackets or invalid encoding", res
class TestCapability:
@pytest.mark.p3
def test_delete_dataset_1k(self, api_key):
ids = batch_create_datasets(api_key, 1_000)
res = delete_datasets(api_key, {"ids": ids})
def test_delete_dataset_1k(self, HttpApiAuth):
ids = batch_create_datasets(HttpApiAuth, 1_000)
res = delete_datasets(HttpApiAuth, {"ids": ids})
assert res["code"] == 0, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert len(res["data"]) == 0, res
@pytest.mark.p3
def test_concurrent_deletion(self, api_key):
def test_concurrent_deletion(self, HttpApiAuth):
count = 1_000
ids = batch_create_datasets(api_key, count)
ids = batch_create_datasets(HttpApiAuth, count)
with ThreadPoolExecutor(max_workers=5) as executor:
futures = [executor.submit(delete_datasets, api_key, {"ids": ids[i : i + 1]}) for i in range(count)]
futures = [executor.submit(delete_datasets, HttpApiAuth, {"ids": ids[i : i + 1]}) 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)
@ -106,64 +106,64 @@ class TestDatasetsDelete:
],
ids=["single_dataset", "multiple_datasets"],
)
def test_ids(self, api_key, add_datasets_func, func, expected_code, expected_message, remaining):
def test_ids(self, HttpApiAuth, add_datasets_func, func, expected_code, expected_message, remaining):
dataset_ids = add_datasets_func
if callable(func):
payload = func(dataset_ids)
res = delete_datasets(api_key, payload)
res = delete_datasets(HttpApiAuth, payload)
assert res["code"] == expected_code, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert len(res["data"]) == remaining, res
@pytest.mark.p1
@pytest.mark.usefixtures("add_dataset_func")
def test_ids_empty(self, api_key):
def test_ids_empty(self, HttpApiAuth):
payload = {"ids": []}
res = delete_datasets(api_key, payload)
res = delete_datasets(HttpApiAuth, payload)
assert res["code"] == 0, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert len(res["data"]) == 1, res
@pytest.mark.p1
@pytest.mark.usefixtures("add_datasets_func")
def test_ids_none(self, api_key):
def test_ids_none(self, HttpApiAuth):
payload = {"ids": None}
res = delete_datasets(api_key, payload)
res = delete_datasets(HttpApiAuth, payload)
assert res["code"] == 0, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert len(res["data"]) == 0, res
@pytest.mark.p2
@pytest.mark.usefixtures("add_dataset_func")
def test_id_not_uuid(self, api_key):
def test_id_not_uuid(self, HttpApiAuth):
payload = {"ids": ["not_uuid"]}
res = delete_datasets(api_key, payload)
res = delete_datasets(HttpApiAuth, payload)
assert res["code"] == 101, res
assert "Invalid UUID1 format" in res["message"], res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert len(res["data"]) == 1, res
@pytest.mark.p3
@pytest.mark.usefixtures("add_dataset_func")
def test_id_not_uuid1(self, api_key):
def test_id_not_uuid1(self, HttpApiAuth):
payload = {"ids": [uuid.uuid4().hex]}
res = delete_datasets(api_key, payload)
res = delete_datasets(HttpApiAuth, payload)
assert res["code"] == 101, res
assert "Invalid UUID1 format" in res["message"], res
@pytest.mark.p2
@pytest.mark.usefixtures("add_dataset_func")
def test_id_wrong_uuid(self, api_key):
def test_id_wrong_uuid(self, HttpApiAuth):
payload = {"ids": ["d94a8dc02c9711f0930f7fbc369eab6d"]}
res = delete_datasets(api_key, payload)
res = delete_datasets(HttpApiAuth, payload)
assert res["code"] == 108, res
assert "lacks permission for dataset" in res["message"], res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert len(res["data"]) == 1, res
@pytest.mark.p2
@ -175,46 +175,46 @@ class TestDatasetsDelete:
lambda r: {"ids": r + ["d94a8dc02c9711f0930f7fbc369eab6d"]},
],
)
def test_ids_partial_invalid(self, api_key, add_datasets_func, func):
def test_ids_partial_invalid(self, HttpApiAuth, add_datasets_func, func):
dataset_ids = add_datasets_func
if callable(func):
payload = func(dataset_ids)
res = delete_datasets(api_key, payload)
res = delete_datasets(HttpApiAuth, payload)
assert res["code"] == 108, res
assert "lacks permission for dataset" in res["message"], res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert len(res["data"]) == 3, res
@pytest.mark.p2
def test_ids_duplicate(self, api_key, add_datasets_func):
def test_ids_duplicate(self, HttpApiAuth, add_datasets_func):
dataset_ids = add_datasets_func
payload = {"ids": dataset_ids + dataset_ids}
res = delete_datasets(api_key, payload)
res = delete_datasets(HttpApiAuth, payload)
assert res["code"] == 101, res
assert "Duplicate ids:" in res["message"], res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert len(res["data"]) == 3, res
@pytest.mark.p2
def test_repeated_delete(self, api_key, add_datasets_func):
def test_repeated_delete(self, HttpApiAuth, add_datasets_func):
dataset_ids = add_datasets_func
payload = {"ids": dataset_ids}
res = delete_datasets(api_key, payload)
res = delete_datasets(HttpApiAuth, payload)
assert res["code"] == 0, res
res = delete_datasets(api_key, payload)
res = delete_datasets(HttpApiAuth, payload)
assert res["code"] == 108, res
assert "lacks permission for dataset" in res["message"], res
@pytest.mark.p2
@pytest.mark.usefixtures("add_dataset_func")
def test_field_unsupported(self, api_key):
def test_field_unsupported(self, HttpApiAuth):
payload = {"unknown_field": "unknown_field"}
res = delete_datasets(api_key, payload)
res = delete_datasets(HttpApiAuth, payload)
assert res["code"] == 101, res
assert "Extra inputs are not permitted" in res["message"], res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert len(res["data"]) == 1, res

View File

@ -43,10 +43,10 @@ class TestAuthorization:
class TestCapability:
@pytest.mark.p3
def test_concurrent_list(self, api_key):
def test_concurrent_list(self, HttpApiAuth):
count = 100
with ThreadPoolExecutor(max_workers=5) as executor:
futures = [executor.submit(list_datasets, api_key) for i in range(count)]
futures = [executor.submit(list_datasets, HttpApiAuth) 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)
@ -55,14 +55,14 @@ class TestCapability:
@pytest.mark.usefixtures("add_datasets")
class TestDatasetsList:
@pytest.mark.p1
def test_params_unset(self, api_key):
res = list_datasets(api_key, None)
def test_params_unset(self, HttpApiAuth):
res = list_datasets(HttpApiAuth, None)
assert res["code"] == 0, res
assert len(res["data"]) == 5, res
@pytest.mark.p2
def test_params_empty(self, api_key):
res = list_datasets(api_key, {})
def test_params_empty(self, HttpApiAuth):
res = list_datasets(HttpApiAuth, {})
assert res["code"] == 0, res
assert len(res["data"]) == 5, res
@ -78,8 +78,8 @@ class TestDatasetsList:
],
ids=["normal_middle_page", "normal_last_partial_page", "beyond_max_page", "string_page_number", "full_data_single_page"],
)
def test_page(self, api_key, params, expected_page_size):
res = list_datasets(api_key, params)
def test_page(self, HttpApiAuth, params, expected_page_size):
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 0, res
assert len(res["data"]) == expected_page_size, res
@ -92,15 +92,15 @@ class TestDatasetsList:
],
ids=["page_0", "page_a"],
)
def test_page_invalid(self, api_key, params, expected_code, expected_message):
res = list_datasets(api_key, params=params)
def test_page_invalid(self, HttpApiAuth, params, expected_code, expected_message):
res = list_datasets(HttpApiAuth, params=params)
assert res["code"] == expected_code, res
assert expected_message in res["message"], res
@pytest.mark.p2
def test_page_none(self, api_key):
def test_page_none(self, HttpApiAuth):
params = {"page": None}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 0, res
assert len(res["data"]) == 5, res
@ -116,8 +116,8 @@ class TestDatasetsList:
],
ids=["min_valid_page_size", "medium_page_size", "page_size_equals_total", "page_size_exceeds_total", "string_type_page_size"],
)
def test_page_size(self, api_key, params, expected_page_size):
res = list_datasets(api_key, params)
def test_page_size(self, HttpApiAuth, params, expected_page_size):
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 0, res
assert len(res["data"]) == expected_page_size, res
@ -129,15 +129,15 @@ class TestDatasetsList:
({"page_size": "a"}, 101, "Input should be a valid integer, unable to parse string as an integer"),
],
)
def test_page_size_invalid(self, api_key, params, expected_code, expected_message):
res = list_datasets(api_key, params)
def test_page_size_invalid(self, HttpApiAuth, params, expected_code, expected_message):
res = list_datasets(HttpApiAuth, params)
assert res["code"] == expected_code, res
assert expected_message in res["message"], res
@pytest.mark.p2
def test_page_size_none(self, api_key):
def test_page_size_none(self, HttpApiAuth):
params = {"page_size": None}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 0, res
assert len(res["data"]) == 5, res
@ -153,8 +153,8 @@ class TestDatasetsList:
],
ids=["orderby_create_time", "orderby_update_time", "orderby_create_time_upper", "orderby_update_time_upper", "whitespace"],
)
def test_orderby(self, api_key, params, assertions):
res = list_datasets(api_key, params)
def test_orderby(self, HttpApiAuth, params, assertions):
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 0, res
if callable(assertions):
assert assertions(res), res
@ -168,15 +168,15 @@ class TestDatasetsList:
],
ids=["empty", "unknown"],
)
def test_orderby_invalid(self, api_key, params):
res = list_datasets(api_key, params)
def test_orderby_invalid(self, HttpApiAuth, params):
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 101, res
assert "Input should be 'create_time' or 'update_time'" in res["message"], res
@pytest.mark.p3
def test_orderby_none(self, api_key):
def test_orderby_none(self, HttpApiAuth):
params = {"orderby": None}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 0, res
assert is_sorted(res["data"], "create_time", True), res
@ -197,8 +197,8 @@ class TestDatasetsList:
],
ids=["desc=True", "desc=False", "desc=true", "desc=false", "desc=1", "desc=0", "desc=yes", "desc=no", "desc=y", "desc=n"],
)
def test_desc(self, api_key, params, assertions):
res = list_datasets(api_key, params)
def test_desc(self, HttpApiAuth, params, assertions):
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 0, res
if callable(assertions):
assert assertions(res), res
@ -212,88 +212,88 @@ class TestDatasetsList:
],
ids=["empty", "unknown"],
)
def test_desc_invalid(self, api_key, params):
res = list_datasets(api_key, params)
def test_desc_invalid(self, HttpApiAuth, params):
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 101, res
assert "Input should be a valid boolean, unable to interpret input" in res["message"], res
@pytest.mark.p3
def test_desc_none(self, api_key):
def test_desc_none(self, HttpApiAuth):
params = {"desc": None}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 0, res
assert is_sorted(res["data"], "create_time", True), res
@pytest.mark.p1
def test_name(self, api_key):
def test_name(self, HttpApiAuth):
params = {"name": "dataset_1"}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 0, res
assert len(res["data"]) == 1, res
assert res["data"][0]["name"] == "dataset_1", res
@pytest.mark.p2
def test_name_wrong(self, api_key):
def test_name_wrong(self, HttpApiAuth):
params = {"name": "wrong name"}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 108, res
assert "lacks permission for dataset" in res["message"], res
@pytest.mark.p2
def test_name_empty(self, api_key):
def test_name_empty(self, HttpApiAuth):
params = {"name": ""}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 0, res
assert len(res["data"]) == 5, res
@pytest.mark.p2
def test_name_none(self, api_key):
def test_name_none(self, HttpApiAuth):
params = {"name": None}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 0, res
assert len(res["data"]) == 5, res
@pytest.mark.p1
def test_id(self, api_key, add_datasets):
def test_id(self, HttpApiAuth, add_datasets):
dataset_ids = add_datasets
params = {"id": dataset_ids[0]}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 0
assert len(res["data"]) == 1
assert res["data"][0]["id"] == dataset_ids[0]
@pytest.mark.p2
def test_id_not_uuid(self, api_key):
def test_id_not_uuid(self, HttpApiAuth):
params = {"id": "not_uuid"}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 101, res
assert "Invalid UUID1 format" in res["message"], res
@pytest.mark.p2
def test_id_not_uuid1(self, api_key):
def test_id_not_uuid1(self, HttpApiAuth):
params = {"id": uuid.uuid4().hex}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 101, res
assert "Invalid UUID1 format" in res["message"], res
@pytest.mark.p2
def test_id_wrong_uuid(self, api_key):
def test_id_wrong_uuid(self, HttpApiAuth):
params = {"id": "d94a8dc02c9711f0930f7fbc369eab6d"}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 108, res
assert "lacks permission for dataset" in res["message"], res
@pytest.mark.p2
def test_id_empty(self, api_key):
def test_id_empty(self, HttpApiAuth):
params = {"id": ""}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 101, res
assert "Invalid UUID1 format" in res["message"], res
@pytest.mark.p2
def test_id_none(self, api_key):
def test_id_none(self, HttpApiAuth):
params = {"id": None}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 0, res
assert len(res["data"]) == 5, res
@ -306,11 +306,11 @@ class TestDatasetsList:
],
ids=["name_and_id_match", "name_and_id_mismatch"],
)
def test_name_and_id(self, api_key, add_datasets, func, name, expected_num):
def test_name_and_id(self, HttpApiAuth, add_datasets, func, name, expected_num):
dataset_ids = add_datasets
if callable(func):
params = {"id": func(dataset_ids), "name": name}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 0, res
assert len(res["data"]) == expected_num, res
@ -323,19 +323,19 @@ class TestDatasetsList:
],
ids=["name", "id"],
)
def test_name_and_id_wrong(self, api_key, add_datasets, dataset_id, name):
def test_name_and_id_wrong(self, HttpApiAuth, add_datasets, dataset_id, name):
dataset_ids = add_datasets
if callable(dataset_id):
params = {"id": dataset_id(dataset_ids), "name": name}
else:
params = {"id": dataset_id, "name": name}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 108, res
assert "lacks permission for dataset" in res["message"], res
@pytest.mark.p2
def test_field_unsupported(self, api_key):
def test_field_unsupported(self, HttpApiAuth):
params = {"unknown_field": "unknown_field"}
res = list_datasets(api_key, params)
res = list_datasets(HttpApiAuth, params)
assert res["code"] == 101, res
assert "Extra inputs are not permitted" in res["message"], res

View File

@ -49,10 +49,10 @@ class TestAuthorization:
class TestRquest:
@pytest.mark.p3
def test_bad_content_type(self, api_key, add_dataset_func):
def test_bad_content_type(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
BAD_CONTENT_TYPE = "text/xml"
res = update_dataset(api_key, dataset_id, {"name": "bad_content_type"}, headers={"Content-Type": BAD_CONTENT_TYPE})
res = update_dataset(HttpApiAuth, dataset_id, {"name": "bad_content_type"}, headers={"Content-Type": BAD_CONTENT_TYPE})
assert res["code"] == 101, res
assert res["message"] == f"Unsupported content type: Expected application/json, got {BAD_CONTENT_TYPE}", res
@ -65,34 +65,34 @@ class TestRquest:
],
ids=["malformed_json_syntax", "invalid_request_payload_type"],
)
def test_payload_bad(self, api_key, add_dataset_func, payload, expected_message):
def test_payload_bad(self, HttpApiAuth, add_dataset_func, payload, expected_message):
dataset_id = add_dataset_func
res = update_dataset(api_key, dataset_id, data=payload)
res = update_dataset(HttpApiAuth, dataset_id, data=payload)
assert res["code"] == 101, res
assert res["message"] == expected_message, res
@pytest.mark.p2
def test_payload_empty(self, api_key, add_dataset_func):
def test_payload_empty(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
res = update_dataset(api_key, dataset_id, {})
res = update_dataset(HttpApiAuth, dataset_id, {})
assert res["code"] == 101, res
assert res["message"] == "No properties were modified", res
@pytest.mark.p3
def test_payload_unset(self, api_key, add_dataset_func):
def test_payload_unset(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
res = update_dataset(api_key, dataset_id, None)
res = update_dataset(HttpApiAuth, dataset_id, None)
assert res["code"] == 101, res
assert res["message"] == "Malformed JSON syntax: Missing commas/brackets or invalid encoding", res
class TestCapability:
@pytest.mark.p3
def test_update_dateset_concurrent(self, api_key, add_dataset_func):
def test_update_dateset_concurrent(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
count = 100
with ThreadPoolExecutor(max_workers=5) as executor:
futures = [executor.submit(update_dataset, api_key, dataset_id, {"name": f"dataset_{i}"}) for i in range(count)]
futures = [executor.submit(update_dataset, HttpApiAuth, dataset_id, {"name": f"dataset_{i}"}) 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)
@ -100,23 +100,23 @@ class TestCapability:
class TestDatasetUpdate:
@pytest.mark.p3
def test_dataset_id_not_uuid(self, api_key):
def test_dataset_id_not_uuid(self, HttpApiAuth):
payload = {"name": "not uuid"}
res = update_dataset(api_key, "not_uuid", payload)
res = update_dataset(HttpApiAuth, "not_uuid", payload)
assert res["code"] == 101, res
assert "Invalid UUID1 format" in res["message"], res
@pytest.mark.p3
def test_dataset_id_not_uuid1(self, api_key):
def test_dataset_id_not_uuid1(self, HttpApiAuth):
payload = {"name": "not uuid1"}
res = update_dataset(api_key, uuid.uuid4().hex, payload)
res = update_dataset(HttpApiAuth, uuid.uuid4().hex, payload)
assert res["code"] == 101, res
assert "Invalid UUID1 format" in res["message"], res
@pytest.mark.p3
def test_dataset_id_wrong_uuid(self, api_key):
def test_dataset_id_wrong_uuid(self, HttpApiAuth):
payload = {"name": "wrong uuid"}
res = update_dataset(api_key, "d94a8dc02c9711f0930f7fbc369eab6d", payload)
res = update_dataset(HttpApiAuth, "d94a8dc02c9711f0930f7fbc369eab6d", payload)
assert res["code"] == 108, res
assert "lacks permission for dataset" in res["message"], res
@ -124,13 +124,13 @@ class TestDatasetUpdate:
@given(name=valid_names())
@example("a" * 128)
@settings(max_examples=20, suppress_health_check=[HealthCheck.function_scoped_fixture])
def test_name(self, api_key, add_dataset_func, name):
def test_name(self, HttpApiAuth, add_dataset_func, name):
dataset_id = add_dataset_func
payload = {"name": name}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert res["code"] == 0, res
assert res["data"][0]["name"] == name, res
@ -146,50 +146,50 @@ class TestDatasetUpdate:
],
ids=["empty_name", "space_name", "too_long_name", "invalid_name", "None_name"],
)
def test_name_invalid(self, api_key, add_dataset_func, name, expected_message):
def test_name_invalid(self, HttpApiAuth, add_dataset_func, name, expected_message):
dataset_id = add_dataset_func
payload = {"name": name}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101, res
assert expected_message in res["message"], res
@pytest.mark.p3
def test_name_duplicated(self, api_key, add_datasets_func):
def test_name_duplicated(self, HttpApiAuth, add_datasets_func):
dataset_ids = add_datasets_func[0]
name = "dataset_1"
payload = {"name": name}
res = update_dataset(api_key, dataset_ids, payload)
res = update_dataset(HttpApiAuth, dataset_ids, payload)
assert res["code"] == 102, res
assert res["message"] == f"Dataset name '{name}' already exists", res
@pytest.mark.p3
def test_name_case_insensitive(self, api_key, add_datasets_func):
def test_name_case_insensitive(self, HttpApiAuth, add_datasets_func):
dataset_id = add_datasets_func[0]
name = "DATASET_1"
payload = {"name": name}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 102, res
assert res["message"] == f"Dataset name '{name}' already exists", res
@pytest.mark.p2
def test_avatar(self, api_key, add_dataset_func, tmp_path):
def test_avatar(self, HttpApiAuth, add_dataset_func, tmp_path):
dataset_id = add_dataset_func
fn = create_image_file(tmp_path / "ragflow_test.png")
payload = {
"avatar": f"data:image/png;base64,{encode_avatar(fn)}",
}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert res["code"] == 0, res
assert res["data"][0]["avatar"] == f"data:image/png;base64,{encode_avatar(fn)}", res
@pytest.mark.p2
def test_avatar_exceeds_limit_length(self, api_key, add_dataset_func):
def test_avatar_exceeds_limit_length(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
payload = {"avatar": "a" * 65536}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101, res
assert "String should have at most 65535 characters" in res["message"], res
@ -204,52 +204,52 @@ class TestDatasetUpdate:
],
ids=["empty_prefix", "missing_comma", "unsupported_mine_type", "invalid_mine_type"],
)
def test_avatar_invalid_prefix(self, api_key, add_dataset_func, tmp_path, avatar_prefix, expected_message):
def test_avatar_invalid_prefix(self, HttpApiAuth, add_dataset_func, tmp_path, avatar_prefix, expected_message):
dataset_id = add_dataset_func
fn = create_image_file(tmp_path / "ragflow_test.png")
payload = {"avatar": f"{avatar_prefix}{encode_avatar(fn)}"}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101, res
assert expected_message in res["message"], res
@pytest.mark.p3
def test_avatar_none(self, api_key, add_dataset_func):
def test_avatar_none(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
payload = {"avatar": None}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert res["code"] == 0, res
assert res["data"][0]["avatar"] is None, res
@pytest.mark.p2
def test_description(self, api_key, add_dataset_func):
def test_description(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
payload = {"description": "description"}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0
res = list_datasets(api_key, {"id": dataset_id})
res = list_datasets(HttpApiAuth, {"id": dataset_id})
assert res["code"] == 0, res
assert res["data"][0]["description"] == "description"
@pytest.mark.p2
def test_description_exceeds_limit_length(self, api_key, add_dataset_func):
def test_description_exceeds_limit_length(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
payload = {"description": "a" * 65536}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101, res
assert "String should have at most 65535 characters" in res["message"], res
@pytest.mark.p3
def test_description_none(self, api_key, add_dataset_func):
def test_description_none(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
payload = {"description": None}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0, res
res = list_datasets(api_key, {"id": dataset_id})
res = list_datasets(HttpApiAuth, {"id": dataset_id})
assert res["code"] == 0, res
assert res["data"][0]["description"] is None
@ -263,13 +263,13 @@ class TestDatasetUpdate:
],
ids=["builtin_baai", "builtin_youdao", "tenant_zhipu"],
)
def test_embedding_model(self, api_key, add_dataset_func, embedding_model):
def test_embedding_model(self, HttpApiAuth, add_dataset_func, embedding_model):
dataset_id = add_dataset_func
payload = {"embedding_model": embedding_model}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert res["code"] == 0, res
assert res["data"][0]["embedding_model"] == embedding_model, res
@ -284,10 +284,10 @@ class TestDatasetUpdate:
],
ids=["unknown_llm_name", "unknown_llm_factory", "tenant_no_auth_default_tenant_llm", "tenant_no_auth"],
)
def test_embedding_model_invalid(self, api_key, add_dataset_func, name, embedding_model):
def test_embedding_model_invalid(self, HttpApiAuth, add_dataset_func, name, embedding_model):
dataset_id = add_dataset_func
payload = {"name": name, "embedding_model": embedding_model}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101, res
if "tenant_no_auth" in name:
assert res["message"] == f"Unauthorized model: <{embedding_model}>", res
@ -306,10 +306,10 @@ class TestDatasetUpdate:
],
ids=["missing_at", "empty_model_name", "empty_provider", "whitespace_only_model_name", "whitespace_only_provider"],
)
def test_embedding_model_format(self, api_key, add_dataset_func, name, embedding_model):
def test_embedding_model_format(self, HttpApiAuth, add_dataset_func, name, embedding_model):
dataset_id = add_dataset_func
payload = {"name": name, "embedding_model": embedding_model}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101, res
if name == "missing_at":
assert "Embedding model identifier must follow <model_name>@<provider> format" in res["message"], res
@ -317,10 +317,10 @@ class TestDatasetUpdate:
assert "Both model_name and provider must be non-empty strings" in res["message"], res
@pytest.mark.p2
def test_embedding_model_none(self, api_key, add_dataset_func):
def test_embedding_model_none(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
payload = {"embedding_model": None}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101, res
assert "Input should be a valid string" in res["message"], res
@ -336,13 +336,13 @@ class TestDatasetUpdate:
],
ids=["me", "team", "me_upercase", "team_upercase", "whitespace"],
)
def test_permission(self, api_key, add_dataset_func, permission):
def test_permission(self, HttpApiAuth, add_dataset_func, permission):
dataset_id = add_dataset_func
payload = {"permission": permission}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert res["code"] == 0, res
assert res["data"][0]["permission"] == permission.lower().strip(), res
@ -356,18 +356,18 @@ class TestDatasetUpdate:
],
ids=["empty", "unknown", "type_error"],
)
def test_permission_invalid(self, api_key, add_dataset_func, permission):
def test_permission_invalid(self, HttpApiAuth, add_dataset_func, permission):
dataset_id = add_dataset_func
payload = {"permission": permission}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101
assert "Input should be 'me' or 'team'" in res["message"]
@pytest.mark.p3
def test_permission_none(self, api_key, add_dataset_func):
def test_permission_none(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
payload = {"permission": None}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101, res
assert "Input should be 'me' or 'team'" in res["message"], res
@ -390,13 +390,13 @@ class TestDatasetUpdate:
],
ids=["naive", "book", "email", "laws", "manual", "one", "paper", "picture", "presentation", "qa", "table", "tag"],
)
def test_chunk_method(self, api_key, add_dataset_func, chunk_method):
def test_chunk_method(self, HttpApiAuth, add_dataset_func, chunk_method):
dataset_id = add_dataset_func
payload = {"chunk_method": chunk_method}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert res["code"] == 0, res
assert res["data"][0]["chunk_method"] == chunk_method, res
@ -410,30 +410,30 @@ class TestDatasetUpdate:
],
ids=["empty", "unknown", "type_error"],
)
def test_chunk_method_invalid(self, api_key, add_dataset_func, chunk_method):
def test_chunk_method_invalid(self, HttpApiAuth, add_dataset_func, chunk_method):
dataset_id = add_dataset_func
payload = {"chunk_method": chunk_method}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101, res
assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in res["message"], res
@pytest.mark.p3
def test_chunk_method_none(self, api_key, add_dataset_func):
def test_chunk_method_none(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
payload = {"chunk_method": None}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101, res
assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in res["message"], res
@pytest.mark.p2
@pytest.mark.parametrize("pagerank", [0, 50, 100], ids=["min", "mid", "max"])
def test_pagerank(self, api_key, add_dataset_func, pagerank):
def test_pagerank(self, HttpApiAuth, add_dataset_func, pagerank):
dataset_id = add_dataset_func
payload = {"pagerank": pagerank}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0
res = list_datasets(api_key, {"id": dataset_id})
res = list_datasets(HttpApiAuth, {"id": dataset_id})
assert res["code"] == 0, res
assert res["data"][0]["pagerank"] == pagerank
@ -446,18 +446,18 @@ class TestDatasetUpdate:
],
ids=["min_limit", "max_limit"],
)
def test_pagerank_invalid(self, api_key, add_dataset_func, pagerank, expected_message):
def test_pagerank_invalid(self, HttpApiAuth, add_dataset_func, pagerank, expected_message):
dataset_id = add_dataset_func
payload = {"pagerank": pagerank}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101, res
assert expected_message in res["message"], res
@pytest.mark.p3
def test_pagerank_none(self, api_key, add_dataset_func):
def test_pagerank_none(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
payload = {"pagerank": None}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101, res
assert "Input should be a valid integer" in res["message"], res
@ -565,13 +565,13 @@ class TestDatasetUpdate:
"raptor_random_seed_min",
],
)
def test_parser_config(self, api_key, add_dataset_func, parser_config):
def test_parser_config(self, HttpApiAuth, add_dataset_func, parser_config):
dataset_id = add_dataset_func
payload = {"parser_config": parser_config}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert res["code"] == 0, res
for k, v in parser_config.items():
if isinstance(v, dict):
@ -696,21 +696,21 @@ class TestDatasetUpdate:
"parser_config_type_invalid",
],
)
def test_parser_config_invalid(self, api_key, add_dataset_func, parser_config, expected_message):
def test_parser_config_invalid(self, HttpApiAuth, add_dataset_func, parser_config, expected_message):
dataset_id = add_dataset_func
payload = {"parser_config": parser_config}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101, res
assert expected_message in res["message"], res
@pytest.mark.p2
def test_parser_config_empty(self, api_key, add_dataset_func):
def test_parser_config_empty(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
payload = {"parser_config": {}}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert res["code"] == 0, res
assert res["data"][0]["parser_config"] == {
"chunk_token_num": 128,
@ -721,13 +721,13 @@ class TestDatasetUpdate:
}, res
@pytest.mark.p3
def test_parser_config_none(self, api_key, add_dataset_func):
def test_parser_config_none(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
payload = {"parser_config": None}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0, res
res = list_datasets(api_key, {"id": dataset_id})
res = list_datasets(HttpApiAuth, {"id": dataset_id})
assert res["code"] == 0, res
assert res["data"][0]["parser_config"] == {
"chunk_token_num": 128,
@ -738,35 +738,35 @@ class TestDatasetUpdate:
}, res
@pytest.mark.p3
def test_parser_config_empty_with_chunk_method_change(self, api_key, add_dataset_func):
def test_parser_config_empty_with_chunk_method_change(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
payload = {"chunk_method": "qa", "parser_config": {}}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert res["code"] == 0, res
assert res["data"][0]["parser_config"] == {"raptor": {"use_raptor": False}}, res
@pytest.mark.p3
def test_parser_config_unset_with_chunk_method_change(self, api_key, add_dataset_func):
def test_parser_config_unset_with_chunk_method_change(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
payload = {"chunk_method": "qa"}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert res["code"] == 0, res
assert res["data"][0]["parser_config"] == {"raptor": {"use_raptor": False}}, res
@pytest.mark.p3
def test_parser_config_none_with_chunk_method_change(self, api_key, add_dataset_func):
def test_parser_config_none_with_chunk_method_change(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
payload = {"chunk_method": "qa", "parser_config": None}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0, res
res = list_datasets(api_key, {"id": dataset_id})
res = list_datasets(HttpApiAuth, {"id": dataset_id})
assert res["code"] == 0, res
assert res["data"][0]["parser_config"] == {"raptor": {"use_raptor": False}}, res
@ -788,24 +788,24 @@ class TestDatasetUpdate:
{"unknown_field": "unknown_field"},
],
)
def test_field_unsupported(self, api_key, add_dataset_func, payload):
def test_field_unsupported(self, HttpApiAuth, add_dataset_func, payload):
dataset_id = add_dataset_func
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 101, res
assert "Extra inputs are not permitted" in res["message"], res
@pytest.mark.p2
def test_field_unset(self, api_key, add_dataset_func):
def test_field_unset(self, HttpApiAuth, add_dataset_func):
dataset_id = add_dataset_func
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert res["code"] == 0, res
original_data = res["data"][0]
payload = {"name": "default_unset"}
res = update_dataset(api_key, dataset_id, payload)
res = update_dataset(HttpApiAuth, dataset_id, payload)
assert res["code"] == 0, res
res = list_datasets(api_key)
res = list_datasets(HttpApiAuth)
assert res["code"] == 0, res
assert res["data"][0]["avatar"] == original_data["avatar"], res
assert res["data"][0]["description"] == original_data["description"], res