列表去重的四种方法、获取验证码的图片代码、图片上传、获取图片服务器url
# 第一种方法:用set方法
a = [1, 1, 2, 2, 3, 4, 5, 5, 5, 6, 7, 6]
b = set(a)
print(b)
# 第二种方法:列表生成式去重
list1 = [1, 1, 2, 2, 3, 4, 5, 5, 5, 6, 7, 6]
list2 = []
[list2.append(i) for i in list1 if i not in list2]
print(list2)
# 第三种方法:定义一个空list去重(和上面一样)
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) # b是一个字典,key是去重的顺序值,value是None
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()