Beispiel #1
0
    def CheckDataStoreKind(self, HostAndPort, Page, modelKind, modelGroup,
                           kindAllEntityAttributeDic):
        """ Download and Check All Entities of modelKind in a modelGroup.

        KindAllEntityAttributeDic provides reference data to check against"""
        # Create a query
        ACTION = 'Query'
        parameterDic = {}
        parameterDic['SearchType'] = 'ModelKindAll'
        parameterDic['ModelKind'] = modelKind
        parameterDic['ModelGroup'] = modelGroup
        QueryJSON = DataConversion.dict_to_json(parameterDic)
        print "JSON Query for %s:" % modelKind
        print QueryJSON

        # Send Query and Get Results
        res = HttpInterface.get_data(HostAndPort, Page, ACTION, QueryJSON)
        if res is None:
            print "Query for %s Model returned no results" % modelKind
            return 1

        # First check number of results from query
        ResultsDic = {}
        errorCount = 0
        returnedChangeSetDic = DataConversion.json_to_dict(res)
        print 'CheckDataStoreKind()- returnedChangeSetDic from Query for Model %s:' % modelKind
        print returnedChangeSetDic
        returnedClassEntityDic = returnedChangeSetDic['c']
        returnedEntityAttributeDic = returnedClassEntityDic[modelKind]

        numberEntitiesFound = len(returnedEntityAttributeDic)
        numberEntitiesExpected = len(kindAllEntityAttributeDic)
        ResultsDic['numberEntitiesFound'] = numberEntitiesFound
        ResultsDic['numberEntitiesExpected'] = numberEntitiesExpected
        if numberEntitiesFound < numberEntitiesExpected:
            print "Failed to retrieve all entities, number sent = %d, number received = %d" % \
                  (numberEntitiesExpected, numberEntitiesFound)

        # Compare each uploaded entity against entities downloaded

        for modelKeyName in kindAllEntityAttributeDic:
            if not modelKeyName in returnedEntityAttributeDic:
                print "modelKeyName %s not found in data downloaded" % modelKeyName
                errorCount += 1
            else:
                if not self.CompareAttributes(
                        kindAllEntityAttributeDic[modelKeyName],
                        returnedEntityAttributeDic[modelKeyName]):
                    errorCount += 1

        return errorCount
    def CheckDataStoreKind(self,HostAndPort,Page, modelKind ,modelGroup, kindAllEntityAttributeDic):
        """ Download and Check All Entities of modelKind in a modelGroup.

        KindAllEntityAttributeDic provides reference data to check against"""
        # Create a query
        ACTION = 'Query'
        parameterDic = {}
        parameterDic['SearchType'] = 'ModelKindAll'
        parameterDic['ModelKind'] = modelKind
        parameterDic['ModelGroup'] = modelGroup
        QueryJSON = DataConversion.dict_to_json(parameterDic)
        print "JSON Query for %s:" % modelKind
        print QueryJSON

        # Send Query and Get Results
        res = HttpInterface.get_data(HostAndPort,Page,ACTION,QueryJSON)
        if res is None:
            print "Query for %s Model returned no results" % modelKind
            return 1

        # First check number of results from query
        ResultsDic = {}
        errorCount = 0
        returnedChangeSetDic = DataConversion.json_to_dict(res)
        print 'CheckDataStoreKind()- returnedChangeSetDic from Query for Model %s:' % modelKind
        print returnedChangeSetDic
        returnedClassEntityDic = returnedChangeSetDic['c']
        returnedEntityAttributeDic = returnedClassEntityDic[modelKind]

        numberEntitiesFound = len(returnedEntityAttributeDic)
        numberEntitiesExpected = len(kindAllEntityAttributeDic)
        ResultsDic['numberEntitiesFound'] = numberEntitiesFound
        ResultsDic['numberEntitiesExpected'] = numberEntitiesExpected
        if numberEntitiesFound < numberEntitiesExpected:
            print "Failed to retrieve all entities, number sent = %d, number received = %d" % \
                  (numberEntitiesExpected, numberEntitiesFound)

        # Compare each uploaded entity against entities downloaded

        for modelKeyName in kindAllEntityAttributeDic:
            if not modelKeyName in returnedEntityAttributeDic:
                print "modelKeyName %s not found in data downloaded" % modelKeyName
                errorCount += 1
            else:
                if not self.CompareAttributes(kindAllEntityAttributeDic[modelKeyName],
                              returnedEntityAttributeDic[modelKeyName]):
                    errorCount += 1

        return errorCount
    def RunLocationByProximityQuery(self):
        """Runs a query for locations within random miles from random center location

         Returns a location Entity-Attribute dictionary
         """
        self.CenterPoint = self.randomGenerator.CreateRandomLattitudeLongitude(
        )
        self.SearchDistanceMiles = self.randomGenerator.CreateRandomNumber(
            self.minDistanceMiles, self.maxDistanceMiles)
        self.SearchDistanceMeters = GeoConversion.ConvertMilesToMeters(
            self.SearchDistanceMiles)
        QueryParameterDic = {}
        QueryParameterDic['SearchType'] = 'LocationByProximity'
        QueryParameterDic['MaxResults'] = self.maxSearchResults
        QueryParameterDic[
            'MaxDistanceMeters'] = GeoConversion.ConvertMilesToMeters(
                self.SearchDistanceMiles)
        QueryParameterDic['CenterPt'] = self.CenterPoint
        QueryParameterDic['HasShopsOnly'] = 'True'
        QueryParameterDic['FilterByTrueDistance'] = 'True'
        # Get a list of GpGridCells to search
        gpSearch = GpSearch()
        gpSearch.MaxSearchCellCount = self.MaxSearchCellCount
        centerGpPoint = GpPoint(self.CenterPoint[0], self.CenterPoint[1])
        gpSearch.ComputeSearchListForMetersProximity(centerGpPoint,
                                                     self.SearchDistanceMeters)
        self.FinalSearchResolution = gpSearch.FinalSearchResolution
        self.SearchGpGridCells = gpSearch.SearchCellList

        QueryParameterDic['SearchGridCells'] = self.SearchGpGridCells

        # Convert Query to JSON
        QueryJSON = DataConversion.dict_to_json(QueryParameterDic)
        print 'QueryJSON ='
        print QueryJSON
        resultsJSON = HttpInterface.get_data(self.HostAndPort, self.HttpPage,
                                             self.HttpAction, QueryJSON)
        if resultsJSON == "":
            # No entities found in search
            locationEntityAttributeDic = {}
        elif resultsJSON.startswith('Not found error'):
            locationEntityAttributeDic = {}
        else:
            results = DataConversion.json_to_dict(resultsJSON)
            locationClassEntityDic = results['c']
            locationEntityAttributeDic = locationClassEntityDic['Location']
        return locationEntityAttributeDic
 def ToJSON(self):
     """ Convert the ChangeSet to JSON format"""
     try:
         json = DataConversion.dict_to_json(self.ChangeSetDic)
     except:
         logging.error('ChangeSet.ToJSON() Threw Exception %s',sys.exc_info())
         json = ""
     return json
    def RunLocationByProximityQuery(self):
        """Runs a query for locations within random miles from random center location

         Returns a location Entity-Attribute dictionary
         """
        self.CenterPoint = self.randomGenerator.CreateRandomLattitudeLongitude()
        self.SearchDistanceMiles = self.randomGenerator.CreateRandomNumber(self.minDistanceMiles,self.maxDistanceMiles)
        self.SearchDistanceMeters =  GeoConversion.ConvertMilesToMeters(self.SearchDistanceMiles)
        QueryParameterDic = {}
        QueryParameterDic['SearchType'] ='LocationByProximity'
        QueryParameterDic['MaxResults'] = self.maxSearchResults
        QueryParameterDic['MaxDistanceMeters'] = GeoConversion.ConvertMilesToMeters(self.SearchDistanceMiles)
        QueryParameterDic['CenterPt'] = self.CenterPoint
        QueryParameterDic['HasShopsOnly'] = 'True'
        QueryParameterDic['FilterByTrueDistance'] = 'True'
        # Get a list of GpGridCells to search
        gpSearch = GpSearch()
        gpSearch.MaxSearchCellCount = self.MaxSearchCellCount
        centerGpPoint = GpPoint(self.CenterPoint[0],self.CenterPoint[1])
        gpSearch.ComputeSearchListForMetersProximity(centerGpPoint,self.SearchDistanceMeters)
        self.FinalSearchResolution = gpSearch.FinalSearchResolution
        self.SearchGpGridCells = gpSearch.SearchCellList
       
        QueryParameterDic['SearchGridCells'] = self.SearchGpGridCells

        # Convert Query to JSON
        QueryJSON = DataConversion.dict_to_json(QueryParameterDic)
        print 'QueryJSON ='
        print QueryJSON
        resultsJSON = HttpInterface.get_data(self.HostAndPort,self.HttpPage,self.HttpAction,QueryJSON)
        if resultsJSON == "":
            # No entities found in search
            locationEntityAttributeDic = {}
        elif resultsJSON.startswith('Not found error'):
            locationEntityAttributeDic = {}
        else:
            results = DataConversion.json_to_dict(resultsJSON)
            locationClassEntityDic = results['c']
            locationEntityAttributeDic = locationClassEntityDic['Location']
        return locationEntityAttributeDic
    def RunSavedQuery(self,QueryParameterDic):
        """Runs a query for locations within random miles from random center location

         Returns a location Entity-Attribute dictionary
         """

        # Convert Query to JSON
        QueryJSON = DataConversion.dict_to_json(QueryParameterDic)
        self.logger.info('QueryJSON =')
        self.logger.info('%s',QueryJSON)
        
        resultsJSON = HttpInterface.get_data(self.HostAndPort,self.HttpPage,self.HttpAction,QueryJSON)
        if resultsJSON == "":
            # No entities found in search
            locationEntityAttributeDic = {}
        elif resultsJSON.startswith('Not found error'):
            locationEntityAttributeDic = {}
        else:
            results = DataConversion.json_to_dict(resultsJSON)
            locationClassEntityDic = results['c']
            self.queryStats = results['stats']
            locationEntityAttributeDic = locationClassEntityDic['Location']
        return locationEntityAttributeDic
    def RunSavedQuery(self, QueryParameterDic):
        """Runs a query for locations within random miles from random center location

         Returns a location Entity-Attribute dictionary
         """

        # Convert Query to JSON
        QueryJSON = DataConversion.dict_to_json(QueryParameterDic)
        self.logger.info('QueryJSON =')
        self.logger.info('%s', QueryJSON)

        resultsJSON = HttpInterface.get_data(self.HostAndPort, self.HttpPage,
                                             self.HttpAction, QueryJSON)
        if resultsJSON == "":
            # No entities found in search
            locationEntityAttributeDic = {}
        elif resultsJSON.startswith('Not found error'):
            locationEntityAttributeDic = {}
        else:
            results = DataConversion.json_to_dict(resultsJSON)
            locationClassEntityDic = results['c']
            self.queryStats = results['stats']
            locationEntityAttributeDic = locationClassEntityDic['Location']
        return locationEntityAttributeDic
Beispiel #8
0
    def PrintRunResultsJSON(self):
        self.RunResults["AllSearchResults"] = self.AllSearchResultsDic

        RunResultsJSON = DataConversion.dict_to_json(self.RunResults)
        print RunResultsJSON