예제 #1
0
    def compare_Json_Req(self,
                         httpRequest,
                         jsonExpected,
                         suffix,
                         keysFromJson=None,
                         printIfFalse=True):
        ''' 
        the method will get the request json file name from the client request and will get from the two repo
        off the client and the server the json expected and the real json sent from the client 
        '''
        self.dontCheckNode = []

        try:
            jsonExpectedObj = JsonComparisonUtils.get_Node_Of_Json_Parsed(
                jsonExpected, suffix, self.confFile, self.dirPath)
        except Exception as e:
            raise IOError(e.message)
        if (consts.REGISTRATION_SUFFIX_HTTP +
                consts.REQUEST_NODE_NAME == suffix):
            self.add_reg_params_to_json(jsonExpectedObj, httpRequest)
        else:
            JsonComparisonUtils.ordered_dict_prepend(jsonExpectedObj[0],
                                                     "cbsdId",
                                                     str(self.cbsdId))
            if ((consts.HEART_BEAT_SUFFIX_HTTP + consts.REQUEST_NODE_NAME
                 == suffix) or (consts.RELINQUISHMENT_SUFFIX_HTTP +
                                consts.REQUEST_NODE_NAME == suffix)):
                JsonComparisonUtils.ordered_dict_prepend(
                    jsonExpectedObj[0], "grantId", str(self.grantId))
        try:
            jsonExpectedObj = self.add_Json_Optional_Parameters(
                jsonExpectedObj, httpRequest, suffix)
        except Exception as E:
            raise IOError("ERROR - loading optional parameters not succeeded" +
                          str(E))

        self.add_Actual_Params_To_Json_If_Not_Exists(jsonExpectedObj[0],
                                                     httpRequest)

        if (bool(
                self.get_Attribute_Value_From_Json(
                    jsonExpected, "measReportRequested")) == True):
            self.measurement_Report_Decision(httpRequest, jsonExpectedObj,
                                             suffix)

        if (bool(
                self.get_Attribute_Value_From_Json(jsonExpected,
                                                   "fullBandReport")) == True):
            self.check_Fullband_Measurement_Report(httpRequest)

        x = JsonComparisonUtils.are_same(jsonExpectedObj[0], httpRequest,
                                         False, self.dontCheckNode)
        if (False in x and printIfFalse == True):
            self.loggerHandler.print_to_Logs_Files(x, True)
        try:
            assert True in x
        except:
            raise IOError(consts.ERROR_VALIDATION_MESSAGE + "in the json : " +
                          jsonExpected)
        return x
예제 #2
0
 def compare_Json_Req(self,httpRequest,jsonExpected,suffix):
     
     ''' 
     the method will get the request json file name from the client request and will get from the two repo
     off the client and the server the json expected and the real json sent from the client 
     '''
     try:
         jsonExpectedObj = JsonComparisonUtils.get_Node_Of_Json_Parsed(jsonExpected,suffix,self.confFile,self.dirPath)
         jsonExpectedObj = self.add_Json_Optional_Parameters(jsonExpectedObj,httpRequest,suffix)
     except Exception as e:
         raise IOError(e.message)  
     if(consts.REGISTRATION_SUFFIX_HTTP in suffix):
         # example for insert to request defaults params from specific config file
         JsonComparisonUtils.ordered_dict_prepend(jsonExpectedObj[0],"fccId" , self.cbrsConfFile.getElementsByTagName("fccId")[0].firstChild.data)
         JsonComparisonUtils.ordered_dict_prepend(jsonExpectedObj[0],"userId" , self.cbrsConfFile.getElementsByTagName("userId")[0].firstChild.data)
     '''if(consts.HEART_BEAT_SUFFIX_HTTP in suffix):
         ignoreKeys = []
         ignoreKeys.append("operationState")
         x = JsonComparisonUtils.are_same(jsonExpectedObj[0],httpRequest,False,ignoreKeys)'''
     '''else:'''
     x = JsonComparisonUtils.are_same(jsonExpectedObj[0],httpRequest)
     if(False in x):
         self.loggerHandler.print_to_Logs_Files(x,True)
     try:
         assert True in x
     except:
         raise IOError(consts.ERROR_VALIDATION_MESSAGE + "in the json : " + jsonExpected)
     return x
