Soap接口功能测试(获取电话归属地信息接口)

接口地址:

http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl

 

1、通过python脚本,进行查询

#先导入需要的包,加载包文件
from suds.client import Client

#定义url
url = 'http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl'

#创建对象
client = Client(url)
print(client)

#进行soap接口测试
# 对象client调用services方法,再调用接口方法getMobileCodeInfo
res = client.service.getMobileCodeInfo('18561317472')
print(res)

#结果比对
print(type(res)) #打印接口的结果类型
ex_res = str(res) #把接口的结果转化为字符串类型
result = ex_res.find('山东联通GSM卡')
print(result)

if result>-1:
    print("pass")
else:
    print('no found')

2、将代码封装


#先导入需要的包,加载包文件
from suds.client import Client

class GMCInfo():
    def __init__(self):
    #初始化url
        self.url = 'http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl'
    def getmobilecodeinfo(self):
        client = Client(self.url)
        #进行soap接口测试
        res = client.service.getMobileCodeInfo('18561317472')  #对象client调用services方法,再调用接口方法getMobileCodeInfo
        print(res)
        #结果比对,把接口的结果转化为字符串类型
        ex_res = str(res)
        result = ex_res.find('山东联通GSM卡')
        if result>-1:
            print("pass")
        else:
            print('no found')

if __name__=='__main__':
    obj = GMCInfo()
    obj.getmobilecodeinfo()

3、用框架封装,进行soap进行接口测试

#先导入框架
import unittest2
from suds.client import Client
import datetime
class GMCInfo_uni(unittest2.TestCase): #使用unittest2的框架,需集成unittest2的TestCase类
    def setUp(self): #TestCase类里的初始化方法
        # 初始化url和tel属性
        self.url = 'http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl'
        self.tel = '18561317452'
    def test_getmobilecodeinfo(self):
        client = Client(self.url)
        # 进行soap接口测试
        res = client.service.getMobileCodeInfo(self.tel)  # 对象client调用services方法,再调用接口方法getMobileCodeInfo
        print(res)
        self.ex_res = str(res)  # 把接口的结果转化为字符串类型
    def tearDown(self):
        self.assertIn('山东联通GSM卡',self.ex_res)

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值