python nosetests

本文通过两个测试案例,验证了Cxx服务接口的功能正确性。第一个案例使用单一参数测试了接口返回的特定值;第二个案例增加了更多参数,进一步验证了接口的稳定性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#coding=utf-8
import json
import re
import unittest
import urllib2, urllib 

from django.http import response

#################
##Author:Chen
##Date:2015-04-13
##Title:
#################
class TestprofileIndex(unittest.TestCase):
    '''Cxx服务:接口文档:'''

    def setUp(self):
        '''测试前的准备工作'''
        pass
    def tearDown(self):
        '''测试结束后的清除工作'''
        pass

    def testProfileIndexSucc_singleParametertest(self):
        '1.测试目的:查看'
        expected_code ='11'
        #print 'code1:',(type(code1))
        data = {'itemid':'1005051809031027_-_'}
        res1 = urllib2.urlopen(url = ' http://.xx.com/component/likescard/profileindex.json?source=3818214747',data=urllib.urlencode(data)).read()
         
        getactual_code = re.findall('card_type":(.*?),',res1)
        assert getactual_code[0] == expected_code,'显示错误'
       
    def testProfileIndexSucc_andoidParameter(self):
        '2.测试目的:查看'
        expected_code2 ='11' 
        #print 'code1:',(type(code1))
        data = {'itemid':'1005051809031027_-_',
                'uid':'5175065084',
                'v_p':'0',
                'c':'android'}
        res2 = urllib2.urlopen(url = ' http://xx.com/component/likescard/profileindex.json?source=3818214747',data=urllib.urlencode(data)).read()
         
        getactual_code2 = re.findall('card_type":(.*?),',res2)
        assert getactual_code2[0] == expected_code2,'显示错误'
     
     
       
def suite():
    return unittest.makeSuite(TestprofileIndex,"test")   #运行所有test开头的用例顺序:英文
     
if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    #unittest.main()
    runner = unittest.TextTestRunner(verbosity = 2)
    runner.run(suite())

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值