def param_kp(self, base_json):
        """
        "reqPromKeys": [
        {
            "promId": "PEOHQO210200003",
            "promMethodId": "1",
            "keyCode": "HQ20210201"
        }]

        ==========================
        [TestCase]
        1.PROMPARAM_KDKP : promId=PEOHQO200900006,promMethodId=1,keyCode=HQ20210201
        2.PROMPARAM_KDKP : promKeyCode=HQ20210201  (salesitem)
        """
        if self.flag:
            if kp_method_id == '':
                self.cls.skipTest('请补全config [PromParams] 下 KPMethodId 的信息')
            promparam_kps = None
            testcase_desci = "<br><font color='red' style='font-weight:bold'>" \
                             "请补全testcase中PROMPARAM_KDKP下的 keycode或 promid和keycode的信息</font>"
            info = '请补全testcase中PROMPARAM_KDKP下的 keycode 或 promid和keycode的信息'
            Flag = False
            for i, case in enumerate(self.testcase):
                if case['PROMPARAM_KDKP'] is not None:
                    if len(
                            re.findall(r'\bpromid\b|\bkeycode\b',
                                       case['PROMPARAM_KDKP'],
                                       re.IGNORECASE)) == 2:
                        Flag = True
                        promparam_kps = get_param_to_dict(
                            self.cls, 'PROMPARAM_KDKP', self.testcase, REQUEST,
                            'promid', 'keycode')
                        break
                    elif len(
                            re.findall(r'\bpromkeycode\b',
                                       case['PROMPARAM_KDKP'],
                                       re.IGNORECASE)) == 1:
                        promparam_kps = get_param_to_dict(
                            self.cls, 'PROMPARAM_KDKP', self.testcase, REQUEST,
                            'promkeycode')
                        break
                    else:
                        if i == len(self.testcase) - 1:
                            self.cls._testMethodDoc += testcase_desci
                            self.cls.skipTest(info)
                else:
                    if i == len(self.testcase) - 1:
                        self.cls._testMethodDoc += testcase_desci
                        self.cls.skipTest(info)
