Esempio n. 1
0
    def __pre_data(self,token=None):
        """
        对excel中所传的字典参数进行处理
        :return:
        """
        if self.data is not None and isinstance (self.data, str):
            # param = json.loads (self.data)
            if self.data.find('null') != -1:
                self.data = self.data.replace('null',"None")
            self.data = eval(self.data)   # 使用eval转成字典.eval过程中,如果表达式有涉及计算,会自动计算。

        # 如果是v3版本需要I加上签名
        if cnf.read_section_to_dict("DOMAIN")['auth_type'] == "lemonban.v3" and token is not None:
            sign,time_stamp = generator_sign(token)
            self.data["sign"] = sign
            self.data["timestamp"] = time_stamp
        return self.data
Esempio n. 2
0
    def __handle_header(self,token=None,**kwargs):
        """
        处理请求头,根据项目情况设置必要的请求头部参数
        :param token:传递的token数值
        :param kwargs:动态设置请求头信息
        :return:请求头
        """
        headers = {"Content-Type" : "application/json",
                   # 为了兼容v3版本 所以将v3版本的auth_type 设置到了配置文件中
                "X-Lemonban-Media-Type" : cnf.read_section_to_dict("DOMAIN")["auth_type"]}

        if token:
            headers["Authorization"] ="Bearer {}".format(token)
        for key,value in kwargs.items():
            if key not in headers.keys():
                headers[key] =value
        return headers
Esempio n. 3
0
def re_replace(target,obj=EnvData):
    """
    # 通过字符串正则匹配的方式将excel中读取参数化数据进行替换
     真实数据只从2个地方去获取:1个是配置文件当中的DATA区域 。另1个是,EvnData的类属性。
    :param target:字典中每个key对应的value
    :param obj: EnvData类的实例对象
    :return:
    """
    p = "#(.*?)#"
    while re.search(p,target):
        ret=re.search(p,target)
        key = ret.group(1)
        try:
            value= cnf.read_section_to_dict('DATA')[key]
        except:
            try:
                value = getattr(obj,key)
            except Exception:
                logger.info("EnvData类中不存在此【{}】".format(key))
                raise

        target = re.sub(p,str(value),target,count=1)
    return target
Esempio n. 4
0
# -*- coding: utf-8 -*-
#@Time      :2020/7/3    22:37
#@Author    :xj
#@Email     :[email protected]
#@File      :handle_db.py
#@Software  :PyCharm

import pymysql
from d2020_07_01.common.myconfig import cnf
db_cnf = cnf.read_section_to_dict("DB")


class HandleDb(object):
    def __init__(self):

        self.cnn = pymysql.connect(
            host=db_cnf["host"],
            user=db_cnf["user"],
            port=db_cnf["port"],
            password=db_cnf["password"],
            database=db_cnf["database"],
            charset="utf8",
            cursorclass=pymysql.cursors.DictCursor
        )  # cursorclass 声明读取出来的数据为字典格式 最外层为列表 如果不设置该参数每行返回数据是元组类型,最外层也是元组

        self.cur = self.cnn.cursor()

    def select_one_data(self, sql):
        try:
            self.cnn.commit()  # 查询之前先commit 同步最新数据库数据
            self.cur.execute(sql)
Esempio n. 5
0
#-*- coding:utf-8 -*-
# @Time : 2020/6/30 17:42 
# @Author : wangj38
# @File : handle_request.py 
# @Software: PyCharm
import requests
from d2020_07_01.common.myconfig import cnf
from d2020_07_01.common.mylog import logger
from d2020_07_01.common.handle_rsa import generator_sign
import json
domain_url =cnf.read_section_to_dict("DOMAIN")["ip"]

class MyRequest(object):
    def __init__(self,method,url,data):
        self.url =url
        self.method =method
        self.data =data

    def __handle_header(self,token=None,**kwargs):
        """
        处理请求头,根据项目情况设置必要的请求头部参数
        :param token:传递的token数值
        :param kwargs:动态设置请求头信息
        :return:请求头
        """
        headers = {"Content-Type" : "application/json",
                   # 为了兼容v3版本 所以将v3版本的auth_type 设置到了配置文件中
                "X-Lemonban-Media-Type" : cnf.read_section_to_dict("DOMAIN")["auth_type"]}

        if token:
            headers["Authorization"] ="Bearer {}".format(token)
Esempio n. 6
0
#@Software  :PyCharm

import unittest
from ddt import ddt, data
from d2020_07_01.common.myconfig import cnf
from d2020_07_01.common.mylog import logger
from d2020_07_01.common.EnvData import *
from d2020_07_01.common.read_excel import ReadExcel
from d2020_07_01.common.load_path import load_data_path
from d2020_07_01.common.handle_phone import *
from d2020_07_01.common.handle_request import MyRequest
import json
from d2020_07_01.common.handle_db import HandleDb
from decimal import *

