Exemple #1
0
def queryCivilByRepoID(repoID):
    url = "http://%s:%s/api/repositories/%s/entities" % (DATA.DEEPCLOUD_IP, DATA.DEEPCLOUD_PORT, repoID)
    resQueryCivilByRepoIDObject = HTTP_REQUEST.get_request(url)
    if resQueryCivilByRepoIDObject[1] == 200:
        return resQueryCivilByRepoIDObject
    else:
        raise MYEXCEPTION.MyException("Query civil by repoID error.")
Exemple #2
0
    def test_addOrg(self):

        # 增加组织
        addUrl = "http://%s:%s/api/orgs" % (CONFIG.DEEP_IP, CONFIG.DEEP_PORT)
        addOrgSource = self.parameterListForAddOrg
        resAddObject = HTTP_REQUEST.post_request(addUrl, addOrgSource)
        orgIdStr = resAddObject[0]["OrgId"]

        # 获得上级组织的名称
        getSuperOrgNameUrl = "http://%s:%s/api/orgs/%s" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT, addOrgSource["SuperiorOrgId"])
        resGetSuperOrgNameObject = HTTP_REQUEST.get_request(getSuperOrgNameUrl)

        # 验证
        self.assertEqual(200, resAddObject[1])
        self.assertEqual(
            unicode(self.parameterListForAddOrg["Comment"], "utf-8"),
            resAddObject[0]["Comment"])
        self.assertEqual(
            unicode(self.parameterListForAddOrg["OrgName"], "utf-8"),
            resAddObject[0]["OrgName"])
        self.assertEqual(
            unicode(self.parameterListForAddOrg["SuperiorOrgId"], "utf-8"),
            resAddObject[0]["SuperiorOrgId"])
        self.assertEqual(self.parameterListForAddOrg["OrgLevel"],
                         resAddObject[0]["OrgLevel"])
        self.assertEqual(resGetSuperOrgNameObject[0]["SuperiorOrgName"],
                         resAddObject[0]["SuperiorOrgName"])

        # 删除组织(复原)
        delUrl = "http://%s:%s/api/orgs/%s" % (CONFIG.DEEP_IP,
                                               CONFIG.DEEP_PORT, orgIdStr)
        resDelObject = HTTP_REQUEST.del_request(delUrl)

        self.assertEqual(200, resDelObject[1])
Exemple #3
0
    def test_getRepoById(self):

        repoIdStr = "16435f08-9cb2-4986-891d-09e832b842d0"
        url = "http://%s:%s/api/repositories/%s" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT, repoIdStr)

        resObject = HTTP_REQUEST.get_request(url)

        # 验证返回码
        self.assertEqual(200, resObject[1])
Exemple #4
0
    def test_delRepoById(self):
        """
        验证过程:
        1. 调用增加接口,增加新比对库,获取比对库ID
        2. 查询新增比对库,比对库存在
        3. 删除新增比对库,验证返回码
        4. 查询新增比对库,比对库不存在
        """
        # 传入参数准备
        addSource = self.paramListForDelRepo

        # 增加比对库
        addUrl = "http://%s:%s/api/repositories" % (CONFIG.DEEP_IP,
                                                    CONFIG.DEEP_PORT)
        resAddObject = HTTP_REQUEST.post_request(addUrl, addSource)
        self.assertEqual(201, resAddObject[1])
        print resAddObject[0]["id"]

        # 查询新增比对库
        getUrl = "http://%s:%s/api/repositories/%s" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT, resAddObject[0]["id"])
        resGetObject = HTTP_REQUEST.get_request(getUrl)
        self.assertEqual(200, resGetObject[1])

        # 删除新增比对库
        delUrl = "http://%s:%s/api/repositories/%s" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT, resAddObject[0]["id"])
        resDelObject = HTTP_REQUEST.del_request(delUrl)
        print resDelObject

        self.assertEqual(204, resDelObject[1])  #  此处与文档不一致,文档要求返回204,实际返回200
        self.assertEqual(resAddObject[0]["id"], resDelObject[0]["id"])
        self.assertEqual(unicode(self.paramListForDelRepo["type"], "utf-8"),
                         resDelObject[0]["type"])
        self.assertEqual(unicode(self.paramListForDelRepo["name"], "utf-8"),
                         resDelObject[0]["name"])
        self.assertEqual(unicode(self.paramListForDelRepo["mode"], "utf-8"),
                         resDelObject[0]["mode"])

        # 再次查询
        resGetObject = HTTP_REQUEST.get_request(getUrl)
        self.assertEqual(404, resGetObject[1])
