conftest.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import json
  2. import os
  3. from pathlib import Path
  4. import pytest
  5. import requests
  6. from common.yaml_util import clear_yaml, read_testcase, read_config_yaml, write_yaml, clear_out_yaml
  7. path = Path(__file__).parent.glob("**/test_001_登录接口.yaml")
  8. for yaml_path1 in path:
  9. yaml_path = yaml_path1
  10. path = Path(__file__).parent.glob("**/test_001_登录获取key.yaml")
  11. for yaml_path1 in path:
  12. yzm_path = yaml_path1
  13. @pytest.fixture(scope="session", autouse=True)
  14. def clear_yam():
  15. clear_yaml()
  16. clear_out_yaml()
  17. login_new()
  18. # key_login(yzm_path)
  19. # login_system(yaml_path)
  20. #
  21. # def login_system(yaml_path: Path):
  22. # global i
  23. # data = read_testcase(yaml_path)
  24. # for i in data:
  25. # method = i['request'].pop("method")
  26. # url = read_config_yaml("base", "base_qccq_sc") + i['request'].pop("url")
  27. # # 发送请求
  28. # res = requests.request(method, url, **i['request'])
  29. # token = res.json()['data']["token"]
  30. # write_yaml({"token": token})
  31. #
  32. #
  33. # def key_login(yzm_path):
  34. # global i
  35. # data = read_testcase(yzm_path)
  36. # for i in data:
  37. # method = i['request'].pop('method')
  38. # url = read_config_yaml("base", "base_qccq_sc") + i['request'].pop("url")
  39. # res = requests.request(method, url)
  40. # write_yaml({"captchaKey": res.json()["data"]["captchaKey"]})
  41. # write_yaml({"captcha": res.json()["data"]["length"]})
  42. def login_new():
  43. url = "https://app.youth.cq.cqyl.org.cn/api/service-sysmgr/LoginController/getCaptchaLength?accountId=18983394419"
  44. method = "get"
  45. res = requests.request(method, url)
  46. data = res.json()["data"]
  47. url1 = "https://app.youth.cq.cqyl.org.cn/api/service-sysmgr/LoginController/login"
  48. method1 = "post"
  49. request_data = {
  50. "captchaKey": data["captchaKey"],
  51. "captcha": data["length"],
  52. "mobile": "18983394419",
  53. 'password': "4E797559645371504E71767A563733444C2F7250785176504C79696231427977737073446347774A4C4A5631486A5231554B7455744B692B56423446673473562B4755504E737064767665674753445672334A6A4836434B447A336B6F63346F6C554654786D5467516768684D7661564A4D6B49327A75377A72535A6745746A4E546A535058344B39312B794A6C57634B4E45334E4F723043704E505031653145686C337033767330354D3D",
  54. "scope": "PHONE",
  55. "username": '18983394419'
  56. }
  57. print(request_data)
  58. response = requests.request(url=url1, method=method1, json=request_data)
  59. token = response.json()["data"]["token"]
  60. write_yaml({"token": token})