Esempio n. 1
0
 def register(self, mobile, password):
     """
     注册
     :param mobile:
     :param password:
     :param code:验证码,虚构手机号收不到验证码短信,暂时屏蔽
     :return:
     """
     post_data = {"mobile": "%s" % mobile, "password": "******" % password}
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         "Date": "%s" % GetTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     register_url = "http://%s/user/register" % ConfigFile().host()
     request = requests.post(register_url, data=post_data, headers=headers)
     time = GetTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
     finally:
         log_list = [
             u'注册', u"post", register_url,
             str(post_data), time, status_code, info
         ]
Esempio n. 2
0
 def ban_list(self, token):
     post_data = {"screenings": "%d" % self.screening}
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         'Authorization': token,
         "Date": "%s" % GetTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     ban_list_url = "http://%s/activity/%d/banheros" % (ConfigFile().host(),
                                                        self.match_id)
     request = requests.get(ban_list_url, post_data, headers=headers)
     time = GetTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
     finally:
         log_list = [
             u'获取对手选择的英雄或地图', u"get", ban_list_url,
             str(post_data), time, status_code, info
         ]  # 单条日志记录
Esempio n. 3
0
 def award_for_match(self, token):
     post_data = {}
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         'Authorization': token,
         "Date": "%s" % GetTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     award_for_match_url = "http://%s/activity/goldrule" % ConfigFile(
     ).host()
     request = requests.get(award_for_match_url, headers=headers)
     time = GetTime().getCurrentTime()
     status_code = request.status_code
     print(award_for_match_url)
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
             print(info)
     finally:
         log_list = [
             u'我裁定的', u"get", award_for_match_url,
             str(post_data), time, status_code, info
         ]  # 单条日志记录
Esempio n. 4
0
 def login(self, mobile, password):
     """
     模拟用户登录
     :param mobile:
     :param password:
     :return:接口返回的json数据
     """
     post_data = {'mobile': '%s' % mobile, 'password': '******' % password}
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         "Date": "%s" % GetTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     login_url = "http://%s/user/login" % ConfigFile().host()
     request = requests.post(login_url, data=post_data, headers=headers)
     time = GetTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
     finally:
         log_list = [
             u'登录', u"post", login_url,
             str(post_data), time, status_code, info
         ]