Exemple #5
0
    def test_getSensorByOriId(self):
        """
        验证过程:
        1. 添加组织,获得组织ID
        2. 为组织添加设备
        3. 通过组织ID查询设备
        4. 删除设备
        5. 删除组织
        """

        addOrgUrl = "http://%s:%s/api/orgs" % (CONFIG.DEEP_IP,
                                               CONFIG.DEEP_PORT)
        addOrgSource = {
            "OrgName": "add org for test sensor search by org.",
            "OrgLevel": 1,
            "SuperiorOrgId": "0000",
            "Comment": "just for test"
        }
        resAddOrgObject = HTTP_REQUEST.post_request(addOrgUrl, addOrgSource)
        orgIdStr = resAddOrgObject[0]["OrgId"]
        self.assertEqual(201, resAddOrgObject[1])

        addCloudSensorSource = {
            "OrgId": orgIdStr,
            "SensorId": self.sensorIdForSearchSensorByOrgId,
            "SensorName": self.sensorIdForSearchSensorByOrgId,
        }
        addSensorUrl = "http://%s:%s/api/cloudsources" % (CONFIG.DEEP_IP,
                                                          CONFIG.DEEP_PORT)
        resAddCloudSensor = HTTP_REQUEST.post_request(addSensorUrl,
                                                      addCloudSensorSource)
        self.assertEqual(201, resAddCloudSensor[1])

        getSensorByOrgUrl = "http://%s:%s/api/sources/orgs/%s" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT, orgIdStr)
        resGetSensorByOrgObject = HTTP_REQUEST.get_request(getSensorByOrgUrl)
        # 验证通过组织查询设备
        self.assertEqual(200, resGetSensorByOrgObject[1])
        self.assertEqual(1, len(resGetSensorByOrgObject[0]["list"]))

        # 删除设备
        delSensorUrl = "http://%s:%s/api/sources/%s" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT, resAddCloudSensor[0]["SensorId"])
        resDelSensorObject = HTTP_REQUEST.del_request(delSensorUrl)
        self.assertEqual(200, resDelSensorObject[1])

        # 删除组织
        delOrgUrl = "http://%s:%s/api/orgs/%s" % (CONFIG.DEEP_IP,
                                                  CONFIG.DEEP_PORT, orgIdStr)
        resDelOrgObject = HTTP_REQUEST.del_request(delOrgUrl)

        self.assertEqual(200, resDelOrgObject[1])
Exemple #6
0
    def test_putRepoById(self):
        '''
            id:唯一标识,应该是不支持修改
            mode:类型,不支持修改
            name:名称,可修改
            type:类别,目前只支持person,所以相当于不可修改
            count:比对库中对象的数量,不通过当前接口修改
            capacity:容量,目前不可修改
            so可修改的只有name
            验证过程:查询指定id的比对库,获得原名称,
                                修改名称
                                再次查询
                                当前名称不等于原名称,当前名称等于修改后名称
                                修改对比库名称为原名称
        '''

        repoIdStr = "7d7bc829-e1d4-4d7e-a02e-53e1a2c2e41e"
        newRepoSource = self.paramListForUpdateRepo
        getUrl = "http://%s:%s/api/repositories/%s" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT, repoIdStr)
        updateUrl = "http://%s:%s/api/repositories/%s" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT, repoIdStr)

        # 查询原名称
        getRepoByIdResObject = HTTP_REQUEST.get_request(getUrl)
        originalNameStr = getRepoByIdResObject[0]["name"]
        originalRepoSource = {
            "mode": "white_list",
            "name": originalNameStr,
            "type": "person",
            "capacity": 10006
        }

        # 调用接口修改名称
        updateRepoResObject = HTTP_REQUEST.put_request(updateUrl,
                                                       newRepoSource)
        # 验证返回码
        self.assertEqual(200, updateRepoResObject[1])
        # 验证名称已修改
        self.assertEqual(unicode(newRepoSource["name"], "utf-8"),
                         updateRepoResObject[0]["name"])
        self.assertNotEqual(originalNameStr, updateRepoResObject[0]["name"])

        # 调用修改接口将名称复原
        recoverRepoResObject = HTTP_REQUEST.put_request(
            updateUrl, originalRepoSource)
        self.assertEqual(200, recoverRepoResObject[1])
        self.assertEqual(originalNameStr, recoverRepoResObject[0]["name"])
Exemple #7
0
    def test_getOrgss(self):

        for i in self.paramListForGetOrgs:
            offsetStr, limitStr = i
            url = "http://%s:%s/api/orgs?offset=%s&limit=%s" % (
                CONFIG.DEEP_IP, CONFIG.DEEP_PORT, offsetStr, limitStr)

            resObject = HTTP_REQUEST.get_request(url)

            # 接口调用成功,验证返回码
            self.assertEqual(200, resObject[1])

            # print len(resObject[0]["list"])

            # 验证返回结果
            if limitStr == "*":
                pass
            else:
                self.assertTrue(len(resObject[0]["list"]) <= int(limitStr))
