代码拉取完成,页面将自动刷新
import os
import random, redis
import uuid
from locust import task, between, HttpUser, constant
from locust.contrib.fasthttp import FastHttpUser
import json
import re
import bodyhtml
import time
shippingPlans_key = "shippingPlans_key"
phoneCode = "phoneCode"
Key_collections_handle = "1collections_handles"
Key_storeIds = "1storeIds"
Key_Customer = "1Customer_Email"
Key_Product_id = "1Product_id"
Key_product_title = "1product_title"
Key_product_vendor = "1product_vendor"
Key_product_productTypeList = "1product_productTypeList"
Key_product_tags = "1product_tags"
Key_CountryCode = "1CountryCode"
Key_currencies = "1currencies"
Key_collectionIdList = "1collectionIdList"
Key_product_handle = "1product_handle"
Key_product_sku = "1product_sku"
Key_search_suggest = "1search_suggest"
Key_cart_variantId = "1cart_variantId"
Key_collection_title = "Key_collection_title"
Key_metafield_name = "metafield_name"
Key_metafield_key = "Key_metafield_key"
Key_metafield_type = "metafield_type"
Key_file_url = "Key_file_url"
phonenumber = "phonenumber"
product_image_id = "product_image_id"
metafield_id = "metafield_id"
metafield_collections_id = "metafield_collections_id"
metafield_variant_id = "metafield_variant_id"
product_id = "product_id"
product_handle = "product_handle"
product_sku = "product_sku"
collection_id = "collection_id"
collection_handle = "collection_handle"
collection_title = "collection_title"
collection_product = "collection_product"
collection_manual_id = "collection_manual_id"
collection_manual_handle = "collection_manual_handle"
collection_manual_title = "collection_manual_title"
shippingCountrys = "shippingCountrys"
collection_auto_id = "collection_auto_id"
collection_auto_handle = "collection_auto_handle"
collection_auto_title = "collection_auto_title"
Key_metafield_value = "Key_metafield_value"
page_id = "page_id"
page_handle = "page_handle"
customer = "customer"
menus_id = "menus_id"
menus_handle = "menus_handle"
shipping = "shipping"
CountryCodes = "CountryCodes"
page_title = "page_title"
CountryCodesProvince = "CountryCodesProvince"
collection_condition = ["all", "or"]
collection_type = ["manual", "manual", "manual"]
collection_item_condition = ["isEqualTo", "isNotEqualTo", "startWith", "endWith", "contains", "doesNotContain"]
flage_metafield_products = "metafield_products"
flage_metafield_collections = "metafield_collections"
collection_key_values = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
"t", "u", "v", "w", "x", "y", "z", "A"]
product_title = "product_title"
class MaiYuanTaskSet(HttpUser):
wait_time = constant(1)
host = 'https://api.beta.lazyshop.com'
def on_start(self):
self.pool = redis.ConnectionPool(host='localhost', password="maiyuan123", port=6379, decode_responses=True)
# self.pool = redis.ConnectionPool(host='localhost', port=6379, decode_responses=True)
self.r = redis.Redis(connection_pool=self.pool)
# self.len_storeIds = self.r.llen(Key_storeIds)
# self.len_collections_handle = self.r.llen(Key_collections_handle)
# self.token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJHVUVTVCJdLCJhZG1pbl9pZCI6IjllNTZjYjYzLWUxZmYtNDYyNS1hYjc3LTNiYjIyNWE4ZWYyMSIsImFkbWluX3JvbGVzIjpbIkFETUlOOlNVUEVSQURNSU4iXSwiaXNzIjoibGF6eXNob3A6cGVybWlzc2lvbiIsImN1c3RvbWVyX2lkIjoiZTQ0ZTBlMmEtYWQ3Ny00ZDVkLWFmZjYtNTAzY2NhMGNlOTM5IiwiZXhwIjoxNjY3Mjk1MDY4LCJpYXQiOjE2MzU3NTg5NDgsInNvdXJjZV9pcCI6IjExMi4xMDMuNDUuMTQyIn0.LxevxaHH7oihN096c0KOogOJgVluwyh0bOYcmGYJdsY"
self.token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJHVUVTVCJdLCJhZG1pbl9pZCI6ImM5Njc1OWI1LWQzOTYtNDE2NC05MmY0LTNlYTE0ZmVjOGE4YiIsImFkbWluX3JvbGVzIjpbIkFETUlOOlNVUEVSQURNSU4iXSwiaXNzIjoibGF6eXNob3A6cGVybWlzc2lvbiIsImN1c3RvbWVyX2lkIjoiMzM4MmNiYTMtMzQ1NS00YTVkLWEwOTYtYWIzYzliNTAzNjNkIiwiZXhwIjoxNjY4OTI2OTY3LCJpYXQiOjE2MzczOTA4NDcsInNvdXJjZV9pcCI6IjQyLjE4NS42OS4xMSJ9.Z231SIL77wZeYuOJTVcBYk5FR5qTOFuBJ7-yiR2BWJo"
# self.collectionIdList = self.r.llen(Key_collectionIdList) - 1
# self.product_ID = self.r.llen(Key_Product_id) - 1
# self.product_handle = self.r.llen(Key_product_handle) - 1
# self.currencies = self.r.llen(Key_currencies) - 1
# self.search_suggest = self.r.llen(Key_search_suggest) - 1
# self.cart_variantId = self.r.llen(Key_cart_variantId) - 1
self.metafield_total_count = 0
self.file_hashMap = ["PRODUCT", "COLLECTION", "PRODUCT", "PRODUCT", "PRODUCT"]
self.file_oss = [True, False]
self.Key_path_file = "Key_path_file"
# self.file_name(r"/home/ec2-user/imagefile")
self.store_count = 0
self.password = "P12345678"
self.page = 1
# self.resources_currencies()
# ok
def file_name(self, file_dir):
for root, dirs, files in os.walk(file_dir):
for file in files:
self.r.sadd(self.Key_path_file, os.path.join(root, file))
print(os.path.join(root, file))
# # NO.1
# @task(1)
def stores_post(self):
if self.token == None and self.store_count > 2:
return
uid = str(uuid.uuid4())
suid = ''.join(uid.split('-'))
body = {
"name": "name-{}".format(suid),
"symbol": "symbol-{}".format(suid),
}
header = {
"token": self.token,
}
with self.client.post("/stores", headers=header, name="stores_post", data=body,
catch_response=True) as response:
print(response.status_code)
print(response.text)
if response.status_code == 200 and response.text.find('SUCCESS') > -1:
respdata = json.loads(response.text)
if respdata.get("data") is not None:
store = respdata.get("data").get("store")
if store is not None:
storeId = store.get("id")
self.r.sadd(Key_storeIds, storeId)
self.store_count = self.store_count + 1
print(storeId)
response.success()
else:
response.failure('stores_post Failed!')
# NO.2
# 新增元数据模板
# @task(3)
def products_metafield_add(self):
if self.token == None:
return
name = self.r.srandmember(Key_metafield_name)
key = "{}{}{}{}{}{}{}".format(collection_key_values[random.randint(0, len(collection_key_values) - 1)],
collection_key_values[random.randint(0, len(collection_key_values) - 1)],
collection_key_values[random.randint(0, len(collection_key_values) - 1)],
collection_key_values[random.randint(0, len(collection_key_values) - 1)],
collection_key_values[random.randint(0, len(collection_key_values) - 1)],
collection_key_values[random.randint(0, len(collection_key_values) - 1)],
collection_key_values[random.randint(0, len(collection_key_values) - 1)])
body = {
"description": "black coller",
"key": key,
"name": "{}_{}".format(name, key),
"namespace": "namespace_{}".format(name),
"type": self.r.srandmember(Key_metafield_type),
"typeConfig": {"color": "#58514"}
}
storeId = self.r.srandmember(Key_storeIds)
header = {
"Content-Type": "application/json",
"token": self.token,
"store-id": storeId
}
# print(body)
with self.client.post("/products/metafield", headers=header, name="products_metafield_add",
data=json.dumps(body),
catch_response=True) as response:
# print(response.status_code)
# print(response.text)
if response.status_code == 200 and response.text.find('"code":200') > -1:
response.success()
else:
print(response.text)
response.failure('collections_post Failed!')
# NO.2
# 查询元数据模板列表
# @task(1)
def products_metafield_get(self):
if self.token == None:
return
body = {
"limit": 100,
"page": random.randint(1, 1)
}
storeId = self.r.srandmember(Key_storeIds)
header = {
"token": self.token,
"store-id": storeId
}
# print(body)
with self.client.get("/products/metafield", headers=header, name="products_metafield_get",
params=body, catch_response=True) as response:
# print(response.status_code)
# print(response.text)
if response.status_code == 200 and response.text.find('"code":200') > -1:
respdata = json.loads(response.text)
if respdata.get("data") is not None:
metafieldTemplates = respdata.get("data").get("metafieldTemplates")
if metafieldTemplates is not None and len(metafieldTemplates) > 0:
for item in metafieldTemplates:
print(item.get("id"))
self.r.sadd(storeId + metafield_id, item.get("id"))
self.r.set(flage_metafield_products + item.get("id"), "metafield_" + item.get("type"))
response.success()
else:
print(response.text)
response.failure('collections_post Failed!')
# # NO.3
# 新增元数据模板
# @task(3)
def collections_metafield_add(self):
if self.token == None:
print(1)
return
name = self.r.srandmember(Key_metafield_name)
key = "{}{}{}{}{}{}{}".format(collection_key_values[random.randint(0, len(collection_key_values) - 1)],
collection_key_values[random.randint(0, len(collection_key_values) - 1)],
collection_key_values[random.randint(0, len(collection_key_values) - 1)],
collection_key_values[random.randint(0, len(collection_key_values) - 1)],
collection_key_values[random.randint(0, len(collection_key_values) - 1)],
collection_key_values[random.randint(0, len(collection_key_values) - 1)],
collection_key_values[random.randint(0, len(collection_key_values) - 1)])
body = {
"description": "black coller",
"key": key,
"name": "{}_{}".format(name, key),
"namespace": "namespace_{}".format(name),
"type": self.r.srandmember(Key_metafield_type),
"typeConfig": {"color": "#58514"}
}
storeId = self.r.srandmember(Key_storeIds)
header = {
"Content-Type": "application/json",
"token": self.token,
"store-id": storeId
}
# print(body)
with self.client.post("/collections/metafield", headers=header, name="collections_metafield_add",
data=json.dumps(body),
catch_response=True) as response:
# print(response.status_code)
# print(response.text)
if response.status_code == 200 and response.text.find('"code":200') > -1:
response.success()
else:
print(response.status_code)
print(response.text)
response.failure('collections_metafield_add Failed!')
# # NO.3
# 查询元数据模板列表
# @task(1)
def collections_metafield_get(self):
if self.token == None:
return
body = {
"limit": 100,
"page": random.randint(1, 1)
}
storeId = self.r.srandmember(Key_storeIds)
header = {
"token": self.token,
"store-id": storeId
}
# print(body)
with self.client.get("/collections/metafield", headers=header, name="collections_metafield_get",
params=body, catch_response=True) as response:
# print(response.status_code)
# print(response.text)
if response.status_code == 200 and response.text.find('"code":200') > -1:
respdata = json.loads(response.text)
if respdata.get("data") is not None:
metafieldTemplates = respdata.get("data").get("metafieldTemplates")
if metafieldTemplates is not None and len(metafieldTemplates) > 0:
for item in metafieldTemplates:
print(item.get("id"))
self.r.sadd(storeId + metafield_collections_id, item.get("id"))
self.r.set(flage_metafield_collections + item.get("id"), "metafield_" + item.get("type"))
response.success()
else:
print(response.text)
response.failure('collections_metafield_get Failed!')
# NO.4 文件上传ok1
# @task(1)
def files_post(self):
if self.token == None:
return
storeId = self.r.srandmember(Key_storeIds)
header = {
"token": self.token,
"store-id": storeId
}
prefix = self.file_hashMap[random.randint(0, len(self.file_hashMap) - 1)]
body = {
"hashMap": '{"prefix": "' + prefix + '"}',
}
file_path = self.r.srandmember(self.Key_path_file)
file_data = {"file": open(file_path, 'rb')}
with self.client.post("/files", headers=header, name="files_post", data=body,
files=file_data, catch_response=True) as response:
# print(response.status_code)
# print(response.text)
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
respdata = json.loads(response.text)
if respdata.get("data") is not None:
urlbody = respdata.get("data").get("url")
if urlbody is not None:
if urlbody.get("url") is not None:
self.r.sadd(Key_file_url + prefix, urlbody.get("url"))
response.success()
else:
print(body)
print(header)
print(response.text)
response.failure('products_post Failed!')
#
# # # NO.5
# # 获取货币类型 ok
# @task(1)
def resources_currencies(self):
if self.token == None:
return
header = {
"token": self.token,
}
url = "/resources/currencies"
with self.client.get(url, headers=header, name="resources_currencies",
catch_response=True) as response:
print(response.text)
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
respdata = json.loads(response.text)
if respdata.get("data") is not None:
currencies = respdata.get("data").get("currencies")
if currencies is not None and len(currencies) > 0:
for item in currencies:
self.r.sadd(Key_currencies, item.get("code"))
print(item.get("code"))
response.success()
else:
response.failure('products_cache_all Failed!')
# # # N0.6
# @task(1)
def collections_post(self):
if self.token == None:
return
suid = ''.join(str(uuid.uuid4()).split('-'))
handle = "collections{}".format(suid)
storeId = self.r.srandmember(Key_storeIds)
title = "{}{}".format(self.r.srandmember(Key_collection_title), suid)
html = """<li class="site-nav-menu_pc site-nav-menu site-nav-pc">
<a href="/collections/mini-me" class="site-nav__link site-nav__link--main site-nav__link--active">
MINIME PILLOW
</a>
<ul class="site-nav list--inline" id="SiteNav"><li>
<ul class="site-nav list--inline" id="SiteNav"><li>
<ul class="site-nav list--inline" id="SiteNav"><li>"""
title_relation = collection_item_condition[random.randint(0, len(collection_item_condition) - 1)]
type_relation = collection_item_condition[random.randint(0, len(collection_item_condition) - 1)]
type_m_a = collection_type[random.randint(0, len(collection_type) - 1)]
# metafieldTemplateId1 = self.r.srandmember(storeId + metafield_collections_id)
# metafield_key1 = self.r.get(flage_metafield_collections + metafieldTemplateId1)
# metafieldTemplateId_value1 = self.r.srandmember(metafield_key1)
body = {
"bodyHtml": html,
"condition": collection_condition[random.randint(0, 1)],
"handle": handle,
"images": [
{
"alt": suid,
"position": random.randint(0, 30),
"src": self.r.srandmember(Key_file_url + "COLLECTION")
}, {
"alt": ''.join(str(uuid.uuid4()).split('-')),
"position": random.randint(0, 30),
"src": self.r.srandmember(Key_file_url + "COLLECTION")
}
],
# "metafields": [
# {
# "metafieldTemplateId": metafieldTemplateId1,
# "value": metafieldTemplateId_value1
# }
# ],
"rules": [
{
"colName": "title",
"condition": self.r.srandmember(Key_product_title + title_relation),
"relation": title_relation
},
{
"colName": "type",
"condition": self.r.srandmember(Key_product_productTypeList + type_relation),
"relation": type_relation
},
{
"colName": "tag",
"condition": self.r.srandmember(Key_product_tags + "isEqualTo"),
"relation": "isEqualTo"
}
],
"seoDescription": "seoDescription{}".format(suid),
"seoKeyWords": "seoKeyWords{}".format(suid),
"seoTitle": "seoTitle{}".format(suid),
"template": "",
"title": self.r.srandmember(Key_product_title),
"type": type_m_a
}
header = {
"Content-Type": "application/json",
"token": self.token,
"store-id": storeId
}
# print(header)
# print(body)
with self.client.post("/collections", headers=header, name="collections_post", data=json.dumps(body),
catch_response=True) as response:
if response.status_code == 200 and response.text.find('"code":200') > -1:
id = self.collections_id(storeId, handle)
if id is not False:
print("ok")
# print("strore id:{}".format(storeId))
# print("handle:{}".format(handle))
# print("id:{}".format(id))
self.r.sadd(collection_id + storeId, id)
self.r.sadd(collection_handle + storeId, handle)
self.r.sadd(collection_title + storeId, title)
if type_m_a == "manual":
self.r.sadd(collection_manual_id + storeId, id)
self.r.sadd(collection_manual_handle + storeId, handle)
self.r.set(collection_manual_handle + id, handle)
self.r.sadd(collection_manual_title + storeId, title)
else:
self.r.sadd(collection_auto_id + storeId, id)
self.r.sadd(collection_auto_handle + storeId, handle)
self.r.sadd(collection_auto_title + storeId, title)
self.r.set(collection_auto_handle + id, handle)
response.success()
else:
print("error")
print(response.status_code)
print(response.text)
response.failure('collections_post Failed!')
def collections_id(self, storeId, handle):
if self.token == None:
return
header = {
"token": self.token,
"store-id": storeId
}
# print(handle)
# print(storeId)
with self.client.get("/collections/{}".format(handle), headers=header, name="collections_id",
catch_response=True) as response:
# print(response.status_code)
# print(response.text)
if response.status_code == 200 and response.text.find('"code":200') > -1:
respdata = json.loads(response.text)
# print("code:".format(respdata.get("code")))
if respdata.get("data") is not None:
if respdata.get("data").get("collection") is not None:
# print("id:" + respdata.get("data").get("collection").get("id"))
return respdata.get("data").get("collection").get("id")
return False
# # N0.7
# @task(30)
# @task(2)
def products_post_single1(self):
if self.token == None:
return
uid = str(uuid.uuid4())
suid = ''.join(uid.split('-'))
handle = "products-limin-{}".format(suid)
storeId = self.r.srandmember(Key_storeIds)
# collectionIds = self.r.srandmember(collection_manual_id + storeId, random.randint(1, 3))
color = ["blue"]
size = ["size1", "size2", "size3", "size4", "size5", "size6", "size7", "size8"]
model = ["material1", "material2", "material3", "material4", "material5", "material6", "material7", "material8"
]
# metafieldTemplateId1 = self.r.srandmember(storeId + metafield_id)
# keyvalue1 = self.r.get(flage_metafield_products + metafieldTemplateId1)
sku1 = ''.join(str(uuid.uuid4()).split('-'))
title = "title{}".format(suid)
body = {
"allowTrackInventory": True,
"attributes": [
{
"optionName": "color",
"optionValues": color,
"position": 1,
"remark": "颜色"
}
],
"barcode": "barcode 条码123456",
"bodyHtml": bodyhtml.product_html,
# "collectionIds": collectionIds,
"handle": handle,
"images": [
{
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 1,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "png"
}, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 2,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "jpeg"
}
, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 3,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "jpeg"
}
, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 4,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "png"
}
, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 5,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "png"
}
],
"inventory": 20000,
"levyTariff": True,
# "metafields": [
# {
# "metafieldTemplateId": metafieldTemplateId1,
# "value": self.r.srandmember(keyvalue1)
# }
# ],
"method": "variants",
"originalPrice": 4.9,
"outOfStockBehavior": "off",
"productType": self.r.srandmember(Key_product_productTypeList),
"published": True,
"sellingPrice": 8.8,
"seoDescription": "SEO描述",
"seoKeywords": "SEO关键词1",
"seoTitle": title,
"sku": sku1,
"tags": [
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
}
],
"variants": [
{
"allowTrackInventory": True,
"barcode": "barcode 条码132432423456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[0],
"option2Name": "",
"option2Value": "",
"option3Name": "",
"option3Value": "",
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 9.9 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 1,
"sellingPrice": 8.8 + random.randint(0, 5),
"sku": "sku2",
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.3 + random.randint(0, 5),
"weightUnit": "kg"
}],
"tariffCode": "HS关税代码123456qq",
"template": "product",
"title": self.r.srandmember(Key_product_title),
"vendor": self.r.srandmember(Key_product_vendor),
"weight": 0.2 + random.randint(0, 5),
"weightUnit": "kg"
}
# print(body)
header = {
"Content-Type": "application/json",
"token": self.token,
"store-id": storeId
}
with self.client.post("/products", headers=header, name="products_post_single", data=json.dumps(body),
catch_response=True) as response:
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
id = self.get_product_id(storeId, handle)
if id is not False:
self.r.sadd(product_id + storeId, id)
self.r.sadd(product_handle + storeId, handle)
self.r.set(product_handle + id, handle)
self.r.set(product_title + id, title)
print(self.r.get(product_handle + id))
self.r.sadd(product_sku + storeId, sku1)
response.success()
else:
print(body)
print(" ")
print("*******************")
print(header)
print(response.status_code)
print(response.text)
response.failure('products_post Failed!')
# @task(10)
def products_post_single2(self):
if self.token == None:
return
uid = str(uuid.uuid4())
suid = ''.join(uid.split('-'))
handle = "products-limin-{}".format(suid)
storeId = self.r.srandmember(Key_storeIds)
# collectionIds = self.r.srandmember(collection_manual_id + storeId, random.randint(1, 3))
color = ["blue"]
size = ["size1", "size2", "size3", "size4", "size5", "size6", "size7", "size8"]
model = ["material1", "material2", "material3", "material4", "material5", "material6", "material7", "material8"
]
metafieldTemplateId1 = self.r.srandmember(storeId + metafield_id)
keyvalue1 = self.r.get(flage_metafield_products + metafieldTemplateId1)
sku1 = ''.join(str(uuid.uuid4()).split('-'))
title = "title{}".format(suid)
body = {
"allowTrackInventory": True,
"attributes": [
{
"optionName": "color",
"optionValues": color,
"position": 1,
"remark": "颜色"
}
],
"barcode": "barcode 条码123456",
"bodyHtml": bodyhtml.product_html,
# "collectionIds": collectionIds,
"handle": handle,
"images": [
{
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 1,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "png"
}, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 2,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "jpeg"
}
, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 3,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "jpeg"
}
, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 4,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "png"
}
, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 5,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "png"
}
],
"inventory": 20000,
"levyTariff": True,
"metafields": [
{
"metafieldTemplateId": metafieldTemplateId1,
"value": self.r.srandmember(keyvalue1)
}
],
"method": "variants",
"originalPrice": 4.9,
"outOfStockBehavior": "off",
"productType": self.r.srandmember(Key_product_productTypeList),
"published": True,
"sellingPrice": 8.8,
"seoDescription": "SEO描述",
"seoKeywords": "SEO关键词1",
"seoTitle": title,
"sku": sku1,
"tags": [
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
}
],
"variants": [
{
"allowTrackInventory": True,
"barcode": "barcode 条码132432423456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[0],
"option2Name": "",
"option2Value": "",
"option3Name": "",
"option3Value": "",
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 9.9 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 1,
"sellingPrice": 8.8 + random.randint(0, 5),
"sku": "sku2",
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.3 + random.randint(0, 5),
"weightUnit": "kg"
}],
"tariffCode": "HS关税代码123456qq",
"template": "product",
"title": self.r.srandmember(Key_product_title),
"vendor": self.r.srandmember(Key_product_vendor),
"weight": 0.2 + random.randint(0, 5),
"weightUnit": "kg"
}
# print(body)
header = {
"Content-Type": "application/json",
"token": self.token,
"store-id": storeId
}
with self.client.post("/products", headers=header, name="products_post_single_mMM", data=json.dumps(body),
catch_response=True) as response:
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
id = self.get_product_id(storeId, handle)
if id is not False:
self.r.sadd(product_id + storeId, id)
self.r.sadd(product_handle + storeId, handle)
self.r.set(product_handle + id, handle)
self.r.set(product_title + id, title)
self.r.sadd(product_sku + storeId, sku1)
response.success()
else:
print(body)
print(" ")
print("*******************")
print(header)
print(response.status_code)
print(response.text)
response.failure('products_post Failed!')
# # N0.7
# @task(90)
def products_post(self):
if self.token == None:
return
uid = str(uuid.uuid4())
suid = ''.join(uid.split('-'))
handle = "products-limin-{}".format(suid)
storeId = self.r.srandmember(Key_storeIds)
# collectionIds = self.r.srandmember(collection_manual_id + storeId, random.randint(1, 2))
color = ["blue", "red", "yellow", "green", "black", "pink", "red1", "yellow2"]
size = ["size1", "size2", "size3", "size4", "size5", "size6", "size7", "size8"]
model = ["material1", "material2", "material3", "material4", "material5", "material6", "material7", "material8"
]
metafieldTemplateId1 = self.r.srandmember(storeId + metafield_id)
keyvalue1 = self.r.get(flage_metafield_products + metafieldTemplateId1)
metafieldTemplateId2 = self.r.srandmember(storeId + metafield_id)
keyvalue2 = self.r.get(flage_metafield_products + metafieldTemplateId2)
sku1 = ''.join(str(uuid.uuid4()).split('-'))
sku2 = ''.join(str(uuid.uuid4()).split('-'))
sku3 = ''.join(str(uuid.uuid4()).split('-'))
sku4 = ''.join(str(uuid.uuid4()).split('-'))
sku5 = ''.join(str(uuid.uuid4()).split('-'))
sku6 = ''.join(str(uuid.uuid4()).split('-'))
sku7 = ''.join(str(uuid.uuid4()).split('-'))
sku8 = ''.join(str(uuid.uuid4()).split('-'))
sku9 = ''.join(str(uuid.uuid4()).split('-'))
title = "title{}".format(suid)
body = {
"allowTrackInventory": True,
"attributes": [
{
"optionName": "color",
"optionValues": color,
"position": 1,
"remark": "颜色"
},
{
"optionName": "size",
"optionValues": size,
"position": 2,
"remark": "大小"
},
{
"optionName": "model",
"optionValues": model,
"position": 3,
"remark": "型号"
}
],
"barcode": "barcode 条码123456",
"bodyHtml": bodyhtml.product_html,
# "collectionIds": collectionIds,
"handle": handle,
"images": [
{
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 1,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "png"
}, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 2,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "jpeg"
}
, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 3,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "jpeg"
}
, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 4,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "png"
}
, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 5,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "png"
}
],
"inventory": 200000,
"levyTariff": True,
# "metafields": [
# {
# "metafieldTemplateId": metafieldTemplateId1,
# "value": self.r.srandmember(keyvalue1)
# }, {
# "metafieldTemplateId": metafieldTemplateId2,
# "value": self.r.srandmember(keyvalue2)
# }
# ],
"method": "variants",
"originalPrice": 4.9,
"outOfStockBehavior": "off",
"productType": self.r.srandmember(Key_product_productTypeList),
"published": True,
"sellingPrice": 8.8,
"seoDescription": "SEO描述",
"seoKeywords": "SEO关键词1",
"seoTitle": title,
"sku": sku1,
"tags": [
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
}
],
"tariffCode": "HS关税代码123456qq",
"template": "product",
"title": self.r.srandmember(Key_product_title),
"variants": [
{
"allowTrackInventory": True,
"barcode": "barcode 条码132432423456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[0],
"option2Name": "size",
"option2Value": size[0],
"option3Name": "model",
"option3Value": model[0],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 19.9 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 1,
"sellingPrice": 28.8 + random.randint(0, 5),
"sku": sku2,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.3 + random.randint(0, 5),
"weightUnit": "kg"
},
{
"allowTrackInventory": True,
"barcode": "barcode 条码432123dd456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[1],
"option2Name": "size",
"option2Value": size[1],
"option3Name": "model",
"option3Value": model[1],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 9.4 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 2,
"sellingPrice": 8.7 + random.randint(0, 5),
"sku": sku3,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.9 + random.randint(0, 5),
"weightUnit": "kg"
},
{
"allowTrackInventory": True,
"barcode": "barcode 条码12233ddg456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[2],
"option2Name": "size",
"option2Value": size[2],
"option3Name": "model",
"option3Value": model[2],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 19.4 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 3,
"sellingPrice": 28.7 + random.randint(0, 5),
"sku": sku4,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.9 + random.randint(0, 5),
"weightUnit": "kg"
},
{
"allowTrackInventory": True,
"barcode": "barcode 条码123444ddg456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[3],
"option2Name": "size",
"option2Value": size[3],
"option3Name": "model",
"option3Value": model[3],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 9.4 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 3,
"sellingPrice": 8.7 + random.randint(0, 5),
"sku": sku5,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.9 + random.randint(0, 5),
"weightUnit": "kg"
},
{
"allowTrackInventory": True,
"barcode": "barcode 条码12332ddg456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[4],
"option2Name": "size",
"option2Value": size[4],
"option3Name": "model",
"option3Value": model[4],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 9.6 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 3,
"sellingPrice": 8.2 + random.randint(0, 5),
"sku": sku6,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.5 + random.randint(0, 5),
"weightUnit": "kg"
},
{
"allowTrackInventory": True,
"barcode": "barcode 条码123ddg33456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[5],
"option2Name": "size",
"option2Value": size[5],
"option3Name": "model",
"option3Value": model[5],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 6.2 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 3,
"sellingPrice": 8.2 + random.randint(0, 5),
"sku": sku7,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.5 + random.randint(0, 5),
"weightUnit": "kg"
},
{
"allowTrackInventory": True,
"barcode": "barcode 条码123ddg456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[6],
"option2Name": "size",
"option2Value": size[6],
"option3Name": "model",
"option3Value": model[6],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 3.1 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 3,
"sellingPrice": 8.2 + random.randint(0, 5),
"sku": sku8,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.5 + random.randint(0, 5),
"weightUnit": "kg"
},
{
"allowTrackInventory": True,
"barcode": "barcode 条码123ddg456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[7],
"option2Name": "size",
"option2Value": size[7],
"option3Name": "model",
"option3Value": model[7],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 7.7 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 3,
"sellingPrice": 8.2 + random.randint(0, 5),
"sku": sku9,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.5 + random.randint(0, 5),
"weightUnit": "kg"
}
],
"vendor": self.r.srandmember(Key_product_vendor),
"weight": 12.2 + random.randint(0, 50),
"weightUnit": "kg"
}
# print(body)
header = {
"Content-Type": "application/json",
"token": self.token,
"store-id": storeId
}
with self.client.post("/products", headers=header, name="products_post", data=json.dumps(body),
catch_response=True) as response:
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
id = self.get_product_id(storeId, handle)
if id is not False:
self.r.sadd(product_id + storeId, id)
self.r.sadd(product_handle + storeId, handle)
self.r.set(product_handle + id, handle)
self.r.set(product_title + id, title)
self.r.sadd(product_sku + storeId, sku1)
self.r.sadd(product_sku + storeId, sku2)
self.r.sadd(product_sku + storeId, sku3)
self.r.sadd(product_sku + storeId, sku4)
self.r.sadd(product_sku + storeId, sku5)
self.r.sadd(product_sku + storeId, sku6)
self.r.sadd(product_sku + storeId, sku7)
self.r.sadd(product_sku + storeId, sku8)
self.r.sadd(product_sku + storeId, sku9)
response.success()
else:
print(body)
print(" ")
print("*******************")
print(header)
print(response.status_code)
print(response.text)
response.failure('products_post Failed!')
# @task(15)
def products_post1(self):
if self.token == None:
return
uid = str(uuid.uuid4())
suid = ''.join(uid.split('-'))
handle = "products-limin-{}".format(suid)
storeId = self.r.srandmember(Key_storeIds)
# collectionIds = self.r.srandmember(collection_manual_id + storeId, random.randint(1, 2))
color = ["blue", "red", "yellow", "green", "black", "pink", "red1", "yellow2"]
size = ["size1", "size2", "size3", "size4", "size5", "size6", "size7", "size8"]
model = ["material1", "material2", "material3", "material4", "material5", "material6", "material7", "material8"
]
metafieldTemplateId1 = self.r.srandmember(storeId + metafield_id)
keyvalue1 = self.r.get(flage_metafield_products + metafieldTemplateId1)
metafieldTemplateId2 = self.r.srandmember(storeId + metafield_id)
keyvalue2 = self.r.get(flage_metafield_products + metafieldTemplateId2)
sku1 = ''.join(str(uuid.uuid4()).split('-'))
sku2 = ''.join(str(uuid.uuid4()).split('-'))
sku3 = ''.join(str(uuid.uuid4()).split('-'))
sku4 = ''.join(str(uuid.uuid4()).split('-'))
sku5 = ''.join(str(uuid.uuid4()).split('-'))
sku6 = ''.join(str(uuid.uuid4()).split('-'))
sku7 = ''.join(str(uuid.uuid4()).split('-'))
sku8 = ''.join(str(uuid.uuid4()).split('-'))
sku9 = ''.join(str(uuid.uuid4()).split('-'))
title = "title{}".format(suid)
body = {
"allowTrackInventory": True,
"attributes": [
{
"optionName": "color",
"optionValues": color,
"position": 1,
"remark": "颜色"
},
{
"optionName": "size",
"optionValues": size,
"position": 2,
"remark": "大小"
},
{
"optionName": "model",
"optionValues": model,
"position": 3,
"remark": "型号"
}
],
"barcode": "barcode 条码123456",
"bodyHtml": bodyhtml.product_html,
# "collectionIds": collectionIds,
"handle": handle,
"images": [
{
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 1,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "png"
}, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 2,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "jpeg"
}
, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 3,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "jpeg"
}
, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 4,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "png"
}
, {
"alt": self.r.srandmember(Key_file_url + "PRODUCT"),
"position": 5,
"src": self.r.srandmember(Key_file_url + "PRODUCT"),
# "type": "png"
}
],
"inventory": 200000,
"levyTariff": True,
"metafields": [
{
"metafieldTemplateId": metafieldTemplateId1,
"value": self.r.srandmember(keyvalue1)
}, {
"metafieldTemplateId": metafieldTemplateId2,
"value": self.r.srandmember(keyvalue2)
}
],
"method": "variants",
"originalPrice": 4.9,
"outOfStockBehavior": "off",
"productType": self.r.srandmember(Key_product_productTypeList),
"published": True,
"sellingPrice": 8.8,
"seoDescription": "SEO描述",
"seoKeywords": "SEO关键词1",
"seoTitle": title,
"sku": sku1,
"tags": [
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
},
{
"name": self.r.srandmember(Key_product_tags)
}
],
"tariffCode": "HS关税代码123456qq",
"template": "product",
"title": self.r.srandmember(Key_product_title),
"variants": [
{
"allowTrackInventory": True,
"barcode": "barcode 条码132432423456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[0],
"option2Name": "size",
"option2Value": size[0],
"option3Name": "model",
"option3Value": model[0],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 19.9 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 1,
"sellingPrice": 28.8 + random.randint(0, 5),
"sku": sku2,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.3 + random.randint(0, 5),
"weightUnit": "kg"
},
{
"allowTrackInventory": True,
"barcode": "barcode 条码432123dd456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[1],
"option2Name": "size",
"option2Value": size[1],
"option3Name": "model",
"option3Value": model[1],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 9.4 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 2,
"sellingPrice": 8.7 + random.randint(0, 5),
"sku": sku3,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.9 + random.randint(0, 5),
"weightUnit": "kg"
},
{
"allowTrackInventory": True,
"barcode": "barcode 条码12233ddg456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[2],
"option2Name": "size",
"option2Value": size[2],
"option3Name": "model",
"option3Value": model[2],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 19.4 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 3,
"sellingPrice": 28.7 + random.randint(0, 5),
"sku": sku4,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.9 + random.randint(0, 5),
"weightUnit": "kg"
},
{
"allowTrackInventory": True,
"barcode": "barcode 条码123444ddg456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[3],
"option2Name": "size",
"option2Value": size[3],
"option3Name": "model",
"option3Value": model[3],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 9.4 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 3,
"sellingPrice": 8.7 + random.randint(0, 5),
"sku": sku5,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.9 + random.randint(0, 5),
"weightUnit": "kg"
},
{
"allowTrackInventory": True,
"barcode": "barcode 条码12332ddg456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[4],
"option2Name": "size",
"option2Value": size[4],
"option3Name": "model",
"option3Value": model[4],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 9.6 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 3,
"sellingPrice": 8.2 + random.randint(0, 5),
"sku": sku6,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.5 + random.randint(0, 5),
"weightUnit": "kg"
},
{
"allowTrackInventory": True,
"barcode": "barcode 条码123ddg33456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[5],
"option2Name": "size",
"option2Value": size[5],
"option3Name": "model",
"option3Value": model[5],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 6.2 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 3,
"sellingPrice": 8.2 + random.randint(0, 5),
"sku": sku7,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.5 + random.randint(0, 5),
"weightUnit": "kg"
},
{
"allowTrackInventory": True,
"barcode": "barcode 条码123ddg456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[6],
"option2Name": "size",
"option2Value": size[6],
"option3Name": "model",
"option3Value": model[6],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 3.1 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 3,
"sellingPrice": 8.2 + random.randint(0, 5),
"sku": sku8,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.5 + random.randint(0, 5),
"weightUnit": "kg"
},
{
"allowTrackInventory": True,
"barcode": "barcode 条码123ddg456",
"imageId": "",
"inventory": random.randint(10000, 50000),
"levyTariff": True,
"option1Name": "color",
"option1Value": color[7],
"option2Name": "size",
"option2Value": size[7],
"option3Name": "model",
"option3Value": model[7],
"option4Name": "",
"option4Value": "",
"option5Name": "",
"option5Value": "",
"originalPrice": 7.7 + random.randint(0, 5),
"outOfStockBehavior": "off",
"position": 3,
"sellingPrice": 8.2 + random.randint(0, 5),
"sku": sku9,
"storeId": "",
"tariffCode": "HS关税代码123456",
"weight": 0.5 + random.randint(0, 5),
"weightUnit": "kg"
}
],
"vendor": self.r.srandmember(Key_product_vendor),
"weight": 2.2 + random.randint(0, 5),
"weightUnit": "kg"
}
# print(body)
header = {
"Content-Type": "application/json",
"token": self.token,
"store-id": storeId
}
with self.client.post("/products", headers=header, name="products_post_MM", data=json.dumps(body),
catch_response=True) as response:
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
id = self.get_product_id(storeId, handle)
if id is not False:
self.r.sadd(product_id + storeId, id)
self.r.sadd(product_handle + storeId, handle)
self.r.set(product_handle + id, handle)
self.r.set(product_title + id, title)
self.r.sadd(product_sku + storeId, sku1)
self.r.sadd(product_sku + storeId, sku2)
self.r.sadd(product_sku + storeId, sku3)
self.r.sadd(product_sku + storeId, sku4)
self.r.sadd(product_sku + storeId, sku5)
self.r.sadd(product_sku + storeId, sku6)
self.r.sadd(product_sku + storeId, sku7)
self.r.sadd(product_sku + storeId, sku8)
self.r.sadd(product_sku + storeId, sku9)
response.success()
else:
print(body)
print(" ")
print("*******************")
print(header)
print(response.status_code)
print(response.text)
response.failure('products_post Failed!')
# # N0.7
# @task(5)
def products_delete(self):
if self.token == None:
return
storeId = self.r.srandmember(Key_storeIds)
self.r.spop(product_handle + storeId)
body = self.r.spop(product_id + storeId, 3)
# print(body)
header = {
"Content-Type": "application/json",
"token": self.token,
"store-id": storeId
}
with self.client.delete("/products/batch/product_id", headers=header, name="products_delete",
data=json.dumps(body),
catch_response=True) as response:
print(response.text)
for item in body:
len_v = self.r.scard(item)
if len_v > 0:
for i in range(0, len_v):
self.r.spop(product_id)
self.r.delete(item)
self.r.delete(product_handle + item)
self.r.delete(product_title + item)
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
response.success()
else:
print(response.text)
response.failure('products_post Failed!')
# # N0.7
# @task(1)
# def products_batch(self):
# if self.token == None:
# return
#
# storeId = self.r.srandmember(Key_storeIds)
#
# body = [{
# "id": self.r.srandmember(product_id + storeId),
# "template": "product"
# },{
# "id": self.r.srandmember(product_id + storeId),
# "template": "product"
# },{
# "id": self.r.srandmember(product_id + storeId),
# "template": "product"
# },{
# "id": self.r.srandmember(product_id + storeId),
# "template": "product"
# },{
# "id": self.r.srandmember(product_id + storeId),
# "template": "product"
# }]
# print(body)
# header = {
# "Content-Type": "application/json",
# "token": self.token,
# "store-id": storeId
# }
# with self.client.put("/products/batch", headers=header, name="products_batch", data=json.dumps(body),
# catch_response=True) as response:
# if response.status_code == 200 and response.text.find("SUCCESS") > -1:
# response.success()
# else:
# response.failure('products_post Failed!')
def get_product_id(self, storeId, handle):
if self.token == None:
return
header = {
"token": self.token,
"store-id": storeId
}
# print("start")
# print(handle)
with self.client.get("/products/{}".format(handle), headers=header, name="products_id",
catch_response=True) as response:
# print("status_code:{}".format(response.status_code))
# print(response.text)
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
respdata = json.loads(response.text)
if respdata.get("data") is not None:
if respdata.get("data").get("product") is not None:
if respdata.get("data").get("product").get("id") is not None:
return respdata.get("data").get("product").get("id")
return False
# # 根据产品ID或handle查询产品图片
# @task(1)
def products_id_images_get(self):
if self.token == None:
return
storeId = self.r.srandmember(Key_storeIds)
header = {
"token": self.token,
"store-id": storeId
}
productid = self.r.srandmember(product_id + storeId)
with self.client.get("/products/{}/images".format(productid), headers=header,
name="products_id_images_get",
catch_response=True) as response:
# print(response.text)
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
respdata = json.loads(response.text)
if respdata.get("data") is not None:
productImages = respdata.get("data").get("productImages")
if productImages is not None and len(productImages) > 1:
for item in productImages:
self.r.sadd(product_image_id + storeId, item.get("id"))
response.success()
else:
response.failure('products_id_images_get Failed!')
# #No.8
# @task(3)
def products_variants_get(self):
if self.token == None:
return
storeId = self.r.srandmember(Key_storeIds)
# print("storeid:{}".format(storeId))
product_id_variants = self.r.srandmember(product_id + storeId)
# print("product_id:{}".format(product_id_variants))
header = {
"token": self.token,
"store-id": storeId
}
with self.client.get("/products/{}/variants".format(product_id_variants), headers=header,
name="products_variants_get",
catch_response=True) as response:
# print(response.status_code)
# print(response.text)
if response.status_code == 200 and response.text.find('"code":200') > -1:
respdata = json.loads(response.text)
if respdata.get("data") is not None:
productVariants = respdata.get("data").get("productVariants")
if productVariants is not None and len(product_id_variants) > 0:
for item in productVariants:
self.r.sadd(product_id_variants, item.get("id"))
# print("Variant:{}".format(item.get("id")))
response.success()
else:
print(response.status_code)
print(response.text)
response.failure('collections_post Failed!')
# #No.9
# 集合ids和产品id做关联(产品服务调用)
# @task(1)
def collections_product_productId_post(self):
if self.token == None:
return
storeId = self.r.srandmember(Key_storeIds)
header = {
"Content-Type": "application/json",
"token": self.token,
"store-id": storeId
}
collection_id_value = self.r.srandmember(collection_manual_id + storeId)
collection_m_handle_value = self.r.get(collection_manual_handle + collection_id_value)
productid = self.r.srandmember(product_id + storeId)
# print("collection_m_handle_value" + collection_m_handle_value)
product_handle_value = self.r.get(product_handle + productid)
# print("product_handle_value" + product_handle_value)
body = [collection_id_value]
# print(body)
with self.client.post("/collections/product/{}".format(productid),
headers=header, data=json.dumps(body),
name="collections_product_productId_post", catch_response=True) as response:
# print(response.text)
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
self.r.sadd(collection_product + collection_m_handle_value, product_handle_value)
# print(collection_product + collection_m_handle_value)
# print(product_handle_value)
response.success()
else:
print(response.text)
print(response.status_code)
response.failure('collections_product_productId_post Failed!')
# # #No.10
# @task(1)
def pages_post(self):
if self.token == None:
return
uid = str(uuid.uuid4())
suid = ''.join(uid.split('-'))
handle = "page{}".format(suid)
storeId = self.r.srandmember(Key_storeIds)
body = {
"comment": "备注page用于XX商品,XX类型集合,用于XX商品,XX类型集合",
"content": bodyhtml.product_html,
"handle": handle,
"isEnabled": True,
"seoDescrition": "seoDescrition-{}".format(suid),
"seoKeywords": "seoKeywords-{}".format(suid),
"seoTitle": "seoTitle-{}".format(suid),
"template": "template-{}".format(suid),
"title": "title-{}".format(suid),
"storeId": storeId
}
header = {
"Content-Type": "application/json",
"token": self.token,
"store-id": storeId
}
with self.client.post("/pages", headers=header, name="pages_post", data=json.dumps(body),
catch_response=True) as response:
print(response.status_code)
print(response.text)
print("*********storeid")
print(storeId)
print("********handle")
print(handle)
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
respdata = json.loads(response.text)
if respdata.get("data") is not None:
if respdata.get("data").get("id") is not None:
id = respdata.get("data").get("id")
self.r.sadd(page_id + storeId, id)
self.r.sadd(page_handle + storeId, handle)
self.r.sadd(page_title + storeId, "title-{}".format(suid))
print("*************id")
print(id)
response.success()
else:
response.failure('collections_post Failed!')
# #No.11
# @task(1)
def menus_post(self):
if self.token == None:
return
uid = str(uuid.uuid4())
suid = ''.join(uid.split('-'))
handle = "menuslimintest{}".format(suid)
storeId = self.r.srandmember(Key_storeIds)
body = {
"storeId": storeId,
"title": "menus—title-test-{}".format(suid),
"handle": handle,
"items": [
{
"handle": "/",
"type": "home",
"title": "首页",
"id": "id1"
},
{
"handle": "/collections",
"type": "collections",
"title": "集合",
"children": [
{
"handle": "/collections/children1",
"type": "collections_children1",
"title": "集合1",
"children": [
{
"handle": "/collections1/shi-li-shou-dong-ji-he14-ji-he-test12123243243243242485",
"type": "collections",
"title": "集合11",
"children": [
{
"handle": "/collections11/shi-li-shou-dong-ji-he14-ji-he-test1212324324324324245",
"type": "collections",
"title": "集合113",
"children": [
{
"handle": "/collections121/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合121",
"id": "1627888180700"
}, {
"handle": "/collections122/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合122",
"id": "1627888180700"
}
, {
"handle": "/collections123/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合123",
"id": "1627888180700"
}
, {
"handle": "/collections124/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合124",
"id": "1627888180700"
}
]
},
{
"handle": "/collections12/shi-li-shou-dong-ji-he14-ji-he-test1212324324324324245",
"type": "collections",
"title": "集合123",
"children": [
{
"handle": "/collections1231/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合1231",
"id": "1627888180700"
}, {
"handle": "/collections1232/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合1232",
"id": "1627888180700"
}
, {
"handle": "/collections123/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合1233",
"id": "1627888180700"
}
, {
"handle": "/collections124/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合1234",
"id": "1627888180700"
}
]
},
{
"handle": "/collections134/shi-li-shou-dong-ji-he14-ji-he-test1212324324324324245",
"type": "collections",
"title": "集合134",
"children": [
{
"handle": "/collections1341/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合1131",
"id": "1627888180700"
}, {
"handle": "/collections1342/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合1342",
"id": "1627888180700"
}
, {
"handle": "/collections1343/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合1343",
"id": "1627888180700"
}
, {
"handle": "/collections1344/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合1344",
"id": "1627888180700"
}
]
}
]
}
]
},
{
"handle": "/collections/children2",
"type": "collections_children2",
"title": "集合2",
"children": [
{
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test12123243243243242485",
"type": "collections",
"title": "集合2",
"children": [
{
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test1212324324324324245",
"type": "collections",
"title": "集合3",
"children": [
{
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合4",
"id": "1627888180700"
}
],
"id": "1627888169782"
}
],
"id": "1627888157450"
}, {
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test12123243243243242485",
"type": "collections",
"title": "集合2",
"children": [
{
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test1212324324324324245",
"type": "collections",
"title": "集合3",
"children": [
{
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合4",
"id": "1627888180700"
}
],
"id": "1627888169782"
}
],
"id": "1627888157450"
}, {
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test12123243243243242485",
"type": "collections",
"title": "集合2",
"children": [
{
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test1212324324324324245",
"type": "collections",
"title": "集合3",
"children": [
{
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合4",
"id": "1627888180700"
}
]
}
]
}
]
},
{
"handle": "/collections/children3",
"type": "collections_children3",
"title": "集合3",
"children": [
{
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test12123243243243242485",
"type": "collections",
"title": "集合2",
"children": [
{
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test1212324324324324245",
"type": "collections",
"title": "集合3",
"children": [
{
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合4",
"id": "1627888180700"
}
],
"id": "1627888169782"
}
],
"id": "1627888157450"
}
]
},
{
"handle": "/collections/children3",
"type": "collections_children3",
"title": "集合3",
"children": [
{
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test12123243243243242485",
"type": "collections",
"title": "集合2",
"children": [
{
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test1212324324324324245",
"type": "collections",
"title": "集合3",
"children": [
{
"handle": "/collections/shi-li-shou-dong-ji-he14-ji-he-test12",
"type": "collections",
"title": "集合4",
"id": "1627888180700"
}
],
"id": "1627888169782"
}
],
"id": "1627888157450"
}
]
}
]
},
{
"handle": "/products",
"type": "products",
"title": "商品",
"children": [
{
"handle": "/products/short-sleeve-t-9970008660k1",
"type": "products",
"title": "商品1",
"id": "1627888201430"
},
{
"handle": "/products/short-sleeve-t-997000866",
"type": "products",
"title": "商品2",
"id": "1627888211641"
}
],
"id": "1627888191308"
},
{
"handle": "/pages",
"type": "pages",
"title": "页面",
"children": [
{
"handle": "/pages/ce-shi-ye-mian-1",
"type": "pages",
"title": "页面1",
"id": "1627888312804"
}
],
"id": "1627888303533"
}
]
}
header = {
"Content-Type": "application/json",
"token": self.token,
"store-id": storeId
}
with self.client.post("/menus", headers=header, name="menus_post", data=json.dumps(body),
catch_response=True) as response:
print(response.status_code)
print(response.text)
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
id = self.menus_id(storeId, handle)
# print("**************************************")
# print("menusid:{}".format(id))
# print("storeId:" + storeId)
# print("handle:{}".format(handle))
if id is not False:
# self.r.sadd(menus_id + storeId, id)
# self.r.sadd(menus_handle + storeId, handle)
self.r.sadd(menus_id + storeId, id)
self.r.sadd(menus_handle + storeId, handle)
response.success()
else:
response.failure('menus_post Failed!')
def menus_id(self, storeId, handle):
if self.token == None:
return
header = {
"token": self.token,
"store-id": storeId
}
with self.client.get("/menus/{}".format(handle), headers=header, name="menus_id",
catch_response=True) as response:
print(response.status_code)
# print(response.text)
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
respdata = json.loads(response.text)
if respdata.get("data") is not None:
if respdata.get("data").get("menus") is not None:
if respdata.get("data").get("menus").get("id") is not None:
return respdata.get("data").get("menus").get("id")
return False
# #N0.12
# 注册
def get_login_token(self):
# header = {
# "Accept": "*/*",
# "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
# }
with self.client.get("/admin/get_login_token", name="get_login_token",
catch_response=True) as response:
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
respdata = json.loads(response.text)
if respdata.get("data") is not None:
return respdata.get("data").get("token")
return None # 注册
@task(10)
def CustomerRegister(self):
tokenlogin = self.get_login_token()
# print(tokenlogin)
if tokenlogin == None:
return
uid = str(uuid.uuid4())
suid = ''.join(uid.split('-'))
email = "{}@126.com".format(suid)
storeId = self.r.srandmember(Key_storeIds)
body = {
"email": email,
"firstName": "li",
"gender": 0,
"isSubscribed": False,
"lastName": "min",
"password": self.password,
}
header = {
"Content-Type": "application/json",
"token": tokenlogin,
"store-id": storeId
}
url = "/customers"
with self.client.post(url, headers=header, name="用户注册", data=json.dumps(body),
catch_response=True) as response:
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
re = self.customers_activation(email, storeId)
if re == True:
self.r.sadd(customer + storeId, email)
response.success()
else:
response.failure('CustomerAddress Failed!')
# @task(1)
def customers_activation(self, email, storeId):
tokenlogin = self.get_login_token()
if tokenlogin == None:
return
body = {
"email": email,
"password": self.password,
}
header = {
"token": tokenlogin,
"store-id": storeId
}
url = "/customers/activation"
with self.client.post(url, headers=header, name="客户激活", data=body,
catch_response=True) as response:
# print('*********************')
# print(response.text)
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
response.success()
return True
else:
response.failure('CustomerAddress Failed!')
return False
# 登录ok
def CustomerLogin(self):
self.token = self.get_login_token()
if self.token == None:
return None, None
storeId = self.r.srandmember(Key_storeIds)
email = self.r.srandmember(customer + storeId)
if email == None:
return None, None
body = {
"email": email,
"password": "P12345678"
}
header = {
"Content-Type": "application/json",
"token": self.token,
"store-id": storeId
}
url = "/front/customers/login"
with self.client.post(url, headers=header, name="客户登录", data=json.dumps(body),
catch_response=True) as response:
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
# print(response.text)
respdata = json.loads(response.text)
if respdata.get("data") is not None:
if respdata.get("data").get("token") is not None:
print("**********************")
token = respdata.get("data").get("token")
return token, storeId
return None, None
# #N0.13
# # 添加地址 ok
# @task(1)
def CustomerAddress(self):
token, storeId = self.CustomerLogin()
if token == None:
print("token None1234")
return
uid = str(uuid.uuid4())
suid = ''.join(uid.split('-'))
body = {
"address1": "haerbingshisongbeiqu-{}".format(suid),
"address2": "haerbingshisongbeiqu-{}".format(suid),
"city": "heerddbin",
"company": "maiyuan",
"country": "CN",
"firstName": "li",
# "internationalAreaCode": 86,
"isDefault": True,
"lastName": "min",
"phone": "1367014{}".format(random.randint(1000, 9999)),
"province": "heilongjiang",
"zip": "150000"
}
header = {
"Content-Type": "application/json",
"token": token,
"store-id": storeId
}
url = "/front/customers/address"
with self.client.post(url, headers=header, name="/CustomerAddress", data=json.dumps(body),
catch_response=True) as response:
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
response.success()
else:
print(storeId)
print(token)
print(response.text)
response.failure('CustomerAddress Failed!')
# # 新增运费区域方案 ok
#
# # 获取国家列表 ok
def resources_countries(self, storeId):
if self.token == None:
return
header = {
"token": self.token,
"store-id": storeId
}
url = "/resources/countries"
with self.client.get(url, headers=header, name="resources_countries",
catch_response=True) as response:
# print(response.text)
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
respdata = json.loads(response.text)
if respdata.get("data") is not None:
countries = respdata.get("data").get("countries")
if countries is not None and len(countries) > 0:
# print(countries)
return countries
return None
def JoinBySignal(self, key, lendata):
res = ""
resColl = []
for i in range(0, lendata):
collectionstr = self.r.srandmember(key)
resColl.append(collectionstr)
res = res + "{},".format(self.r.srandmember(key))
return res.strip(','), resColl
def add_shippings(self, countries, storeId):
if self.token == None:
print("token None")
return
uid = str(uuid.uuid4())
suid = uid.split('-')[0]
len_colenction = self.r.scard(collection_manual_id + storeId)
# collections1, colenctionshiping = self.JoinBySignal(collection_manual_id + storeId, 10)
countAreas = random.randint(2, 5)
shippingAreas = []
for i in range(0, countAreas):
country = countries[random.randint(0, len(countries) - 1)]
flage = False
if len(shippingAreas) > 0:
for item in shippingAreas:
if item.get("country") == country.get("code"):
flage = True
if flage:
break
provinces = country.get("provinces")
if provinces == None:
provinces = []
areas = {
"continent": country.get("continent"),
"cnName": country.get("cnName"),
"name": country.get("name"),
"flag": country.get("flag"),
"country": country.get("code"),
"provinces": provinces
}
shippingAreas.append(areas)
# print(shippingAreas)
print("))))))))))))))))))))))))))))))))))))))))))))))))")
# print(len(shippingAreas))
body = {
"shippingAreas": shippingAreas,
"shippingPlans": [
{
"activityDetail": suid,
"activityEndTime": "2{}21-11-11T11:11:11.000".format(random.randint(1, 6)),
"activityFlag": 0,
"activityStartTime": "2021-10-{}T11:11:11.000".format(random.randint(10, 28)),
"baseMoney": random.randint(1, 10),
"baseWeight": random.randint(1, 10),
"cartRuleType": "any",
"continuationMoney": random.randint(1, 3),
"continuationWeight": random.randint(1, 3),
"description": "",
"freightMoney": random.randint(1, 10),
"freightRuleType": random.randint(1, 3),
"isEnabled": True,
"shippingCartRules": [
{
"applyToOrder": True,
# "collectionIds": collections1,
"includeGiftNumFlag": True,
"includeGiftWeightFlag": True,
"orderPriceMax": random.randint(66666, 100000),
"orderPriceMin": 0.1,
"orderWeightMax": random.randint(66660, 100000),
"orderWeightMin": 0.1,
"productNumMax": random.randint(66660, 100000),
"productNumMin": 1,
"ruleType": random.randint(1, 1)
}
],
"sort": 0,
"title": "title1:{}".format(suid)
}
],
"storeId": storeId,
"title": "title2:{}".format(suid)
}
header = {
"Content-Type": "application/json",
"token": self.token,
"store-id": storeId
}
url = "/shippings"
with self.client.post(url, headers=header, name="add_shippings", data=json.dumps(body),
catch_response=True) as response:
# print(response.text)
if response.status_code == 200 and (
response.text.find("SUCCESS") > -1 or response.text.find("already been set") > -1):
response.success()
else:
print("++++++++++++++++++++")
print(body)
print(header)
print(response.text)
response.failure('CustomerAddress Failed!')
def Get_shippings(self, storeId):
if self.token == None:
print(2)
return
print(1)
header = {
"token": self.token,
"store-id": storeId
}
url = "/shippings"
with self.client.get(url, headers=header, name="Get_shippings",
catch_response=True) as response:
print(response.text)
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
respdata = json.loads(response.text)
time.sleep(10)
if respdata.get("data") is not None:
shippings = respdata.get("data").get("shippings")
if shippings is not None and len(shippings) > 0:
for item in shippings:
print(item.get("id"))
self.r.sadd(shipping + storeId, item.get("id"))
shippingAreas = item.get("shippingAreas")
for area in shippingAreas:
self.r.sadd(shippingCountrys + item.get("id"), area.get("country"))
print(1)
print(shippingCountrys + item.get("id"))
shippingPlans = item.get("shippingPlans")
for plan in shippingPlans:
self.r.sadd(shippingPlans_key + item.get("id"), plan.get("id"))
print(2)
print(shippingPlans_key + item.get("id"))
response.success()
else:
response.failure("Get_shippings")
# @task(1)
def add_all_shippings(self):
storeId = self.r.srandmember(Key_storeIds)
print("dddddd:{}".format(storeId))
countries = self.resources_countries(storeId)
# print(countries)
if countries == None:
return
count = 0
while count < 1:
self.add_shippings(countries, storeId)
count = count + 1
print("count:{}".format(count))
time.sleep(10)
self.Get_shippings(storeId)
# @task(1)
def delete_shipping(self):
if self.token == None:
return
storeId = self.r.srandmember(Key_storeIds)
header = {
"token": self.token,
"store-id": storeId
}
shippingid = self.r.spop(shipping + storeId)
count = self.r.scard(shippingCountrys + shippingid)
for i in range(0, count):
print(self.r.spop(shippingCountrys + shippingid))
url = "/shippings/{}".format(shippingid)
with self.client.delete(url, headers=header, name="delete_shipping",
catch_response=True) as response:
# print(response.text)
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
response.success()
else:
response.failure("Get_shippings")
# # #获取国家列表
# # @task(1)
# def resources_countries(self):
# if self.token == None:
# return
# header = {
# "token": self.token,
# }
# url = "/resources/countries"
# with self.client.get(url, headers=header, name="resources_countries",
# catch_response=True) as response:
# if response.status_code == 200 and response.text.find("SUCCESS") > -1:
# respdata = json.loads(response.text)
# if respdata.get("data") is not None:
# countries = respdata.get("data").get("countries")
# if countries is not None and len(countries) > 0:
# for item in countries:
# CountryCode = item.get("code")
# self.r.sadd(CountryCodes, CountryCode)
# Province = item.get("provinces")
# if Province is not None and len(Province) > 0:
# self.r.sadd(CountryCodesProvince + CountryCode, item.get("code"))
# response.success()
# else:
# response.failure('pages_get Failed!')
# #获取电话区号列表ok
# @task(1)
def resources_phones(self):
if self.token == None:
return
storeId = self.r.srandmember(Key_storeIds)
header = {
"token": self.token,
"store-id": storeId
}
print(self.token)
url = "/resources/phones"
with self.client.get(url, headers=header, name="获取电话区号列表",
catch_response=True) as response:
print(response.text)
if response.status_code == 200 and response.text.find("SUCCESS") > -1:
data_res = json.loads(response.text)
data = data_res.get("data")
if data is None:
return
phones = data.get("phones")
if phones is None or len(phones) < 1:
return
for item in phones:
self.r.set(phoneCode + item.get("isoCode2"), item.get("phoneKey"))
print(phoneCode + item.get("isoCode2"))
print(item.get("phoneKey"))
response.success()
else:
response.failure('front_cart_checkout_id Failed!')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。