sheet_name = cnf.read_section_to_dict("EXCEL")['invest']
datas = ReadExcel(load_data_path, sheet_name).load_data()
db = HandleDb()


@ddt
class TestInvest(unittest.TestCase):
    '投资类用例'

    @classmethod
    def setUpClass(cls):
        logger.info('========  start ============》开始执行{}类下的用例'.format(
            cls.__name__))
        clear_Envdata_attr()
        cls.count = 0
Esempio n. 7
0
# -*- coding: utf-8 -*-
#@Time      :2020/7/4    1:23
#@Author    :xj
#@Email     :[email protected]
#@File      :handle_phone.py
#@Software  :PyCharm
import random
from d2020_07_01.common.handle_db import HandleDb
from d2020_07_01.common.myconfig import cnf
from d2020_07_01.common.handle_request import MyRequest

old_user=cnf.read_section_to_dict('PHONE')

#随机生成11位数手机号码
def generate_phone():
    second = [3,5,7,8][random.randint(0,3)] #[3,4,5,6,7,8,9] 正常的数据是这样的 这里为了适应项目调整一下
    third ={3:random.randint(0,9),
            4:[5,7,9][random.randint(0,2)],
            5:[i for i in range(0,10) if i !=4][random.randint(0,8)],
            6:6,
            7:[i for i in range(0,10) if i not in [4,9]][random.randint(0,7)],
            8:random.randint(0,9),
            9:[1,9][random.randint(0,1)]
            }[second]
    other_eight = random.randint(10000000,99999999)
    return int("1{}{}{}".format(second,third,other_eight))

#检验注册表中是否存在这个手机号
def check_phone():
    db = HandleDb()
    while True:
Esempio n. 8
0
class EnvData(object):
    old_phone = cnf.read_section_to_dict("PHONE")['mobile'] # 充值用例中用到
    def __init__(self):
        self.phone = handle_phone.check_phone() # 生成一个数据库中不存在的手机号码
Esempio n. 9
0
#@File      :test_register.py
#@Software  :PyCharm

import unittest
from ddt import ddt, data
import json
import re
from d2020_07_01.common.handle_request import MyRequest
from d2020_07_01.common.read_excel import ReadExcel
from d2020_07_01.common.mylog import logger
from d2020_07_01.common.load_path import load_data_path
from d2020_07_01.common.myconfig import cnf
from d2020_07_01.common.handle_db import HandleDb
from d2020_07_01.common.EnvData import re_replace

sheet_name = cnf.read_section_to_dict("EXCEL")[
    "register"]  # 读取配置文件中register表数据
datas = ReadExcel(load_data_path, sheet_name).load_data()
db = HandleDb()


@ddt
class TestRegister(unittest.TestCase):
    "注册类用例"

    @classmethod
    def setUpClass(cls):
        logger.info('========  start ============》开始执行{}类下的用例'.format(
            cls.__name__))
        cls.count = 0

    @classmethod
Esempio n. 10
0
import re
import json
from d2020_07_01.common.mylog import logger
from d2020_07_01.common.handle_phone import get_old_phone
from d2020_07_01.common.handle_request import MyRequest
import jsonpath
from d2020_07_01.common.EnvData import EnvData
from d2020_07_01.common.myconfig import cnf
from d2020_07_01.common.read_excel import ReadExcel
from d2020_07_01.common.load_path import load_data_path
from d2020_07_01.common.EnvData import re_replace
from d2020_07_01.common.EnvData import clear_Envdata_attr
from d2020_07_01.common.handle_db import HandleDb
from decimal import *

sheet_name = cnf.read_section_to_dict("EXCEL")['withdraw']
datas = ReadExcel(load_data_path, sheet_name).load_data()
db = HandleDb()


@ddt
class TestWithDraw(unittest.TestCase):
    '提现类测试用例'

    @classmethod
    def setUpClass(cls):
        logger.info('========  start ============》开始执行{}类下的用例'.format(
            cls.__name__))
        clear_Envdata_attr()
        cls.count = 0
        user, pwd = get_old_phone()
Esempio n. 11
0
import jsonpath
import json
import unittest
from d2020_07_01.common.mylog import logger
from d2020_07_01.common.EnvData import clear_Envdata_attr
from d2020_07_01.common.EnvData import EnvData
from ddt import ddt, data
from d2020_07_01.common.myconfig import cnf
from d2020_07_01.common.read_excel import ReadExcel
from d2020_07_01.common.load_path import load_data_path
from d2020_07_01.common.EnvData import re_replace
from d2020_07_01.common.handle_request import MyRequest
from d2020_07_01.common.EnvData import extract_data_from_excel
from d2020_07_01.common.handle_db import HandleDb

