Commit 37daeabf authored by 张伟男's avatar 张伟男

add master

parent 9fdecaf2
......@@ -17,4 +17,5 @@ class account_request(BaseRequest):
if __name__ == '__main__':
print(account_request().login_vfc("beijing", "+8612345678912", 1234, "", ""))
\ No newline at end of file
# print(account_request().user_info())
print(account_request.loginvfc(""))
\ No newline at end of file
......@@ -9,3 +9,5 @@ login_vfc:
vfc_type: ${vfc_type}
face_token: ${face_token}
json: {}
from backend_auto import path_setting
from backend_auto.in_common.base_request import BaseRequest
class diary_data_reqest(BaseRequest):
def __init__(self):
self.data = self.api_load(path_setting.DIARY_DATA_CONFIG)
def diary_data(self, current_city_id, diary_referrer, sort, count , start_num):
self.params["current_city_id"] = current_city_id
self.params["diary_referrer"] = diary_referrer
self.params["sort"] = sort
self.params["count"] = count
self.params["start_num"] = start_num
return self.api_send(self.data["diary_data"])
# if __name__ == '__main__':
# print(send_reqest().login_vfc("beijing", "+8612345678912", 1234, "", ""))
# print(send_reqest().diary_data("beijing", "my_diary", 0, 8, 2))
# print(1)
\ No newline at end of file
diary_data:
method: get
url: /api/diary/topic/15261339/_data
params:
current_city_id: ${current_city_id}
diary_referrer: ${diary_referrer}
sort: ${sort}
count: ${count}
start_num: ${start_num}
data:
json: {}
......@@ -7,3 +7,4 @@ index_v9:
current_city_id: ${current_city_id}
data:
json: {}
isLogin: 1
......@@ -7,9 +7,18 @@ class hospitals_request(BaseRequest):
def __init__(self):
self.data = self.api_load(path_setting.HDYAML_CONFIG)
#医院主页详情
def detail(self):
return self.api_send(self.data["detail"])
#医院主页医生列表
def doctor(self):
return self.api_send(self.data["doctor"])
if __name__ == '__main__':
print(hospitals_request().detail())
\ No newline at end of file
#打印医院主页详情接口返回
print(hospitals_request().detail())
#打印医院主页医生列表接口返回
print(hospitals_request().doctor())
\ No newline at end of file
#详情
detail:
method: get
url: /api/hospitals/bjxyjcpfbyy/detail
params: {}
data: {}
json: {}
#医生列表
doctor:
method: get
url: /api/hospitals/bjxyjcpfbyy/doctors
params:
related: 0
data: {}
json: {}
\ No newline at end of file
import path_setting
from in_common.base_request import BaseRequest
class search_request(BaseRequest):
def __init__(self):
self.data = self.api_load(path_setting.KEYWORDS_CONFIG)
#搜索首页-热门搜索模块(点击搜索框即调接口)
def keywords(self,current_city_id,search_tab):
self.params["current_city_id"] = current_city_id
self.params["search_tab"] = search_tab
return self.api_send(self.data["keywords"])
\ No newline at end of file
keywords:
method: get
#接口地址
url: /api/search/keywords
#列出所有定义函数时的参数
params:
current_city_id: ${current_city_id}
search_tab: ${search_tab}
data: {}
json: {}
\ No newline at end of file
import path_setting
from in_common.base_request import BaseRequest
class service_request(BaseRequest):
def __init__(self):
self.data = self.api_load(path_setting.HOME_V5_CONFIG)
def home_v5(self):
return self.api_send(self.data["home_v5"])
if __name__ == '__main__':
print(service_request().home_v5())
\ No newline at end of file
home_v5:
method: get
url: /api/service/home/v5
params: {}
data: {}
json: {}
import path_setting
from in_common.base_request import BaseRequest
class web2_request(BaseRequest):
def __init__(self):
self.data = self.api_load(path_setting.SERVICE_URL)
def service_list(self, page,pagesize,is_online):
self.params["page"] = page
self.params["pagesize"] = pagesize
self.params["is_online"] = is_online
return self.api_send(self.data["service_list"])
if __name__ == '__main__':
print(web2_request().service_list("1", "10", "-1"))
\ No newline at end of file
service_list:
method: get
url: /api/web2/service/list
params:
page: ${page}
pagesize: ${pagesize}
is_online: ${is_online}
data: {}
json: {}
\ No newline at end of file
develop_host:
url: http://backend.paas-develop.env
# url: http://doctor.paas-develop.env/
backend: http://backend.paas-develop.env
# doctor: http://doctor.paas-develop.env/
......@@ -4,6 +4,7 @@ import string
import requests
import yaml
from jsonpath import jsonpath
from login_session_function import LoginFunction
# from pymysql import OperationalError
import path_setting
......@@ -33,7 +34,7 @@ class BaseRequest:
if r is None:
r = self.r.json()
return jsonpath(r, path)
'''
def get_cookie(self, req: dict):
host = self.api_load(path_setting.HOSTYAML_CONFIG)
......@@ -50,15 +51,6 @@ class BaseRequest:
for i in r.cookies:
dict[i.name] = i.value
headers = '_gtid={};sessionid={}'.format(dict["_gtid"], dict["sessionid"])
# item = r.cookies.values()
# print("ppppppp",item)
# if len(item) == 1:
# headers = '_gtid={}'.format(item[0])
# print("cookie异常")
#
# else:
# headers = '_gtid={};sessionid={}'.format(item[0], item[1])
#
return headers
def read_header(self):
......@@ -66,27 +58,24 @@ class BaseRequest:
cookies = f.read()
headers = {"cookie": cookies}
return headers
'''
# 接口请求的封装
def api_send(self, req: dict):
host = self.api_load(path_setting.HOSTYAML_CONFIG)
raw = yaml.dump(req) # 将一个python对象生成为yaml文档
for key, value in self.params.items():
raw = raw.replace(f"${{{key}}}", repr(value))
req = yaml.safe_load(raw)
print('req:',req)
# print('------', req.get('headers'))
# hd = req.get('headers')
# if hd == None:
# user_headers = self.read_header()
# elif hd["Cookie"]:
# user_headers = req.get('headers')
# else:
# user_headers = self.read_header()
r = requests.request(
print('req:', req)
s = requests
if req.get('isLogin'):
s = LoginFunction().get_session()
# 调用具体case的url
r = s.request(
req['method'],
url=host['develop_host']['url'] + req['url'],
url=host['develop_host']['backend'] + req['url'],
params=req.get('params'),
# headers=user_headers,
data=req.get('data'),
......@@ -99,7 +88,7 @@ class BaseRequest:
return ''.join(random.sample(string.ascii_lowercase + string.digits, 32))
if __name__ == '__main__':
BaseRequest().api_load("../api/api.yaml")
# BaseRequest().api_load("../api/api.yaml")
# print(BaseApi().trace_id())
BaseRequest().read_header()
BaseRequest().a()
import path_setting
import requests
import yaml
"""
此文件是封装session的
"""
class LoginFunction:
def __init__(self):
self.host = self.login_yaml_load(path_setting.HOSTYAML_CONFIG)
self.params = self.login_yaml_load(path_setting.LOGIN_FUNCTION_DATA)
def login_yaml_load(self, path) -> list:
with open(path, encoding='utf-8') as f:
return yaml.safe_load(f)
def get_session(self):
hostList = self.host['develop_host']
for key in hostList:
if 'backend' == key:
return self.get_develop_session()
elif 'doctor' == key:
return self.get_doctor_session()
def get_develop_session(self):
url = self.host["develop_host"]["backend"] + self.params["backend_login"]["url"]
s = requests.session()
r = s.request(
self.params["backend_login"]["method"],
url=url,
params=self.params["backend_login"]["params"],
data=self.params["backend_login"]["data"],
headers={'Connection': 'close'}
)
return s
def get_doctor_session(self):
pass
if __name__ == '__main__':
LoginFunction().get_session()
\ No newline at end of file
backend_login:
method: POST
url: /api/account/login/login_vfc
params:
current_city_id: "beijing"
data:
phone_num: "+8612345678912"
vfc_code: 1234
vfc_type:
face_token:
#doctor_login:
# method: post
# url: /api
# params:
# a: "a"
# data:
# b: "b"
......@@ -4,9 +4,21 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.append(BASE_DIR)
HOSTYAML_CONFIG = os.path.join(BASE_DIR, "backend_auto", "host.yaml")
LOGIN_FUNCTION_DATA = os.path.join(BASE_DIR, "backend_auto", "login_session_function.yaml")
APYAML_CONFIG = os.path.join(BASE_DIR, "backend_auto/all_backend_api", "account_request.yaml")
LOGIN_VFC = os.path.join(BASE_DIR, "backend_auto/test_backend_data/account_data", "login_vfc.yaml")
DIARY_DATA_CONFIG = os.path.join(BASE_DIR, "backend_auto/all_backend_api", "diary_data_request.yaml")
DIARY_DATA = os.path.join(BASE_DIR, "backend_auto/test_backend_data/account_data", "diary_data.yaml")
#搜索首页-热门搜索
KEYWORDS_CONFIG = os.path.join(BASE_DIR, "backend_auto/all_backend_api", "search_request.yaml")
KEYWORDS = os.path.join(BASE_DIR, "backend_auto/test_backend_data/search_data", "keywords.yaml")
SERVICE_DATA=os.path.join(BASE_DIR, "backend_auto/test_doctor_data/web2_data", "service_list.yaml")
SERVICE_URL=os.path.join(BASE_DIR, "backend_auto/all_doctor_api", "web2_request.yaml")
# 首页灰度dev
FEED_INDEXV9_CONFIG = os.path.join(BASE_DIR, "backend_auto/all_backend_api", "feed_request.yaml")
......@@ -18,6 +30,12 @@ LOGIN_CONFIG = os.path.join(BASE_DIR, "backend_auto/all_backend_api", "accounts_
#医院主页详情
HDYAML_CONFIG = os.path.join(BASE_DIR, "backend_auto/all_backend_api", "hospitals_request.yaml")
HOSPITAL_DETAIL = os.path.join(BASE_DIR, "backend_auto/test_backend_data/hospitals_data", "detail.yaml")
#医院主页医生列表
HOSPITAL_DOCTOR = os.path.join(BASE_DIR, "backend_auto/test_backend_data/hospitals_data", "doctor.yaml")
HOME_V5_CONFIG = os.path.join(BASE_DIR, "backend_auto/all_backend_api", "service_request.yaml")
HOME_V5=os.path.join(BASE_DIR,"backend_auto/test_backend_data/service_data","home_v5.yaml")
if __name__ == '__main__':
......
from test_backend_case.account_case import test_login_vfc
from test_backend_case.account_case import test_diary_data
import pytest
......
import pytest
from ids_list import get_ids
import path_setting
from in_common.base_request import BaseRequest
from all_backend_api.diary_data_request import diary_data_reqest
class TestDIARYDATA:
data = BaseRequest().api_load(path_setting.DIARY_DATA)
diary_data_case, diary_data_data = get_ids(data, "diary_data")
@pytest.mark.parametrize("param",diary_data_data,ids=diary_data_case)
def test_diary_data(self,param):
# print(2)
r = diary_data_reqest().diary_data(param["current_city_id"], param["diary_referrer"], param["sort"], param["count"], param["start_num"])
# print(1)
if r["error"] == 0:
assert r["error"] == param["assert"]
# assert(r[""])
if r["error"] == 1:
assert r["error"] == param["assert"]
import pytest
import path_setting
@pytest.fixture()
def login():
self.data = self.api_load(path_setting.APYAML_CONFIG)
import pytest
from all_backend_api.hospitals_request import hospitals_request
from ids_list import get_ids
import path_setting
from in_common.base_request import BaseRequest
class TestDoctor:
data = BaseRequest().api_load(path_setting.HOSPITAL_DOCTOR)
doctor_case, doctor_data = get_ids(data, "doctor")
@pytest.mark.parametrize("param", doctor_data, ids=doctor_case)
def test_doctor(self, param):
r = hospitals_request().doctor()
assert r["error"] == param["assert_error"]
assert r["data"][0]["id"] == param["assert_id"]
assert r["data"][0]["doctor_name"] == param["assert_name"]
assert r["data"][0]["good_at"][0] == param["assert_good_at"]
assert r["data"][0]["cases"][0]["name"] == param["assert_cases"]
assert r["data"][0]["title"] == param["assert_title"]
import pytest
import path_setting
from all_backend_api.search_request import search_request
from ids_list import get_ids
from in_common.base_request import BaseRequest
#搜索首页-热门搜索
class TestKeywords:
data = BaseRequest().api_load(path_setting.KEYWORDS)
keywords_case, keywords_data = get_ids(data, "keywords")
@pytest.mark.parametrize("param", keywords_data, ids=keywords_case)
def test_keywords(self, param):
r = search_request().keywords(param["current_city_id"], param["search_tab"])
if r["error"] == 0:
assert r["error"] == param["assert"]
print("接口调用成功了~")
import pytest
from ids_list import get_ids
import path_setting
from in_common.base_request import BaseRequest
from all_backend_api.service_request import service_request
class TestHomeV5:
data = BaseRequest().api_load(path_setting.HOME_V5)
homev5_case, homev5_data = get_ids(data, "home_v5")
print(data)
@pytest.mark.parametrize("param",homev5_data,ids=homev5_case)
def test_home_v5(self,param):
#print(param["home_v5"])
r = service_request().home_v5()
print(r)
#if r["error"] == 0:
assert r["error"] == param["assert"]
diary_data:
#字段正常case
-
case: "接口正常case"
current_city_id: "beijing"
diary_referrer: "my_diary"
sort: 0
count: 8
start_num: 2
assert: 0
-
case: "接口传参数失败,但不报错case"
current_city_id: "beijing"
diary_referrer: "my_diary"
sort: 0
count: 8
start_num: 2
assert: 0
doctor:
-
case: "校验接口返回成功case"
assert_error: 0
assert_id: "ad99d0b0b6eb4a2c97ffadad48b7cdfd"
assert_name: "赵希军"
assert_good_at: "吸脂瘦身"
assert_cases: "自体脂肪填充面部 80例"
assert_title: "副主任"
-
case: "校验医生id case"
assert_error: 0
assert_id: "ad99d0b0b6eb4a2c97ffadad48b7cdfd"
assert_name: "赵希军"
assert_good_at: "吸脂瘦身"
assert_cases: "自体脂肪填充面部 80例"
assert_title: "副主任"
-
case: "校验医生名称case"
assert_error: 0
assert_id: "ad99d0b0b6eb4a2c97ffadad48b7cdfd"
assert_name: "赵希军"
assert_good_at: "吸脂瘦身"
assert_cases: "自体脂肪填充面部 80例"
assert_title: "副主任"
-
case: "校验医生明星项目case"
assert_error: 0
assert_id: "ad99d0b0b6eb4a2c97ffadad48b7cdfd"
assert_name: "赵希军"
assert_good_at: "吸脂瘦身"
assert_cases: "自体脂肪填充面部 80例"
assert_title: "副主任"
-
case: "校验医生案例case"
assert_error: 0
assert_id: "ad99d0b0b6eb4a2c97ffadad48b7cdfd"
assert_name: "赵希军"
assert_good_at: "吸脂瘦身"
assert_cases: "自体脂肪填充面部 80例"
assert_title: "副主任"
-
case: "校验医生title case"
assert_error: 0
assert_id: "ad99d0b0b6eb4a2c97ffadad48b7cdfd"
assert_name: "赵希军"
assert_good_at: "吸脂瘦身"
assert_cases: "自体脂肪填充面部 80例"
assert_title: "副主任"
\ No newline at end of file
keywords:
-
#进入搜索首页
case : "进入搜索首页-成功调用搜索首页接口"
current_city_id : "beijing"
search_tab : "0"
assert : 0
home_v5:
#获取商城首页
-
case: "获取商城首页--case首页"
assert: 0
import pytest
import path_setting
from all_doctor_api.web2_request import web2_request
from ids_list import get_ids
from in_common.base_request import BaseRequest
class TestServiceList:
data = BaseRequest().api_load(path_setting.SERVICE_DATA)
ServiceList_case, ServiceList_data = get_ids(data, "service_list")
@pytest.mark.parametrize("params",ServiceList_data,ids=ServiceList_case)
def test_ServiceList(self,params):
r = web2_request().service_list(params['page'],params['pagesize'],params['is_online'])
if r["error"] == 0:
assert r["data"]["page"] == params["assert"]
elif r["error"] == 1:
assert r["message"] == params["assert"]
# else:
# assert r['error'] == 0
\ No newline at end of file
service_list:
#有数据返回
-
case: "数据"
page: "1"
pagesize: "10"
is_online: "-1"
assert: "1"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment