def send_dingding_msg(self, msg="", url="https://oapi.dingtalk.com/robot/send"): timestamp, sign = Dingding.get_sign() headers = { "Content-Type": "application/json; charset=utf-8", "timestamp": "{}".format(timestamp), "sign": "{}".format(sign) } at_mobiles = config_obj_of_authority['dingding']['at_mobiles'].strip( ).split(",") body_data = { "msgtype": "text", "text": { "content": msg.format("@".join(at_mobiles)) }, "at": { "atMobiles": at_mobiles, "isAtAll": False } } url = url + "?access_token={0}×tamp={1}&sign={2}".format( config_obj_of_authority['dingding']['access_token'], timestamp, sign) r = requests.post(url=url, json=body_data, headers=headers) logging.info(r.json())
def get_sign(secret=""): if not secret: secret = config_obj_of_authority['dingding']['secret'].strip() timestamp = str(round(time.time() * 1000)) secret_enc = secret.encode('utf-8') string_to_sign = '{}\n{}'.format(timestamp, secret) string_to_sign_enc = string_to_sign.encode('utf-8') hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest() sign = urllib.parse.quote_plus(base64.b64encode(hmac_code)) logging.info("Timestamp is [{0}]. Sign is [{1}].".format(timestamp, sign)) return timestamp, sign
def extract_suggestions_from_edit_html_label(self, edit_html_info, label): """提取 editHtml 中的 suggestions-data 数据的信息""" if not self.argues_relation.get(label): self.argues_relation.setdefault(label, {}) options = re.findall( '"label":"([\s\S]{1,20})","value":"(\d+)","icon"', edit_html_info) options = set(options) for option in options: self.argues_relation.get(label).setdefault(option[0], option[-1]) logging.info(option) return self.argues_relation.get(label)
def extract_options_from_edit_html_label(self, edit_html_info, label): """提取 editHtml 中的 option标签的信息""" if not self.argues_relation.get(label): self.argues_relation.setdefault(label, {}) options = re.findall( 'value=\\"(\w+?)\\"[\s\S]*?>\\n*\s*(\S+)\s*</option>', edit_html_info) for option in options: self.argues_relation.get(label).setdefault(option[-1], option[0]) logging.debug(self.argues_relation.get(label)) logging.info(option) return self.argues_relation.get(label)
def set_request_argues(self, label, bug_content, config_obj): """请求入参格式化""" param, need_transform = config_obj["default"][label].split(",") try: if label == "描述": d1, d2, d3, d4 = bug_content.split("|||") description = """ 【前置条件】:{0}\n【操作步骤】:{1}\n【预期结果】:{2}\n【实际结果】:{3}\n """.format(d1, d2, d3, d4) self.request_argues.setdefault(param, description) return self.request_argues.setdefault( param, self.argues_relation.get(label).get(bug_content)) logging.info("Request argue [{0}] is [{1}]".format( param, self.request_argues.get(param))) except AttributeError as e: self.request_argues.setdefault(self.argues_relation.get(label), bug_content) logging.warning("Something wrong when dealing with label.Argues is: [label:{0}],[bug_content:{1}]"\ .format(label, bug_content))
def set_aruges_relation(self, field_info): """判断是否为可选项数据, 若是返回可选项的数据列表; 否则,返回 False""" label_id = field_info.get("id") label = field_info.get("label") edit_html_info = field_info.get("editHtml") logging.info(label + "=" + label_id + ",1") if label in Create.OPTIONS: logging.info("*" * 10 + label + "*" * 10) argues_relation = self.extract_options_from_edit_html_label( edit_html_info=edit_html_info, label=label) elif label in Create.SUGGESTIONS: logging.info("=" * 10 + label + "=" * 10) argues_relation = self.extract_suggestions_from_edit_html_label( edit_html_info=edit_html_info, label=label) else: self.argues_relation.setdefault(label, label_id) logging.info( "Label [{}] do not in OPTIONS or SUGGESTIONS.".format(label)) return logging.debug("label:{0}\n{1}".format(label, argues_relation)) return
def phatomjs_login(self): from selenium import webdriver from selenium.webdriver.chrome.options import Options # driver = webdriver.Chrome() # 模拟无界面谷歌浏览器操作 chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') driver = webdriver.Chrome(options=chrome_options) driver.get(url=self.login_url) time.sleep(1) # 登录 driver.find_element_by_xpath(xpath='//*[@id="username"]').send_keys(self.authority['default']['username']) driver.find_element_by_xpath(xpath='//*[@id="password"]').send_keys(self.authority['default']['password']) driver.find_element_by_xpath(xpath='//*[@id="submit_psd"]/input').click() # 获取登录后token信息 token = driver.get_cookie(name="atlassian.xsrf.token") logging.info("atlassian.xsrf.token info is [{}]".format(token)) jessionid = driver.get_cookie(name="JSESSIONID") logging.info("JSESSIONID info is [{}]".format(jessionid)) self.cookie += token.get("name") + "=" + token.get("value") + "; jira.editor.user.mode=wysiwyg;" self.cookie += jessionid.get("name") + "=" + jessionid.get("value") logging.info("The valid cookie is [{}]".format(self.cookie)) driver.quit()