forked from MerlinCN/BliveMusicBoard
/
test.py
66 lines (47 loc) · 1.71 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import requests
import random
import string
from faker import Faker
BASE_URL = "http://localhost:4220"
# 生成随机英文字符串
def random_english_string(length):
# 选择所有字母和数字作为字符集
characters = string.ascii_letters + string.digits
# 使用random.choices()函数生成指定长度的随机字符串
return ''.join(random.choices(characters, k=length))
# 生成随机中文字符串
def random_chinese_string(length):
result = ''
for i in range(length):
# 随机选择Unicode编码值,转换为中文字符
result += chr(random.randint(0x4e00, 0x9fbf))
return result
def random_integer():
# 生成1~5位的随机整数
return random.randint(1, 10**5)
def test_add_song(name, user, uid):
url = BASE_URL + "/songs/add"
payload = {"name": name, "user": user, "uid": uid}
response = requests.post(url, data=payload)
print("add_song: ", response.status_code, response.text)
def test_list_songs():
url = BASE_URL + "/songs"
response = requests.get(url)
print("list_songs: ", response.status_code, response.text)
def test_delete_song(number):
url = BASE_URL + f"/songs/del"
payload = {"number": number}
response = requests.post(url, data=payload)
print("delete_song: ", response.status_code, response.text)
def test_clear_song():
url = BASE_URL + f"/songs/clear"
payload = {}
response = requests.post(url, data=payload)
print("clear_song: ", response.status_code, response.text)
def add_test_songs(n):
for i in range(n):
f1 = Faker(['en_US'])
f2 = Faker(['zh_CN'])
test_add_song(f1.name(),f2.name(),random_integer())
if __name__ == "__main__":
add_test_songs(5)