test_guanlian.py放在case文件夹下

test_guanlian.pyimport unittest

import requests
from urllib.parse import urljoin

class TestChoice(unittest.TestCase):
base_url = 'http://abc.cn/'
def login(self):
uri = '/abd/login'
url = urljoin(self.base_url,uri)
data = {'username':'username','passwd':'111111'}
print('开始登录',data)
response = requests.post(url,data).json()
print('调用登录接口结束,返回结果',response)
self.assertIsNotNone(response.get('login_info'),'登录失败')
#校验非空
session_id = response['login_info']['sign']
user_id = response['login_info']['userId']
return session_id,user_id

def choice(self,session_id,user_id):
uri = '/abd/choice'
url = urljoin(self.base_url,uri)
data = {'userid':user_id,'sign':session_id}
print('抽奖接口开始=====',data)
response = requests.get(url,params=data).json()
print('抽奖接口结束=======',response)
self.assertIsNotNone(response.get('product_info'),'抽奖失败')


def add_product(self,session_id,user_id):
uri = '/abd/add'
url = urljoin(self.base_url,uri)
data = {'userid':user_id,'sign':session_id,'name':'iphoneXs max'}
files = {'file':open(r'/Downloads/aaa.jpg','rb')}
response = requests.post(url,data,files=files).json()
self.assertEqual('添加成功',response.get('msg'))

def test_login_choice(self):
'''测试抽奖流程的,先登录后抽奖'''
session_id,user_id = self.login()
self.choice(session_id,user_id)

def test_login(self):
'''测试登录的'''
self.login()

def test_add_product(self):
'''测试添加商品的'''
session_id,user_id = self.login()
self.add_product(session_id,user_id)

start.py 放在与case文件夹同级目录下

 
import BeautifulReportimport unittest

test=unittest.defaultTestLoader.discover('case','test*.py')
# print(test)
runner = BeautifulReport.BeautifulReport(test)
runner.report('接口测试','interface.html')
posted on 2019-04-25 22:23  yulinlin_coding  阅读(265)  评论(0编辑  收藏  举报