Beispiel #1
0
 def test_remove_json_multiple(self):
     idx = inmemory.InMemoryIndex('idx-name', ['key'])
     idx.add_json('doc-id', simple_doc)
     idx.add_json('doc2-id', simple_doc)
     self.assertEqual({'value': ['doc-id', 'doc2-id']}, idx._values)
     idx.remove_json('doc-id', simple_doc)
     self.assertEqual({'value': ['doc2-id']}, idx._values)
Beispiel #2
0
 def test__find_non_wildcards(self):
     idx = inmemory.InMemoryIndex('idx-name', ['k1', 'k2', 'k3'])
     self.assertEqual(-1, idx._find_non_wildcards(('a', 'b', 'c')))
     self.assertEqual(2, idx._find_non_wildcards(('a', 'b', '*')))
     self.assertEqual(3, idx._find_non_wildcards(('a', 'b', 'c*')))
     self.assertEqual(2, idx._find_non_wildcards(('a', 'b*', '*')))
     self.assertEqual(0, idx._find_non_wildcards(('*', '*', '*')))
     self.assertEqual(1, idx._find_non_wildcards(('a*', '*', '*')))
     self.assertRaises(errors.InvalidValueForIndex, idx._find_non_wildcards,
                       ('a', 'b'))
     self.assertRaises(errors.InvalidValueForIndex, idx._find_non_wildcards,
                       ('a', 'b', 'c', 'd'))
     self.assertRaises(errors.InvalidGlobbing, idx._find_non_wildcards,
                       ('*', 'b', 'c'))
Beispiel #3
0
 def test_lookup(self):
     idx = inmemory.InMemoryIndex('idx-name', ['key'])
     idx.add_json('doc-id', simple_doc)
     self.assertEqual(['doc-id'], idx.lookup(['value']))
Beispiel #4
0
 def test_update_adds_entry(self):
     idx = inmemory.InMemoryIndex('idx-name', ['key'])
     idx.add_json('doc-id', simple_doc)
     self.assertEqual({'value': ['doc-id']}, idx._values)
Beispiel #5
0
 def test_update_ignores_None(self):
     idx = inmemory.InMemoryIndex('idx-name', ['nokey'])
     idx.add_json('doc-id', simple_doc)
     self.assertEqual({}, idx._values)
Beispiel #6
0
 def test_evaluate_multi_index(self):
     doc = '{"key": "value", "key2": "value2"}'
     idx = inmemory.InMemoryIndex('idx-name', ['key', 'key2'])
     self.assertEqual(['value\x01value2'], idx.evaluate_json(doc))
Beispiel #7
0
 def test_evaluate_json_subfield_None(self):
     idx = inmemory.InMemoryIndex('idx-name', ['key', 'missing'])
     self.assertEqual([], idx.evaluate_json(simple_doc))
Beispiel #8
0
 def test_evaluate_json(self):
     idx = inmemory.InMemoryIndex('idx-name', ['key'])
     self.assertEqual(['value'], idx.evaluate_json(simple_doc))
Beispiel #9
0
 def test_has_name_and_definition(self):
     idx = inmemory.InMemoryIndex('idx-name', ['key'])
     self.assertEqual('idx-name', idx._name)
     self.assertEqual(['key'], idx._definition)