Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. from libs.auth import RAGFlowHttpApiAuth
  20. HOST_ADDRESS = os.getenv('HOST_ADDRESS', 'http://127.0.0.1:9380')
  21. # def generate_random_email():
  22. # return 'user_' + ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))+'@1.com'
  23. def generate_email():
  24. return 'user_123@1.com'
  25. EMAIL = generate_email()
  26. # password is "123"
  27. PASSWORD = '''ctAseGvejiaSWWZ88T/m4FQVOpQyUvP+x7sXtdv3feqZACiQleuewkUi35E16wSd5C5QcnkkcV9cYc8TKPTRZlxappDuirxghxoOvFcJxFU4ixLsD
  28. fN33jCHRoDUW81IH9zjij/vaw8IbVyb6vuwg6MX6inOEBRRzVbRYxXOu1wkWY6SsI8X70oF9aeLFp/PzQpjoe/YbSqpTq8qqrmHzn9vO+yvyYyvmDsphXe
  29. X8f7fp9c7vUsfOCkM+gHY3PadG+QHa7KI7mzTKgUTZImK6BZtfRBATDTthEUbbaTewY4H0MnWiCeeDhcbeQao6cFy1To8pE3RpmxnGnS8BsBn8w=='''
  30. def register():
  31. url = HOST_ADDRESS + "/v1/user/register"
  32. name = "user"
  33. register_data = {"email": EMAIL, "nickname": name, "password": PASSWORD}
  34. res = requests.post(url=url, json=register_data)
  35. res = res.json()
  36. if res.get("code") != 0:
  37. raise Exception(res.get("message"))
  38. def login():
  39. url = HOST_ADDRESS + "/v1/user/login"
  40. login_data = {"email": EMAIL, "password": PASSWORD}
  41. response = requests.post(url=url, json=login_data)
  42. res = response.json()
  43. if res.get("code") != 0:
  44. raise Exception(res.get("message"))
  45. auth = response.headers["Authorization"]
  46. return auth
  47. @pytest.fixture(scope="session")
  48. def get_api_key_fixture():
  49. try:
  50. register()
  51. except Exception as e:
  52. print(e)
  53. auth = login()
  54. url = HOST_ADDRESS + "/v1/system/new_token"
  55. auth = {"Authorization": auth}
  56. response = requests.post(url=url, headers=auth)
  57. res = response.json()
  58. if res.get("code") != 0:
  59. raise Exception(res.get("message"))
  60. return res["data"].get("token")
  61. @pytest.fixture(scope="session")
  62. def get_auth():
  63. try:
  64. register()
  65. except Exception as e:
  66. print(e)
  67. auth = login()
  68. return auth
  69. @pytest.fixture(scope="session")
  70. def get_email():
  71. return EMAIL
  72. @pytest.fixture(scope="session")
  73. def get_http_api_auth(get_api_key_fixture):
  74. return RAGFlowHttpApiAuth(get_api_key_fixture)