From 04a492919bcde29f22f74d2427ced748bb4f448a Mon Sep 17 00:00:00 2001 From: floraachy Date: Tue, 31 Mar 2020 09:30:46 +0800 Subject: [PATCH] commit --- .../unitTest/class03262020/operateMySql.py | 10 ++++ .../unitTest/class03282020/README.txt | 9 +++ .../unitTest/class03282020/conf/config.ini | 33 +++++++++++ .../class03282020/conf/handle_config.py | 22 +++++++ .../unitTest/class03282020/conf/handle_dir.py | 43 ++++++++++++++ .../unitTest/class03282020/decimalData.py | 27 +++++++++ python27Class/unitTest/class03282020/login.py | 57 +++++++++++++++++++ .../unitTest/class03282020/manageConf.py | 51 +++++++++++++++++ 8 files changed, 252 insertions(+) create mode 100644 python27Class/unitTest/class03282020/README.txt create mode 100644 python27Class/unitTest/class03282020/conf/config.ini create mode 100644 python27Class/unitTest/class03282020/conf/handle_config.py create mode 100644 python27Class/unitTest/class03282020/conf/handle_dir.py create mode 100644 python27Class/unitTest/class03282020/decimalData.py create mode 100644 python27Class/unitTest/class03282020/login.py create mode 100644 python27Class/unitTest/class03282020/manageConf.py diff --git a/python27Class/unitTest/class03262020/operateMySql.py b/python27Class/unitTest/class03262020/operateMySql.py index 7195770..bcf1673 100644 --- a/python27Class/unitTest/class03262020/operateMySql.py +++ b/python27Class/unitTest/class03262020/operateMySql.py @@ -61,4 +61,14 @@ conn.commit() pymysql操作数据库, 默认是开启了事务 所以在执行增删改的相关操作之后一定要提交事务才会生效 连接对象.commit() + + +2052976,2053131,2053207,2053209,2053220,2053130,2038001,2038000,2037999,2037620,2037619,2053284,2053301,2048577,2053317,2053323,2052877,2052857,2052846,2052844,2053045,2053357,2048575,2048576 + + +7,6,9,14,9,7,20,2,6,4,32,7,3,13,7,7,19,26,7,6,2,3,10,8 + + +810500,809502,810623,914941,914947,914936 + """ \ No newline at end of file diff --git a/python27Class/unitTest/class03282020/README.txt b/python27Class/unitTest/class03282020/README.txt new file mode 100644 index 0000000..90860fd --- /dev/null +++ b/python27Class/unitTest/class03282020/README.txt @@ -0,0 +1,9 @@ +课程内容: + 实战接口:编写充值功能的测试用例 + 关于unittest中用例环境管理的配置方法(用例执行的前置条件/后置条件):利用setupClass解决了充值之前登录的问题 + 充值前后数据库校验,涉及到decimal数据类型 + + + + + diff --git a/python27Class/unitTest/class03282020/conf/config.ini b/python27Class/unitTest/class03282020/conf/config.ini new file mode 100644 index 0000000..abe7c11 --- /dev/null +++ b/python27Class/unitTest/class03282020/conf/config.ini @@ -0,0 +1,33 @@ +# 日志文件相关配置 +[LOG] +# 自定义日志收集器名称 +LOG_LOGGER = floralog +# 日志收集等级 +LOG_LEVEL = DEBUG +# 输出到文件的日志等级 +LOG_FILE_LEVEL = DEBUG +# 输出到控制台的日志等级 +LOG_SH_LEVEL = ERROR +# 日志文件的名称 +LOG_FILENAME = all.log +# 日志格式 +LOG_FORMATS = %%(asctime)s ---%%(name)s--- [%%(filename)s-->line:%%(lineno)d] - %%(levelname)s: %%(message)s + +[ENV] +BASE_URL = http://api.lemonban.com/futureloan +BASE_HEADERS = {'X-lemonban-Media-Type': 'lemonban.v2'} +PHONE = 131 + + +[MYSQL] +HOST=120.78.128.25 +PORT=3306 +USER=future +PASSWORD=123456 +CHARSET=utf8 + +[TEST] +PHONE=15500005678 +PWD=00005678 +LOGIN_URL=/member/login +lOGIN_METHOD=post \ No newline at end of file diff --git a/python27Class/unitTest/class03282020/conf/handle_config.py b/python27Class/unitTest/class03282020/conf/handle_config.py new file mode 100644 index 0000000..68aa976 --- /dev/null +++ b/python27Class/unitTest/class03282020/conf/handle_config.py @@ -0,0 +1,22 @@ +""" +================================= +Author: Flora Chen +Time: 2020/3/17 21:15 +-_- -_- -_- -_- -_- -_- -_- -_- +================================= +""" +import os +from configparser import ConfigParser +from python27Class.unitTest.class03282020.conf.handle_dir import CONF_DIR + +class HandleConfig(ConfigParser): + """ + 配置文件解析器类的封装 + """ + def __init__(self, filename): + super().__init__() + self.read(filename, encoding='utf-8') + +conf = HandleConfig(os.path.join(CONF_DIR, 'config.ini')) + + diff --git a/python27Class/unitTest/class03282020/conf/handle_dir.py b/python27Class/unitTest/class03282020/conf/handle_dir.py new file mode 100644 index 0000000..def0523 --- /dev/null +++ b/python27Class/unitTest/class03282020/conf/handle_dir.py @@ -0,0 +1,43 @@ +""" +================================= +Author: Flora Chen +Time: 2020/3/21 19:49 +-_- -_- -_- -_- -_- -_- -_- -_- +================================= +""" +import os + +""" + +相关路径处理 + +""" + +# 项目目录路径 + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +# 配置文件路径 + +CONF_DIR = os.path.join(BASE_DIR, "conf") + +# 用例数据路径 + +DATA_DIR = os.path.join(BASE_DIR, "testdata") + +# 日志文件路径 + +LOG_DIR = os.path.join(BASE_DIR, "logs") + +# 测试报告文件路径 + +REPORT_DIR = os.path.join(BASE_DIR, "reports") + +# 测试用例文件路径 + +CASES_DIR = os.path.join(BASE_DIR, "testcases") + +# 第三方库文件路径 + +LIB_DIR = os.path.join(BASE_DIR, "library") + diff --git a/python27Class/unitTest/class03282020/decimalData.py b/python27Class/unitTest/class03282020/decimalData.py new file mode 100644 index 0000000..579fd72 --- /dev/null +++ b/python27Class/unitTest/class03282020/decimalData.py @@ -0,0 +1,27 @@ +""" +================================= +Author: Flora Chen +Time: 2020/3/28 11:19 +-_- -_- -_- -_- -_- -_- -_- -_- +================================= +""" +import decimal + +a = 601.1 +b = decimal.Decimal('601.1') +c = decimal.Decimal(601.1) + +print(a) # 601.1 +print(b) # 601.1 +print(c) # 601.1000000000000227373675443232059478759765625 + +""" +decimal类型的数据,要保持数据的精度,要加引号。 +""" +num1 = 2.3 +num2 = 1.1 +print(num1-num2) # 1.1999999999999997 + +num3 = decimal.Decimal('2.3') +num4 = decimal.Decimal('1.1') +print(num3-num4) # 1.2 \ No newline at end of file diff --git a/python27Class/unitTest/class03282020/login.py b/python27Class/unitTest/class03282020/login.py new file mode 100644 index 0000000..07f34e3 --- /dev/null +++ b/python27Class/unitTest/class03282020/login.py @@ -0,0 +1,57 @@ +""" +================================= +Author: Flora Chen +Time: 2020/3/25 14:23 +-_- -_- -_- -_- -_- -_- -_- -_- +================================= +""" + +from requests import request +from python27Class.unitTest.class03282020.conf.handle_config import conf +import jsonpath + + +def loginapi(method, url, headers, data): + """ + 登录的接口 + :param url: + :param method: + :param headers: + :param data: + :return: + """ + response = request(method=method, url=url, headers=headers, json=data) + token_type = jsonpath.jsonpath(response.json(), '$.data..token_info..token_type')[0] + token = jsonpath.jsonpath(response.json(), '$.data..token_info..token')[0] + member_id = jsonpath.jsonpath(response.json(), '$.data..id')[0] + return token_type, token, member_id + + +if __name__ == '__main__': + url = conf.get('ENV', 'BASE_URL') + '/member/login' + headers = eval(conf.get('ENV', 'BASE_HEADERS')) + user = {"mobile_phone": conf.get('TEST', 'PHONE'), "pwd": conf.get('TEST', 'PWD')} + method = 'post' + token_info = loginapi(method, url, headers, user) + print(type(token_info[0])) + print(token_info[0] + ' ' + token_info[1], token_info[2]) + + +""" +{'code': 0, 'msg': 'OK', +'data': + {'id': 7800355, + 'leave_amount': 0.0, + 'mobile_phone': '15500005678', + 'reg_name': '小柠檬', + 'reg_time': '2020-03-21 21:26:09.0', + 'type': 0, + 'token_info': + {'token_type': 'Bearer', + 'expires_in': '2020-03-25 14:36:51', + 'token': 'eyJhbGciOiJIUzUxMiJ9.eyJtZW1iZXJfaWQiOjc4MDAzNTUsImV4cCI6MTU4NTExODIxMX0.pNjMUeC9v638hR_LiKRvnJqBljaSKmMIO6NtVIzLVdwj_jgG8xb5845eK-w8u-zygsg-7k3R6fsg1nYpMP70bA' + } + }, + 'copyright': 'Copyright 柠檬班 © 2017-2019 湖南省零檬信息技术有限公司 All Rights Reserved' +} +""" \ No newline at end of file diff --git a/python27Class/unitTest/class03282020/manageConf.py b/python27Class/unitTest/class03282020/manageConf.py new file mode 100644 index 0000000..fbabfdc --- /dev/null +++ b/python27Class/unitTest/class03282020/manageConf.py @@ -0,0 +1,51 @@ +""" +================================= +Author: Flora Chen +Time: 2020/3/28 9:55 +-_- -_- -_- -_- -_- -_- -_- -_- +================================= +""" +import unittest + +class MyTest(unittest.TestCase): + + def setUp(self): + """ + 每条用例执行之前都会执行 + :return: + """ + print('-----------1------setUp----') + pass + + def tearDown(self): + """ + 每条用例执行之后都会执行 + :return: + """ + print('-----------2-----tearDown-----') + pass + + @classmethod + def setUpClass(cls): + """ + 该测试用例类中所有用例执行之前都会执行 + :return: + """ + print('-----------3----setUpClass------') + pass + + @classmethod + def tearDownClass(cls): + """ + 该测试用例类中所有用例执行之后都会执行 + :return: + """ + print('-----------4-----tearDownClass-----') + pass + + def test_01(self): + self.assertEqual(100, 100) + + def test_02(self): + self.assertEqual(200, 200) +