test_rm_kb.py


Overview

test_rm_kb.py is a test suite designed to validate the behavior of the knowledge base removal functionality within the InfiniFlow system. Specifically, it tests the rm_kb function, which appears to handle the deletion of knowledge bases (KBs) from the system, ensuring proper authorization and correct handling of input parameters.

This file uses the pytest framework to define and organize test cases into two main classes:

The tests leverage helper functions rm_kb and list_kbs from the common module and use authorization tokens from libs.auth and configs modules.


Classes and Methods

Class: TestAuthorization

This class contains tests that verify the behavior of the system when removing KBs with invalid or missing authorization.

Method: test_auth_invalid(self, invalid_auth, expected_code, expected_message)

invalid_auth = None
response = rm_kb(invalid_auth)
assert response["code"] == 401
assert "<Unauthorized" in response["message"]

Class: TestDatasetsDelete

This class focuses on testing the deletion functionality of knowledge bases under various scenarios.

Method: test_kb_id(self, WebApiAuth, add_datasets_func)

kb_ids = add_datasets_func
payload = {"kb_id": kb_ids[0]}
response = rm_kb(WebApiAuth, payload)
assert response["code"] == 0

response = list_kbs(WebApiAuth)
assert len(response["data"]["kbs"]) == expected_count_after_deletion

Method: test_id_wrong_uuid(self, WebApiAuth)

invalid_kb_id = "d94a8dc02c9711f0930f7fbc369eab6d"  # malformed UUID
payload = {"kb_id": invalid_kb_id}
response = rm_kb(WebApiAuth, payload)
assert response["code"] == 109
assert "No authorization." in response["message"]

response = list_kbs(WebApiAuth)
assert len(response["data"]["kbs"]) == expected_count_before_deletion

Important Implementation Details and Algorithms


Interaction with Other Parts of the System

This file fits into the system as a regression and validation test to ensure that KB removal functionality respects authorization and input validation rules, preventing unauthorized or invalid deletions.


Visual Diagram

classDiagram
    class TestAuthorization {
        +test_auth_invalid(invalid_auth, expected_code, expected_message)
    }

    class TestDatasetsDelete {
        +test_kb_id(WebApiAuth, add_datasets_func)
        +test_id_wrong_uuid(WebApiAuth)
    }

    TestAuthorization --> rm_kb
    TestDatasetsDelete --> rm_kb
    TestDatasetsDelete --> list_kbs

Summary

test_rm_kb.py is a concise yet critical test file verifying the correctness and security of the knowledge base removal functionality in InfiniFlow. It ensures that only authorized users can delete KBs, that deletions with valid IDs succeed, and that invalid requests are properly handled. The tests rely on external fixtures and helper functions, making it part of a larger integration testing framework.