def test_addRepositories(self): ''' 验证过程:添加对比库,验证返回结果,删除新增的对比库 ''' url = "http://%s:%s/api/repositories" % (CONFIG.DEEP_IP, CONFIG.DEEP_PORT) source = self.paramListForAddRepo resObject = HTTP_REQUEST.post_request(url, source) repoIdStr = resObject[0]['id'] # 验证返回码 self.assertEqual(201, resObject[1]) # 验证返回结果 self.assertEqual(self.paramListForAddRepo["mode"], resObject[0]["mode"]) self.assertEqual(self.paramListForAddRepo["type"], resObject[0]["type"]) # print self.paramListForAddRepo["name"] # print resObject[0]["name"] self.assertEqual(unicode(self.paramListForAddRepo["name"], "utf-8"), resObject[0]["name"]) # 删除新增的对比库 delUrl = "http://%s:%s/api/repositories/%s" % ( CONFIG.DEEP_IP, CONFIG.DEEP_PORT, repoIdStr) HTTP_REQUEST.del_request(delUrl)
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])
def delCivilByRepoIDAndCivilID(repoID, civilID): url = "http://%s:%s/api/repositories/%s/entities/%s" % (DATA.DEEPCLOUD_IP, DATA.DEEPCLOUD_PORT, repoID, civilID) resDelCivilByRepoIDAndCivilIDObject = HTTP_REQUEST.del_request(url) if resDelCivilByRepoIDAndCivilIDObject[1] == 200: return resDelCivilByRepoIDAndCivilIDObject else: raise MYEXCEPTION.MyException("Delete civil by repoID and civilID error.")
def test_updateOrg(self): """ 1. 增加组织 2. 修改组织名称 3. 删除组织 """ updateOrgSource = self.parameterListForUpdateOrg addOrgUrl = "http://%s:%s/api/orgs" % (CONFIG.DEEP_IP, CONFIG.DEEP_PORT) resAddOrgObject = HTTP_REQUEST.post_request(addOrgUrl, updateOrgSource) orgIdStr = resAddOrgObject[0]["OrgId"] updateOrgUrl = "http://%s:%s/api/orgs/%s" % ( CONFIG.DEEP_IP, CONFIG.DEEP_PORT, orgIdStr) updateOrgSource = resAddOrgObject[0] updateOrgSource["OrgName"] = "update org test updated." resUpdateOrgObject = HTTP_REQUEST.put_request(updateOrgUrl, updateOrgSource) self.assertEqual(200, resUpdateOrgObject[1]) self.assertEqual("update org test updated.", resUpdateOrgObject[0]["OrgName"]) 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])
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])
def delRuleById(ruleId): url = "http://%s:%s/api/monitors/%s" % (DATA.DEEPCLOUD_IP, DATA.DEEPCLOUD_PORT, ruleId) resDelRuleByIdObject = HTTP_REQUEST.del_request(url) if resDelRuleByIdObject[1] != 200: # 此处按照文档描述,应该是204 raise MYEXCEPTION.MyException( "Del rule by id error. errorCode: %s, errorMessage: %s" % (resDelRuleByIdObject[0], resDelRuleByIdObject[1])) else: return resDelRuleByIdObject
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])
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])