Beispiel #1
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
Beispiel #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
Beispiel #3
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
Beispiel #4
0
 def add_meas_report_config_json(self,httpRequest,suffix):
     if("measReport" in httpRequest):
         try:
             optional = JsonComparisonUtils.get_Node_Of_Json_Parsed("measReportOptional"+consts.SUFFIX_OF_JSON_FILE,"measReport",self.confFile,self.dirPath)[0]
         except :
             raise IOError("ERROR - do not have meas report eutra json") 
         for varInHttp in httpRequest["measReport"]["rcvdPowerMeasReports"]:
             result = JsonComparisonUtils.are_same(optional["rcvdPowerMeasReports"][0], varInHttp,False)
             if False in result:
                 raise IOError("ERROR - the meas report from the http is not allowed ")
         self.dontCheckNode.append("measReport")