Beispiel #1
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)
Beispiel #2
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
Beispiel #3
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")
Beispiel #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 
     '''
     ###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 #5
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 ")
Beispiel #6
0
 def parse_Json_To_Dic_By_File_Name(self, jsonFileName, nodeName, confFile):
     try:
         return jsonComparer.get_Node_Of_Json_Parsed(
             jsonFileName, nodeName, confFile, self.dirPath)
     except Exception as e:
         if e.message == "node not exists":
             return consts.SUFFIX_NOT_EXISTS_IN_EXPECTED_JSON_FILE
Beispiel #7
0
 def get_Attribute_Value_From_Json(self,jsonExpected,keyToVerify):
     '''
     the method get key check if it exists in the expected json and return the value as a string      
     '''
     if(self.is_Json_File_Contains_Key(jsonExpected, keyToVerify)):
         return JsonComparisonUtils.get_Node_Of_Json_Parsed(jsonExpected,keyToVerify,self.confFile,self.dirPath)
     return False
Beispiel #8
0
 def get_Duration_Time_From_Grant_Json(self,jsonExpected):
     try:
         responsePart = JsonComparisonUtils.get_Node_Of_Json_Parsed(jsonExpected,consts.RESPONSE_NODE_NAME,self.confFile,self.dirPath)
     except Exception as e:
         if e.message == "node not exists":
             return consts.SUFFIX_NOT_EXISTS_IN_EXPECTED_JSON_FILE
     return responsePart[consts.GRANT_SUFFIX_HTTP+consts.RESPONSE_NODE_NAME.title()][0]['heartbeatInterval']
Beispiel #9
0
    def set_Current_Json_Steps(self, testDefinition, confFile, dirPath):
        cbsdFoundInJsons = False
        for jsonCol in testDefinition.jsonNamesOfSteps:
            xmlFileLinked = jsonComparer.get_Node_Of_Json_Parsed(
                jsonCol[0], "xmlFilelLinked", confFile, dirPath)
            xmlPath = str(
                self.dirPath
            ) + "\\Configuration\\CBSDconfig\\" + xmlFileLinked + ".xml"
            if os.path.exists(xmlPath) == False:
                raise IOError("ERROR - missing cbrs conf file of the CBSD : " +
                              self.cbsdSerialNumber)
            self.cbrsConfFile = minidom.parse(xmlPath)

            if str(
                    self.cbrsConfFile.getElementsByTagName("cbsdSerialNumber")
                [0].firstChild.data).replace('"', "") == self.cbsdSerialNumber:
                cbsdFoundInJsons = True
                self.jsonSteps = jsonCol
                self.assertion = Assertion(self.enviormentConfFile, dirPath,
                                           self.loggerHandler,
                                           self.cbrsConfFile)

        if (not cbsdFoundInJsons):
            raise IOError(
                "ERROR - missing registration json in one of the csv columns with the cbsd serial number "
                + self.cbsdSerialNumber)
        try:
            grantExpireTime = int(
                self.cbrsConfFile.getElementsByTagName(
                    "secondsToAddForGrantExpireTime")[0].firstChild.data)
            transmitTime = int(
                self.cbrsConfFile.getElementsByTagName(
                    "secondsToAddForTransmitExpireTime")[0].firstChild.data)
        except Exception:
            raise IOError(
                "ERROR - for the cbrs with the serial number : " +
                self.cbsdSerialNumber + " the conf file" +
                " must include the parameters : secondsToAddForGrantExpireTime,secondsToAddForTransmitExpireTime"
            )
        if (grantExpireTime < transmitTime):
            raise IOError(
                "ERROR - for the cbrs with the serial number : " +
                self.cbsdSerialNumber +
                " the transmit time is bigger than the grant expire time")

        for availableInqueryStep in self.jsonSteps:
            currentJson = self.parse_Json_To_Dic_By_File_Name(
                availableInqueryStep, consts.SPECTRUM_INQUIERY_SUFFIX_HTTP +
                consts.REQUEST_NODE_NAME, self.enviormentConfFile)
            if currentJson != None:
                if bool(
                        self.assertion.get_Attribute_Value_From_Json(
                            availableInqueryStep, "appearAlways")) == True:
                    self.spectrumInquieryAvailableRepeatsEveryWhereRequest.append(
                        availableInqueryStep)
        for step in self.spectrumInquieryAvailableRepeatsEveryWhereRequest:
            self.jsonSteps.remove(step)
Beispiel #10
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
     
     
     
Beispiel #11
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 #12
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 #13
0
    def Check_Request_Parameters(self, httpRequest, typeOfCalling):
        '''
        the method get the requested parameters checked to see if they are valid, jsonschema is used for the data validation.
        '''
        suffix = typeOfCalling + consts.REQUEST_NODE_NAME
        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.enviormentConfFile,
                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 in optional_laterDefined["properties"]:
                try:
                    jsonschema.validate(OrderedDict([(key, value)]),
                                        optional_laterDefined)
                except jsonschema.ValidationError as e:
                    raise Exception(str(e))
                    self.validationRequestDataError = True

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

            else:
                raise Exception(
                    "- some parameters in http request are not defined by Specifications or bad names"
                )
                self.validationRequestDataError = True
Beispiel #14
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
Beispiel #15
0
 def set_Current_Json_Steps(self, testDefinition, confFile, dirPath):
     for jsonCol in testDefinition.jsonNamesOfSteps:
         if jsonComparer.get_Node_Of_Json_Parsed(
                 jsonCol[0], "registrationRequest", confFile,
                 dirPath)[0]["cbsdSerialNumber"] == self.cbsdSerialNumber:
             self.jsonSteps = jsonCol
             try:
                 self.cbrsConfFile = minidom.parse(
                     str(self.dirPath) + "\\cbrsPython\\model\\CBRSConf\\" +
                     self.cbsdSerialNumber + ".xml")
             except:
                 raise IOError(
                     "ERROR - missing cbrs conf file of the CBSD : " +
                     self.cbsdSerialNumber)
             self.assertion = Assertion(self.enviormentConfFile, dirPath,
                                        self.loggerHandler,
                                        self.cbrsConfFile)
Beispiel #16
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)
Beispiel #17
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")
Beispiel #18
0
 def is_Json_File_Contains_Key(self, jsonExpected,keyToVerify):
     return JsonComparisonUtils.Is_Json_contains_key(jsonExpected, keyToVerify, self.confFile, self.dirPath)