Esempio n. 5
0
 def create_match(self, post_data):
     headers = {
         "Cache - Control": "no-cache",
         "Content - Type": "application/json;charset = UTF - 8",
         'Accept': 'application/json',
         'Authorization': self.judgement_token,
         "Date": "%s" % GetTime().getHeaderTime(),
         "Proxy-Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     create_match_url = "http://%s/activity" % self.config_file.host()
     request = requests.post(create_match_url,
                             json=post_data,
                             headers=headers)
     time = GetTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json_ = request.json()
             info = json_["info"]
             return json_
         else:
             info = request.reason
     finally:
         log_list = [
             u'发布比赛', u"post", create_match_url,
             str(post_data), time, status_code, info
         ]  # 单条日志记录
Esempio n. 6
0
 def confirm(self, token):
     """
     确认参赛
     :param login: json格式,获取token
     :param id: 赛事ID
     :return:
     """
     post_data = {}
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         'Authorization': token,
         "Date": "%s" % GetTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     confirm_url = "http://%s/activity/%d/confirm" % (ConfigFile().host(),
                                                      self.match_id)
     request = requests.put(confirm_url, data=post_data, headers=headers)
     time = GetTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
     finally:
         log_list = [
             u'确认参赛', u"put", confirm_url,
             str(post_data), time, status_code, info
         ]  # 单条日志记录
Esempio n. 7
0
 def check_password(self, token):
     post_data = {"password": "******" % self.password}
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         'Authorization': token,
         "Date": "%s" % GetTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     check_password_url = "http://%s/activity/%d/checkpassword" % (
         ConfigFile().host(), self.match_id)
     request = requests.post(check_password_url, post_data, headers=headers)
     time = GetTime().getCurrentTime()
     status_code = request.status_code
     print(check_password_url)
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
     finally:
         log_list = [
             u'提交房间密码', u"post", check_password_url,
             str(post_data), time, status_code, info
         ]  # 单条日志记录
         GetReport().get_report()  # 生成或打开日志文件
         GetReport().record_into_report(log_list)  # 逐条写入日志
Esempio n. 8
0
 def apply_match(self, token, role_id, password=None):
     """
     报名比赛
     :param login: json,获取token
     :param role_id: 角色ID
     :param password: 房间密码
     :return: json
     """
     post_data = {
         "id": "%d" % self.match_id,
         "roleId": "%d" % role_id,
         "password": "******" % password
     }
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         'Authorization': token,
         "Date": "%s" % GetTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     apply_match_url = "http://%s/activity/%s/sign" % (ConfigFile().host(),
                                                       self.match_id)
     request = requests.post(apply_match_url,
                             data=post_data,
                             headers=headers)
     time = GetTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
             print(info)
     finally:
         log_list = [
             u'报名比赛', u"post", apply_match_url,
             str(post_data), time, status_code, info
         ]  # 单条日志记录
Esempio n. 9
0
 def add_role(self, login, game_id, name):
     """
     添加游戏角色
     :param login:登录
     :param game_id: 游戏编号
     :return:
     """
     post_data = {
         "gameId": "%d" % game_id,
         "gamePlayer":
         "%s" % name,  #% ConfigFile().game_role_name(game_id),
         "gameServiceId": '146'
     }  #"%s" %  GameRegion().game_region(game_id)["data"][0]["id"]}
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         'Authorization': login["data"]["auth_token"],
         "Date": "%s" % GetTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     add_role_url = "http://%s/usergames/addRole" % ConfigFile().host()
     request = requests.post(add_role_url, data=post_data, headers=headers)
     time = GetTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
     finally:
         log_list = [
             u'添加游戏角色', u"post", add_role_url,
             str(post_data), time, status_code, info
         ]  # 单条日志记录
Esempio n. 10
0
 def match_status(self):
     """
     获取比赛状态
     :param token:
     :param match_id:
     :return:
     """
     post_data = {}
     headers = {
         "Cache - Control": "no - cache",
         "Content - Type": "text / html;charset = UTF - 8",
         'Accept': 'application/json',
         'Authorization': self.judgement_token,
         "Date": "%s" % GetTime().getHeaderTime(),
         "Proxy - Connection": "Keep - alive",
         "Server": "nginx / 1.9.3(Ubuntu)",
         "Transfer - Encoding": "chunked"
     }
     match_status_url = "http://%s/activity/%d/checkuseractstatus" % (
         ConfigFile().host(), self.match_id)
     request = requests.get(match_status_url,
                            data=post_data,
                            headers=headers)
     time = GetTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
     finally:
         log_list = [
             u'获取比赛状态', u"get", match_status_url,
             str(post_data), time, status_code, info
         ]  # 单条日志记录
Esempio n. 11
0
 def appraise_text(self, text=""):
     post_data = {"item": "%d" % self.item(),
                  "explain": "%s" % text}
     headers = {"Cache - Control": "no - cache",
                "Content - Type": "text / html;charset = UTF - 8",
                'Accept': 'application/json',
                'Authorization': self.token,
                "Date": "%s" % GetTime().getHeaderTime(),
                "Proxy - Connection": "Keep - alive",
                "Server": "nginx / 1.9.3(Ubuntu)",
                "Transfer - Encoding": "chunked"}
     appraise_text_url = "http://%s/activity/%d/feedback" % (ConfigFile().host(), self.match_id)
     request = requests.put(appraise_text_url, post_data, headers=headers)
     time = GetTime().getCurrentTime()
     status_code = request.status_code
     try:
         if status_code in (200, 422):
             json = request.json()
             info = json["info"]
             return json
         else:
             info = request.reason
     finally:
         log_list = [u'评价内容', u"put", appraise_text_url, str(post_data), time, status_code, info]  # 单条日志记录
Esempio n. 12
0
class GetReport:
    """
    日志文件相关操作
    """
    report_path = ConfigFile().report_path()
    sheet_name = GetTime().sheet_time()

    def get_report(self):
        """
        生成xls文件
        :param sheet_name:工作表名称
        """
        title = ["ID", "接口描述", "请求方式", "API", "参数", "执行时间", "状态码",
                 "执行结果"]  # 定义表头
        if not os.path.exists(r"%s" % self.report_path):
            workbook = xlwt.Workbook(encoding="utf-8")  #
            worksheet = workbook.add_sheet(self.sheet_name)
            self.col_width(title, worksheet)
            workbook.save(r"%s" % self.report_path)
        else:
            open_xls = xlrd.open_workbook(r"%s" % self.report_path,
                                          formatting_info=True)
            workbook = copy(open_xls)
            if self.sheet_name not in open_xls.sheet_names():
                worksheet = workbook.add_sheet(self.sheet_name)
                self.col_width(title, worksheet)
                workbook.save(r"%s" % self.report_path)
            else:
                workbook.save(r"%s" % self.report_path)
                # print open_xls.sheet_names()

    def col_width(self, title, worksheet):
        """
        设置表格列宽、表头内容
        :param title: 表头
        :param worksheet: 工作表
        """
        worksheet.col(0).width = 3000  # ID列宽
        worksheet.col(1).width = 6000  # 接口描述列宽
        worksheet.col(2).width = 3000  # 请求方式列宽
        worksheet.col(3).width = 15000  # API列宽
        worksheet.col(4).width = 20000  # 参数列宽
        worksheet.col(5).width = 6000  # 执行时间列宽
        worksheet.col(6).width = 3000  # 状态码列宽
        worksheet.col(7).width = 10000  # 执行结果列宽
        for i in range(len(title)):
            worksheet.write(0, i, title[i], self.style()[0])

    def style(self):
        """
        设置单元格格式
        :return:[style_title, style_error, style_normal]
                  style_title:表头湖蓝色背景黑色宋体
                  style_error:红色字体
                  style_normal:黑色字体
        """
        # 设置表头背景色
        pattern_title = xlwt.Pattern()  # 创建一个模式
        pattern_title.pattern = xlwt.Pattern.SOLID_PATTERN  # 设置该模式为实型
        pattern_title.pattern_fore_colour = 0x1b  # 设置背景色为湖蓝色

        # 设置表头字体
        font_title = xlwt.Font()  # 创建字体对象
        font_title.name = 'SimSun'  # 设置字体:宋体
        font_title.colour_index = 8  # 设置字体颜色:黑色
        font_title.bold = True  # 设置边框

        # 设置错误记录字体
        font_error = xlwt.Font()  # 创建错误记录字体对象
        font_error.colour_index = 2  # 设置错误记录字体颜色:红色

        style_title = xlwt.XFStyle()  # 创建表头单元格格式对象
        style_title.font = font_title  # 设置表头字体
        style_title.pattern = pattern_title  # 设置表头背景色
        # style_title.alignment = 0x02  # 设置表头字体居中

        style_normal = xlwt.XFStyle()  # 创建普通单元格格式对象
        # style_normal.alignment = 0x01  # 设置普通单元格字体居左

        style_error = xlwt.XFStyle()  # 创建出错记录单元格格式对象
        style_error.font = font_error  # 设置错误记录字体
        # style_error.alignment = 0x01  # 设置错误记录字体居左

        return [style_title, style_error, style_normal]

    def get_blank_row_id(self):
        """
        获取当前工作表记录条数
        :param sheet_name: 工作表名称
        :return: 有内容的行数
        """
        workbook = xlrd.open_workbook(r"%s" % self.report_path)
        sheet = workbook.sheet_by_name(self.sheet_name)
        return sheet.nrows

    def record_into_report(self, api_data):
        """
        将本条日志写入文件
        :param api_data: list
        :return:
        """
        id = GetReport().get_blank_row_id()
        report_copy = copy(
            xlrd.open_workbook(r"%s" % ConfigFile().report_path(),
                               formatting_info=True))
        sheet = report_copy.get_sheet(self.sheet_name)
        api_data.insert(0, id)
        if api_data[6] == 200:
            for i in range(len(api_data)):
                sheet.write(id, i, api_data[i], self.style()[2])
                report_copy.save(r"%s" % ConfigFile().report_path())
        else:
            for i in range(len(api_data)):
                sheet.write(id, i, api_data[i], self.style()[1])
                report_copy.save(r"%s" % ConfigFile().report_path())
Esempio n. 13
0
    def post_data(self, model, password=None):
        type = random.choice(MatchType().match_type(
            self.judgement_token, self.game_id)["data"])["id"]
        rule = random.choice(MatchRule().match_rule(
            self.judgement_token, self.game_id)["data"])["id"]
        people_data = random.choice(MatchPeople().match_people(
            self.judgement_token, self.game_id)["data"])
        people_id = people_data["id"]
        people_num = people_data["count"]
        # print(type(people_num))
        time_rule = GetTime().rule_time(int(people_num))
        if self.game_id == 1:
            game = "炉石"
        elif self.game_id == 2:
            game = "英雄"
        else:
            game = "守望"
        if model == "common":
            model_name = "常规"
            frozen = self.config_file.frozen()
            reward = self.config_file.raward(people_num, frozen)
            post_data02 = {
                "frozen": frozen,  # int,总蟠桃数
                "common_rewardrule": reward
            }  # Array,奖金规则,数组的键一定不能变(1,2,3,4,8,16)
        else:
            model_name = "奖池"
            entry_fee = self.config_file.entry_fee()
            reward = self.config_file.raward(people_num)
            post_data02 = {
                "apply_money": entry_fee,  # Int,报名费用.
                "money_rewardrule": reward
            }  # Array,奖金规则.eg:{"1":50}
        match_time = GetTime().match_time()
        title = game + model_name + match_time
        print(title)
        remark = random.choice(("""战城南,死郭北,野死不葬乌可食。\n
                                为我谓乌:“且为客豪,野死谅不葬,
                                腐肉安能去子逃?”\n
                                水深激激,蒲苇冥冥。\n
                                枭骑战斗死,驽马独徘徊。\n
                                梁筑室,何以南,何以北,\n
                                禾黍不获君何食?\n
                                愿为忠臣安可得?\n
                                思子良臣,良臣诚可思:\n
                                臣朝行出攻,暮不夜归。""", """有所思,乃在大海南。\n
                                何用问遗君,双珠玳瑁簪,用玉绍缭之。\n
                                闻君有他心,拉杂摧烧之。\n
                                摧烧之,当风扬其灰。\n
                                从今以往,勿复相思!\n
                                相思与君绝,鸡鸣狗吠,\n
                                兄嫂当知之。\n
                                妃呼豨!\n
                                秋风肃肃晨风飔,东方须臾高知之。""", " "))
        post_data01 = {
            "gameId": self.game_id,  # Int,游戏的Id
            "activityType": type,  # String,类型的ID
            "title": title,  # String,赛事标题
            "activity_rule_id": rule,  # Int,赛事规则的ID
            "activity_people": people_id,  # Int,选择人数的ID
            "model": model,  # String,常规模式(common),奖金池模式(money)
            "timerule": time_rule,  # Array,时间规则(eg:["2017-03-02 00:00:00"])
            "password": password,  # Int,赛事的房间密码,非必填
            "remark": remark
        }  # String,比赛的介绍,非必填
        post_data = dict(post_data01, **post_data02)
        print(post_data)
        return post_data