You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

conftest.py 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import os
  2. import pytest
  3. import requests
  4. HOST_ADDRESS = os.getenv('HOST_ADDRESS', 'http://127.0.0.1:9380')
  5. # def generate_random_email():
  6. # return 'user_' + ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))+'@1.com'
  7. def generate_email():
  8. return 'user_123@1.com'
  9. EMAIL = generate_email()
  10. # password is "123"
  11. PASSWORD='''ctAseGvejiaSWWZ88T/m4FQVOpQyUvP+x7sXtdv3feqZACiQleuewkUi35E16wSd5C5QcnkkcV9cYc8TKPTRZlxappDuirxghxoOvFcJxFU4ixLsD
  12. fN33jCHRoDUW81IH9zjij/vaw8IbVyb6vuwg6MX6inOEBRRzVbRYxXOu1wkWY6SsI8X70oF9aeLFp/PzQpjoe/YbSqpTq8qqrmHzn9vO+yvyYyvmDsphXe
  13. X8f7fp9c7vUsfOCkM+gHY3PadG+QHa7KI7mzTKgUTZImK6BZtfRBATDTthEUbbaTewY4H0MnWiCeeDhcbeQao6cFy1To8pE3RpmxnGnS8BsBn8w=='''
  14. def register():
  15. url = HOST_ADDRESS + "/v1/user/register"
  16. name = "user"
  17. register_data = {"email":EMAIL,"nickname":name,"password":PASSWORD}
  18. res = requests.post(url=url,json=register_data)
  19. res = res.json()
  20. if res.get("code") != 0:
  21. raise Exception(res.get("message"))
  22. def login():
  23. url = HOST_ADDRESS + "/v1/user/login"
  24. login_data = {"email":EMAIL,"password":PASSWORD}
  25. response=requests.post(url=url,json=login_data)
  26. res = response.json()
  27. if res.get("code")!=0:
  28. raise Exception(res.get("message"))
  29. auth = response.headers["Authorization"]
  30. return auth
  31. @pytest.fixture(scope="session")
  32. def get_api_key_fixture():
  33. try:
  34. register()
  35. except Exception as e:
  36. print(e)
  37. auth = login()
  38. url = HOST_ADDRESS + "/v1/system/new_token"
  39. auth = {"Authorization": auth}
  40. response = requests.post(url=url,headers=auth)
  41. res = response.json()
  42. if res.get("code") != 0:
  43. raise Exception(res.get("message"))
  44. return res["data"].get("token")
  45. @pytest.fixture(scope="session")
  46. def get_auth():
  47. try:
  48. register()
  49. except Exception as e:
  50. print(e)
  51. auth = login()
  52. return auth
  53. @pytest.fixture(scope="session")
  54. def get_email():
  55. return EMAIL