Beispiel #2
0
    def param_xp_check(self, test_cls, testcase, response):
        """
        【request】
        不需要额外传输特定的参数
        【response】

        PROMPARAM_XP: ;PEOHQO210400007:batchs={batchNo=HQ003,qty=1#batchNo=HQ004,qty=1},packCode=01
        或者 PROMPARAM_XP: PEOHQO210400007:batchs={batchNo=HQ003,qty=1#batchNo=HQ004,qty=1},packCode=01#PEOHQO210400008:batchs={batchNo=HQ005,qty=1#batchNo=HQ006,qty=1},packCode=01)
        """
        Flag = ParamChecker._check_promdetail(testcase)
        if Flag:
            # ;PEOHQO210400007:batchs={batchNo=HQ003,qty=1#batchNo=HQ004,qty=1},packCode=01
            # {'response': {'PEOHQO210400007':{'batchs':[{'batchNo':'HQ003','qty':1},{'batchNo':'HQ004','qty':1}],'packCode':'01'}}}
            param_xp = get_param_to_dict(test_cls, 'PROMPARAM_XP', testcase,
                                         RESPONSE, 'batchs', 'batchno', 'qty',
                                         'packcode')
            param_xp_log = getattr(ParamLog, 'param_xp_log')
            b_log = ''
            param_xp_dict = {}  # expected param_xp_dict
            for xp in param_xp:
                if xp['response'] is not None:
                    param_xp_dict.update(xp['response'])
            for k, v in param_xp_dict.items():
                for i, batch in enumerate(v['batchs']):
                    param_xp_dict[k]['batchs'][i]['qty'] = float(batch['qty'])
            res_relyon_consumes = response['resRelyOnConsume']
            res_relyon_consume_dict = {}  # actual param_xp_dict
            for res_relyon_consume in res_relyon_consumes:
                if res_relyon_consume['material'] == 'COUPONPACKAGE_ISSUE':
                    promid = res_relyon_consume['promId']
                    pack_code = res_relyon_consume['resource']['packCode']
                    batchs = []
                    for batch in res_relyon_consume['resource']['batchs']:
                        b_dict = {}
                        b_dict['batchno'] = batch['batchNo']
                        b_dict['qty'] = batch['qty']
                        batchs.append(b_dict)
                    tmp_dict = {}
                    tmp_dict['batchs'] = batchs
                    tmp_dict['packcode'] = pack_code
                    res_relyon_consume_dict[promid] = tmp_dict
            if operator.eq(param_xp_dict, res_relyon_consume_dict):
                pass
            else:
                b_log += param_xp_log(ParamLog, test_cls, testcase,
                                      param_xp_dict, res_relyon_consume_dict)
                test_cls.fail(b_log)
        else:
            pass
 def param_br(self, base_json):
     """
         是否加入XE 参数
         promid: PEOHQO201100039
         【request】
         "reqPromBonusRedeem": {
             "method": 2,
             "details": [
                 {
                     "gradeCenter": "*",
                     "bonusCenter": "*",
                     "bonus": 90160
                 }
             ]
         }
     =====================================
     [TestCase] PROMPARAM_BR:  bonus=90160
     """
     if self.flag:
         if br_method_id == '':
             self.cls.skipTest('请补全config [PromParams] 下 BRMethodId 的信息')
         # base_json = self.param_xe(base_json)
         vipinfo = None
         promparam_brs = get_param_to_dict(self.cls, 'PROMPARAM_BR',
                                           self.testcase, REQUEST, 'bonus')
         promparam_br = None
         for pb in promparam_brs:
             if pb['request'] is not None:
                 promparam_br = pb
         for row in self.testcase:
             if row['VIPINFO'] is not None:
                 vipinfo = to_dict(self.cls, 'VIPINFO', row['VIPINFO'])
                 break
         bonus_redeem_value = {'method': 0, 'details': []}
         req_prombonus_redeem = {'reqPromBonusRedeem': {}}
         bonus_redeem_value['method'] = br_method_id
         detail = {'gradeCenter': '', 'bonusCenter': '', 'bonus': 0}
         detail['gradeCenter'] = vipinfo['vipgradecenter']
         detail['bonusCenter'] = vipinfo['vipbonuscenter']
         detail['bonus'] = int(promparam_br['request']['bonus'])
         bonus_redeem_value['details'].append(detail)
         req_prombonus_redeem['reqPromBonusRedeem'] = bonus_redeem_value
         base_json.update(req_prombonus_redeem)
         return base_json
     else:
         return base_json
    def param_gt(self, base_json):
        """
            "reqGiftUserInput": [{
                "promId": "PEOHQO201100015",
                "promMethodId": "1"
            }]

        =====================================
        [TestCase] PROMPARAM_GT : promId=PEOHQO201100015
        """
        if self.flag:
            promid_dict = get_param_to_dict(self.cls, 'PROMPARAM_GT',
                                            self.testcase, REQUEST, 'promid')
            req_gift_user_input_dict = {'reqGiftUserInput': []}
            req_gitf_user_inputs = []
            # to tag PROMPARAM_GT whether it is None
            PROMPARAM_GT_FLAG = True
            for promid_d in promid_dict:
                if promid_d['request'] is None:
                    pass
                else:
                    PROMPARAM_GT_FLAG = False
                    req_gitf_user_input = {}
                    requests = promid_d['request']
                    for req in requests:
                        req_gitf_user_input.update(req)
                        req_gitf_user_input['promMethodId'] = gt_method_id
                        req_gitf_user_inputs.append(req_gitf_user_input)
            # if no promid is including in PROMPARAM_GT, skip this testcase
            if PROMPARAM_GT_FLAG:
                for i, case in enumerate(self.testcase):
                    if case['PROMLESSDETAIL'] is None or case[
                            'PROMLESSDETAIL'].strip() == '':
                        pass
                    else:
                        self.cls._testMethodDoc += "<br><font color='red' style='font-weight:bold'> TESTCASE 下" \
                        "【PROMPARAM_GT】缺少promId数据</font>"
                        self.cls.skipTest('TESTCASE 下【PROMPARAM_GT】缺少promId数据')
            req_gift_user_input_dict['reqGiftUserInput'] = req_gitf_user_inputs
            base_json.update(req_gift_user_input_dict)
            return base_json
        else:
            return base_json
