コード例 #1
0
    def test_userdevice_02(self, dataFormat, networkType, productName,
                           productNodeType, sub, title):

        # '''数据初始化'''
        a = initData()
        a.initdata({'productName': productName})

        # 变量用来控制调取接口索引
        i = 0
        '''获取test_userdevice2.yaml中的数据'''
        data = userDeviceTest02()
        request = requestMethod()
        urls = data.url
        headers = data.header
        para = data.data
        expcode = data.code
        '''给所有url补充域名'''
        url = [None] * len(urls)
        for n in range(0, len(urls)):
            if 'oauth/login' not in urls[n]:
                url[n] = Config.host + urls[n]
            else:
                url[n] = urls[n]
        '''登录用户'''
        print('\n' + url[i])
        print('------登录用户入参------')
        print(para[i])
        response = request.get_post(url[i], headers[i], para[i])
        res_usrtoken = json.loads(response.text)
        curcode = response.status_code
        print('------登录用户返回------')
        print('status:%s' % str(curcode))
        print(str(response.text))

        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''给接口添加token'''
        for n in range(1, len(headers)):
            if 'deviceOwner' not in urls[n]:
                #开发者接口
                headers[n].update(Authorization='bearer ' + loginToken().token)
            else:
                #用户接口
                headers[n].update(Authorization=res_usrtoken['token_type'] +
                                  ' ' + res_usrtoken['access_token'])
        '''实例化调用测试数据的类'''
        case_function = CaseFunction()
        '''创建产品'''
        print('\n' + url[i])
        print('------创建产品入参------')
        createproduct = case_function.post_request(
            request, url[i], headers[i], para[i], {
                'dataFormat': dataFormat,
                'networkType': networkType,
                'productNodeType': productNodeType,
                'productName': productName,
                'sub': sub
            })
        curcode = createproduct.status_code
        print('------创建产品返回------')
        print('status:%s' % str(curcode))
        print(createproduct.text)
        self.assertEqual(expcode[i], curcode)
        createproduct = json.loads(createproduct.text)
        productkeys = createproduct['productKey']
        print('获取产品Key:' + productkeys)
        i = i + 1
        '''创建设备'''
        print('\n' + url[i])
        print('------创建设备入参------')
        createdevice = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'productKey': productkeys})
        curcode = createdevice.status_code
        print('------创建设备返回------')
        print('status:%s' % str(curcode))
        print(createdevice.text)
        self.assertEqual(expcode[i], curcode)
        deviceinfo = json.loads(createdevice.text)
        devicesecret = deviceinfo['deviceSecret']
        i = i + 1
        '''绑定用户'''
        print('\n' + url[i])
        print('------绑定用户入参------')
        binduser = case_function.post_request(request, url[i], headers[i],
                                              para[i], {
                                                  'productKey': productkeys,
                                                  'deviceSecret': devicesecret
                                              })
        curcode = binduser.status_code
        print('------绑定用户返回------')
        print('status:%s' % str(curcode))
        print(str(binduser.text))
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''增量更新设备标签'''
        print('\n' + url[i])
        print('------增量更新设备标签入参------')
        devicetag = case_function.post_request(request, url[i], headers[i],
                                               para[i],
                                               {'productKey': productkeys})
        curcode = devicetag.status_code
        print('------增量更新设备标签返回------')
        print('status:%s' % str(curcode))
        print(devicetag.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1

        print('\n' + url[i])
        print('------全量更新设备标签入参------')
        devicetags = case_function.post_request(request, url[i], headers[i],
                                                para[i],
                                                {'productKey': productkeys})
        curcode = devicetags.status_code
        print('------全量更新设备标签返回------')
        print('status:%s' % str(curcode))
        print(devicetags.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询设备标签'''
        print('\n' + url[i])
        getdevicetag = case_function.get_request(request, url[i], headers[i],
                                                 para[i],
                                                 {'productKey': productkeys})
        curcode = getdevicetag.status_code
        print('------查询设备标签返回------')
        print('status:%s' % str(curcode))
        print(getdevicetag.text)
        self.assertIn(expcode[i][0], getdevicetag.text)
        i = i + 1
        '''批量解绑设备'''
        print('\n' + url[i])
        para[i]['deviceKeys'][0]['productKey'] = productkeys
        print('------解绑设备入参------')
        unbinddevice = case_function.post_request(request, url[i], headers[i],
                                                  para[i])
        curcode = unbinddevice.status_code
        print('------解绑设备返回------')
        print('status:%s' % str(curcode))
        print(unbinddevice.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''数据清理'''
        a.initdata({'productName': productName})
コード例 #2
0
    def test_edgeuser_01(self):

        # '''数据初始化'''
        a = initData()
        a.initdata({'productName': 'apitest_autoEdge'})
        a.initdata({'productName': 'apitest_autoSub'})

        # 变量用来控制调取接口索引
        i = 0
        '''获取test_edgeuser.yaml中的数据'''
        data = EdgeuserTest01()
        request = requestMethod()
        urls = data.url
        headers = data.header
        para = data.data
        expcode = data.code
        '''给所有url补充域名'''
        url = [None] * len(urls)
        for n in range(0, len(urls)):
            if 'oauth/login' not in urls[n]:
                url[n] = Config.host + urls[n]
            else:
                url[n] = urls[n]
        '''登录用户'''
        print('\n' + url[i])
        print('------登录用户入参------')
        print(para[i])
        response = request.get_post(url[i], headers[i], para[i])
        res_usrtoken = json.loads(response.text)
        curcode = response.status_code
        print('------登录用户返回------')
        print('status:%s' % str(curcode))
        print(str(response.text))
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''给接口添加token'''
        for n in range(1, len(headers)):
            if 'Owner' not in urls[n]:
                #开发者接口
                headers[n].update(Authorization='bearer ' + loginToken().token)
            else:
                #用户接口
                headers[n].update(Authorization=res_usrtoken['token_type'] +
                                  ' ' + res_usrtoken['access_token'])
        '''实例化调用测试数据的类'''
        case_function = CaseFunction()
        '''开发者创建产品'''
        print('\n' + url[i])
        print('------开发者创建产品入参------')
        createproduct = case_function.post_request(request, url[i], headers[i],
                                                   para[i])
        curcode = createproduct.status_code
        print('------开发者创建产品返回------')
        print('status:%s' % str(curcode))
        print(createproduct.text)
        self.assertEqual(expcode[i], curcode)
        createproduct = json.loads(createproduct.text)
        productkeys = createproduct['productKey']
        print('获取产品Key:' + productkeys)
        i = i + 1
        '''开发者创建设备'''
        print('\n' + url[i])
        print('------开发者创建设备入参------')
        createdevice = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'productKey': productkeys})
        curcode = createdevice.status_code
        print('------开发者创建设备返回------')
        print('status:%s' % str(curcode))
        print(createdevice.text)
        self.assertEqual(expcode[i], curcode)
        deviceinfo = json.loads(createdevice.text)
        devicesecret = deviceinfo['deviceSecret']
        i = i + 1
        '''用户绑定至网关'''
        print('\n' + url[i])
        print('------用户绑定至网关入参------')
        binduser = case_function.post_request(request, url[i], headers[i],
                                              para[i], {
                                                  'productKey': productkeys,
                                                  'deviceSecret': devicesecret
                                              })
        curcode = binduser.status_code
        print('------用户绑定至网关返回------')
        print('status:%s' % str(curcode))
        print(str(binduser.text))
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''用户查询设备详情'''
        print('\n' + url[i])
        getdevice = case_function.get_request(request, url[i], headers[i],
                                              para[i],
                                              {'productKey': productkeys})
        curcode = getdevice.status_code
        print('------用户查询设备详情返回------')
        print('status:%s' % str(curcode))
        print(getdevice.text)
        self.assertIn(expcode[i], getdevice.text)
        deviceinstance = json.loads(getdevice.text)
        instanceid = deviceinstance['instanceId']
        print('获取实例id:' + instanceid)
        i = i + 1
        '''用户绑定驱动'''
        print('\n' + url[i])
        print('------用户绑定驱动入参------')
        binddriver = case_function.post_request(request, url[i], headers[i],
                                                para[i],
                                                {'instanceId': instanceid})
        curcode = binddriver.status_code
        print('------用户绑定驱动返回------')
        print('status:%s' % str(curcode))
        print(binddriver.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''开发者查询驱动'''
        print('\n' + url[i])
        getdriver = case_function.get_request(request, url[i], headers[i],
                                              para[i],
                                              {'instanceId': instanceid})
        curcode = getdriver.status_code
        print('------开发者查询驱动返回------')
        print('status:%s' % str(curcode))
        print(getdriver.text)
        self.assertIn(expcode[i], getdriver.text)
        i = i + 1
        '''用户配置驱动'''
        print('\n' + url[i])
        print('------用户配置驱动入参------')
        setdriver = case_function.post_request(request, url[i], headers[i],
                                               para[i],
                                               {'instanceId': instanceid})
        curcode = setdriver.status_code
        print('------用户配置驱动返回------')
        print('status:%s' % str(curcode))
        print(setdriver.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''开发者查询驱动配置'''
        print('\n' + url[i])
        getdriverconf = case_function.get_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'instanceId': instanceid})
        curcode = getdriverconf.status_code
        print('------开发者查询驱动配置返回------')
        print('status:%s' % str(curcode))
        print(getdriverconf.text)
        self.assertIn(expcode[i], getdriverconf.text)
        i = i + 1
        '''开发者创建子设备产品'''
        print('\n' + url[i])
        print('------创建子设备产品入参------')
        createsubproduct = case_function.post_request(request, url[i],
                                                      headers[i], para[i])
        curcode = createsubproduct.status_code
        print('------创建子设备产品返回------')
        print('status:%s' % str(curcode))
        print(createsubproduct.text)
        self.assertEqual(expcode[i], curcode)
        createsubproduct = json.loads(createsubproduct.text)
        subproductkeys = createsubproduct['productKey']
        print('获取子设备产品Key:' + subproductkeys)
        i = i + 1
        '''开发者创建子设备'''
        print('\n' + url[i])
        print('------创建设备入参------')
        createsubdevice = case_function.post_request(
            request, url[i], headers[i], para[i],
            {'productKey': subproductkeys})
        curcode = createsubdevice.status_code
        print('------创建设备返回------')
        print('status:%s' % str(curcode))
        print(createsubdevice.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''用户绑定子设备'''
        print('\n' + url[i])
        print('------用户绑定子设备入参------')
        para[i]['deviceKeys'][0]['productKey'] = subproductkeys
        para[i]['instanceId'] = instanceid
        bindsubdevice = case_function.post_request(request, url[i], headers[i],
                                                   para[i])
        curcode = bindsubdevice.status_code
        print('------用户绑定子设备返回------')
        print('status:%s' % str(curcode))
        print(bindsubdevice.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''用户查询实例设备'''
        print('\n' + url[i])
        getedgedevice = case_function.get_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'instanceId': instanceid})
        curcode = getedgedevice.status_code
        print('------用户查询实例设备返回------')
        print('status:%s' % str(curcode))
        print(getedgedevice.text)
        self.assertIn(expcode[i], getedgedevice.text)
        i = i + 1
        '''用户创建实例部署单'''
        print('\n' + url[i])
        print('------用户创建实例部署单入参------')
        createdeploy = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'instanceId': instanceid})
        curcode = createdeploy.status_code
        print('------用户创建实例部署单返回------')
        print('status:%s' % str(curcode))
        print(createdeploy.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''数据清理'''
        a.initdata({'productName': 'apitest_autoEdge'})
        a.initdata({'productName': 'apitest_autoSub'})
コード例 #3
0
    def test_driver_01(self):

        # '''数据初始化'''
        a = initData()
        a.initdata({'productName': 'testdriver'})

        # 变量用来控制调取接口索引
        i = 0
        '''获取test_driver1.yaml中的数据'''
        data = DriverTest01()
        request = requestMethod()
        urls = data.url
        headers = data.header
        para = data.data
        expcode = data.code
        '''给所有url补充域名'''
        url = [None] * len(urls)
        for n in range(0, len(urls)):
            if 'smallfile' not in urls[n]:
                url[n] = Config.host + urls[n]
            else:
                url[n] = urls[n]
        '''给所有接口添加token'''
        for n in range(0, len(headers)):
            headers[n].update(Authorization='bearer ' + loginToken().token)
        '''实例化调用测试数据的类'''
        case_function = CaseFunction()
        '''上传驱动文件'''
        f1 = open('\\ioT-uat\\testdriverfile.txt', 'rb')
        files = {'file': ('testdriverfile.text', f1, 'text/plain')}
        print('\n' + url[i])
        print('------上传驱动文件入参------')
        print(para[i])
        response = request.get_post(url[i], headers[i], para[i], files)
        curcode = response.status_code
        print('------上传驱动文件返回------')
        print('status:%s' % str(curcode))
        print(str(response.text))
        f1.close()

        self.assertEqual(expcode[i], curcode)
        res_address = json.loads(response.text)
        address = res_address['host'] + '/' + res_address['key']
        print('获取文件地址:' + str(address))
        i = i + 1

        time.sleep(2)
        '''创建驱动'''
        print('\n' + url[i])
        print('------创建驱动入参------')
        createdriver = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'fileUrl': address})
        curcode = createdriver.status_code
        print('------创建驱动返回------')
        print('status:%s' % str(curcode))
        print(createdriver.text)
        self.assertEqual(expcode[i], curcode)
        res_driverid = json.loads(createdriver.text)
        driverid = res_driverid['driverId']
        print('获取driverid:' + str(driverid))
        i = i + 1
        '''创建产品'''
        print('\n' + url[i])
        print('------创建产品入参------')
        createproduct = case_function.post_request(request, url[i], headers[i],
                                                   para[i])
        curcode = createproduct.status_code
        print('------创建产品返回------')
        print('status:%s' % str(curcode))
        print(createproduct.text)
        self.assertEqual(expcode[i], curcode)
        createproduct = json.loads(createproduct.text)
        productkeys = createproduct['productKey']
        print('获取产品Key:' + productkeys)
        i = i + 1
        '''绑定驱动'''
        print('\n' + url[i])
        print('------绑定驱动入参------')
        binddriver = case_function.post_request(request, url[i], headers[i],
                                                para[i], {
                                                    'productKey': productkeys,
                                                    'driverId': driverid
                                                })
        curcode = binddriver.status_code
        print('------绑定驱动返回------')
        print('status:%s' % str(curcode))
        print(binddriver.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''更新驱动'''
        print('\n' + url[i])
        print('------更新驱动入参------')
        updatedriver = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'driverId': driverid})
        curcode = updatedriver.status_code
        print('------更新驱动返回------')
        print('status:%s' % str(curcode))
        print(updatedriver.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''删除驱动失败'''
        print('\n' + url[i])
        print('------删除驱动入参------')
        deletedriver = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'driverId': driverid})
        curcode = deletedriver.status_code
        print('------删除驱动返回------')
        print('status:%s' % str(curcode))
        print(deletedriver.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''解绑驱动'''
        print('\n' + url[i])
        print('------解绑驱动入参------')
        unbinddriver = case_function.post_request(
            request, url[i], headers[i], para[i], {
                'productKey': productkeys,
                'driverId': driverid
            })
        curcode = unbinddriver.status_code
        print('------解绑驱动返回------')
        print('status:%s' % str(curcode))
        print(unbinddriver.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''删除驱动成功'''
        print('\n' + url[i])
        print('------删除驱动入参------')
        deletedriver = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'driverId': driverid})
        curcode = deletedriver.status_code
        print('------删除驱动返回------')
        print('status:%s' % str(curcode))
        print(deletedriver.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询驱动'''
        print('\n' + url[i])
        getdriver = case_function.get_request(request, url[i], headers[i],
                                              para[i], {'driverId': driverid})
        curcode = getdriver.status_code
        print('------查询驱动返回------')
        print('status:%s' % str(curcode))
        print(getdriver.text)
        self.assertEqual(expcode[i], curcode)
        '''数据清理'''
        a.initdata({'productName': 'testdriver'})
コード例 #4
0
    def test_edgedev_01(self):

        # '''数据初始化'''
        a = initData()
        a.initdata({'productName': 'apitest_autoEdge'})
        a.initdata({'productName': 'apitest_autoSub'})

        # 变量用来控制调取接口索引
        i = 0
        '''获取test_device1.yaml中的数据'''
        data = EdgedevTest01()
        request = requestMethod()
        urls = data.url
        headers = data.header
        para = data.data
        expcode = data.code
        '''给所有url补充域名'''
        url = [None] * len(urls)
        for n in range(0, len(urls)):
            url[n] = Config.host + urls[n]
        '''给所有接口添加token'''
        for n in range(0, len(headers)):
            headers[n].update(Authorization='bearer ' + loginToken().token)
        '''实例化调用测试数据的类'''
        case_function = CaseFunction()
        '''创建产品'''
        print('\n' + url[i])
        print('------创建产品入参------')
        createproduct = case_function.post_request(request, url[i], headers[i],
                                                   para[i])
        curcode = createproduct.status_code
        print('------创建产品返回------')
        print('status:%s' % str(curcode))
        print(createproduct.text)
        self.assertEqual(expcode[i], curcode)
        createproduct = json.loads(createproduct.text)
        productkeys = createproduct['productKey']
        print('获取产品Key:' + productkeys)
        i = i + 1
        '''创建设备'''
        print('\n' + url[i])
        print('------创建设备入参------')
        createdevice = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'productKey': productkeys})
        curcode = createdevice.status_code
        print('------创建设备返回------')
        print('status:%s' % str(curcode))
        print(createdevice.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询设备详情'''
        print('\n' + url[i])
        getdevice = case_function.get_request(request, url[i], headers[i],
                                              para[i],
                                              {'productKey': productkeys})
        curcode = getdevice.status_code
        print('------查询设备返回------')
        print('status:%s' % str(curcode))
        print(getdevice.text)
        self.assertIn(expcode[i], getdevice.text)
        deviceinstance = json.loads(getdevice.text)
        instanceid = deviceinstance['instanceId']
        print('获取实例id:' + instanceid)
        i = i + 1
        '''绑定驱动'''
        print('\n' + url[i])
        print('------绑定驱动入参------')
        binddriver = case_function.post_request(request, url[i], headers[i],
                                                para[i],
                                                {'instanceId': instanceid})
        curcode = binddriver.status_code
        print('------绑定驱动返回------')
        print('status:%s' % str(curcode))
        print(binddriver.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询驱动'''
        print('\n' + url[i])
        getdriver = case_function.get_request(request, url[i], headers[i],
                                              para[i],
                                              {'instanceId': instanceid})
        curcode = getdriver.status_code
        print('------查询驱动返回------')
        print('status:%s' % str(curcode))
        print(getdriver.text)
        self.assertIn(expcode[i], getdriver.text)
        i = i + 1
        '''配置驱动'''
        print('\n' + url[i])
        print('------配置驱动入参------')
        setdriver = case_function.post_request(request, url[i], headers[i],
                                               para[i],
                                               {'instanceId': instanceid})
        curcode = setdriver.status_code
        print('------配置驱动返回------')
        print('status:%s' % str(curcode))
        print(setdriver.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询驱动配置'''
        print('\n' + url[i])
        getdriverconf = case_function.get_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'instanceId': instanceid})
        curcode = getdriverconf.status_code
        print('------查询驱动配置返回------')
        print('status:%s' % str(curcode))
        print(getdriverconf.text)
        self.assertIn(expcode[i], getdriverconf.text)
        i = i + 1
        '''创建子设备产品'''
        print('\n' + url[i])
        print('------创建子设备产品入参------')
        createsubproduct = case_function.post_request(request, url[i],
                                                      headers[i], para[i])
        curcode = createsubproduct.status_code
        print('------创建子设备产品返回------')
        print('status:%s' % str(curcode))
        print(createsubproduct.text)
        self.assertEqual(expcode[i], curcode)
        createsubproduct = json.loads(createsubproduct.text)
        subproductkeys = createsubproduct['productKey']
        print('获取子设备产品Key:' + subproductkeys)
        i = i + 1
        '''创建子设备'''
        print('\n' + url[i])
        print('------创建设备入参------')
        createsubdevice = case_function.post_request(
            request, url[i], headers[i], para[i],
            {'productKey': subproductkeys})
        curcode = createsubdevice.status_code
        print('------创建设备返回------')
        print('status:%s' % str(curcode))
        print(createsubdevice.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''绑定子设备'''
        print('\n' + url[i])
        print('------绑定子设备入参------')
        para[i]['deviceKeys'][0]['productKey'] = subproductkeys
        para[i]['instanceId'] = instanceid
        bindsubdevice = case_function.post_request(request, url[i], headers[i],
                                                   para[i])
        curcode = bindsubdevice.status_code
        print('------绑定子设备返回------')
        print('status:%s' % str(curcode))
        print(bindsubdevice.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询实例设备'''
        print('\n' + url[i])
        getedgedevice = case_function.get_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'instanceId': instanceid})
        curcode = getedgedevice.status_code
        print('------查询实例设备返回------')
        print('status:%s' % str(curcode))
        print(getedgedevice.text)
        self.assertIn(expcode[i], getedgedevice.text)
        i = i + 1
        '''解绑驱动'''
        print('\n' + url[i])
        print('------解绑驱动入参------')
        unbinddriver = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'instanceId': instanceid})
        curcode = unbinddriver.status_code
        print('------解绑驱动返回------')
        print('status:%s' % str(curcode))
        print(unbinddriver.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''配置设备'''
        print('\n' + url[i])
        print('------配置设备入参------')
        para[i]['deviceConfigs'][0]['productKey'] = subproductkeys
        para[i]['instanceId'] = instanceid
        setdevice = case_function.post_request(request, url[i], headers[i],
                                               para[i])
        curcode = setdevice.status_code
        print('------配置设备返回------')
        print('status:%s' % str(curcode))
        print(setdevice.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询设备配置'''
        print('\n' + url[i])
        getdeviceconf = case_function.get_request(
            request, url[i], headers[i], para[i], {
                'instanceId': instanceid,
                'deviceKeys[0].productKey': subproductkeys
            })
        curcode = getdeviceconf.status_code
        print('------查询设备配置返回------')
        print('status:%s' % str(curcode))
        print(getdeviceconf.text)
        self.assertIn(expcode[i], getdeviceconf.text)
        i = i + 1
        '''创建实例部署单'''
        print('\n' + url[i])
        print('------创建实例部署单入参------')
        createdeploy = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'instanceId': instanceid})
        curcode = createdeploy.status_code
        print('------创建实例部署单返回------')
        print('status:%s' % str(curcode))
        print(createdeploy.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''清空设备配置'''
        print('\n' + url[i])
        print('------清空设备配置入参------')
        para[i]['deviceKeys'][0]['productKey'] = subproductkeys
        para[i]['instanceId'] = instanceid
        setdevice = case_function.post_request(request, url[i], headers[i],
                                               para[i])
        curcode = setdevice.status_code
        print('------清空设备配置返回------')
        print('status:%s' % str(curcode))
        print(setdevice.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询设备配置'''
        print('\n' + url[i])
        getdeviceconf = case_function.get_request(
            request, url[i], headers[i], para[i], {
                'instanceId': instanceid,
                'deviceKeys[0].productKey': subproductkeys
            })
        curcode = getdeviceconf.status_code
        print('------查询设备配置返回------')
        print('status:%s' % str(curcode))
        print(getdeviceconf.text)
        self.assertNotIn(expcode[i], getdeviceconf.text)
        i = i + 1
        '''清空驱动配置'''
        print('\n' + url[i])
        print('------清空驱动配置入参------')
        setdriver = case_function.post_request(request, url[i], headers[i],
                                               para[i],
                                               {'instanceId': instanceid})
        curcode = setdriver.status_code
        print('------清空驱动配置返回------')
        print('status:%s' % str(curcode))
        print(setdriver.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询驱动配置'''
        print('\n' + url[i])
        getdriverconf = case_function.get_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'instanceId': instanceid})
        curcode = getdriverconf.status_code
        print('------查询驱动配置返回------')
        print('status:%s' % str(curcode))
        print(getdriverconf.text)
        self.assertNotIn(expcode[i], getdriverconf.text)
        i = i + 1
        '''解绑子设备'''
        print('\n' + url[i])
        print('------解绑子设备参------')
        para[i]['deviceKeys'][0]['productKey'] = subproductkeys
        para[i]['instanceId'] = instanceid
        unbindsubdevice = case_function.post_request(request, url[i],
                                                     headers[i], para[i])
        curcode = unbindsubdevice.status_code
        print('------解绑子设备返回------')
        print('status:%s' % str(curcode))
        print(unbindsubdevice.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询实例设备'''
        print('\n' + url[i])
        getedgedevice = case_function.get_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'instanceId': instanceid})
        curcode = getedgedevice.status_code
        print('------查询实例设备返回------')
        print('status:%s' % str(curcode))
        print(getedgedevice.text)
        self.assertNotIn(expcode[i], getedgedevice.text)
        i = i + 1
        '''解绑驱动'''
        print('\n' + url[i])
        print('------解绑驱动入参------')
        unbinddriver = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'instanceId': instanceid})
        curcode = unbinddriver.status_code
        print('------绑定驱动返回------')
        print('status:%s' % str(curcode))
        print(unbinddriver.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询驱动'''
        print('\n' + url[i])
        getdriver = case_function.get_request(request, url[i], headers[i],
                                              para[i],
                                              {'instanceId': instanceid})
        curcode = getdriver.status_code
        print('------查询驱动返回------')
        print('status:%s' % str(curcode))
        print(getdriver.text)
        self.assertNotIn(expcode[i], getdriver.text)
        i = i + 1

        time.sleep(5)
        '''创建实例部署单'''
        print('\n' + url[i])
        print('------创建实例部署单入参------')
        createdeploy = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'instanceId': instanceid})
        curcode = createdeploy.status_code
        print('------创建实例部署单返回------')
        print('status:%s' % str(curcode))
        print(createdeploy.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''数据清理'''
        a.initdata({'productName': 'apitest_autoEdge'})
        a.initdata({'productName': 'apitest_autoSub'})
コード例 #5
0
    def test_userdevice_03(self, dataFormat, networkType, productName,
                           productNodeType, sub, title):

        # '''数据初始化'''
        a = initData()
        a.initdata({'productName': productName})

        # 变量用来控制调取接口索引
        i = 0
        '''获取test_userdevice3.yaml中的数据'''
        data = userDeviceTest03()
        request = requestMethod()
        urls = data.url
        headers = data.header
        para = data.data
        expcode = data.code
        '''给所有url补充域名'''
        url = [None] * len(urls)
        for n in range(0, len(urls)):
            if 'oauth/login' not in urls[n] and 'utmodel' not in urls[n]:
                url[n] = Config.host + urls[n]
            else:
                url[n] = urls[n]
        '''登录用户'''
        print('\n' + url[i])
        print('------登录用户入参------')
        print(para[i])
        response = request.get_post(url[i], headers[i], para[i])
        res_usrtoken = json.loads(response.text)
        curcode = response.status_code
        print('------登录用户返回------')
        print('status:%s' % str(curcode))
        print(str(response.text))

        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''给接口添加token'''
        for n in range(1, len(headers)):
            if 'deviceOwner' not in urls[n]:
                #开发者接口
                headers[n].update(Authorization='bearer ' + loginToken().token)
            else:
                #用户接口
                headers[n].update(Authorization=res_usrtoken['token_type'] +
                                  ' ' + res_usrtoken['access_token'])
        '''实例化调用测试数据的类'''
        case_function = CaseFunction()
        '''创建产品'''
        print('\n' + url[i])
        print('------创建产品入参------')
        createproduct = case_function.post_request(
            request, url[i], headers[i], para[i], {
                'dataFormat': dataFormat,
                'networkType': networkType,
                'productNodeType': productNodeType,
                'productName': productName,
                'sub': sub
            })
        curcode = createproduct.status_code
        print('------创建产品返回------')
        print('status:%s' % str(curcode))
        print(createproduct.text)
        self.assertEqual(expcode[i], curcode)
        createproduct = json.loads(createproduct.text)
        productkeys = createproduct['productKey']
        print('获取产品Key:' + productkeys)
        i = i + 1
        '''创建设备'''
        print('\n' + url[i])
        print('------创建设备入参------')
        createdevice = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'productKey': productkeys})
        curcode = createdevice.status_code
        print('------创建设备返回------')
        print('status:%s' % str(curcode))
        print(createdevice.text)
        self.assertEqual(expcode[i], curcode)
        deviceinfo = json.loads(createdevice.text)
        devicesecret = deviceinfo['deviceSecret']
        i = i + 1
        '''绑定用户'''
        print('\n' + url[i])
        print('------绑定用户入参------')
        binduser = case_function.post_request(request, url[i], headers[i],
                                              para[i], {
                                                  'productKey': productkeys,
                                                  'deviceSecret': devicesecret
                                              })
        curcode = binduser.status_code
        print('------绑定用户返回------')
        print('status:%s' % str(curcode))
        print(str(binduser.text))
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询产品虚拟子产品key'''
        print('\n' + url[i])
        getproduct = case_function.get_request(request, url[i], headers[i],
                                               para[i],
                                               {'productKey': productkeys})
        curcode = getproduct.status_code
        print('------查询产品虚拟子产品key返回------')
        print('status:%s' % str(curcode))
        print(getproduct.text)
        gmtmodel_res = json.loads(getproduct.text)
        gmtmodelid = gmtmodel_res["subProductKey"]
        i = i + 1
        '''查询产品优模型id'''
        if para[1]['productName'] == 'apitest_auto42':
            para[i]['identifier'] = gmtmodelid
        else:
            para[i]['identifier'] = productkeys
        print('\n' + url[i])
        getmodel = case_function.get_request(request, url[i], headers[i],
                                             para[i])
        curcode = getmodel.status_code
        print('------查询产品优模型id返回------')
        print('status:%s' % str(curcode))
        print(getmodel.text)
        self.assertIn(expcode[i], getmodel.text)
        model_res = json.loads(getmodel.text)
        modelid = model_res["id"]
        i = i + 1
        '''定义属性'''
        print('\n' + url[i])
        print('------定义属性入参------')
        definedserver = case_function.post_request(request, url[i], headers[i],
                                                   para[i],
                                                   {'modelId': modelid})
        curcode = definedserver.status_code
        print('------定义属性返回------')
        print('status:%s' % str(curcode))
        print(definedserver.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''发布产品'''
        print('\n' + url[i])
        print('------发布产品入参------')
        releaseproduct = case_function.post_request(
            request, url[i], headers[i], para[i], {'productKey': productkeys})
        curcode = releaseproduct.status_code
        print('------发布产品返回------')
        print('status:%s' % str(curcode))
        print(str(releaseproduct.text))
        self.assertEqual(expcode[i], curcode)
        i = i + 1

        time.sleep(2)
        '''设置属性'''
        print('\n' + url[i])
        print('------设置属性入参------')
        setserver = case_function.post_request(request, url[i], headers[i],
                                               para[i],
                                               {'productKey': productkeys})
        curcode = setserver.status_code
        print('------设置属性返回------')
        print('status:%s' % str(curcode))
        print(str(setserver.text))
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询属性'''
        print('\n' + url[i])
        getserver = case_function.get_request(request, url[i], headers[i],
                                              para[i],
                                              {'productKey': productkeys})
        curcode = getserver.status_code
        print('------查询属性返回------')
        print('status:%s' % str(curcode))
        print(getserver.text)
        self.assertNotIn(expcode[i], getserver.text)
        i = i + 1
        '''批量设置属性'''
        print('\n' + url[i])
        print('------批量设置属性入参------')
        setservers = case_function.post_request(request, url[i], headers[i],
                                                para[i],
                                                {'productKey': productkeys})
        curcode = setservers.status_code
        print('------批量设置属性返回------')
        print('status:%s' % str(curcode))
        print(str(setservers.text))
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询属性'''
        print('\n' + url[i])
        getserver = case_function.get_request(request, url[i], headers[i],
                                              para[i],
                                              {'productKey': productkeys})
        curcode = getserver.status_code
        print('------查询属性返回------')
        print('status:%s' % str(curcode))
        print(getserver.text)
        self.assertNotIn(expcode[i], getserver.text)
        i = i + 1
        '''设置期望属性值'''
        print('\n' + url[i])
        print('------设置期望属性值入参------')
        setdesire = case_function.post_request(request, url[i], headers[i],
                                               para[i],
                                               {'productKey': productkeys})
        curcode = setdesire.status_code
        print('------设置期望属性值返回------')
        print('status:%s' % str(curcode))
        print(str(setdesire.text))
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询期望属性值'''
        print('\n' + url[i])
        getdesire = case_function.get_request(request, url[i], headers[i],
                                              para[i],
                                              {'productKey': productkeys})
        curcode = getdesire.status_code
        print('------查询期望属性值返回------')
        print('status:%s' % str(curcode))
        print(getdesire.text)
        self.assertIn(expcode[i], getdesire.text)
        '''数据清理'''
        a.initdata({'productName': productName})
コード例 #6
0
    def test_product_01(self, dataFormat, networkType, productName,
                        productNodeType, sub, title):

        # '''数据初始化'''
        a = initData()
        a.initdata({'productName': productName})

        # 变量用来控制调取接口索引
        i = 0
        '''获取test_product1.yaml中的数据'''
        data = ProductTest01()
        request = requestMethod()
        urls = data.url
        headers = data.header
        para = data.data
        expcode = data.code
        '''给所有url补充域名'''
        url = [None] * len(urls)
        for n in range(0, len(urls)):
            url[n] = Config.host + urls[n]
        '''给所有header添加token'''
        for n in range(0, len(headers)):
            headers[n].update(Authorization='bearer ' + loginToken().token)
        '''实例化调用测试数据的类'''
        case_function = CaseFunction()
        '''创建产品'''
        print('\n' + url[i])
        print('------创建产品入参------')
        createproduct = case_function.post_request(
            request, url[i], headers[i], para[i], {
                'dataFormat': dataFormat,
                'networkType': networkType,
                'productNodeType': productNodeType,
                'productName': productName,
                'sub': sub
            })
        curcode = createproduct.status_code
        print('------创建产品返回------')
        print('status:%s' % str(curcode))
        print(createproduct.text)
        self.assertEqual(expcode[i], curcode)
        createproduct = json.loads(createproduct.text)
        productkeys = createproduct['productKey']
        print('获取产品Key:' + productkeys)
        i = i + 1
        '''发布产品'''
        print('\n' + url[i])
        print('------发布产品入参------')
        createproduct = case_function.post_request(request, url[i], headers[i],
                                                   para[i],
                                                   {'productKey': productkeys})
        curcode = createproduct.status_code
        print('------发布产品返回------')
        print('status:%s' % str(curcode))
        print(str(createproduct.text))
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''更新产品:失败'''
        print('\n' + url[i])
        print('------更新产品入参------')
        updateproduct = case_function.post_request(request, url[i], headers[i],
                                                   para[i],
                                                   {'productKey': productkeys})
        curcode = updateproduct.status_code
        print('------更新产品返回------')
        print('status:%s' % str(curcode))
        print(str(updateproduct.text))
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''删除产品:失败'''
        print('\n' + url[i])
        print('------删除产品入参------')
        deleteproduct = case_function.post_request(request, url[i], headers[i],
                                                   para[i],
                                                   {'productKey': productkeys})
        curcode = deleteproduct.status_code
        print('------删除产品返回------')
        print('status:%s' % str(curcode))
        print(deleteproduct.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''撤销发布产品'''
        print('\n' + url[i])
        print('------撤销产品入参------')
        cancelproduct = case_function.post_request(request, url[i], headers[i],
                                                   para[i],
                                                   {'productKey': productkeys})
        curcode = cancelproduct.status_code
        print('------撤销产品返回------')
        print('status:%s' % str(curcode))
        print(cancelproduct.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''更新产品:成功'''
        print('\n' + url[i])
        print('------更新产品入参------')
        updateproduct = case_function.post_request(request, url[i], headers[i],
                                                   para[i],
                                                   {'productKey': productkeys})
        curcode = updateproduct.status_code
        print('------更新产品返回------')
        print('status:%s' % str(curcode))
        print(updateproduct.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''增量更新标签'''
        print('\n' + url[i])
        print('------增量更新标签入参------')
        producttag = case_function.post_request(request, url[i], headers[i],
                                                para[i],
                                                {'productKey': productkeys})
        curcode = producttag.status_code
        print('------增量更新标签返回------')
        print('status:%s' % str(curcode))
        print(producttag.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''全量更新标签'''
        print('\n' + url[i])
        print('------全量更新标签入参------')
        producttags = case_function.post_request(request, url[i], headers[i],
                                                 para[i],
                                                 {'productKey': productkeys})
        curcode = producttags.status_code
        print('------全量更新标签入参------')
        print('status:%s' % str(curcode))
        print(producttags.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询产品详情'''
        print('\n' + url[i])
        getproduct = case_function.get_request(request, url[i], headers[i],
                                               para[i],
                                               {'productKey': productkeys})
        curcode = getproduct.status_code
        print('------查询产品返回------')
        print('status:%s' % str(curcode))
        print(getproduct.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''删除产品:成功'''
        print('\n' + url[i])
        print('------删除产品入参------')
        deleteproduct = case_function.post_request(request, url[i], headers[i],
                                                   para[i],
                                                   {'productKey': productkeys})
        curcode = deleteproduct.status_code
        print('------删除产品返回------')
        print('status:%s' % str(curcode))
        print(deleteproduct.text)
        self.assertEqual(expcode[i], curcode)
コード例 #7
0
    def test_device_05(self, dataFormat, networkType, productName,
                       productNodeType, sub, title):

        # '''数据初始化'''
        a = initData()
        a.initdata({'productName': productName})

        # 变量用来控制调取接口索引
        i = 0
        '''获取test_device5.yaml中的数据'''
        data = DeviceTest05()
        request = requestMethod()
        urls = data.url
        headers = data.header
        para = data.data
        expcode = data.code
        '''给所有url补充域名'''
        url = [None] * len(urls)
        for n in range(0, len(urls)):
            if 'utmodel' not in urls[n]:
                url[n] = Config.host + urls[n]
            else:
                url[n] = urls[n]
        '''给所有接口添加token'''
        for n in range(0, len(headers)):
            headers[n].update(Authorization='bearer ' + loginToken().token)
        '''实例化调用测试数据的类'''
        case_function = CaseFunction()
        '''创建产品'''
        print('\n' + url[i])
        print('------创建产品入参------')
        createproduct = case_function.post_request(
            request, url[i], headers[i], para[i], {
                'dataFormat': dataFormat,
                'networkType': networkType,
                'productNodeType': productNodeType,
                'productName': productName,
                'sub': sub
            })
        curcode = createproduct.status_code
        print('------创建产品返回------')
        print('status:%s' % str(curcode))
        print(createproduct.text)
        self.assertEqual(expcode[i], curcode)
        createproduct = json.loads(createproduct.text)
        productkeys = createproduct['productKey']
        print('获取产品Key:' + productkeys)
        i = i + 1
        '''创建设备'''
        print('\n' + url[i])
        print('------创建设备入参------')
        createdevice = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'productKey': productkeys})
        curcode = createdevice.status_code
        print('------创建设备返回------')
        print('status:%s' % str(curcode))
        print(createdevice.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询产品虚拟子产品key'''
        print('\n' + url[i])
        getproduct = case_function.get_request(request, url[i], headers[i],
                                               para[i],
                                               {'productKey': productkeys})
        curcode = getproduct.status_code
        print('------查询产品虚拟子产品key返回------')
        print('status:%s' % str(curcode))
        print(getproduct.text)
        gmtmodel_res = json.loads(getproduct.text)
        gmtmodelid = gmtmodel_res["subProductKey"]
        i = i + 1
        '''查询产品优模型id'''
        if para[0]['productName'] == 'apitest_auto30':
            para[i]['identifier'] = gmtmodelid
        else:
            para[i]['identifier'] = productkeys
        print('\n' + url[i])
        getmodel = case_function.get_request(request, url[i], headers[i],
                                             para[i])
        curcode = getmodel.status_code
        print('------查询产品优模型id返回------')
        print('status:%s' % str(curcode))
        print(getmodel.text)
        self.assertIn(expcode[i], getmodel.text)
        model_res = json.loads(getmodel.text)
        modelid = model_res["id"]
        i = i + 1
        '''定义服务'''
        print('\n' + url[i])
        print('------定义服务入参------')
        definedserver = case_function.post_request(request, url[i], headers[i],
                                                   para[i],
                                                   {'modelId': modelid})
        curcode = definedserver.status_code
        print('------定义服务返回------')
        print('status:%s' % str(curcode))
        print(definedserver.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''发布产品'''
        print('\n' + url[i])
        print('------发布产品入参------')
        releaseproduct = case_function.post_request(
            request, url[i], headers[i], para[i], {'productKey': productkeys})
        curcode = releaseproduct.status_code
        print('------发布产品返回------')
        print('status:%s' % str(curcode))
        print(str(releaseproduct.text))
        self.assertEqual(expcode[i], curcode)
        i = i + 1

        time.sleep(2)
        '''调用服务'''
        starttime = int(round(time.time() * 1000))
        print('\n' + url[i])
        print('------调用服务入参------')
        setserver = case_function.post_request(request, url[i], headers[i],
                                               para[i],
                                               {'productKey': productkeys})
        curcode = setserver.status_code
        print('------调用服务返回------')
        print('status:%s' % str(curcode))
        print(str(setserver.text))
        endtime = int(round(time.time() * 1000))
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询服务'''
        print('\n' + url[i])
        getserver = case_function.get_request(request, url[i], headers[i],
                                              para[i], {
                                                  'productKey': productkeys,
                                                  'startTime': starttime,
                                                  'endTime': endtime
                                              })
        curcode = getserver.status_code
        print('------查询服务返回------')
        print('status:%s' % str(curcode))
        print(getserver.text)
        self.assertNotIn(expcode[i], getserver.text)
        i = i + 1
        '''批量调用服务'''
        starttime = int(round(time.time() * 1000))
        print('\n' + url[i])
        print('------批量调用服务入参------')
        setservers = case_function.post_request(request, url[i], headers[i],
                                                para[i],
                                                {'productKey': productkeys})
        curcode = setservers.status_code
        print('------批量调用服务返回------')
        print('status:%s' % str(curcode))
        print(str(setservers.text))
        endtime = int(round(time.time() * 1000))
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询服务'''
        print('\n' + url[i])
        getserver = case_function.get_request(request, url[i], headers[i],
                                              para[i], {
                                                  'productKey': productkeys,
                                                  'startTime': starttime,
                                                  'endTime': endtime
                                              })
        curcode = getserver.status_code
        print('------查询服务返回------')
        print('status:%s' % str(curcode))
        print(getserver.text)
        self.assertNotIn(expcode[i], getserver.text)
        '''数据清理'''
        a.initdata({'productName': productName})
コード例 #8
0
    def test_device_03(self, dataFormat, networkType, productName,
                       productNodeType, sub, title):

        # '''数据初始化'''
        a = initData()
        a.initdata({'productName': productName})

        # 变量用来控制调取接口索引
        i = 0
        '''获取test_device3.yaml中的数据'''
        data = DeviceTest03()
        request = requestMethod()
        urls = data.url
        headers = data.header
        para = data.data
        expcode = data.code
        '''给所有url补充域名'''
        url = [None] * len(urls)
        for n in range(0, len(urls)):
            url[n] = Config.host + urls[n]
        '''给所有接口添加token'''
        for n in range(0, len(headers)):
            headers[n].update(Authorization='bearer ' + loginToken().token)
        '''实例化调用测试数据的类'''
        case_function = CaseFunction()
        '''创建产品'''
        print('\n' + url[i])
        print('------创建产品入参------')
        createproduct = case_function.post_request(
            request, url[i], headers[i], para[i], {
                'dataFormat': dataFormat,
                'networkType': networkType,
                'productNodeType': productNodeType,
                'productName': productName,
                'sub': sub
            })
        curcode = createproduct.status_code
        print('------创建产品返回------')
        print('status:%s' % str(curcode))
        print(createproduct.text)
        self.assertEqual(expcode[i], curcode)
        createproduct = json.loads(createproduct.text)
        productkeys = createproduct['productKey']
        print('获取产品Key:' + productkeys)
        i = i + 1
        '''创建设备'''
        print('\n' + url[i])
        print('------创建设备入参------')
        createdevice = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'productKey': productkeys})
        curcode = createdevice.status_code
        print('------创建设备返回------')
        print('status:%s' % str(curcode))
        print(createdevice.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''增量更新设备标签'''
        print('\n' + url[i])
        print('------增量更新设备标签入参------')
        devicetag = case_function.post_request(request, url[i], headers[i],
                                               para[i],
                                               {'productKey': productkeys})
        curcode = devicetag.status_code
        print('------增量更新设备标签返回------')
        print('status:%s' % str(curcode))
        print(devicetag.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''全量更新设备标签'''
        print('\n' + url[i])
        print('------全量更新设备标签入参------')
        devicetags = case_function.post_request(request, url[i], headers[i],
                                                para[i],
                                                {'productKey': productkeys})
        curcode = devicetags.status_code
        print('------全量更新设备标签返回------')
        print('status:%s' % str(curcode))
        print(devicetags.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询设备标签'''
        print('\n' + url[i])
        getdevicetag = case_function.get_request(request, url[i], headers[i],
                                                 para[i],
                                                 {'productKey': productkeys})
        curcode = getdevicetag.status_code
        print('------查询设备标签返回------')
        print('status:%s' % str(curcode))
        print(getdevicetag.text)
        self.assertIn(expcode[i][0], getdevicetag.text)
        self.assertIn(expcode[i][1], getdevicetag.text)
        i = i + 1
        '''数据清理'''
        a.initdata({'productName': productName})
コード例 #9
0
    def test_product_05(self, dataFormat, networkType, productName,
                        productNodeType, sub, title):

        # '''数据初始化'''
        a = initData()
        a.initdata({'productName': productName})

        # 变量用来控制调取接口索引
        i = 0
        '''获取test_product5.yaml中的数据'''
        data = ProductTest05()
        request = requestMethod()
        urls = data.url
        headers = data.header
        para = data.data
        expcode = data.code
        '''给所有url补充域名'''
        url = [None] * len(urls)
        for n in range(0, len(urls)):
            url[n] = Config.host + urls[n]
        '''给所有接口添加token'''
        for n in range(0, len(headers)):
            headers[n].update(Authorization='bearer ' + loginToken().token)
        '''实例化调用测试数据的类'''
        case_function = CaseFunction()
        '''创建产品'''
        print('\n' + url[i])
        print('------创建产品入参------')
        createproduct = case_function.post_request(
            request, url[i], headers[i], para[i], {
                'dataFormat': dataFormat,
                'networkType': networkType,
                'productNodeType': productNodeType,
                'productName': productName,
                'sub': sub
            })
        curcode = createproduct.status_code
        print('------创建产品返回------')
        print('status:%s' % str(curcode))
        print(createproduct.text)
        self.assertEqual(expcode[i], curcode)
        createproduct = json.loads(createproduct.text)
        productkeys = createproduct['productKey']
        print('获取产品Key:' + productkeys)
        i = i + 1
        '''绑定驱动'''
        print('\n' + url[i])
        print('------绑定驱动入参------')
        binddriver = case_function.post_request(request, url[i], headers[i],
                                                para[i],
                                                {'productKey': productkeys})
        curcode = binddriver.status_code
        print('------绑定驱动返回------')
        print('status:%s' % str(curcode))
        print(str(binddriver.text))
        if para[0]['productName'] == 'apitest_auto13':
            self.assertEqual(409, curcode)
            i = i + 1
        else:
            self.assertEqual(expcode[i], curcode)
            i = i + 1
        '''查询产品已绑定驱动'''
        print('\n' + url[i])
        getbinddriver = case_function.get_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'productKey': productkeys})
        curcode = getbinddriver.status_code
        print('------查询产品Topic返回------')
        print('status:%s' % str(curcode))
        print(getbinddriver.text)
        if para[0]['productName'] == 'apitest_auto13':
            self.assertNotIn(expcode[i], getbinddriver.text)
            i = i + 1
        else:
            self.assertIn(expcode[i], getbinddriver.text)
            i = i + 1
        '''解绑驱动'''
        print('\n' + url[i])
        print('------解绑驱动入参------')
        unbinddriver = case_function.post_request(request, url[i], headers[i],
                                                  para[i],
                                                  {'productKey': productkeys})
        curcode = unbinddriver.status_code
        print('------解绑驱动返回------')
        print('status:%s' % str(curcode))
        print(str(unbinddriver.text))
        if para[0]['productName'] == 'apitest_auto13':
            self.assertEqual(409, curcode)
            i = i + 1
        else:
            self.assertEqual(expcode[i], curcode)
            i = i + 1
        '''删除产品:成功'''
        print('\n' + url[i])
        print('------删除产品入参------')
        deleteproduct = case_function.post_request(request, url[i], headers[i],
                                                   para[i],
                                                   {'productKey': productkeys})
        curcode = deleteproduct.status_code
        print('------删除产品返回------')
        print('status:%s' % str(curcode))
        print(deleteproduct.text)
        self.assertEqual(expcode[i], curcode)
        i = i + 1
        '''查询产品详情'''
        print('\n' + url[i])
        getproduct = case_function.get_request(request, url[i], headers[i],
                                               para[i],
                                               {'productKey': productkeys})
        curcode = getproduct.status_code
        print('------查询产品返回------')
        print('status:%s' % str(curcode))
        print(getproduct.text)
        self.assertEqual(expcode[i], curcode)
コード例 #10
0
    def test_device_06(self,dataFormat,networkType,productName,productNodeType,sub,title):

        # '''数据初始化'''
        a=initData()
        a.initdata({'productName':productName})

        # 变量用来控制调取接口索引
        i=0

        '''获取test_device6.yaml中的数据'''
        data=DeviceTest06()
        request=requestMethod()
        urls=data.url
        headers=data.header
        para=data.data
        expcode=data.code

        '''给所有url补充域名'''
        url=[None]*len(urls)
        for n in range(0,len(urls)):
            url[n]=Config.host+urls[n]

        '''给所有接口添加token'''
        for n in range(0,len(headers)):
            headers[n].update(Authorization='bearer '+loginToken().token)
            

        '''实例化调用测试数据的类'''
        case_function=CaseFunction()  

        '''创建产品'''
        print('\n'+url[i])
        print('------创建产品入参------')
        createproduct=case_function.post_request(request,url[i],headers[i],para[i],{'dataFormat':dataFormat,'networkType':networkType,'productNodeType':productNodeType,'productName':productName,'sub':sub})
        curcode=createproduct.status_code
        print('------创建产品返回------')
        print('status:%s'%str(curcode))
        print(createproduct.text)
        self.assertEqual(expcode[i],curcode)
        createproduct=json.loads(createproduct.text)
        productkeys=createproduct['productKey']
        print('获取产品Key:'+productkeys)
        i=i+1

        '''批量创建设备'''
        print('\n'+url[i])
        print('------批量创建设备入参------')
        createdevice=case_function.post_request(request,url[i],headers[i],para[i],{'productKey':productkeys})
        curcode=createdevice.status_code
        print('------批量创建设备返回------')
        print('status:%s'%str(curcode))
        print(createdevice.text)        
        self.assertEqual(expcode[i],curcode)
        res_applyid=json.loads(createdevice.text)
        applyid=res_applyid['applyId']
        print('获取批次id:'+str(applyid))
        i=i+1
        
        time.sleep(5)

        '''查询批次列表'''
        print('\n'+url[i])
        getapplyid=case_function.get_request(request,url[i],headers[i],para[i],{'productKey':productkeys})
        curcode=getapplyid.status_code
        print('------查询批次列表返回------')   
        print('status:%s'%str(curcode))
        print(getapplyid.text) 
        self.assertIn(str(applyid),getapplyid.text)
        i=i+1

        time.sleep(5)

        '''查询批次详情'''
        print('\n'+url[i])
        getapplyinfo=case_function.get_request(request,url[i],headers[i],para[i],{'productKey':productkeys,'applyId':str(applyid)})
        curcode=getapplyinfo.status_code
        print('------查询批次详情返回------')   
        print('status:%s'%str(curcode))
        print(getapplyinfo.text) 
        res_info=json.loads(getapplyinfo.text)
        self.assertEqual(expcode[i],len(res_info['content']))
        i=i+1

        time.sleep(5)

        '''查询批次详情列表'''
        print('\n'+url[i])
        getapplylist=case_function.get_request(request,url[i],headers[i],para[i],{'applyId':str(applyid)})
        curcode=getapplylist.status_code
        print('------查询批次详情列表返回------')   
        print('status:%s'%str(curcode))
        print(getapplylist.text)       
        res_infolist=json.loads(getapplylist.text)        
        self.assertEqual(expcode[i],len(res_infolist['deviceInfos']))
        devicenames=[]
        for m in range(0,len(res_infolist['deviceInfos'])):                
            devicenames.append(res_infolist['deviceInfos'][m]['deviceName'])
        print('获取批量创建的设备deviceName:'+str(devicenames))
        i=i+1

        time.sleep(15)
        '''查询设备'''
        print('\n'+url[i])
        print('------查询设备------')
        for n in range(0,len(devicenames)):
            getdevice=case_function.get_request(request,url[i],headers[i],para[i],{'deviceName':devicenames[n],'productKey':productkeys})           
            curcode=getdevice.status_code
            print('查询设备:%s status:%s'%(devicenames[n],str(curcode)))
            print(getdevice.text)  
            self.assertIn(devicenames[n],getdevice.text)               
        i=i+1             

        '''删除设备'''
        print('\n'+url[i])
        print('------删除设备------')
        for n in range(0,len(devicenames)):          
            deletedevice=case_function.post_request(request,url[i],headers[i],para[i],{'deviceName':devicenames[n],'productKey':productkeys})
            curcode=deletedevice.status_code
            print('删除设备:%s status:%s'%(devicenames[n],str(curcode)))
            print(str(deletedevice.text))
            self.assertEqual(expcode[i],curcode)                
        i=i+1

        time.sleep(3)

        '''删除产品'''        
        print('\n'+url[i])
        print('------删除产品入参------')
        deleteproduct=case_function.post_request(request,url[i],headers[i],para[i],{'productKey':productkeys})
        curcode=deleteproduct.status_code
        print('------删除产品返回------')
        print('status:%s'%str(curcode))
        print(deleteproduct.text)
        self.assertEqual(expcode[i],curcode)
        i=i+1              

        '''查询批次详情'''
        print('\n'+url[i])
        getapplyinfo=case_function.get_request(request,url[i],headers[i],para[i],{'productKey':productkeys,'applyId':str(applyid)})
        curcode=getapplyinfo.status_code
        print('------查询批次详情返回------')   
        print('status:%s'%str(curcode))
        print(getapplyinfo.text) 
        res_info=json.loads(getapplyinfo.text)
        self.assertEqual(expcode[i],curcode)