tmp.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import json
  2. import unittest
  3. import requests
  4. def print_json_pretty(obj):
  5. print(json.dumps(obj, indent=4, ensure_ascii=False))
  6. def print_json_plain(obj):
  7. print(json.dumps(obj, ensure_ascii=False))
  8. def req(url, json_dict):
  9. res = requests.post(url, json=json_dict, headers={
  10. "cookie": "lang=zh-CN; MJSESSIONID=YmQ1YTAyOTktMjBiMy00MmZhLWJmMmUtNjQyODJmYjU0ODM4; satoken-server=d6e42d1a-2372-4746-a032-f5690ff6fbbc"})
  11. print_json_plain(json_dict)
  12. print_json_pretty(res.json())
  13. class MyTest(unittest.TestCase):
  14. def test1(self):
  15. json_dict = {
  16. "name": "wwW",
  17. "type": "MYSQL",
  18. "description": "dolor dolor tempor",
  19. "ip": "eip-mysql-2.qa.mlamp.cn",
  20. "port": 3306,
  21. "index_name": "",
  22. "db_name": "hao_rec_pro",
  23. "userName": "hao_rec",
  24. "passwd": "Hao_rec@123456"
  25. }
  26. req("http://127.0.0.1:8500/ui/datasource/newDataSource", json_dict)
  27. # 测试死锁
  28. def test2(self):
  29. req(1, '粉底液', '祛痘')
  30. req(1, '眼霜', '修护')
  31. # 测试兜底策略
  32. def test3(self):
  33. req(1, '', '')