??????????????
??????????????????????????????:
??????????????????????url???????
?????????????ζ?????????????
?????????requests session??????
?????????ò????????á?
???????????????????????????????:
??class DemoApi(object):
????def __init__(self?? base_url):
????self.base_url = base_url
????@request(url='login'?? method='post')
????def login(self?? username?? password):
????"""
??????????
????"""
????data = {
????'username': username??
????'password': password
????}
????return {'data': data}
????@request(url='info'?? method='get')
????def info(self):
????"""
??????????
????"""
????pass
???????????????????
??******************************************************
????1?????????
??????????
????2??????url
????http://127.0.0.1:5000/login
????3????????
????post
????4??????headers
????{
????"Accept": "*/*"??
????"Accept-Encoding": "gzip?? deflate"??
????"Connection": "keep-alive"??
????"User-Agent": "python-requests/2.7.0 CPython/2.7.10 Darwin/16.4.0"
????}
????5??body????
????{
????"password": "123456"??
????"username": "admin"
????}
????6????????
????{
????"code": 200??
????"msg": "success"
????}
?????????????????python?????????????????????????????????????????о?????????????????????????????????????????????μ?????????????????????????????????·??
????????????????
???????????/????????
???????????????????????????
???????url
????????requests session???????????????????????
??????????в?????????http??????????
????????????????????г?????????????????????????????
???????????????https://github.com/yuyu1987/pithy-test/blob/master/pithy/api.py
??????????
????http??????????????????????????????????Щ?????
????[x] ??HTTPЭ????
????[x] ??????????д
????[x] ???????????
????[x] ???????????
????[x] ???????д
????[x] ???????????
????[x] ????????
????[x] ?????
??????????????????????????????????????????????????????????????????ж??
???????????????????????Ч???
?????????????????????????
???????????????????????
???????漸??????????????????????????????????????
???????????
?????????????????????????????????????????
??????python?????????????????report???????????????????д??????????????????
????pytest????????pytest-html??allure pytest??
????unittest????????HTMLTestRunner??
????????????
??????????????????Jenkins?????л???????????????????С????????????й??????????Jenkins??????
??????????????д
??????????????1???
???????????????????????????????????????????
????????????????????????????????飬??????????????飬?????????????????
??????????????????????????????????????????????????????????????????????????????????????к????????????????????????????????????????
???????????????????????????д?????????????????????????????????????????????????????
?????????????
???????????????????????????????Щ???????????????????????????л??????л??????????????????Щ???ò???????????????????????????????дЧ???
???????????????
??????????????д???????д???????????(xml??yaml??json??.py??excel??)??д??????????????????????????????????????????????????????????
???????pithy?????????
????pithy????????????????????????????????????Ч???
?????????????????
??????????????????
????????????????£?
?????????????????
????http client???
????thrift?????
????????????????
???????JSON?????????????
??????д??????????????pytest??pytest??????????????????????????????????????
???????
pip install pithy-test
pip install pytest
???????
?????????????????
??>>>  pithy-cli init
?????????????????????api????app: api
????????????????????pithy-api-test: pithy-api-test
???????????pithy-api-test???
??????????...
???????? api/.gitignore                   [√]
???????? api/apis/__init__.py             [√]
???????? api/apis/pithy_api.py            [√]
???????? api/cfg.yaml                     [√]
???????? api/db/__init__.py               [√]
???????? api/db/pithy_db.py               [√]
???????? api/README.MD                    [√]
???????? api/requirements.txt             [√]
???????? api/test_suites/__init__.py      [√]
???????? api/test_suites/test_login.py    [√]
???????? api/utils/__init__.py            [√]
???????????????????????????
???????????????
>>> tree pithy-api-test
????pithy-api-test
?????????? README.MD
?????????? apis
??????   ?????? __init__.py
??????   ?????? pithy_api.py
?????????? cfg.yaml
?????????? db
??????   ?????? __init__.py
??????   ?????? pithy_db.py
?????????? requirements.txt
?????????? test_suites
??????   ?????? __init__.py
??????   ?????? test_login.py
?????????? utils
?????????? __init__.py
????4 directories?? 10 files
????????HTTP?????????
????from pithy import request
????@request(url='http://httpbin.org/post'?? method='post')
????def post(self?? key1='value1'):
????"""
????post method
????"""
????data = {
????'key1': key1
????}
????return dict(data=data)
????# ???
????response = post('test').to_json()     # ????json????????????
????response = post('test').json          # ????json????????????
????response = post('test').to_content()  # ?????????
????response = post('test').content       # ?????????
????response = post('test').get_cookie()  # ???cookie????
????response = post('test').cookie        # ???cookie????
????# ??????? ??????response = {'a': 1?? 'b': { 'c': [1?? 2?? 3?? 4]}}
????response = post('13111111111'?? '123abc').json
????print response.b.c   # ??????????????[1?? 2?? 3?? 4]
????print response('$.a') # ???object path????????1
????for i in response('$..c[@>3]'): # ???object path???????????c????????3?????
????print i
???????JSON????????
????# 1??????JSON??KEY
????from pithy import JSONProcessor
????dict_data = {'a': 1?? 'b': {'a': [1?? 2?? 3?? 4]}}
????json_data = json.dumps(dict_data)
????result = JSONProcessor(json_data)
????print result.a     # ?????1
????print result.b.a   # ?????[1?? 2?? 3?? 4]
????# 2??????????KEY
????dict_data = {'a': 1?? 'b': {'a': [1?? 2?? 3?? 4]}}
????result = JSONProcessor(dict_data)
????print result.a     # 1
????print result.b.a   # [1?? 2?? 3?? 4]
????# 3??object path??
????raw_dict = {
????'key1':{
????'key2':{
????'key3': [1?? 2?? 3?? 4?? 5?? 6?? 7?? 8]
????}
????}
????}
????jp = JSONProcessor(raw_dict)
????for i in jp('$..key3[@>3]'):
????print i
????# 4???????÷?
????dict_1 = {'a': 'a'}
????json_1 = '{"b": "b"}'
????jp = JSONProcessor(dict_1?? json_1?? c='c')
????print(jp)
??????????
??????????У????????????????Ч?????????????????????????????????????????????δ?漰??????????????????????????MOCK??????·???????????????????????????????????????????????????л??