Пример #1
0
 def testWildcardDataSearch(self):
     schema = {
         'type': 'object',
         'attributes': {
             'name': {
                 'type': 'string'
             },
             'object': {
                 'type': 'object',
                 'attributes': {
                     'nestedName': {
                         'type': 'string'
                     }
                 }
             }
         }
     }
     data = {'name': 'Oli', 'object': {'nestedName': 'Some nested Name'}}
     searchResult = Search(data,
                           schema,
                           dataQuery={'root.*': 'Some nested Name'})
     self.assertEquals(data, searchResult)
     searchResult = Search(
         data,
         schema,
         dataQuery={'root.*\\.nestedName': 'Some nested Name'})
     self.assertEquals(data, searchResult)
Пример #2
0
 def testSimpleStringDataSearch(self):
     schema = {'type': 'string'}
     data = 'Hello world'
     searchResult = Search(data, schema, dataQuery={'root': 'Hello world'})
     self.assertEquals(data, searchResult)
     searchResult = Search(data,
                           schema,
                           dataQuery={'root': 'this will not be found'})
     self.assertNotEqual(data, searchResult)
Пример #3
0
 def testSimpleFloatDataSearch(self):
     schema = {'type': 'float'}
     data = 5.0
     searchResult = Search(data, schema, dataQuery={'root': 5.0})
     self.assertEquals(data, searchResult)
     searchResult = Search(data,
                           schema,
                           dataQuery={'root': 'this will not be found'})
     self.assertNotEqual(data, searchResult)
Пример #4
0
 def testSimpleStringIgnoreCaseDataSearch(self):
     schema = {'type': 'string'}
     data = 'Hello world'
     searchResult = Search(data,
                           schema,
                           dataQuery={'root': 'hello wORLd'},
                           ignoreCase=True)
     self.assertEquals(data, searchResult)
     searchResult = Search(data,
                           schema,
                           dataQuery={'root': 'this will not be found'},
                           ignoreCase=True)
     self.assertEqual(0, len(searchResult))
Пример #5
0
 def testComplexObjectWithDictionaryDataSearch(self):
     schema = {
         'type': 'object',
         'attributes': {
             'name': {
                 'type': 'string'
             },
             'object': {
                 'type': 'object',
                 'attributes': {
                     'nestedName': {
                         'type': 'string'
                     },
                     'somedict': {
                         'type': 'dict',
                         'keyTypes': {
                             'type': 'int'
                         },
                         'valueTypes': {
                             'type': 'string'
                         }
                     }
                 }
             }
         }
     }
     data = {
         'name': 'Oli',
         'object': {
             'nestedName': 'Some nested Name',
             'somedict': {
                 10: 'fle',
                 100: 'flu',
                 1000: 'fleeee'
             }
         }
     }
     searchResult = Search(
         data,
         schema,
         dataQuery={'root\\.object\\.somedict\\[100\\]': 'flu'})
     self.assertEqual(data, searchResult)
     searchResult = Search(data,
                           schema,
                           dataQuery={
                               'root\\.object\\.somedict\\[100000000\\]':
                               'flasdfasdfasdfu'
                           })
     self.assertNotEqual(data, searchResult)
Пример #6
0
 def testSimpleSchemaSearch(self):
     schema = {'type': 'int'}
     data = 5
     searchResult = Search(data,
                           schema,
                           schemaQuery={'root': {
                               'type': 'int'
                           }})
     self.assertEquals(data, searchResult)
     searchResult = Search(data,
                           schema,
                           schemaQuery={'root': {
                               'type': 'string'
                           }})
     self.assertNotEqual(data, searchResult)
Пример #7
0
 def testSimpleStringRegularExpressionDataSearch(self):
     schema = {'type': 'string'}
     data = 'Hello world'
     searchResult = Search(data,
                           schema,
                           dataQuery={'root': 'Hello .*'},
                           ignoreCase=True,
                           regularExpression=True)
     self.assertEquals(data, searchResult)
     searchResult = Search(data,
                           schema,
                           dataQuery={'root': 'Hallo .*'},
                           ignoreCase=True,
                           regularExpression=True)
     self.assertEqual(0, len(searchResult))
Пример #8
0
 def testSimpleIntRegularExpressionDataSearch(self):
     schema = {'type': 'int'}
     data = 100
     searchResult = Search(data,
                           schema,
                           dataQuery={'root': '10.*'},
                           ignoreCase=True,
                           regularExpression=True)
     self.assertNotEqual(0, searchResult)
Пример #9
0
 def testObjectSchemaSearch(self):
     schema = {'type': 'object', 'attributes': {'name': {'type': 'string'}}}
     data = {'name': 'Oli'}
     searchResult = Search(data,
                           schema,
                           schemaQuery={'root.name': {
                               'type': 'string'
                           }})
     self.assertEqual(1, len(searchResult))
     self.assertEquals(data, searchResult)
Пример #10
0
 def testComplexObjectWithListDataSearch(self):
     schema = {
         'type': 'object',
         'attributes': {
             'name': {
                 'type': 'string'
             },
             'object': {
                 'type': 'object',
                 'attributes': {
                     'nestedName': {
                         'type': 'string'
                     },
                     'somelist': {
                         'type': 'list',
                         'itemTypes': {
                             'type': 'string'
                         }
                     }
                 }
             }
         }
     }
     data = {
         'name': 'Oli',
         'object': {
             'nestedName': 'Some nested Name',
             'somelist': ['fle', 'flu', 'fleeee']
         }
     }
     searchResult = Search(data,
                           schema,
                           dataQuery={'root\\.object\\.somelist': 'flu'})
     self.assertEquals(data, searchResult)
     searchResult = Search(
         data,
         schema,
         dataQuery={'root\\.object\\.somelist': 'flasdfasdfasdfu'})
     self.assertEqual(0, len(searchResult))
Пример #11
0
 def testDictDataSearch(self):
     schema = {
         'type': 'dict',
         'keyTypes': {
             'type': 'int'
         },
         'valueTypes': {
             'type': 'int'
         }
     }
     data = {1: 10, 2: 20, 3: 25}
     searchResult = Search(data, schema, dataQuery={'root\\[2\\]': 20})
     self.assertEqual(1, len(searchResult))
     self.assertEquals({2: 20}, searchResult)
Пример #12
0
 def testListDataSearch(self):
     schema = {'type': 'list', 'itemTypes': {'type': 'string'}}
     data = ['a', 'ble', 'flu']
     searchResult = Search(data, schema, dataQuery={'root\\[.*\\]': 'ble'})
     self.assertEqual(1, len(searchResult))
     self.assertEquals(data[1], searchResult[0])