예제 #3
0
 def add_Actual_Params_To_Json_If_Not_Exists(self, expectedObj,
                                             httpRequest):
     for key in httpRequest:
         if (key not in expectedObj):
             if (key not in self.dontCheckNode):
                 JsonComparisonUtils.ordered_dict_prepend(
                     expectedObj, key, None)
예제 #4
0
    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. json schema is used for the data validation.
        '''
        current_path = str(self.dirPath)
        configurable_file_path = os.path.join(current_path, '',
                                              'Configuration',
                                              'ObjectListConfig')
        later_Defined_params_file = open(
            os.path.join(str(configurable_file_path),
                         "laterDefindedOptional.json"))

        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]
            optional_laterDefined = json.load(later_Defined_params_file,
                                              object_pairs_hook=OrderedDict)

        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 httpRequest.iteritems():
            if key not in expected[0]:
                if key in optional_laterDefined["properties"]:
                    try:
                        jsonschema.validate(OrderedDict([(key, value)]),
                                            optional_laterDefined)
                        self.dontCheckNode.append(key)
                    except jsonschema.ValidationError as e:
                        raise Exception(str(e))

                elif key in optional["properties"]:
                    try:
                        jsonschema.validate(OrderedDict([(key, value)]),
                                            optional)
                        self.dontCheckNode.append(key)
                    except jsonschema.ValidationError as e:
                        raise Exception(str(e))

                else:
                    raise Exception(
                        "- some parameters in http request are not defined by Specifications or bad names"
                    )
            else:
                # where value is a dictionary of nested (key, value) pairs, such as installationParam in Registration Request
                if (isinstance(value, dict)):
                    if len(value) > 1:
                        for key2, value2 in httpRequest[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
예제 #5
0
 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
예제 #6
0
 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 ")
예제 #7
0
 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() :
         if key not in expected[0]:
             if key in httpRequest:
                 JsonComparisonUtils.ordered_dict_prepend(expected[0], key, value)                    
     return expected
     
     
     
예제 #8
0
    def process_response(self, typeOfCalling):
        jsonAfterParse = self.parse_Json_To_Dic_By_File_Name(
            self.get_Expected_Json_File_Name(), consts.RESPONSE_NODE_NAME,
            self.enviormentConfFile)
        if (typeOfCalling == consts.GRANT_SUFFIX_HTTP):
            result = self.get_Expire_Time()
            jsonComparer.ordered_dict_prepend(
                jsonAfterParse[typeOfCalling +
                               consts.RESPONSE_NODE_NAME.title()][0],
                "grantExpireTime", result)
        elif (typeOfCalling == consts.HEART_BEAT_SUFFIX_HTTP):
            result = self.get_Expire_Time()
            jsonComparer.ordered_dict_prepend(
                jsonAfterParse[typeOfCalling +
                               consts.RESPONSE_NODE_NAME.title()][0],
                "transmitExpireTime", result)
        if (len(self.jsonSteps) == self.numberOfStep + 1):
            self.questAnswerPartOfJson = self.parse_Json_To_Dic_By_File_Name(
                self.get_Expected_Json_File_Name(), consts.QUESTION_NODE_NAME,
                self.enviormentConfFile)
            self.isLastStepInCSV = True

        self.numberOfStep += 1
        return jsonAfterParse
예제 #9
0
 def change_Value_Of_Param_In_Dict(self, dictName, attrToChange, value):
     if (attrToChange in dictName):
         del dictName[attrToChange]
     jsonComparer.ordered_dict_prepend(dictName, attrToChange, value)
예제 #10
0
 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")