sheet_name = cnf.read_section_to_dict("EXCEL")['loan']
datas = ReadExcel(load_data_path, sheet_name).load_data()
db = HandleDb()


@ddt
class TestLoan(unittest.TestCase):
    '加标类测试'

    @classmethod
    def setUpClass(cls):
        logger.info(
            "------------>开始执行{} 类下的测试用例集     <-----------------".format(
                cls.__name__))
        cls.count = 0
        clear_Envdata_attr()  # 清理环境类中的类属性
#-*- coding:utf-8 -*-
# @Time : 2020/8/5 15:26
# @Author : wangj38
# @File : handle_yunwen_request.py
# @Software: PyCharm
from d2020_07_01.common.myconfig import cnf
from d2020_07_01.common.mylog import logger
import requests
domain_url = cnf.read_section_to_dict("YUNWEN")['yun_wen_domaim_url']


class HandleYunWenRequest(object):
    def __init__(self, method, url, data):
        self.url = url
        self.method = method
        self.data = data

    def __handle_header(self):
        headers = {"Content-Type": "application/x-www-form-urlencoded"}
        return headers

    def __pre_url(self):
        if self.url.startswith("/"):
            return domain_url + self.url
        elif self.url.startswith('http://') or self.url.startswith("https://"):
            return self.url
        else:
            return domain_url + '/' + self.url

    def __handle_date(self):
        if self.data is not None and isinstance(self.data, str):
Esempio n. 13
0
# -*- coding: utf-8 -*-
#@Time      :2020/6/17    21:13
#@Author    :xj
#@Email     :[email protected]
#@File      :mylog.py
#@Software  :PyCharm

import logging
import colorlog
from d2020_07_01.common.load_path import load_log_path
from d2020_07_01.common.myconfig import cnf
log_dict = cnf.read_section_to_dict('LOG')  # 获取LOG下所有的option


class MyLog(logging.Logger):
    def __init__(self, name=log_dict["name"], level=log_dict["level"]):
        super().__init__(name, level)
        self.setLevel(level)
        self.fmt = logging.Formatter(
            "%(asctime)s-%(name)s-【%(levelname)s】-%(filename)s-【%(lineno)d】:%(message)s"
        )

    def my_log(self,
               file_path=None,
               ch_level=log_dict["ch_level"],
               fh_level=log_dict["fh_level"]):
        if not self.handlers:
            ch = logging.StreamHandler()
            ch.setLevel(ch_level)
            ch.setFormatter(self.fmt)
            self.addHandler(ch)
Esempio n. 14
0
from ddt import ddt,data
import json
import re
from decimal import *
from d2020_07_01.common.handle_request import MyRequest
from d2020_07_01.common.read_excel import ReadExcel
from d2020_07_01.common.mylog import logger
from d2020_07_01.common.load_path import load_data_path
from d2020_07_01.common.myconfig import cnf
from d2020_07_01.common.handle_db import HandleDb
from d2020_07_01.common.EnvData import re_replace,EnvData,clear_Envdata_attr
from d2020_07_01.common.handle_phone import get_old_phone
import jsonpath


sheet_name = cnf.read_section_to_dict("EXCEL")["recharge"] # 读取配置文件中recharge表数据
datas = ReadExcel (load_data_path,sheet_name).load_data ()
db = HandleDb()

@ddt
class TestRecharge(unittest.TestCase):
    "充值类用例"

    @classmethod
    def setUpClass(cls):
        logger.info('========  start ============》开始执行{}类下的用例'.format(cls.__name__))
        clear_Envdata_attr() # 清除上个脚本设置的动态属性
        cls.count = 0
        user,pwd = get_old_phone()
        res = MyRequest('POST','/futureloan/member/login',{"mobile_phone":user,"pwd":pwd}).send_requests()
        cls.user_id = jsonpath.jsonpath(res.json(),'$..id')[0]
# @Time : 2020/8/5 15:49
# @Author : wangj38
# @File : test_chatlogbysession.py
# @Software: PyCharm
from ddt import ddt, data
from d2020_07_01.common.mylog import logger
from d2020_07_01.common.load_path import load_yunwen_data_path
from d2020_07_01.common.read_excel import ReadExcel
from d2020_07_01.common.myconfig import cnf
from d2020_07_01.common.EnvData import re_replace
import unittest
from jsonpath import jsonpath
import json
from d2020_07_01.common.handle_yunwen_request import HandleYunWenRequest
import re
sheet_name = cnf.read_section_to_dict("EXCEL")['chatbysession']
datas = ReadExcel(load_yunwen_data_path, sheet_name).load_data()


@ddt
class TestChatBySession(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        logger.info('开始执行获取访客会话用例')
        cls.count = 0

    @classmethod
    def tearDownClass(cls) -> None:
        logger.info('结束执行获取会话用例')

    def setUp(self) -> None: