def get_code_by_api(saas_token, req_time): host = ReadConf().readconf("HOST", "admin_host") tenant_id = ReadConf().readconf("Tenant", "tenant_id") phone = ReadConf().readconf("PhoneNumber", "phone") start_time = datetime.datetime.strftime( (req_time + datetime.timedelta(seconds=-5)), '%Y-%m-%d %H:%M:%S') end_time = datetime.datetime.strftime( (req_time + datetime.timedelta(seconds=65)), '%Y-%m-%d %H:%M:%S') print(start_time) print(end_time) api = '/api/v1/statistics/sms/list' url = host + api header = {"token": saas_token, "tenantId": tenant_id} body = { "state": 1, "notifyTarget": phone, "startIndex": 0, "pageCount": 20, "startCreated": start_time, "endCreated": end_time, "notifyCode": "vcode" } text = requests.get(url, headers=header, params=body) x = text.json()["body"]["data"] code = None for i in x: code = i["content"][6:12] break return code
def return_visit_token(self): tenant_id = ReadConf().readconf("Tenant", "tenant_id") host = ReadConf().readconf("HOST", "host") api = '/api/v1/login/loginByAnonymous' url = host + api data = {'tenantID': tenant_id, 'belongTenantId': tenant_id} # 请求数据 req = requests.post(url, data) # 发post请求 text = req.json() # 返回string,json串 return text['body']['token']
def get_cart_total_num_api(token): tenant_id = ReadConf().readconf("Tenant", "tenant_id") host = ReadConf().readconf("HOST", "host") api = '/api/v1/shopping/cart/num' url = host + api header = {"token": token, "tenantId": tenant_id} req = requests.get(url, headers=header) text = req.json() return text["body"]
def return_saas_token_by_api(self): host = ReadConf().readconf('HOST', 'admin_host') api = '/api/v1/account/login' url = host + api user = ReadConf().readconf('AdminUser', 'adminuser') pwd = ReadConf().readconf('AdminUser', 'adminpwd') pwd = self.create_md5(pwd) body = {'tenantCode': 'namek', 'account': user, 'password': pwd} text = requests.post(url, data=body) saas_token = text.json()['body']['token'] return saas_token
def return_member_info(self): phone = ReadConf().readconf("PhoneNumber", "phone") tenant_id = ReadConf().readconf("Tenant", "tenant_id") host = ReadConf().readconf("HOST", "host") api = '/api/v1/login/loginByPhone' url = host + api body = {"phone": phone, "tenantId": tenant_id} req = requests.post(url, json=body) text = req.json() info_list = [] info_list.append(text['body']['memberId']) info_list.append(text['body']['token']) return info_list
def login_by_js(self, is_member): phone = ReadConf().readconf("PhoneNumber", "phone") tenant_code = ReadConf().readconf("Tenant", "tenant_code") if is_member: member_list = ReturnToken().return_member_info() member_id = member_list[0] token = member_list[1] self.driver.execute_script( "window.localStorage.setItem('namek_emall@"+tenant_code+"@token',JSON.stringify('" + token + "'))") self.driver.execute_script( "window.localStorage.setItem('namek_emall@"+tenant_code+"@member',JSON.stringify({id: '" + str(member_id) + "', phone: '" + phone + "'}))") else: token = ReturnToken().return_visit_token() self.driver.execute_script("window.localStorage.setItem('namek_emall@"+tenant_code+"@token',JSON.stringify('" + token + "'))") return token
def get_cart_list_api(token): # 获取用户的购物车列表id,name,num tenant_id = ReadConf().readconf("Tenant", "tenant_id") host = ReadConf().readconf("HOST", "host") api = '/api/v1/shopping/cart/list' url = host + api header = {"token": token, "tenantId": tenant_id} req = requests.get(url, headers=header) text = req.json() texts = text["body"] cart_product_info_list = [] for text in texts: cart_id = text["id"] num = text["num"] product_name = text["product"]["name"] cart_product_info_list.append([cart_id, product_name, num]) return cart_product_info_list
def sendmail(filepath, filename): my_sender = ReadConf().readconf('Mail', 'sender_address') # 发件人邮箱账号 my_pass = ReadConf().readconf('Mail', 'sender_pwd') # 发件人邮箱密码 my_user = ReadConf().readconf('Mail', 'recevier_address') # 收件人邮箱账号 my_user = my_user.split(';') mail_host = ReadConf().readconf('Mail', 'mail_host') mail_port = ReadConf().readconf('Mail', 'mail_port') msg = MIMEMultipart() msg['From'] = formataddr(["AutoTest", my_sender]) # 括号里的对应发件人邮箱昵称、发件人邮箱账号 for i in (0, len(my_user) - 1): msg['To'] = formataddr(["", my_user[i]]) # 括号里的对应收件人邮箱昵称、收件人邮箱账号 msg['Subject'] = Header(filename, 'utf-8') # 邮件的主题,也可以说是标题 contents = r'通过:' + str(RunResult.passed) + '\n' + '失败:' + str( RunResult.failed) + '\n' + '错误:' + str( RunResult.errors) + '\n' + '跳过:' + str(RunResult.skiped) msg.attach(MIMEText(contents, 'plain', 'utf-8')) att1 = MIMEText(open(filepath, 'rb').read(), 'base64', 'utf-8') att1['Content-Type'] = 'application/octet-stream' att1['Content-Disposition'] = 'attachment; filename=' + filename msg.attach(att1) try: # server = smtplib.SMTP_SSL("smtp.exmail.qq.com", 465) # 发件人邮箱中的SMTP服务器 server = smtplib.SMTP_SSL(mail_host, mail_port) # 发件人邮箱中的SMTP服务器 server.login(my_sender, my_pass) # 括号中对应的是发件人邮箱账号、邮箱密码 server.sendmail(my_sender, my_user, msg.as_string()) # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件 server.quit() # 关闭连接 print("邮件发送成功") except smtplib.SMTPException: print("Error: 无法发送邮件")
def get_point_item_1_api(self,token): host = ReadConf().readconf('HOST', 'host') tenant_id = ReadConf().readconf('Tenant', 'tenant_id') memberid = ReturnToken().return_member_info()[0] api = '/api/v1/member/'+str(memberid)+'/points/changed/list?startIndex=0&pageCount=1' url=host + api header = { "token": token, "tenantId": tenant_id } text = requests.get(url, headers=header) x = text.json()["body"] points_num = x["points"] points_num = '{:g}'.format(float(points_num)) event_item_list = x["changedList"]["data"][0] event_item_1 = event_item_list["remark"] event_time_1 = event_item_list["created"] event_points_changed_1 = event_item_list["offset"] event_points_changed_1 = '{:g}'.format(float(event_points_changed_1)) points_item_1_api = [event_item_1, event_time_1, str(event_points_changed_1)] return points_num, points_item_1_api
def get_api_special_price_info(product_id, token): host = ReadConf().readconf("HOST", "host") api = '/api/v1/product/emall/' + product_id + '/detail' tenant_id = ReadConf().readconf("Tenant", "tenant_id") url = host + api header = {"token": token, "tenantId": tenant_id} text = requests.get(url, headers=header) x = text.json()["body"] print(x) api_promotion_tag = x["tagList"][0] api_origin_price = x["originPrice"] api_promotion_price = x["promotionPrice"] api_promotion_stock = x["promotionInfo"]["leftProductNum"] api_origin_price = '{:g}'.format(api_origin_price) api_promotion_price = '{:g}'.format(api_promotion_price) api_promotion_stock = str(api_promotion_stock) api_special_info_list = [ api_promotion_tag, api_origin_price, api_promotion_price, api_promotion_stock ] return api_special_info_list
def send_phone(self): phone = ReadConf().readconf("PhoneNumber", "phone") self.sendkey_element(self.find_phone_ele(), phone)
def test_get_code_by_api(self): url = ReadConf().readconf('HOST', 'host') print(url)
def setUp(self): BasePage(self.driver).visit_url(ReadConf().readconf( "URL", "ordersURL"))
def setUp(self): BasePage(self.driver).visit_url(ReadConf().readconf( "URL", "categoryURL"))
def visit_url(self, url=None): if url is None: url = ReadConf().readconf("URL", "homeURL") else: url = url self.driver.get(url)