Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import os
  17. import pytest
  18. import requests
  19. HOST_ADDRESS = os.getenv('HOST_ADDRESS', 'http://127.0.0.1:9380')
  20. # def generate_random_email():
  21. # return 'user_' + ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))+'@1.com'
  22. def generate_email():
  23. return 'user_123@1.com'
  24. EMAIL = generate_email()
  25. # password is "123"
  26. PASSWORD = '''ctAseGvejiaSWWZ88T/m4FQVOpQyUvP+x7sXtdv3feqZACiQleuewkUi35E16wSd5C5QcnkkcV9cYc8TKPTRZlxappDuirxghxoOvFcJxFU4ixLsD
  27. fN33jCHRoDUW81IH9zjij/vaw8IbVyb6vuwg6MX6inOEBRRzVbRYxXOu1wkWY6SsI8X70oF9aeLFp/PzQpjoe/YbSqpTq8qqrmHzn9vO+yvyYyvmDsphXe
  28. X8f7fp9c7vUsfOCkM+gHY3PadG+QHa7KI7mzTKgUTZImK6BZtfRBATDTthEUbbaTewY4H0MnWiCeeDhcbeQao6cFy1To8pE3RpmxnGnS8BsBn8w=='''
  29. def register():
  30. url = HOST_ADDRESS + "/v1/user/register"
  31. name = "user"
  32. register_data = {"email": EMAIL, "nickname": name, "password": PASSWORD}
  33. res = requests.post(url=url, json=register_data)
  34. res = res.json()
  35. if res.get("code") != 0:
  36. raise Exception(res.get("message"))
  37. def login():
  38. url = HOST_ADDRESS + "/v1/user/login"
  39. login_data = {"email": EMAIL, "password": PASSWORD}
  40. response = requests.post(url=url, json=login_data)
  41. res = response.json()
  42. if res.get("code") != 0:
  43. raise Exception(res.get("message"))
  44. auth = response.headers["Authorization"]
  45. return auth
  46. @pytest.fixture(scope="session")
  47. def get_api_key_fixture():
  48. try:
  49. register()
  50. except Exception as e:
  51. print(e)
  52. auth = login()
  53. url = HOST_ADDRESS + "/v1/system/new_token"
  54. auth = {"Authorization": auth}
  55. response = requests.post(url=url, headers=auth)
  56. res = response.json()
  57. if res.get("code") != 0:
  58. raise Exception(res.get("message"))
  59. return res["data"].get("token")
  60. @pytest.fixture(scope="session")
  61. def get_auth():
  62. try:
  63. register()
  64. except Exception as e:
  65. print(e)
  66. auth = login()
  67. return auth
  68. @pytest.fixture(scope="session")
  69. def get_email():
  70. return EMAIL