Пример #1
0
class API_HY(unittest.TestCase):
    '''好友类api接口测试'''
    @classmethod
    def setUpClass(self):
        self.log = LogTools()
        self.yaml = YamlTools()
        self.req = RequestTools()
        self.db = DataBaseTools()
        self.api = CommonApiTools()
        self.api.login_api_pwd()  # 密码登陆
        self.log.info(
            '>>>>>>>>>>>>>>>>>>>>>[HY_api_start]<<<<<<<<<<<<<<<<<<<<')

    @classmethod
    def tearDownClass(self):
        self.api.logout_api()  # 注销退出
        self.log.info('>>>>>>>>>>>>>>>>>>>>>[HY_api_end]<<<<<<<<<<<<<<<<<<<<')

    def test_001_friendsinfo_userid(self):
        '''好友类-获取好友信息(通过userid)'''
        casename = '获取好友信息-userid'
        api = self.yaml.get_HYapi(6)
        sql = 'select * from userlogin;'
        #获取数据
        sqldata = self.db.get_selectdata_row(sql, 0)
        userid = sqldata[3]
        token = sqldata[6]
        data = {'userid': userid, 'token': token}
        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True) and self.assertEqual(
                    result['result']['userid'], userid)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_002_friendinfo_mobile(self):
        '''好友类-获取好友信息(通过mobile)'''
        casename = '获取好友信息-mobile'
        api = self.yaml.get_HYapi(6)
        sql = 'select * from userlogin;'
        #获取数据
        sqldata = self.db.get_selectdata_row(sql, 0)
        token = sqldata[6]
        mobile = sqldata[0]
        data = {'token': token, 'mobile': mobile}
        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True) and self.assertEqual(
                    result['result']['mobile'], mobile)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_003_friendinfo_useridmobile(self):
        '''好友类-获取好友信息(通过userid/mobile)'''
        casename = '获取好友信息-userid/mobile'
        api = self.yaml.get_HYapi(6)
        sql = 'select * from userlogin;'
        #获取数据
        sqldata = self.db.get_selectdata_row(sql, 0)
        token = sqldata[6]
        userid = sqldata[3]
        mobile = sqldata[0]
        data = {'token': token, 'userid': userid, 'mobile': mobile}
        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(
                result['errorCode'], 0) and self.assertSequenceEqual(
                    result['isTrue'], True) and self.assertSequenceEqual(
                        result['result']['userid'],
                        userid) and self.assertSequenceEqual(
                            result['result']['mobile'], mobile)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_004_addfriends(self):
        '''好友类-向指定用户申请成为好友'''
        casename = '向指定用户申请成为好友'
        api = self.yaml.get_HYapi(0)
        sql = 'select * from userlogin;'
        #获取数据
        sqldata = self.db.get_selectdata_row(sql, 0)
        token = sqldata[6]
        friendid = 'user10020'
        info = '123'
        data = 'token=%s&friendid=%s&info=%s' % ('123456', friendid, info)
        #发送请求
        try:
            result = self.req.put_method(api, casename, data=data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True) and self.assertSequenceEqual(
                    result['errorMessage'], '申请成功,请耐心等待对方确认。')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_005_myaddlist(self):
        '''好友类-取得向我提出加好友申请的用户列表'''
        casename = '获取添加自己的用户列表'
        api = self.yaml.get_HYapi(1)
        sql = 'select * from userlogin;'
        #获取数据
        sqldata = self.db.get_selectdata_row(sql, 0)
        token = sqldata[6]
        userid = sqldata[3]
        data = {'token': '123456', 'userid': userid}
        #发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 10304) and self.assertEqual(
                result['isTrue'], False) and self.assertSequenceEqual(
                    result['errorMessage'], '用户不存在')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_006_deletefriend(self):
        '''好友类-删除指定好友'''
        casename = '删除指定好友'
        api = self.yaml.get_HYapi(5)
        sql = 'select * from userlogin;'
        #获取数据
        sqldata = self.db.get_selectdata_row(sql, 0)
        token = sqldata[6]
        friendid = 'user10001'
        data = 'token=%s&friendid=%s' % (token, friendid)
        #发送请求
        try:
            result = self.req.delete_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True) and self.assertEqual(
                    result['errorMessage'], '删除好友成功')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_007_getfriendslist(self):
        '''好友类-获得我的好友列表'''
        casename = '获得我的好友列表'
        api = self.yaml.get_HYapi(7)
        sql = 'select * from userlogin;'
        #获取数据
        sqldata = self.db.get_selectdata_row(sql, 0)
        token = sqldata[6]
        userid = sqldata[3]
        data = {'token': token, 'userid': userid}
        #发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 10306) and self.assertEqual(
                result['errorMessage'], '好友不存在')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_008_nickname(self):
        '''好友类-为我的好友设置昵称'''
        casename = '为我的好友设置昵称'
        api = self.yaml.get_HYapi(8)
        sql = 'select * from userlogin;'
        #获取数据
        sqldata = self.db.get_selectdata_row(sql, 0)
        token = sqldata[6]
        userid = sqldata[3]
        friendid = 'user10033'
        name = '戴眼镜的熊'
        data = 'token=%s&friendid=%s&name=%s' % (token, friendid, name)
        #发送请求
        try:
            result = self.req.put_method(api, casename, data=data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True) and self.assertEqual(
                    result['errorMessage'], '更新昵称成功')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_009_newmessage(self):
        '''好友类-取得待处理好友消息'''
        casename = '取得待处理好友消息'
        api = self.yaml.get_HYapi(11)
        sql = 'select * from userlogin;'
        #获取数据
        token = self.db.get_specific_data(sql, 0, 6)
        data = {'token': token}
        #发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 10811) and self.assertEqual(
                result['errorMessage'], '没有新的朋友消息')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_010_search(self):
        '''好友类-搜索引擎'''
        casename = '搜索引擎'
        api = self.yaml.get_HYapi(12)
        sql = 'select * from userlogin;'
        #获取数据
        token = self.db.get_specific_data(sql, 0, 6)
        type = 'all'
        key = '王'
        data = {'token': token, 'type': type, 'key': key}
        #发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            raise
