-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix KB list bugs and add web api test (#3649)
### What problem does this PR solve? 1. Read KB list path parameter, page_number and page_size, which type isn't int 2. Add cases on create / list / delete datasets. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [x] Test cases Signed-off-by: jinhai <haijin.chn@gmail.com>
- Loading branch information
Showing
4 changed files
with
97 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,26 @@ | ||
import os | ||
HOST_ADDRESS=os.getenv('HOST_ADDRESS', 'http://127.0.0.1:9380') | ||
import requests | ||
|
||
HOST_ADDRESS = os.getenv('HOST_ADDRESS', 'http://127.0.0.1:9380') | ||
|
||
def create_dataset(auth, dataset_name): | ||
authorization = {"Authorization": auth} | ||
url = f"{HOST_ADDRESS}/v1/kb/create" | ||
json = {"name": dataset_name} | ||
res = requests.post(url=url, headers=authorization, json=json) | ||
return res.json() | ||
|
||
|
||
def list_dataset(auth, page_number): | ||
authorization = {"Authorization": auth} | ||
url = f"{HOST_ADDRESS}/v1/kb/list?page={page_number}" | ||
res = requests.get(url=url, headers=authorization) | ||
return res.json() | ||
|
||
|
||
def rm_dataset(auth, dataset_id): | ||
authorization = {"Authorization": auth} | ||
url = f"{HOST_ADDRESS}/v1/kb/rm" | ||
json = {"kb_id": dataset_id} | ||
res = requests.post(url=url, headers=authorization, json=json) | ||
return res.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,63 @@ | ||
from common import HOST_ADDRESS | ||
from common import HOST_ADDRESS, create_dataset, list_dataset, rm_dataset | ||
import requests | ||
def test_create_dataset(get_auth): | ||
authorization={"Authorization": get_auth} | ||
|
||
|
||
def test_dataset(get_auth): | ||
# create dataset | ||
res = create_dataset(get_auth, "test_create_dataset") | ||
assert res.get("code") == 0, f"{res.get('message')}" | ||
|
||
# list dataset | ||
page_number = 1 | ||
dataset_list = [] | ||
while True: | ||
res = list_dataset(get_auth, page_number) | ||
data = res.get("data") | ||
for item in data: | ||
dataset_id = item.get("id") | ||
dataset_list.append(dataset_id) | ||
if len(dataset_list) < page_number * 150: | ||
break | ||
page_number += 1 | ||
|
||
print(f"found {len(dataset_list)} datasets") | ||
# delete dataset | ||
for dataset_id in dataset_list: | ||
res = rm_dataset(get_auth, dataset_id) | ||
assert res.get("code") == 0, f"{res.get('message')}" | ||
print(f"{len(dataset_list)} datasets are deleted") | ||
|
||
|
||
def test_dataset_1k_dataset(get_auth): | ||
# create dataset | ||
authorization = {"Authorization": get_auth} | ||
url = f"{HOST_ADDRESS}/v1/kb/create" | ||
json = {"name":"test_create_dataset"} | ||
res = requests.post(url=url,headers=authorization,json=json) | ||
res = res.json() | ||
assert res.get("code") == 0,f"{res.get('message')}" | ||
for i in range(1000): | ||
res = create_dataset(get_auth, f"test_create_dataset_{i}") | ||
assert res.get("code") == 0, f"{res.get('message')}" | ||
|
||
# list dataset | ||
page_number = 1 | ||
dataset_list = [] | ||
while True: | ||
res = list_dataset(get_auth, page_number) | ||
data = res.get("data") | ||
for item in data: | ||
dataset_id = item.get("id") | ||
dataset_list.append(dataset_id) | ||
if len(dataset_list) < page_number * 150: | ||
break | ||
page_number += 1 | ||
|
||
print(f"found {len(dataset_list)} datasets") | ||
# delete dataset | ||
for dataset_id in dataset_list: | ||
res = rm_dataset(get_auth, dataset_id) | ||
assert res.get("code") == 0, f"{res.get('message')}" | ||
print(f"{len(dataset_list)} datasets are deleted") | ||
|
||
# delete dataset | ||
# create invalid name dataset | ||
# update dataset with different parameters | ||
# create duplicated name dataset | ||
# |