Commit a0965458 authored by 邓莹莹's avatar 邓莹莹

first commit

parents
File added
product_host:
url: https://backend.igengmei.com
\ No newline at end of file
'''
生产环境,公用的方法放到此处,例如json format,yaml文件加载等等
'''
import requests
import yaml
import json
from igengmei_product.common import setting_path
class CommonUnit:
params = {}
print("-------------", params)
@classmethod
def format(cls, r):
cls.r = r
print(json.dumps(json.loads(r.text), indent=2, ensure_ascii=False))
# 封装yaml文件读取
@classmethod
def yaml_load(cls, path) -> list:
with open(path, encoding='utf-8') as f:
return yaml.safe_load(f)
# 调用yaml加载文件API加载
def api_data(self, path):
return self.yaml_load(path)
# 接口请求封装方法
def api_unit(self, req: dict):
print("-------------", self.params)
host = self.api_data(setting_path.DATA_AREANAME)
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("PPPPPPPPPPPPP", req)
req.get('params').update(self.params)
r = requests.request(
req['method'],
url=host['product_host']['url'] + req['url'],
params=req.get('params'),
headers=req.get('headers'),
data=req.get('data'),
json=req.get('json'),
verify=False
)
# print(self.format(r))
print("@@@@@@@@@@@@@@@@", req.get('params'))
print(r.url)
return r.json()
params: &params
platform: iPhone
os_version: 11.4.1
version: 7.34.0
model: iPhone7
release: 1
idfa: 65D3E5E7-DB71-43F3-910D-B0345C752419
idfv: 63823FBA-E745-44AF-9D15-2B3607523B0E
device_id: 65D3E5E7-DB71-43F3-910D-B0345C752419
uqid: 077E8F87-0772-4A03-B50F-EB9FB1645E4D
channel: App Store
app_name: gengmeiios
current_city_id: beijing
lat: 40.00199012279485
lng: 116.4874351590459
is_WiFi: 1
hardware_model: iPhone9,1
cookie: &cookie
Cookie: _gm_token=6b497d1605166515; tgw_l7_route=7a6d1b86fdb757c76599152f7e2b2bc4; csrftoken=y9YpqJD61ircjBdbcJw24jJSjcFYdQhw; sessionid=a1kdgfzyilwb4ysv1rlmco2n79xuu6an; _gtid=00795100232511eb991a32227309dc589809
homepage_icon_v2:
method: get
url: /api/index/homepage_icon_v2
headers: *cookie
params: *params
data: {}
json: {}
api_index_v8:
method: get
url: /api/index/v8
headers: *cookie
params: *params
data: {}
json: {}
api_service_home_v5_specials:
method: get
url: /api/service/home/v5/specials
headers: *cookie
params: *params
data: {}
json: {}
api_service_home_feed:
method: get
url: /api/service/home/feed
headers: *cookie
params: *params
data: {}
json: {}
api_service_home_find_goods:
method: get
url: /api/service/home/find_goods
headers: *cookie
params: *params
data: {}
json: {}
api_service_home_v5:
method: get
url: /api/service/home/v5
headers: *cookie
params: *params
data: {}
json: {}
api_notification_unread:
method: get
url: /api/notification/unread
params: *params
data: {}
json: {}
headers: *cookie
api_shopcart_list_v2:
method: get
url: /api/shopcart/list/v2
params: *params
data: {}
json: {}
headers: *cookie
api_category_polymer:
method: get
url: /api/category/polymer
headers: *cookie
params: *params
data: {}
json: {}
api_feeds_tag_service:
method: get
url: /api/feeds/tag_service
headers: *cookie
params: *params
data: {}
json: {}
api_cache_data_service_filter_v1:
method: get
url: /api/cache/data/service_filter/v1
headers: *cookie
params: *params
data: {}
json: {}
api_polymerization_content:
method: get
url: /api/polymerization/content
headers: *cookie
params: *params
api_search_v2_hospital:
method: get
url: /api/search/v2/hospital
headers: *cookie
params: *params
api_search_v2_new_wiki:
method: get
url: /api/search/v2/new_wiki
headers: *cookie
params: *params
api_search_v2_doctor:
method: get
url: /api/search/v2/doctor
headers: *cookie
params: *params
api_visual_page_detail:
method: get
url: /api/visual/page/detail
headers: *cookie
params: *params
api_visual_service_list:
method: get
url: /api/visual/service_list
headers: *cookie
params: *params
api_visual_unit_filter:
method: get
url: /api/visual/unit_filter
headers: *cookie
params: *params
\ No newline at end of file
这个是针对线上接口的定时监控脚本
首页接口 api:
api/index/homepage_icon_v2
api/index/v8
api/notification/unread
首页品类聚合触发接口
api/shopcart/list/v2 购物车数量接口
api/category/polymer 品类聚合页面结构
api/feeds/tag_service 商品feed流
api/cache/data/service_filter/v1 商品类目筛选项
api/polymerization/content 商品中的社区
api/search/v2/new_wiki 商品百科
api/search/v2/doctor 商品医生
api/search/v2/hospital 商品医院
自定义专题接口
api/visual/page/detail 专题搭建架构
api/visual/unit_filter 筛选项接口
api/visual/service_list 专题商品列表
商城接口
api/notification/unread
api/service/home/feed 商城feed流
api/service/home/v5/specials 商城活动专场
api/service/home/v5 商城页面架构
/api/service/home/find_goods 商城首页接口,不知道作用,返回是空
from igengmei_product.common import setting_path
from igengmei_product.common.common_unit import CommonUnit
class Sendapi(CommonUnit):
def __init__(self):
self.data = self.api_data(setting_path.DATA_API)
# a=self.api_data(setting_path.DATA_PRODUCT)
# print(a)
'''
首页相关接口
'''
def homepage_icon_v2(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
# print("00000000000000000", self.params)
return self.api_unit(self.data["homepage_icon_v2"])
print(self.api_unit(self.data["homepage_icon_v2"]))
def api_index_v8(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_index_v8"])
print(self.api_unit(self.data["api_index_v8"]))
'''
商城首页接口
'''
def api_service_home_v5_specials(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_service_home_v5_specials"])
print(self.api_unit(self.data["api_service_home_v5_specials"]))
def api_service_home_find_goods(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_service_home_find_goods"])
def api_service_home_v5(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data[ "api_service_home_v5"])
def api_notification_unread(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_notification_unread"])
def api_service_home_feed(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_service_home_feed"])
'''
首页品类聚合触发接口
'''
def api_shopcart_list_v2(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_shopcart_list_v2"])
def api_category_polymer(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_category_polymer"])
def api_feeds_tag_service(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_feeds_tag_service"])
def api_cache_data_service_filter_v1(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_cache_data_service_filter_v1"])
def api_polymerization_content(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_polymerization_content"])
def api_search_v2_hospital(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_search_v2_hospital"])
def api_search_v2_new_wiki(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_search_v2_new_wiki"])
def api_search_v2_doctor(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_search_v2_doctor"])
'''
自定义专题接口
'''
def api_visual_service_list(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_visual_service_list"])
def api_visual_page_detail(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_visual_page_detail"])
def api_visual_unit_filter(self, **kwargs):
self.params.clear()
self.params.update(kwargs)
return self.api_unit(self.data["api_visual_unit_filter"])
if __name__ == '__main__':
Sendapi().api_service_home_v5_specials()
# Sendapi().api_service_home_find_goods()
# Sendapi().api_service_home_v5()
# Sendapi().api_notification_unread()
# Sendapi().api_category_polymer()
# Sendapi().api_shopcart_list_v2()
# Sendapi().homepage_icon_v2()
# Sendapi().api_index_v8()
# Sendapi().api_feeds_tag_service()
# Sendapi().api_cache_data_service_filter_v1()
# Sendapi().api_polymerization_content()
# Sendapi().api_search_v2_hospital()
# Sendapi().api_search_v2_new_wiki()
# Sendapi().api_search_v2_doctor()
# Sendapi().api_visual_page_detail()
# Sendapi().api_visual_service_list()
# Sendapi().api_visual_unit_filter()
import os, sys
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.append(BASE_DIR)
DATA_AREANAME = os.path.join(BASE_DIR, "common", "areaname.yaml")
DATA_API = os.path.join(BASE_DIR, "common", "product_api.yaml")
DATA_PRODUCT = os.path.join(BASE_DIR, "testData", "test_product_data.yaml")
import pytest
from igengmei_product.common import setting_path
from igengmei_product.common.common_unit import CommonUnit
from igengmei_product.common.send_api import Sendapi
class Test_product:
data = CommonUnit().api_data(setting_path.DATA_PRODUCT)
print("===============", data)
@pytest.mark.parametrize("params", data["homepage_icon_v2"])
def test_homepage_icon_v2(self, params):
r = Sendapi().homepage_icon_v2(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_index_v8"])
def test_api_index_v8(self, params):
r = Sendapi().api_index_v8(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_service_home_v5_specials"])
def test_api_service_home_v5_specials(self, params):
r = Sendapi().api_service_home_v5_specials(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_service_home_v5"])
def test_api_service_home_v5(self, params):
r = Sendapi().api_service_home_v5(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_service_home_feed"])
def test_api_service_home_feed(self, params):
r = Sendapi().api_service_home_feed(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_service_home_find_goods"])
def test_api_service_home_find_goods(self, params):
r = Sendapi().api_service_home_find_goods(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_notification_unread"])
def test_api_notification_unread(self, params):
r = Sendapi().api_notification_unread(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_visual_service_list"])
def test_api_visual_service_list(self, params):
r = Sendapi().api_visual_service_list(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_visual_unit_filter"])
def test_api_visual_unit_filter(self, params):
r = Sendapi().api_visual_unit_filter(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_visual_page_detail"])
def test_api_visual_page_detail(self, params):
r = Sendapi().api_visual_page_detail(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_shopcart_list_v2"])
def test_api_shopcart_list_v2(self, params):
r = Sendapi().api_shopcart_list_v2(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_category_polymer"])
def test_api_category_polymer(self, params):
r = Sendapi().api_category_polymer(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_feeds_tag_service"])
def test_api_feeds_tag_service(self, params):
r = Sendapi().api_feeds_tag_service(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_cache_data_service_filter_v1"])
def test_api_cache_data_service_filter_v1(self, params):
r = Sendapi().api_cache_data_service_filter_v1(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_polymerization_content"])
def test_api_polymerization_content(self, params):
r = Sendapi().api_polymerization_content(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_search_v2_hospital"])
def test_api_search_v2_hospital(self, params):
r = Sendapi().api_search_v2_hospital(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_search_v2_new_wiki"])
def test_api_search_v2_new_wiki(self, params):
r = Sendapi().api_search_v2_new_wiki(**params)
assert r["error"] == 0
@pytest.mark.parametrize("params", data["api_search_v2_doctor"])
def test_api_search_v2_doctor(self, params):
r = Sendapi().api_search_v2_doctor(**params)
assert r["error"] == 0
if __name__ == '__main__':
Test_product().test_homepage_icon_v2()
homepage_icon_v2:
-
trace_id: '2020/11/11/1554/6de5eb248711'
-
trace_id: '2020/11/11/1554/6de5eb248710'
-
trace_id: '2020/11/11/1554/6de5eb248709'
api_index_v8:
-
count: 10
deeplink_tags: ""
offset: ""
page: 1
tab_id: ""
tabtype: ""
tags_id: ""
user_id: 31910018
-
count: 10
deeplink_tags: ""
offset: "A=0&C=0&B=0&E=0&D=0&G=0&F=0&I=0&H=0&K=0&J=0&M=0&L=0&O=0&N=0&Q=0&P=0&S=0&R=0&U=0&T=0&W=0&V=0&Y=0&page=1"
page: 3
tab_id: 0
tabtype: choice
tags_id: []
user_id: 31910018
-
count: 10
deeplink_tags: ""
offset: "A=0&C=0&B=0&E=0&D=0&G=0&F=0&I=0&H=0&K=0&J=0&M=0&L=0&O=0&N=0&Q=0&P=0&S=0&R=0&U=0&T=0&W=0&V=0&Y=0&page=2"
page: 5
tab_id: 0
tabtype: choice
tags_id: []
user_id: 31910018
api_service_home_v5_specials:
-
trace_id: '2020/11/11/1554/6de5eb248711'
api_service_home_v5:
-
trace_id: '2020/11/11/1554/6de5eb248711'
api_service_home_find_goods:
-
trace_id: '2020/11/11/1554/6de5eb248711'
api_service_home_feed:
-
trace_id: "2020/11/12/1428/7b40d63d6fbe"
area_id: ""
count: 10
current_city_id: beijing
first_load: 1
max_price: ""
min_price: ""
more_filters: ""
offset: ""
order_by: 0
tab_value: service
tag_id: ""
tag_ids: ""
api_notification_unread:
-
trace_id: "2020/11/12/1428/7b40d63d6fbe"
api_visual_service_list:
-
json: ""
unit_id: 20554
page: 0
page_size: 10
tag_ids: ""
order_by: 0
area: worldwide
api_visual_unit_filter:
-
json: ""
unit_id: 20554
api_visual_page_detail:
-
json: ""
page_id: 982
api_shopcart_list_v2:
-
trace_id: "2020/11/12/1428/7b40d63d6fbe"
count_only: 0
-
trace_id: "2020/11/12/1428/7b40d63d6fbe"
count_only: 1
api_category_polymer:
-
trace_id: "2020/11/12/1428/7b40d63d6fbe"
category_polymer_id: 9
api_feeds_tag_service:
-
area_id: ""
area_ref: ""
feed: ""
count: 10
coupon_info_id: ""
cp_id: 9
doctor_id: ""
hospital_id: ""
is_new_tag: ""
max_price: ""
min_price: ""
more_filters: ""
offset: 10
order_by: 0
page_ref: category
referrer: ""
tag_id: ""
tag_ids: "152,885,197,777,115,137,5074,14198,1055,14699,954,200,203,776,141,99,121,123,243,97,868,2412,804"
api_cache_data_service_filter_v1:
-
trace_id: "2020/11/12/1428/7b40d63d6fbe"
api_polymerization_content:
-
trace_id: "2020/11/12/1428/7b40d63d6fbe"
category_polymer_id: 9
new_tag: ""
page: 1
sort_type: 0
source_from: ""
tabtype: choice
tag_id: ""
tag_ids: "[152,885,197,777,115,137,5074,14198,1055,14699,954,200,203,776,141,99,121,123,243,97,868,2412,804]"
target_id: ""
target_type: 0
api_search_v2_hospital:
-
trace_id: "2020/11/12/1428/7b40d63d6fbe"
advanced_filter: ""
area_id: ""
area_ref: feed
count: 10
input_type: 2
is_gray: 1
order_by: 0
page_ref: category
q: "玻尿酸/填充"
start_num: 0
tag_id: ""
api_search_v2_new_wiki:
-
trace_id: "2020/11/12/1428/7b40d63d6fbe"
area_ref: ""
count: 10
is_gray: 1
page_ref: ""
q: "玻尿酸/填充"
start_num: 0
api_search_v2_doctor:
-
trace_id: "2020/11/12/1428/7b40d63d6fbe"
advanced_filter: ""
area_id: ""
area_ref: feed
count: 10
input_type: 2
is_gray: 1
order_by: 0
page_ref: category
q: "玻尿酸/填充"
start_num: 0
tag_id: ""
File added
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