示例#1
0
文件: utils_t.py 项目: ktf/DAS
    def test_parse_filters(self):
        """Test parse_filters function"""
        filters = {'grep': ['monitor', 'file.size=1']}
        spec    = {'monitor': {'$exists':True}, 'file.size': 1}
        query   = {'spec': spec, 'filters': filters}
        expect  = {'file.size': 1}
        result  = parse_filters(query)
        self.assertEqual(expect, result)

        filters = ['file.size>1', 'file.size=1']
        query.update({'filters': filters})
        self.assertRaises(Exception, parse_filters, query)

        filters = {'grep': ['file.size>1', 'file.size<=10']}
        expect  = {'file.size': {'$gt':1, '$lte':10}}
        query.update({'filters': filters})
        result  = parse_filters(query)
        self.assertEqual(expect, result)
示例#2
0
文件: utils_t.py 项目: perrozzi/DAS
    def test_parse_filters(self):
        """Test parse_filters function"""
        filters = {'grep': ['monitor', 'file.size=1']}
        spec = {'monitor': {'$exists': True}, 'file.size': 1}
        query = {'spec': spec, 'filters': filters}
        expect = {'file.size': 1}
        result = parse_filters(query)
        self.assertEqual(expect, result)

        filters = ['file.size>1', 'file.size=1']
        query.update({'filters': filters})
        self.assertRaises(Exception, parse_filters, query)

        filters = {'grep': ['file.size>1', 'file.size<=10']}
        expect = {'file.size': {'$gt': 1, '$lte': 10}}
        query.update({'filters': filters})
        result = parse_filters(query)
        self.assertEqual(expect, result)
示例#3
0
 def get_fields(self, dasquery):
     "Prepare fields to extract from MongoDB"
     fields     = dasquery.mongo_query.get('fields', None)
     if  fields == ['records']:
         fields = None # look-up all records
     filters    = dasquery.filters
     cond       = {}
     if  filters:
         new_fields = []
         for dasfilter in filters:
             if  dasfilter == 'unique':
                 continue
             if  dasfilter not in fields and \
                 dasfilter not in new_fields:
                 if  dasfilter.find('=') == -1 and dasfilter.find('<') == -1\
                 and dasfilter.find('>') == -1:
                     new_fields.append(dasfilter)
                 else:
                     cond = parse_filters(dasquery.mongo_query)
         if  not new_fields and fields:
             new_fields = list(fields)
         return new_fields, cond
     return fields, cond
示例#4
0
 def get_fields(self, dasquery):
     "Prepare fields to extract from MongoDB"
     fields = dasquery.mongo_query.get('fields', [])
     if fields and 'records' in fields:
         fields = None  # look-up all records
     filters = dasquery.filters
     cond = {}
     if filters:
         new_fields = []
         for dasfilter in filters:
             if dasfilter == 'unique':
                 continue
             if  fields and dasfilter not in fields and \
                 dasfilter not in new_fields:
                 if  dasfilter.find('=') == -1 and dasfilter.find('<') == -1\
                 and dasfilter.find('>') == -1:
                     new_fields.append(dasfilter)
                 else:
                     cond = parse_filters(dasquery.mongo_query)
         if not new_fields and fields:
             new_fields = list(fields)
         return new_fields, cond
     return fields, cond