class API_HDGGYY(unittest.TestCase):
    '''活动广告运营api接口测试'''
    @classmethod
    def setUpClass(self):
        self.log = LogTools()
        self.yaml = YamlTools()
        self.req = RequestTools()
        self.db = DataBaseTools()
        self.api = CommonApiTools()
        self.api.login_api_pwd()  # 密码登陆
        self.log.info(
            '>>>>>>>>>>>>>>>>>>>>>[SJCJ_api_start]<<<<<<<<<<<<<<<<<<<<')

    @classmethod
    def tearDownClass(self):
        self.api.logout_api()  # 注销退出
        self.log.info(
            '>>>>>>>>>>>>>>>>>>>>>[SJCJ_api_end]<<<<<<<<<<<<<<<<<<<<')

    def test_001_getadv(self):
        '''活动广告运营类-取得当前用户相关的广告列表'''
        casename = '获取当前用户广告列表'
        api = self.yaml.get_HDGGYYapi(0)
        sql = 'select * from userlogin;'
        #获取数据
        token = self.db.get_specific_data(sql, 0, 6)
        data = {'token': token}
        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_002_signin(self):
        '''活动广告运营类-用户签到,并获得连续打卡天数'''
        casename = '获取用户连续打卡天数'
        api = self.yaml.get_HDGGYYapi(1)
        sql = 'select * from userlogin;'
        # 获取数据
        token = self.db.get_specific_data(sql, 0, 6)
        data = 'token=%s' % token
        # 发送请求
        try:
            result = self.req.post_method('urlencode', api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_003_sendfeedback(self):
        '''活动广告运营类-用户提交问题建议'''
        casename = '用户提交问题建议'
        api = self.yaml.get_HDGGYYapi(2)
        sql = 'select * from userlogin;'
        #获取数据
        userid = self.db.get_specific_data(sql, 0, 3)
        contactinfo = 'QQ:14298246'
        content = '接口测试!'
        data = {
            'userid': userid,
            'contactinfo': contactinfo,
            'content': content
        }
        # 发送请求
        try:
            result = self.req.post_method('json', api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True) and self.assertEqual(
                    result['result'], userid)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_004_getfeedback(self):
        '''活动广告运营类-用户取得自己提交的问题的反馈'''
        casename = '用户取得自己提交的问题的反馈'
        api = self.yaml.get_HDGGYYapi(3)
        sql = 'select * from userlogin;'
        #获取数据
        token = self.db.get_specific_data(sql, 0, 6)
        data = {'token': token}
        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
            #更新数据库信息
            sql2 = 'update feedback set feedid=\'%s\' where userid=\'%s\';' % (
                result['result'][0]['feedid'], result['result'][0]['userid'])
            self.db.execute_sql(sql2)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_005_gettrack(self):
        '''活动广告运营类-获取建议回复信息'''
        casename = '获取建议回复信息'
        api = self.yaml.get_HDGGYYapi(4)
        sql = 'select * from feedback;'
        #获取数据
        feedid = self.db.get_specific_data(sql, 0, 2)
        data = {'feedid': feedid}
        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_006_givestar(self):
        '''活动广告运营类-给予客服评级'''
        casename = '给予客服评级'
        api = self.yaml.get_HDGGYYapi(5)
        sql = 'select * from feedback;'
        #获取数据
        feedid = self.db.get_specific_data(sql, 0, 2)
        rate = random.randint(1, 6)  #1-5星评级
        data = 'feedid=%s&rate=%s' % (feedid, rate)
        # 发送请求
        try:
            result = self.req.put_method(api, casename, data=data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            raise
Пример #3
0
class API_PDDT(unittest.TestCase):
    '''频道电台类api接口测试'''
    @classmethod
    def setUpClass(self):
        self.log = LogTools()
        self.yaml = YamlTools()
        self.req = RequestTools()
        self.db = DataBaseTools()
        self.api = CommonApiTools()
        self.api.login_api_pwd()  # 密码登陆
        self.log.info('>>>>>>>>>>>>>>>>>>>>>[PDDT_api_start]<<<<<<<<<<<<<<<<<<<<')

    @classmethod
    def tearDownClass(self):
        self.api.logout_api()  # 注销退出
        self.log.info('>>>>>>>>>>>>>>>>>>>>>[PDDT_api_end]<<<<<<<<<<<<<<<<<<<<')

    def test_001_makechannel(self):
        '''频道电台类-创建频道(普通频道)'''
        casename='创建频道(普通频道)'
        api=self.yaml.get_PDDTapi(0)
        sql='select * from userlogin;'
        #获取数据
        sqldata=self.db.get_selectdata_row(sql,0)
        token=sqldata[6]
        userid=sqldata[3]
        data={"channelid" : "","channelname" : "接口测试","channelremark" : "","autoname" : 0,"ispublic" : 0,"logoid" : "","memberids" : ["user10400","user10430"],"owner" : userid,"token" : token}
        #发送请求
        try:
            result=self.req.post_method('json',api,casename,data)
            self.assertEqual(result['errorCode'],0) and self.assertEqual(result['isTrue'],True)
            self.log.info('[%s]-[Result]:PASS'%casename)
            self.log.info('-'*60)
            #更新数据库信息--channel
            sql2='update channel set channelid=\'%s\',owner=\'%s\',token=\'%s\',channelname=\'%s\' where cid=1'%\
                 (result['result']['channelid'],result['result']['owner'],result['result']['token'],result['result']['channelname'])
            self.db.execute_sql(sql2)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED'%casename)
            self.log.info('-'*60)
            raise

    def test_002_changenickname(self):
        '''频道电台类-更新自己的昵称'''
        casename='更新自己的昵称'
        api=self.yaml.get_PDDTapi(1)
        sql='select * from channel;'
        #获取数据
        sqldata=self.db.get_selectdata_row(sql,0)
        token=sqldata[3]
        channelid=sqldata[1]
        userid=sqldata[2]
        name='王大锤'
        data='token=%s&channelid=%s&name=%s'%(token,channelid,name)
        #发送请求
        try:
            result=self.req.put_method(api,casename,data=data)
            self.assertEqual(result['errorCode'],0) and self.assertEqual(result['isTrue'],True) and self.assertEqual(result['result'],userid)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED'%casename)
            self.log.info('-'*60)
            raise

    def test_003_changechannelname(self):
        '''频道电台类-管理员更新频道名称'''
        casename='管理员更新频道名称'
        api=self.yaml.get_PDDTapi(2)
        sql='select * from channel;'
        #获取数据
        sqldata=self.db.get_selectdata_row(sql,0)
        token=sqldata[3]
        channelid=sqldata[1]
        userid=sqldata[2]
        name='我心飞翔'
        data='token=%s&channelid=%s&name=%s'%(token,channelid,name)
        #发送请求
        try:
            result=self.req.put_method(api,casename,data=data)
            self.assertEqual(result['errorCode'],0) and self.assertEqual(result['isTrue'],True) and self.assertEqual(result['result'],userid)
            self.log.info('[%s]-[nfResult]:PASS'%casename)
            self.log.info('-'*60)
            #更新数据库--channel
            sql2='update channel set channelname=\'%s\' where owner=\'%s\';'%(name,userid)
            self.db.execute_sql(sql2)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED'%casename)
            self.log.info('-' * 60)
            raise

    def test_004_changeremark(self):
        '''频道电台类-管理员更新频道简介'''
        casename='管理员更新频道简介'
        api=self.yaml.get_PDDTapi(3)
        sql='select * from channel;'
        #获取数据
        sqldata=self.db.get_selectdata_row(sql,0)
        token=sqldata[3]
        channelid=sqldata[1]
        userid=sqldata[2]
        remark='简介更新,接口测试!'
        data='token=%s&channelid=%s&remark=%s'%(token,channelid,remark)
        #发送请求
        try:
            result=self.req.put_method(api,casename,data=data)
            self.assertEqual(result['errorCode'],0) and self.assertEqual(result['isTrue'],True) and self.assertEqual(result['result'],userid)
            self.log.info('[%s]-[Result]:PASS'%casename)
            self.log.info('-'*60)
            #更新数据库--channel
            sql2='update channel set remark=\'%s\' where owner=\'%s\';'%(remark,userid)
            self.db.execute_sql(sql2)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED'%casename)
            self.log.info('-'*60)
            raise

    def test_005_ispublic_yes(self):
        '''频道电台类-管理员更新频道不需验证申请'''
        casename='管理员更新频道不需验证申请'
        api=self.yaml.get_PDDTapi(4)
        sql='select * from channel;'
        # 获取数据
        sqldata=self.db.get_selectdata_row(sql, 0)
        token=sqldata[3]
        channelid=sqldata[1]
        userid=sqldata[2]
        ispublic=1
        data='token=%s&channelid=%s&ispublic=%s'%(token,channelid,ispublic)
        #发送请求
        try:
            result=self.req.put_method(api,casename,data=data)
            self.assertEqual(result['errorCode'],0) and self.assertEqual(result['isTrue'],True) and \
            self.assertEqual(result['errorMessage'],'更新频道成功') and self.assertSequenceEqual(result['result'],userid)
            self.log.info('[%s]-[Result]:PASS'%casename)
            self.log.info('-'*60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED'%casename)
            self.log.info('-'*60)
            raise

    def test_006_ispublic_no(self):
        '''频道电台类-管理员更新频道需要验证申请'''
        casename = '管理员更新频道需要验证申请'
        api = self.yaml.get_PDDTapi(4)
        sql = 'select * from channel;'
        # 获取数据
        sqldata = self.db.get_selectdata_row(sql, 0)
        token = sqldata[3]
        channelid = sqldata[1]
        userid = sqldata[2]
        ispublic = 0
        data = 'token=%s&channelid=%s&ispublic=%s' % (token, channelid, ispublic)
        # 发送请求
        try:
            result = self.req.put_method(api, casename, data=data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(result['isTrue'], True) and \
            self.assertEqual(result['errorMessage'], '更新频道成功') and self.assertSequenceEqual(result['result'], userid)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_007_batchadd(self):
        '''频道电台类-批量增加成员到频道中'''
        casename='批量增加成员到频道中'
        api=self.yaml.get_PDDTapi(6)
        sql='select * from channel;'
        #获取数据
        sqldata=self.db.get_selectdata_row(sql,0)
        token=sqldata[3]
        channelid=sqldata[1]
        userid=sqldata[2]
        body={"channelid" : channelid,"memberlist" : ["user10400","user10430"],"userid" : userid,"token" : token}
        #发送请求
        try:
            result=self.req.put_method(api,casename,body)
            self.assertEqual(result['errorCode'],0) and self.assertEqual(result['isTrue'],True) \
            and self.assertEqual(result['result'],userid)
            self.log.info('[%s]-[Result]:PASS'%casename)
            self.log.info('-'*60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED'%casename)
            self.log.info('-'*60)
            raise

    def test_008_batchkick(self):
        '''频道电台类-从频道中批量删除成员'''
        casename='从频道中批量删除成员'
        api=self.yaml.get_PDDTapi(7)
        sql='select * from channel;'
        #获取数据
        sqldata=self.db.get_selectdata_row(sql,0)
        token=sqldata[3]
        userid=sqldata[2]
        channelid=sqldata[1]
        body={"channelid" : channelid,"memberlist" : ["user10400","user10430"],"userid" : userid,"token" : token}
        #发送请求
        try:
            result=self.req.delete_method(api,casename,body=body)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(result['isTrue'], True) \
            and self.assertEqual(result['result'], userid)
            self.log.info('[%s]-[Result]:PASS'%casename)
            self.log.info('-'*60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED'%casename)
            self.log.info('-'*60)
            raise

    def test_009_applychannel(self):
        '''频道电台类-申请加入频道(需审核)'''
        casename='申请加入频道(需审核)'
        api=self.yaml.get_PDDTapi(8)
        sql = 'select * from channel;'
        # 获取数据
        sqldata = self.db.get_selectdata_row(sql, 0)
        token=sqldata[3]
        userid=sqldata[2]
        channelid='10404'
        reason='申请加入,接口测试!'
        data='token=%s&channelid=%s&reason=%s'%(token,channelid,reason)
        try:
            result=self.req.put_method(api,casename,data=data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(result['isTrue'], True) \
            and self.assertEqual(result['result'], userid)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_010_addchannel(self):
        '''频道电台类-直接加入频道'''
        casename='直接加入频道'
        api=self.yaml.get_PDDTapi(9)
        sql='select * from channel;'
        #获取数据
        sqldata = self.db.get_selectdata_row(sql, 0)
        token = sqldata[3]
        userid = sqldata[2]
        channelid='10404'
        data='token=%s&channelid=%s'%(token,channelid)
        #发送请求
        try:
            result=self.req.put_method(api,casename,data=data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(result['isTrue'], True) \
            and self.assertEqual(result['result'], userid)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_011_getmychannellist(self):
        '''频道电台类-取得自己的频道列表'''
        casename='取得我的频道列表'
        api=self.yaml.get_PDDTapi(14)
        sql='select * from channel;'
        #获取数据
        token=self.db.get_specific_data(sql,0,3)
        data={'token':token}
        #发送请求
        try:
            result=self.req.get_method(api,casename,data)
            self.assertEqual(result['errorCode'],0) and self.assertEqual(result['isTrue'],True)\
            and self.assertEqual(result['errorMessage'],'操作成功')
            self.log.info('[%s]-[Result]:PASS'%casename)
            self.log.info('-'*60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED'%casename)
            self.log.info('-'*60)
            raise

    def test_012_getmember(self):
        '''频道电台类-取得指定频道的成员列表'''
        casename='取得指定频道的成员列表'
        api=self.yaml.get_PDDTapi(15)
        sql='select * from channel;'
        #获取数据
        sqldata=self.db.get_selectdata_row(sql,0)
        token=sqldata[3]
        channelid=sqldata[1]
        data={'token':token,'channelid':channelid}
        #发送请求
        try:
            result=self.req.get_method(api,casename,data)
            self.assertEqual(result['errorCode'],0) and self.assertEqual(result['isTrue'],True)\
            and self.assertEqual(result['errorMessage'],'操作成功')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_013_applylist(self):
        '''频道电台类-获取所有自己创建的频道的相关信息'''
        casename='所有自己创建的频道的相关信息'
        api=self.yaml.get_PDDTapi(16)
        sql='select * from channel;'
        #获取数据
        token=self.db.get_specific_data(sql,0,3)
        data={'token':token}
        #发送请求
        try:
            result=self.req.get_method(api,casename,data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(result['isTrue'], True) \
            and self.assertEqual(result['errorMessage'], '操作成功')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_014_searchchannel(self):
        '''频道电台类-查找频道'''
        casename='查找频道'
        api=self.yaml.get_PDDTapi(17)
        sql='select * from channel;'
        #获取数据
        token=self.db.get_specific_data(sql,0,3)
        key='罗'
        data={'token':token,'key':key}
        #发送请求
        try:
            result=self.req.get_method(api,casename,data)
            self.assertEqual(result['errorCode'],0) and self.assertEqual(result['isTrue'])
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_015_randomrecommend(self):
        '''频道电台类-随机推荐频道'''
        casename='随机推荐频道'
        api=self.yaml.get_PDDTapi(18)
        sql='select * from channel;'
        #获取数据
        token=self.db.get_specific_data(sql,0,3)
        maxnum=3
        data={'token':token,'maxnum':maxnum}
        #发送请求
        try:
            result=self.req.get_method(api,casename,data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(result['isTrue'])
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_016_getchannelinfo(self):
        '''频道电台类-获取指定频道详情'''
        casename='获取指定频道详情'
        api=self.yaml.get_PDDTapi(19)
        sql='select * from channel;'
        #获取数据
        sqldata=self.db.get_selectdata_row(sql,0)
        token=sqldata[3]
        channelid=sqldata[1]
        data={'token':token,'channelid':channelid}
        #发送请求
        try:
            result=self.req.get_method(api,casename,data)
            self.assertEqual(result['errorCode'],0) and self.assertEqual(result['isTrue'],True)\
            and self.assertEqual(result['errorMessage'],'操作成功')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_017_getchannelstatus(self):
        '''频道电台类-用户取得自己的频道的活跃统计'''
        casename='用户取得自己的频道的活跃统计'
        api=self.yaml.get_PDDTapi(21)
        sql='select * from channel;'
        #获取数据
        token=self.db.get_specific_data(sql,0,3)
        data={'token':token}
        #发送请求
        try:
            result=self.req.get_method(api,casename,data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(result['isTrue'], True) \
            and self.assertEqual(result['errorMessage'], '操作成功')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_018_getlogo(self):
        '''频道电台类-获取频道logo图片'''
        casename='获取频道logo图片'
        api=self.yaml.get_PDDTapi(22)
        #获取数据
        channelid='10404'
        data={'channelid':channelid}
        #发送请求
        try:
            result=self.req.get_method(api,casename,data)
            self.assertEqual(result['errorCode'],0) and self.assertEqual(result['isTrue'],True)
            self.log.info('[%s]-[Result]:PASS'%casename)
            self.log.info('-'*60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED'%casename)
            self.log.info('-'*60)
            raise

    def test_019_assertinchannel(self):
        '''频道电台类-判断自己是否在特定频道内'''
        casename='判断自己是否在特定频道内'
        api=self.yaml.get_PDDTapi(23)
        sql='select * from channel;'
        #获取数据
        sqldata=self.db.get_selectdata_row(sql,0)
        token=sqldata[3]
        channelid=sqldata[1]
        data={'token':token,'channelid':channelid}
        #发送请求
        try:
            result=self.req.get_method(api,casename,data)
            #存在时反馈判断
            try:
                self.assertEqual(result['errorCode'],0) and self.assertEqual(result['isTrue'],True)\
                and self.assertEqual(result['result'],True)
                self.log.info('[%s]-[Result]:PASS'%casename)
                self.log.info('-'*60)
            #不存在时反馈判断
            except:
                self.assertEqual(result['errorCode'], 0) and self.assertEqual(result['isTrue'], True) \
                and self.assertEqual(result['result'], False)
                self.log.info('[%s]-[Result]:PASS' % casename)
                self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED'%casename)
            self.log.info('-'*60)
            raise

    def test_020_allmember(self):
        '''频道电台类-取得和我相关的所有频道和频道成员列表(不包含自己)'''
        casename='取得和我相关的所有频道和频道成员列表(不包含自己)'
        api=self.yaml.get_PDDTapi(26)
        sql='select * from channel;'
        #获取数据
        token=self.db.get_specific_data(sql,0,3)
        data={'token':'234123414'}
        #发送请求
        try:
            result=self.req.get_method(api,casename,data)
            self.assertEqual(result['errorCode'],0) and self.assertEqual(result['isTrue'],True)\
            and self.assertEqual(result['errorMessage'],'操作成功')
            self.log.info('[%s]-[Result]:PASS'%casename)
            self.log.info('-'*60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED'%casename)
            self.log.info('-'*60)
            raise

    def test_021_radionews(self):
        '''频道电台类-获取最新路况交通新闻'''
        casename='获取最新路况交通新闻'
        api=self.yaml.get_PDDTapi(27)
        sql='select * from channel;'
        #获取数据
        userid=self.db.get_specific_data(sql,0,2)
        data={'userid':userid}
        #发送请求
        try:
            result=self.req.get_method(api,casename,data)
            self.assertEqual(result['errorCode'],0) and self.assertEqual(result['isTrue'],True)
            self.log.info('[%s]-[Result]:PASS'%casename)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED'%casename)
            raise
Пример #4
0
class API_SJCJ(unittest.TestCase):
    '''数据采集类api接口测试'''
    @classmethod
    def setUpClass(self):
        self.log = LogTools()
        self.yaml = YamlTools()
        self.req = RequestTools()
        self.db = DataBaseTools()
        self.api = CommonApiTools()
        self.api.login_api_pwd()  # 密码登陆
        self.log.info(
            '>>>>>>>>>>>>>>>>>>>>>[SJCJ_api_start]<<<<<<<<<<<<<<<<<<<<')

    @classmethod
    def tearDownClass(self):
        self.api.logout_api()  # 注销退出
        self.log.info(
            '>>>>>>>>>>>>>>>>>>>>>[SJCJ_api_end]<<<<<<<<<<<<<<<<<<<<')

    def test_001_position(self):
        '''数据采集类-提交用户位置信息'''
        casename = '提交用户位置信息'
        api = self.yaml.get_SJCJapi(0)
        sql = 'select * from userlogin;'
        #获取数据信息
        userid = self.db.get_specific_data(sql, 0, 3)
        longitude = '126.23435'  #经度
        latitude = '31.4343'  #纬度
        body = {'userid': userid, 'longitude': longitude, 'latitude': latitude}

        # 发送请求
        try:
            result = self.req.put_method(api, casename, body)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True) and self.assertEqual(
                    result['errorMessage'], '信息更新成功')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_002_mobileinfo(self):
        '''数据采集类-提交用户手机信息'''
        casename = '提交用户手机信息'
        api = self.yaml.get_SJCJapi(1)
        sql = 'select * from userlogin;'
        #获取数据信息
        phoneid = self.db.get_specific_data(sql, 0, 4)
        phonetype = 0  #0:为ios,1:为android,2:为其它
        detail = {
            'brand': 'Iphone',
            'version': '6',
            '运营商': '中国电信',
            'osversion': 'ios12'
        }
        #配置参数
        body = {'phoneid': phoneid, 'phonetype': phonetype, 'detail': detail}

        # 发送请求
        try:
            result = self.req.put_method(api, casename, body)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True) and self.assertEqual(
                    result['errorMessage'], '信息更新成功')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
            raise

    def test_003_networkflow(self):
        '''数据采集类-提交用户使用流量信息'''
        casename = '提交用户使用流量信息'
        api = self.yaml.get_SJCJapi(2)
        sql = 'select * from userlogin;'
        #获取数据信息--整行
        sqldata = self.db.get_selectdata_row(sql, 0)
        #获取单个数据信息
        userid = sqldata[3]
        phoneid = sqldata[4]
        starttime = '1487727617982'  #统计开始时间,单位:毫秒数
        endtime = '1487727634678'  #统计截止时间,单位:毫秒数
        flow = 34434388  #使用的3G/4G流量(不含WiFi),单位:字节Byte
        navtime = 2103  #导航功能实际使用时间(不含目的地搜索和路线规划时间);单位:秒
        chattime = 107  #使用对讲功能的时间(不含聊天机器人,不计算听别人说话的时间);单位:秒
        usetime = 5609  #使用嘟嘟的时间(app启动开始计算,切换或者关掉则停止计算);单位:秒
        sharetimes = 4  #分享图片的次数;单位:次数
        data = {
            'userid': userid,
            'starttime': starttime,
            'endtime': endtime,
            'phoneid': phoneid,
            'flow': flow,
            'navtime': navtime,
            'chattime': chattime,
            'usetime': usetime,
            'sharetimes': sharetimes
        }
        # 发送请求
        try:
            result = self.req.post_method('json', api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True) and self.assertEqual(
                    result['errorMessage'], '信息更新成功')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_004_deletefile(self):
        '''数据采集类-用户删除上传到服务器的文件'''
        casename = '用户删除上传到服务器的文件'
        api = self.yaml.get_SJCJapi(5)
        sql = 'select * from userlogin;'
        #获取数据
        userid = self.db.get_specific_data(sql, 0, 3)
        fileid = 'mro6vatc6fgflnrj54nqtixlyvn21r1r'
        data = 'userid=%s&fileid=%s' % (userid, fileid)
        # 发送请求
        try:
            result = self.req.delete_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            raise
Пример #5
0
class API_USER(unittest.TestCase):
    '''用户类api接口测试'''
    @classmethod
    def setUpClass(self):
        self.log = LogTools()
        self.yaml = YamlTools()
        self.req = RequestTools()
        self.db = DataBaseTools()
        self.api = CommonApiTools()
        self.api.login_api_pwd()  #密码登陆
        self.log.info(
            '>>>>>>>>>>>>>>>>>>>>>[USER_api_start]<<<<<<<<<<<<<<<<<<<<')

    @classmethod
    def tearDownClass(self):
        self.api.logout_api()  #注销退出
        self.log.info(
            '>>>>>>>>>>>>>>>>>>>>>[USER_api_end]<<<<<<<<<<<<<<<<<<<<')

    def test_001_getuserinfo_byuserid(self):
        '''用户类-获取用户公开信息(通过userid)'''
        casename = '获取用户公开信息-通过userid'
        api = self.yaml.get_USERapi(0)
        sql = 'select * from userlogin;'
        #获取数据库信息
        sqldata = self.db.get_selectdata_row(sql, 0)
        userid = sqldata[3]
        mobile = sqldata[0]
        data = {'userid': userid}
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True) and self.assertEqual(
                    result['result']['mobile'], mobile)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_002_getuserinfo_bymobile(self):
        '''用户类-获取用户公开信息(通过mobile)'''
        casename = '获取用户公开信息-通过mobile'
        api = self.yaml.get_USERapi(0)
        sql = 'select * from userlogin;'
        sqldata = self.db.get_selectdata_row(sql, 0)
        userid = sqldata[3]
        mobile = sqldata[0]
        data = {'mobile': mobile}
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True) and self.assertEqual(
                    result['result']['userid'], userid)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_003_getuserinfo_byall(self):
        '''用户类-获取用户公开信息(通过userid和mobile)'''
        casename = '获取用户公开信息-通过userid/mobile'
        api = self.yaml.get_USERapi(0)
        sql = 'select * from userlogin;'
        sqldata = self.db.get_selectdata_row(sql, 0)
        userid = sqldata[3]
        mobile = sqldata[0]
        data = {'userid': userid, 'mobile': mobile}
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True) and self.assertEqual(
                    result['result']['mobile'], mobile)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_004_updateinfo(self):
        '''用户类-更新用户信息'''
        casename = '更新用户信息'
        api = self.yaml.get_USERapi(2)
        sql1 = 'select * from userlogin;'
        sql1data = self.db.get_selectdata_row(sql1, 0)
        #获取数据信息
        userid = sql1data[3]
        mobile = sql1data[0]
        username = sql1data[8]
        city = 'ChengDu'
        phoneid = sql1data[4]
        jpushregisterid = 'lzl198903017'
        password = sql1data[1]
        gendor = random.randint(0, 3)
        introduction = 'Hello!I am bear,I am doing api autotest!'
        body = {
            'userid': userid,
            'mobile': mobile,
            'username': username,
            'city': city,
            'phoneid': phoneid,
            'jpushregisterid': jpushregisterid,
            'password': password,
            'gendor': gendor,
            'introduction': introduction
        }
        try:
            result = self.req.put_method(api, casename, body)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], 0)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
            #更新数据库--userinfo
            sql2='update userinfo set userid=\'%s\',username=\'%s\',mobile=\'%s\',city=\'%s\',phoneid=\'%s\',' \
                 'jpushregisterid=\'%s\',password=\'%s\',gendor=\'%d\',introduction=\'%s\' where infoid=1;'\
                 %(userid,username,mobile,city,phoneid,jpushregisterid,password,gendor,introduction)
            self.db.execute_sql(sql2)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_005_uploadcontacts(self):
        '''用户类-上传通讯录'''
        casename = '上传通讯录'
        api = self.yaml.get_USERapi(5)
        sql = 'select * from userlogin;'
        #配置数据
        token = self.db.get_specific_data(sql, 0, 6)
        contactslist = [{
            'mobile': '13828836568',
            'name': 'feifei'
        }, {
            'mobile': '13921342314',
            'name': 'nannan'
        }]
        contactsjson = json.dumps(contactslist)
        data = 'token=%s' % token
        try:
            result = self.req.post_method('urlencode', api, casename, data,
                                          contactsjson)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_006_getcontacts(self):
        '''用户类-获取用户通讯录'''
        casename = '获取用户通讯录'
        api = self.yaml.get_USERapi(6)
        sql = 'select * from userlogin;'
        #配置数据
        token = self.db.get_specific_data(sql, 0, 6)
        data = {'token': token}
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s-[Result]:FAILED]' % casename)
            self.log.info('-' * 60)
            raise

    def test_007_finduser(self):
        '''用户类-查找嘟嘟用户'''
        casename = '查找嘟嘟用户'
        api = self.yaml.get_USERapi(1)
        sql = 'select * from userlogin;'
        #配置数据
        token = self.db.get_specific_data(sql, 0, 6)
        key = '王'
        data = {'token': token, 'key': key}
        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_008_updateintroduction(self):
        '''用户类-更新签名信息'''
        casename = '更新签名信息'
        api = self.yaml.get_USERapi(3)
        sql1 = 'select * from userlogin;'
        #获取数据信息
        token = self.db.get_specific_data(sql1, 0, 6)
        introduction = '好好学习,天天向上!'
        data = 'token=%s&introduction=%s' % (token, introduction)
        # 发送请求
        try:
            result = self.req.put_method(api, casename, data=data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_009_bindbluetooth(self):
        '''用户类-更新绑定蓝牙'''
        casename = '更新绑定蓝牙'
        api = self.yaml.get_USERapi(7)
        sql = 'select * from userlogin;'
        #获取数据信息
        token = self.db.get_specific_data(sql, 0, 6)
        bluetooth = '5065832AD0A9'
        data = 'token=%s&bluetooth=%s' % (token, bluetooth)
        # 发送请求
        try:
            result = self.req.put_method(api, casename, data=data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_010_unbindbluetooth(self):
        '''用户类-取消绑定蓝牙'''
        casename = '取消绑定蓝牙'
        api = self.yaml.get_USERapi(7)
        sql = 'select * from userlogin;'
        #获取数据信息
        token = self.db.get_specific_data(sql, 0, 6)
        bluetooth = ''
        data = 'token=%s&bluetooth=%s' % (token, bluetooth)
        # 发送请求
        try:
            result = self.req.put_method(api, casename, data=data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
            raise

    def test_011_updateoftenplace(self):
        '''用户类-更新我的导航收藏'''
        casename = '更新我的导航收藏'
        api = self.yaml.get_USERapi(8)
        sql = 'select * from userlogin;'
        #获取数据信息
        userid = self.db.get_specific_data(sql, 0, 3)
        bodylist = [{
            "title": "公司",
            "address": "月光流域",
            "datatype": "history",
            "longitude": "123.422",
            "latitude": "22.2322",
            "updatetime": 2122212122
        }, {
            "title": "家",
            "address": "华侨城",
            "datatype": "favorite",
            "longitude": "123.4",
            "latitude": "22.23",
            "updatetime": 21212122
        }]
        data = 'userid=%s' % userid
        # 发送请求
        try:
            result = self.req.put_method(api, casename, bodylist, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_012_getoftenplace(self):
        '''用户类-获取我的导航收藏'''
        casename = '获取我的导航收藏'
        api = self.yaml.get_USERapi(9)
        sql = 'select * from userlogin;'
        #获取数据信息
        userid = self.db.get_specific_data(sql, 0, 3)
        data = {'userid': userid}
        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_013_updatechatrecord(self):
        '''用户类-更新会话记录'''
        casename = '更新会话记录'
        api = self.yaml.get_USERapi(10)
        sql = 'select * from userlogin;'
        #获取数据信息
        userid = self.db.get_specific_data(sql, 0, 3)
        bodylist = [{
            "type": "channel",
            "objid": "10012",
            "objname": "中华大帝国频道",
            "logourl":
            "http://120.76.194.47:8888/group1/M00/00/05/eEzCL1haOg_Ew5gSAACvGaRuld0687.png",
            "chattime": 21222121
        }]
        data = 'userid=%s' % userid
        # 发送请求
        try:
            result = self.req.put_method(api,
                                         casename,
                                         body=bodylist,
                                         data=data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_014_getchatrecord(self):
        '''用户类-获取会话记录'''
        casename = '获取会话记录'
        api = self.yaml.get_USERapi(11)
        sql = 'select * from userlogin;'
        #获取数据信息
        userid = self.db.get_specific_data(sql, 0, 3)
        data = {'userid': userid}
        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_015_chatrecord_add(self):
        '''用户类-更新会话增量模式--新增会话记录'''
        casename = '更新会话增量模式--新增会话记录'
        api = self.yaml.get_USERapi(12)
        sql = 'select * from userlogin;'
        #获取数据信息
        userid = self.db.get_specific_data(sql, 0, 3)
        mode = 'i'
        bodylist = [{
            "type": "channel",
            "objid": "10012",
            "objname": "中华大帝国频道",
            "logourl":
            "http://120.76.194.47:8888/group1/M00/00/05/eEzCL1haOg_Ew5gSAACvGaRuld0687.png",
            "chattime": 21222121
        }]
        #配置参数
        data = 'userid=%s&mode=%s' % (userid, mode)
        # 发送请求
        try:
            result = self.req.put_method(api, casename, bodylist, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_016_chatrecord_update(self):
        '''用户类-更新会话增量模式--更新会话记录'''
        casename = '更新会话增量模式--更新会话记录'
        api = self.yaml.get_USERapi(12)
        sql = 'select * from userlogin;'
        #获取数据信息
        userid = self.db.get_specific_data(sql, 0, 3)
        mode = 'u'
        bodylist = [{
            "type": "channel",
            "objid": "10012",
            "objname": "中华大帝国频道",
            "logourl":
            "http://120.76.194.47:8888/group1/M00/00/05/eEzCL1haOg_Ew5gSAACvGaRuld0687.png",
            "chattime": 21222233
        }]
        #配置参数
        data = 'userid=%s&mode=%s' % (userid, mode)
        # 发送请求
        try:
            result = self.req.put_method(api, casename, bodylist, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_017_chatrecord_delete(self):
        '''用户类-更新会话增量模式--删除会话记录'''
        casename = '更新会话增量模式--删除会话记录'
        api = self.yaml.get_USERapi(12)
        sql = 'select * from userlogin;'
        #获取数据信息
        userid = self.db.get_specific_data(sql, 0, 3)
        mode = 'd'
        bodylist = [{
            "type": "channel",
            "objid": "10012",
            "objname": "中华大帝国频道",
            "logourl":
            "http://120.76.194.47:8888/group1/M00/00/05/eEzCL1haOg_Ew5gSAACvGaRuld0687.png",
            "chattime": 21222233
        }]
        #配置参数
        data = 'userid=%s&mode=%s' % (userid, mode)
        # 发送请求
        try:
            result = self.req.put_method(api, casename, bodylist, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            raise
Пример #6
0
class API_DL(unittest.TestCase):
    '''登录类api接口测试'''
    def setUp(self):
        self.log = LogTools()
        self.yaml = YamlTools()
        self.req = RequestTools()
        self.db = DataBaseTools()
        self.api = CommonApiTools()

    def tearDown(self):
        self.db.cur_close()  # 关闭游标
        self.api.logout_api()  # 退出登陆

    def test_001_loginbypassword_uid(self):
        '''用户登录类-密码方式登陆认证(通过uid以及password进行登陆)'''
        self.log.info(
            '>>>>>>>>>>>>>>>>>>>>>[DL_api_start]<<<<<<<<<<<<<<<<<<<<')
        casename = '密码方式登陆认证_uid认证'
        api = self.yaml.get_DLapi(0)
        sql1 = 'select * from userlogin;'
        sql1data = self.db.get_selectdata_row(sql1, 0)
        #获取数据库数据
        zcuid = sql1data[2]
        password = sql1data[1]
        phoneid = sql1data[4]
        data = {'userid': zcuid, 'pwd': password, 'phoneid': phoneid}
        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
            #更新数据库信息--用户领驭号、token
            sql2='update userlogin set dlbz=1,userid=\'%s\',token=\'%s\' where phoneid=\'%s\';'\
                 %(result['result']['userid'],result['result']['token'],phoneid)
            self.db.execute_sql(sql2)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_002_loginbypassword_mobile(self):
        '''用户登录类-密码方式登陆认证(通过mobile以及password进行登陆)'''
        casename = '密码方式登陆认证_mobile认证'
        api = self.yaml.get_DLapi(0)
        sql1 = 'select * from userlogin;'
        sql1data = self.db.get_selectdata_row(sql1, 0)
        #获取数据库数据
        mobile = sql1data[0]
        password = sql1data[1]
        phoneid = sql1data[4]
        data = {'mobile': mobile, 'pwd': password, 'phoneid': phoneid}

        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
            #更新数据库信息--用户领驭号、token
            sql2 = 'update userlogin set dlbz=1,userid=\'%s\',token=\'%s\' where phoneid=\'%s\';' \
               % (result['result']['userid'], result['result']['token'], phoneid)
            self.db.execute_sql(sql2)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_003_loginbypassword_uid_mobile(self):
        '''用户登录类-密码方式登陆认证(通过uid、mobile以及password进行登陆)'''
        casename = '密码方式登陆认证_uid/mobile认证'
        api = self.yaml.get_DLapi(0)
        sql1 = 'select * from userlogin;'
        sql1data = self.db.get_selectdata_row(sql1, 0)
        #获取数据库数据
        zcuid = sql1data[2]
        mobile = sql1data[0]
        password = sql1data[1]
        phoneid = sql1data[4]
        data = {
            'userid': zcuid,
            'mobile': mobile,
            'pwd': password,
            'phoneid': phoneid
        }
        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
            #更新数据库信息--用户领驭号、token
            sql2 = 'update userlogin set dlbz=1,userid=\'%s\',token=\'%s\' where phoneid=\'%s\';' \
               % (result['result']['userid'], result['result']['token'], phoneid)
            self.db.execute_sql(sql2)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_004_loginbyverifycode(self):
        '''用户登录类-验证码方式登陆认证'''
        casename = '验证码方式登陆认证'
        api = self.yaml.get_DLapi(1)
        #获取登陆验证码
        self.api.get_verifycode(0)
        #获取数据库数据
        sql1 = 'select * from userlogin;'
        sql1data = self.db.get_selectdata_row(sql1, 0)
        telnum = sql1data[0]
        loginverifycode = sql1data[7]
        phoneid = sql1data[4]
        data = {
            'mobile': telnum,
            'validcode': loginverifycode,
            'phoneid': phoneid
        }

        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True)
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
            # 更新数据库信息--用户领驭号、token、登陆标志
            sql2 = 'update userlogin set dlbz=1,userid=\'%s\',token=\'%s\' where phoneid=\'%s\';' \
                   % (result['result']['userid'], result['result']['token'], phoneid)
            self.db.execute_sql(sql2)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_005_checkmobile(self):
        '''用户登录类-检查手机号码是否注册(手机号码已经注册)'''
        casename = '检查手机号码是否注册-已经注册'
        sql = 'select * from userlogin;'
        #获取数据
        telnum = self.db.get_specific_data(sql, 0, 0)
        api = self.yaml.get_DLapi(2)
        data = {'mobile': telnum}
        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 0) and self.assertEqual(
                result['isTrue'], True) and self.assertEqual(
                    result['errorMessage'], '该手机号码已经注册!')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info('-' * 60)
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info('-' * 60)
            raise

    def test_006_checkmoblie(self):
        '''用户登录类-检查手机号码是否注册(手机号码未注册)'''
        casename = '检查手机号码是否注册-未注册'
        sql = 'select * from userlogin;'
        #获取数据
        telnum = self.db.get_specific_data(sql, 1, 0)
        api = self.yaml.get_DLapi(2)
        data = {'mobile': telnum}
        # 发送请求
        try:
            result = self.req.get_method(api, casename, data)
            self.assertEqual(result['errorCode'], 10351) and self.assertEqual(
                result['isTrue'], False) and self.assertEqual(
                    result['errorMessage'], '该手机未注册')
            self.log.info('[%s]-[Result]:PASS' % casename)
            self.log.info(
                '>>>>>>>>>>>>>>>>>>>>>[DL_api_end]<<<<<<<<<<<<<<<<<<<<<<')
        except Exception:
            self.log.error('[%s]-[Result]:FAILED' % casename)
            self.log.info(
                '>>>>>>>>>>>>>>>>>>>>>[DL_api_end]<<<<<<<<<<<<<<<<<<<<<<')
            raise