コード例 #1
0
 def test_success_failed2(self):
     '''接口测试用例3 '''
     payload = {'CommandCode': 'GetAllCityData', 'Marker': '1482738389646',"TransferData": "{\'CityId\':}"}
     r = requests.post(self.url, data=read_json.dumps(payload), headers=self.headers)
     print(r.status_code)
     assert '无效的 JSON 基元: 。' in read_json.loads(r.text)["ErrorInfo"]
     self.assertEqual(200,r.status_code)
コード例 #2
0
 def test_success_failed3(self):
     '''接口测试用例4 '''
     payload = {'CommandCode': 'GetAllCityData', 'Marker': '1482738389646',"TransferData": "{\'CityId\':123456}"}
     headers = {'Content-Type': 'application/json;charset=UTF-8'}
     r = requests.post(self.url, data=read_json.dumps(payload), headers=self.headers)
     print(r.status_code)
     assert '未找到' in read_json.loads(r.text)["ErrorInfo"]
     self.assertEqual(200,r.status_code)
コード例 #3
0
#coding=utf-8

#7. 序列化和反序列化  json.dumps(a)  json.loads(a)
import requests
from other import read_json

print(read_json.__all__)

dict1 = {'name':'luruifeng','age':28,'address':'深圳'}
print("未序列化之前的数据类型是:",type(dict1))
print('序列化前的数据是:',dict1)

print('-'*30)

#对dict1进行序列化操作
str1 = read_json.dumps(dict1)
print('序列化后的数据类型是:',type(str1))
print('序列化后的数据为:',str1)

print('-'*30)

#对str1进行返序列化
str = read_json.loads(str1)
print('返序列化后的数据类型是:',type(str))
print('返序列化后的数据为:',str)

print('-'*30)

#又或者:
r = requests.get("http://wthrcdn.etouch.cn/weather_mini?city=北京")
print(r.text)
コード例 #4
0
#coding=utf-8
'''
import requests

requests.get('https://github.com/timeline.json')
requests.put('http://httpbin.org/put')
requests.post('http://httpbin.org/post')
requests.delete('http://httpbin/ddelete')

'''

import requests
from other import read_json

data = {'username': '******', 'password': '******'}
r = requests.post('http://m.cyw.com/index.php?m=api&c=login&a=authorized',
                  data=data)

#反序列化
print(read_json.dumps(r.text))
print(r.json())
print(r.json()['code'])
コード例 #5
0
 def test_success_info(self):
     '''接口测试用例1  '''
     payload = {'CommandCode': 'GetAllCityData', 'Marker': '1482738389646',"TransferData": "{\'CityId\':430100}"}
     r = requests.post(self.url, data=read_json.dumps(payload), headers=self.headers)
     print(r.status_code)
     assert '获取成功' in read_json.loads(r.text)["ErrorInfo"]