Exemple #8
0
    def test_addCloudSensor(self):
        """
        验证过程:
        添加设备,验证返回
        """
        addCloudSensorUrl = "http://%s:%s/api/cloudsources" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT)
        addCloudSensorSource = self.paramListForAddCloudSensor

        resAddCloudSensor = HTTP_REQUEST.post_request(addCloudSensorUrl,
                                                      addCloudSensorSource)

        # 验证
        self.assertEqual(201, resAddCloudSensor[1])
        self.assertEqual(1, resAddCloudSensor[0]["status"])

        # 通过ID查询设备
        getSensorUrl = "http://%s:%s/api/sources/%s" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT, addCloudSensorSource["SensorId"])

        resGetSensorByIdObject = HTTP_REQUEST.get_request(getSensorUrl)

        # 验证查询返回码
        self.assertEqual(200, resGetSensorByIdObject[1])
Exemple #9
0
def getSensorList():
    url = DATA.GET_SENSOR_LIST_URL
    resObject = HTTP_REQUEST.get_request(url)
    if resObject[1] == 200:
        # print resObject[0]["list"]
        return resObject
Exemple #10
0
    def test_addCivilByRepoId(self):
        """
            1. 增加比对库,获得比对库ID
            2. 通过比对库ID增加civil
            3. 验证
            4. 删除civil
            5. 删除比对库
        """

        # 添加比对库
        addRepoUrl = "http://%s:%s/api/repositories" % (CONFIG.DEEP_IP,
                                                        CONFIG.DEEP_PORT)
        addRepoSource = self.addRepoSource

        resAddRepoObject = HTTP_REQUEST.post_request(addRepoUrl, addRepoSource)

        repoIdStr = resAddRepoObject[0]["id"]
        print repoIdStr

        # 添加civil
        addCivilByRepoIdUrl = "http://%s:%s/api/repositories/%s/entities" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT, repoIdStr)
        civilAddByRepoIdSource = self.civilAddByRepoIdSource

        resAddCivilByRepoIdObject = HTTP_REQUEST.post_request(
            addCivilByRepoIdUrl, civilAddByRepoIdSource)
        print resAddCivilByRepoIdObject
        civilIdStr = resAddCivilByRepoIdObject[0]["id"]

        # 验证
        self.assertEqual(201, resAddCivilByRepoIdObject[1])

        # 查询
        getCivilByRepoIdAndCivilIdUrl = "http://%s:%s/api/repositories/%s/entities/%s" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT, repoIdStr, civilIdStr)
        resGetCivilByRepoIdObject = HTTP_REQUEST.get_request(
            getCivilByRepoIdAndCivilIdUrl)

        self.assertEqual(200, resGetCivilByRepoIdObject[1])
        self.assertEqual(civilAddByRepoIdSource["name"],
                         resGetCivilByRepoIdObject[0]["name"])

        # 删除civil
        delCivilByRepoIdAndCivilIdUrl = "http://%s:%s/api/repositories/%s/entities/%s" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT, repoIdStr, civilIdStr)

        delCivilByRepoIdAndCivilIdObject = HTTP_REQUEST.del_request(
            delCivilByRepoIdAndCivilIdUrl)

        self.assertEqual(200, delCivilByRepoIdAndCivilIdObject[1])
        self.assertEqual(civilAddByRepoIdSource["name"],
                         delCivilByRepoIdAndCivilIdObject[0]["name"])
        self.assertEqual(civilAddByRepoIdSource["id_no"],
                         delCivilByRepoIdAndCivilIdObject["id_no"])

        # 再次查询,验证结果为Not Found,表示删除成功
        newResGetCivilByRepoIdObject = getCivilByRepoIdAndCivilIdUrl = "http://%s:%s/api/repositories/%s/entities/%s" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT, repoIdStr, civilIdStr)

        self.assertEqual(200, newResGetCivilByRepoIdObject[1])
        self.assertEqual("Not Found", newResGetCivilByRepoIdObject[0]["error"])

        # 删除比对库
        delRepoUrl = "http://%s:%s/api/repositories/%s" % (
            CONFIG.DEEP_IP, CONFIG.DEEP_PORT, repoIdStr)
        resDelRepoObject = HTTP_REQUEST.del_request(delRepoUrl)

        self.assertEqual(200, resDelRepoObject[1])