Beispiel #5
0
    def param_xc_check(self, test_cls, testcase, response):
        """
        【request】
        不需要额外传输特定的参数

        【response】

        PROMPARAM_XG:;PEOHQO210400008:batchno=0HQ002,qty=1
        """
        Flag = ParamChecker._check_promdetail(testcase)
        if Flag:
            param_xc = get_param_to_dict(test_cls, 'PROMPARAM_XC', testcase,
                                         RESPONSE, 'batchno', 'qty')
            # change format into {'PEOHQO210400008':{'batchno':'0HQ002', 'qty':1}}
            param_xc_d = {}
            res_relyon_consumes = response['resRelyOnConsume']
            for xc in param_xc:
                if xc['response'] is not None:
                    for k, v in xc['response'].items():
                        for k_, v_ in v.items():
                            if k_ == 'qty':
                                xc['response'][k]['qty'] = float(v[k_])
                    param_xc_d.update(xc['response'])
            param_xc_log = getattr(ParamLog, 'param_xc_log')
            b_log = ''
            # change format into {'PEOHQO210400008':{'batchno':'0HQ002', 'qty':1}}
            res_relyon_consume_d = {}
            for consume in res_relyon_consumes:
                if consume['material'] == 'COUPON_ISSUE':
                    resource = {}
                    resource['batchno'] = consume['resource']['batchNo']
                    resource['qty'] = consume['resource']['qty']
                    res_relyon_consume_d[consume['promId']] = resource
            # 直接对比期望和实际结果字典,存在不同的直接fail
            if operator.eq(param_xc_d, res_relyon_consume_d):
                pass
            else:
                b_log += param_xc_log(ParamLog, test_cls, testcase, param_xc_d,
                                      res_relyon_consume_d)
                test_cls.fail(b_log)
        else:
            pass
