列表去重的三种方法、获取验证码的图片代码、图片上传、获取图片服务器url...

# 第一种方法:用set方法
a = [1,1,2,2,3,4,5,5,5,6,7,6]
b = set(a)
print(b)

# 第二种方法:列表生成式去重
a = [1,1,2,2,3,4,5,5,5,6,7,6]
b = []
for i in a:
if i not in b:
b.append(i)
print(b)

# 第三种方法:for循环key方法去重
a = [1,1,2,2,3,4,5,5,5,6,7,6]
b = {}.fromkeys(a)
c = []
for i in b:
c.append(i)
print(c)

from conf.settings import HOST_INFO
import requests
import unittest
class ValidateCode(unittest.TestCase):
def setUp(self):
self.url = HOST_INFO + '/deskMember/validateCode'
# self.headers = {"content-type": "application/x-www-form-urlencoded"}

def test_111_validate_code_success(self): # 获取验证码的图片代码
res = requests.get(self.url) # 接口的url
f = open('code.png','wb')
f.write(res.content)
print(res.text)
f.close()

if __name__ == '__main__':
unittest.main()

from conf.settings import HOST_INFO
from lib.tools import my_request
import unittest

class LicenceIdentify(unittest.TestCase):
def setUp(self):
self.url = HOST_INFO + '/imageRec/OCRLicence'

def test_012_licence_identify(self):
"""正常营业执照识别"""
file = {'file': open('yz.jpg', 'rb')}
res = my_request('post', self.url, files=file)
print(res)
self.assertIsInstance(res, dict)
self.assertEqual(200, res.get('code'))
self.assertIn('ok', str(res)
self.assertIn('legalPerson', str(res))
self.assertIn('companyName', str(res))
file.get('file').close()
 
from conf.settings import HOST_INFO
from lib.tools import my_request
import unittest

class IdCardIdentify(unittest.TestCase):
def setUp(self):
self.url = HOST_INFO + '/imageRec/OCRIdCard'
self.headers = {"content-type": "multipart/form-data"}
# self.headers = {'Authorization': AUTHORIZATION}

def test_001_id_card_identify(self):
"""带参数的图片上传"""
file = {'file': open('127.png', 'rb')}
data = {'file': file, 'code': '0'}
res = my_request('post', self.url, data)
print(res)
self.assertIsInstance(res, dict)
self.assertNotEqual(res, {})
file.get('file').close()


if __name__ == '__main__':
unittest.main()
 
from conf.settings import HOST_INFO
import requests
import unittest
class PicUpload(unittest.TestCase):
def setUp(self):
self.url = HOST_INFO + '/pic/upload'

def test_171_pic_upload_success(self):
"""图片上传代码"""
file = {"file": open('20180920171142.jpg', 'rb')}
res = requests.post(self.url, files=file)
print(res.text)
file.get('file').close()


if __name__ == '__main__':
unittest.main()
 
from conf.settings import HOST_INFO
import requests
import json
import unittest


class PicServerUrl(unittest.TestCase):
def setUp(self):
self.url = HOST_INFO + '/pic/getTrackerUrl'

def test_172_pic_server_url_success(self):
"""获取图片服务器url"""
data = {}
data = json.dumps(data)
res = requests.post(self.url, data)
print(res.text)


if __name__ == '__main__':
unittest.main()

转载于:https://www.cnblogs.com/laosun0204/p/9796300.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值