def add_Json_Optional_Parameters(self, expected, httpRequest, suffix): ''' the method get the optional parameter of the suffix type json and check if it requested from the CBSD if it is it add them to the expected json ''' ###httpRequest = httpRequest[suffix][0] if (consts.REQUEST_NODE_NAME in str(suffix)): suffix = str(suffix).replace(consts.REQUEST_NODE_NAME, "") try: optional = JsonComparisonUtils.get_Node_Of_Json_Parsed( suffix + "Optional" + consts.SUFFIX_OF_JSON_FILE, suffix + "OptionalParams", self.confFile, self.dirPath)[0] except: raise IOError(suffix + " do not have optional params json") ### check if the key is optional means its not in the expected json but it is in the requests and its allowed in the protocol for key, value in optional.iteritems(): d = collections.OrderedDict() if key not in expected[0]: if key in httpRequest: if (not self.isThereMoreThenOneValueInside(value)): JsonComparisonUtils.ordered_dict_prepend( expected[0], key, value) else: ## key not exists at all self.dontCheckNode.append(key) for key2 in optional[key]: if key2 in httpRequest[key]: if ("eutraCarrierRssiRpt" in key2 or "rcvdPowerMeasReports" in key2): self.add_meas_report_config_json( httpRequest, suffix) if ("inquiredSpectrum" in key2): for var in optional[key][key2]: for varInHttp in httpRequest[key][ key2]: JsonComparisonUtils.are_same( var, varInHttp, False) else: if not isinstance(optional[key][key2], dict): result = JsonComparisonUtils._are_same( str(optional[key][key2]), str(httpRequest[key][key2]), False) if False in result: result = JsonComparisonUtils._are_same( optional[key][key2], httpRequest[key][key2], False) if False in result: raise Exception( "ERROR - there is an validation error between http request and the optional parameter json" ) else: if len(value) > 1: for key2, value2 in optional[key].iteritems(): if key2 not in expected[0][key]: if key2 in httpRequest[key]: JsonComparisonUtils.ordered_dict_prepend( expected[0][key], key2, value2) return expected
def add_reg_params_to_json(self,jsonExpected,httpRequest): for child in self.cbrsConfFile.childNodes[0].childNodes: #print child.tag, child.attrib if(child.firstChild!=None): if child.tagName == consts.REGISTRATION_SUFFIX_HTTP + "Params": for child2 in child.childNodes: if(child2.firstChild!=None): if len(child2.childNodes)==1: JsonComparisonUtils.ordered_dict_prepend(jsonExpected[0],child2.tagName , child2.firstChild.data) else: for childInChild in child2.childNodes: if(childInChild.firstChild!=None): self.dontCheckNode.append(child2.tagName) result = JsonComparisonUtils._are_same(childInChild.firstChild.data, httpRequest[child2.tagName][childInChild.tagName],False) if False in result: raise Exception("ERROR - there is an validation error between http request and the configuration file attribute ")
def add_reg_params_to_json(self, jsonExpected, httpRequest): for child in self.cbrsConfFile.childNodes[0].childNodes: #print child.tag, child.attrib if (child.firstChild != None): if child.tagName == consts.REGISTRATION_SUFFIX_HTTP + "Params": for child2 in child.childNodes: if (child2.firstChild != None): if len(child2.childNodes) == 1: JsonComparisonUtils.ordered_dict_prepend( jsonExpected[0], child2.tagName, child2.firstChild.data) else: for childInChild in child2.childNodes: if (childInChild.firstChild != None): self.dontCheckNode.append( child2.tagName) result = JsonComparisonUtils._are_same( childInChild.firstChild.data, httpRequest[child2.tagName][ childInChild.tagName], False) if False in result: raise Exception( "ERROR - there is an validation error between http request and the configuration file attribute " ) airInterfaceXml = minidom.parse( str(self.dirPath) + "\\cbrsPython\\model\\CBRSConf\\airInterfaceOptions.xml") for child in airInterfaceXml.childNodes[0].childNodes: if (child.firstChild != None): if child.tagName == consts.REGISTRATION_SUFFIX_HTTP + "Params": for child2 in child.childNodes: if (child2.firstChild != None): for child3 in child2.childNodes: if len(child3.childNodes) == 1: self.dontCheckNode.append(child2.tagName) result = JsonComparisonUtils._are_same( child3.firstChild.data, httpRequest[ child2.tagName][child3.tagName], False) if False in result: raise Exception( "ERROR - air interface object validation error " + "expected value for : " + str(child3.tagName) + " is : " + str(child3.firstChild.data) + " and the actual value is : " + httpRequest[child2.tagName][ child3.tagName]) groupingParamXml = minidom.parse( str(self.dirPath) + "\\cbrsPython\\model\\CBRSConf\\groupingParam.xml") if "groupingParam" in httpRequest: for child in groupingParamXml.childNodes[0].childNodes: if (child.firstChild != None): if child.tagName == "groupingParam": for child2 in child.childNodes: if len(child2.childNodes) == 1: result = JsonComparisonUtils._are_same( child2.firstChild.data, httpRequest[ child.tagName][0][child2.tagName], False) if False in result: raise Exception( "ERROR - grouping param object validation error " + "expected value for : " + str(child2.tagName) + " is : " + str(child2.firstChild.data) + " and the actual value is : " + httpRequest[child.tagName][0][ child2.tagName]) self.dontCheckNode.append("groupingParam")