目录
项目结构
envApi.py
import requests
import yaml
class Api:
env = yaml.safe_load(open("env.yaml"))
def send(self, data: dict):
# data["url"] = str(data["url"]).replace("testing-studio", self.env["testing-studio"][self.env["default"]])
data["url"] = data["url"].replace("testing-studio", self.env["testing-studio"][self.env["default"]])
result = requests.request(method=data["method"],
url=data["url"],
headers=data["headers"])
return result
env.yaml
default: dev
testing-studio:
dev: 127.0.0.1:80
test: 127.0.0.2222:80
test_envApi.py
from api_test_framework.may_env import envApi
class Testenv_api:
data = {
"method": "get",
"url": "http://testing-studio/Downloads/testfile/demo.txt",
"headers": None
}
def test_send(self):
api = envApi.Api()
print(api.send(self.data).text)