Beispiel #6
0
    def param_xe_check(self, test_cls, testcase, response):
        """
        promoid: PEOHQO201100036
        【request】
            "salesTotal": {
                "customerCode": "NV02D0130120000007",
                "bonusBalance": [
                    {
                        "vipGradeCenter": "*",
                        "vipBonusCenter": "*"
                    }
                ]
            }

        salesData 下:
        "vipGradeCenter": [
            "*"
        ],
        "vipBonusCenter": "*"

        【response】
         需要注意: 如果存在多个促销id,对应的促销id的bonusGive
         "resSalesItemConsumes":[
            {
               "bonusGive": 100
            }
         ]

         判断逻辑:
         匹配送积分的所有促销,如果期望结果和实际结果完全匹配,则case pass
         [{'response':{'PEOHQO201100036':[{'bonusGive':1070},{'bonusGive':1080}]}}]
        """
        param_xe = get_param_to_dict(test_cls, 'PROMPARAM_XE', testcase,
                                     RESPONSE, 'bonusGive')
        # 整合param_xe数据
        param_xes = []
        # change format into [{'PEOHQO201100036':[1070,1080], 'PEOHQO201100037':[1070,1080]}, {'PEOHQO201100036':[1070,1080]}]
        # param_xes includes all item information
        for param in param_xe:
            param_xe_one = {}
            promids_detail = param['response']
            if promids_detail is None:
                param_xes.append(None)
            else:
                for k, v in promids_detail.items():
                    if type(v) is list:
                        bonus_gives = []
                        for i_ in v:
                            bonus_gives.append(float(i_['bonusgive']))
                        param_xe_one[k] = bonus_gives
                    else:
                        param_xe_one[k] = []
                        param_xe_one[k].append(float(v['bonusgive']))
            param_xes.append(param_xe_one)
        res_sales_items = response['resSalesItems']
        param_xe_log = getattr(ParamLog, 'param_xe_log')
        b_log = ''
        FLAG = False
        actual_itemindexs = {}
        for j, sales_items in enumerate(res_sales_items):
            # record the relationship about item index in testcase and itemindex in response
            actual_itemindexs[sales_items['itemIndex']] = j
        for i, case in enumerate(testcase):
            if i in actual_itemindexs:
                # change actual bonusGive format into {'PEOHQO201100036':[1070,1080], 'PEOHQO201100037':[1070,1080]}
                bonus_give_d = {}
                res_salesitem_consumes = res_sales_items[
                    actual_itemindexs[i]]['resSalesItemConsumes']
                for res_salesitem_consume in res_salesitem_consumes:
                    if res_salesitem_consume['bonusGive'] == 0:
                        pass
                    else:
                        promid = res_salesitem_consume['promId']
                        if promid in bonus_give_d:
                            bonus_give_d[promid].append(
                                res_salesitem_consume['bonusGive'])
                        else:
                            bonus_give_d[promid] = []
                            bonus_give_d[promid].append(
                                res_salesitem_consume['bonusGive'])
                # when expected bonusGive is None, to compare
                if param_xes[i] is None:
                    if bonus_give_d == {}:
                        pass
                    else:
                        b_log += param_xe_log(ParamLog, test_cls, testcase,
                                              response, param_xes)
                        test_cls.fail(b_log)
                else:
                    # compare expected bonusGive dict with actual bonusGive dict
                    if operator.eq(param_xes[i], bonus_give_d):
                        pass
                    else:
                        b_log += param_xe_log(ParamLog, test_cls, testcase,
                                              response, param_xes)
                        test_cls.fail(b_log)
            else:
                if param_xes[i] is None:
                    pass
                else:
                    b_log += param_xe_log(ParamLog, test_cls, testcase,
                                          response, param_xes)
                    test_cls.fail(b_log)
 def param_nc(self, base_json):
     """
         "reqPromCouponSettle": {
         "method": 3,
         "coupons": [{
             "batchNo": "HQ002",
             "cpNo": "0CF0B21002040100004239",
             "qty": 1,
             "batchDesci": "消费满500可得印花一枚,累计10个印花换礼品"
         }, {
             "batchNo": "HQ002",
             "cpNo": "0CF0B21002230100004375",
             "qty": 1,
             "batchDesci": "消费满500可得印花一枚,累计10个印花换礼品"
         }
         }]
     ================================
     PROMPARAM_NC : batchNo=HQ001,cpNo=0HQOO0001D710010000042,qty=1#batchNo=HQ001,cpNo=0HQOO0001D710010000145,qty=1;
     "#" 分隔符,如果 batchNo=HQ001,cpNo=0HQOO0001D710010000042,qty=1 有多个这样的组合,需要使用 '#' 分隔符分开,如果只有一个组合
     则不需要分隔符 #
     """
     if self.flag:
         if nc_method_id == '':
             self.cls.skipTest('请补全config [PromParams] 下 NCMethodId 的信息')
         promparam_ncs = None
         testcase_desci = "<br><font color='red' style='font-weight:bold'>" \
                          "请补全testcase中PROMPARAM_NC下的 batchNo、cpNo、qty的信息</font>"
         info = '请补全testcase中PROMPARAM_NC下的 batchNo、cpNo、qty的信息'
         Flag = False
         for i, case in enumerate(self.testcase):
             if case['PROMPARAM_NC'] is not None:
                 if len(
                         re.findall(r'\bbatchno\b|\bcpno\b|\bqty\b',
                                    case['PROMPARAM_NC'],
                                    re.IGNORECASE)) >= 3:
                     promparam_ncs = get_param_to_dict(
                         self.cls, 'PROMPARAM_NC', self.testcase, REQUEST,
                         'batchno', 'cpno', 'qty')
                     break
                 else:
                     if i == len(self.testcase) - 1:
                         self.cls._testMethodDoc += testcase_desci
                         self.cls.skipTest(info)
             else:
                 if i == len(self.testcase) - 1:
                     self.cls._testMethodDoc += testcase_desci
                     self.cls.skipTest(info)
         for promparam_nc in promparam_ncs:
             if promparam_nc['request'] is None:
                 pass
             else:
                 Flag = True
                 req_prom_coupon_settle_dict = {
                     'reqPromCouponSettle': {
                         'method': nc_method_id,
                         'coupons': None
                     }
                 }
                 coupons = []
                 if type(promparam_nc['request']) is list:
                     for prom_param in promparam_nc['request']:
                         coupon = {
                             'batchNo': None,
                             'cpNo': None,
                             'qty': None
                         }
                         coupon['batchNo'] = prom_param['batchno']
                         coupon['cpNo'] = prom_param['cpno']
                         coupon['qty'] = prom_param['qty']
                         coupons.append(coupon)
                 elif type(promparam_nc['request']) is dict:
                     coupon = {'batchNo': None, 'cpNo': None, 'qty': None}
                     prom_param = promparam_nc['request']
                     coupon['batchNo'] = prom_param['batchno']
                     coupon['cpNo'] = prom_param['cpno']
                     coupon['qty'] = prom_param['qty']
                 req_prom_coupon_settle_dict['reqPromCouponSettle'][
                     'coupons'] = coupons
                 base_json.update(req_prom_coupon_settle_dict)
                 break
         if Flag:
             pass
         else:
             self.cls.skipTest(info)
         return base_json
 def param_dis(self, base_json):
     """
         【Demo request salesTotal】
         "reqDiscOneItemUserSelect": [
             {
                 "promId": "PEOHQO200900006",
                 "promMethodId": "1",
                 "selectedPromPackages": [
                     {
                         "applySerail": 1,
                         "pkgItems": [
                             {
                                 "itemCode": "DS016",
                                 "itemOrgId": "000000",
                                 "lessItemIndexs": [
                                     {
                                         "lessItemIndex": 0,
                                         "useQty": 1
                                     }
                                 ],
                                 "pkgQty": 1,
                                 "isChecked": true
                             }
                         ]
                     }
                 ]
             }
         ]
     =====================================
     [TestCase] PROMPARAM_DIS : promId=PEOHQO200900006,lessItemIndex=0,useQty=1,pkgQty=1
     """
     # -DIS 参数的case,如果不传入对应需要的参数,促销服务器会奔溃
     if dis_method_id == '':
         self.cls.skipTest('请补全config [PromParams] 下 DISMethodId 的信息')
     elif apply_serail == '':
         self.cls.skipTest(
             '请补全config [reqDiscOneItemUserSelectDefault] 下 applySerail 的信息'
         )
     elif is_checked == '':
         self.cls.skipTest(
             '请补全config [reqDiscOneItemUserSelectDefault] 下 isChecked 的信息')
     _apply_serail = int(apply_serail)
     _is_checked = bool(is_checked)
     if self.testcase == []:
         self.cls.skipTest('找不到TestCase数据')
     promparam_diss = get_param_to_dict(self.cls, 'PROMPARAM_DIS',
                                        self.testcase, REQUEST, 'promid',
                                        'lessitemindex', 'useqty', 'pkgqty')
     promparam_dis = None
     for pd in promparam_diss:
         if pd['request'] is not None:
             promparam_dis = pd
     req_disc_one_item_user_select = {'reqDiscOneItemUserSelect': []}
     req_disc_one_item = {
         'promId': '',
         'promMethodId': '',
         'selectedPromPackages': []
     }
     req_disc_one_item['promId'] = promparam_dis['request']['promid']
     req_disc_one_item['promMethodId'] = dis_method_id
     selectedPromPackage = {'applySerail': 0, 'pkgItems': []}
     selectedPromPackage['applySerail'] = _apply_serail
     pkgItem = {
         'itemCode': '',
         'itemOrgId': '',
         'lessItemIndexs': [],
         'pkgQty': 0,
         'isChecked': True
     }
     less_item_index = int(promparam_dis['request']['lessitemindex'])
     itemcode = self.testcase[less_item_index]['ITEMCODE']
     item_orgid = oracle.select(
         "select xf_itemorgid from xf_itemmas where xf_style = '{}'".format(
             itemcode))
     if item_orgid == []:
         self.cls._testMethodDoc += "<br><font color='red' style='font-weight:bold'> 请检查 itemcode: {} 是否正确 </font>".format(
             itemcode)
         self.cls.skipTest('请检查 itemcode: {} 是否正确'.format(itemcode))
     else:
         item_orgid = item_orgid[0][0]
     pkgItem['itemCode'] = itemcode
     pkgItem['itemOrgId'] = item_orgid
     pkgItem['pkgQty'] = int(promparam_dis['request']['pkgqty'])
     pkgItem['isChecked'] = _is_checked
     lessItemIndex = {'lessItemIndex': 0, 'useQty': 0}
     lessItemIndex['lessItemIndex'] = less_item_index
     lessItemIndex['useQty'] = int(promparam_dis['request']['useqty'])
     pkgItem['lessItemIndexs'].append(lessItemIndex)
     selectedPromPackage['pkgItems'].append(pkgItem)
     req_disc_one_item['selectedPromPackages'].append(selectedPromPackage)
     req_disc_one_item_user_select['reqDiscOneItemUserSelect'].append(
         req_disc_one_item)
     base_json.update(req_disc_one_item_user_select)
     return base_json
 def param_bl(self, base_json):
     # TODO 确认 items 是否会有多个货品信息 ???
     """
         promid: PEOHQO201100039 ???
         promid: Quota
         加入XE参数
         【request】
         "reqPromQuota": [
             {
                 "promId": "PEOHQO201100034",
                 "promMethodId": "1",
                 "items": [
                     {
                         "itemIndex": 0,
                         "useQty": 1
                     }
                 ]
             }
         ]
     ==========================================
     [TestCase] PROMPARAM_BL : promId=PEOHQO201100034,itemIndex=0,useQty=1
     """
     if self.flag:
         if bl_method_id == '':
             self.cls.skipTest('请补全config [PromParams] 下 BLMethodId 的信息')
         promparam_bls = get_param_to_dict(self.cls, 'PROMPARAM_BL',
                                           self.testcase, REQUEST, 'promid',
                                           'itemindex', 'useqty')
         promparam_bl = []
         for pb in promparam_bls:
             if pb['request'] is not None:
                 promparam_bl.append(pb)
         req_prom_quotas = {'reqPromQuota': []}
         req_prom_quota = {'promId': '', 'promMethodId': '', 'items': []}
         # solve the problem that quota multi items
         for i, bl in enumerate(promparam_bl):
             item = {'itemIndex': 0, 'useQty': 0}
             req_prom_quota['promId'] = bl['request']['promid']
             req_prom_quota['promMethodId'] = bl_method_id
             item['itemIndex'] = int(bl['request']['itemindex'])
             item['useQty'] = int(bl['request']['useqty'])
             if i == 0:
                 req_prom_quota['items'].append(item)
                 req_prom_quotas['reqPromQuota'].append(req_prom_quota)
             else:
                 if req_prom_quotas['reqPromQuota'] != []:
                     for prom_quota in req_prom_quotas['reqPromQuota']:
                         if req_prom_quota['promId'] == prom_quota[
                                 'promId']:
                             # req_prom_quotas['reqPromQuota']['']
                             prom_quota['items'].append(item)
                             break
                         else:
                             req_prom_quota['items'].append(item)
                             req_prom_quotas['reqPromQuota'].append(
                                 req_prom_quota)
                             break
                 # req_prom_quota['items'].append(item)
             # req_prom_quotas['reqPromQuota'].append(req_prom_quota)
         base_json.update(req_prom_quotas)
         return base_json
     else:
         return base_json