/bulbs/tests/index_tests.py

https://gitlab.com/tlevine/bulbs · Python · 78 lines · 50 code · 17 blank · 11 comment · 0 complexity · 77dc5fee64d8247a391fbb266528fd81 MD5 · raw file

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright 2011 James Thornton (http://jamesthornton.com)
  4. # BSD License (see LICENSE for details)
  5. #
  6. import unittest
  7. import random
  8. import bulbs.utils
  9. from bulbs.config import Config, DEBUG, ERROR
  10. from bulbs.element import Vertex, VertexProxy, Edge, EdgeProxy
  11. from .testcase import BulbsTestCase
  12. class IndexTestCase(BulbsTestCase):
  13. def setUp(self):
  14. self.indicesV = self.vertex_index_proxy(self.index_class,self.client)
  15. self.indicesE = self.edge_index_proxy(self.index_class,self.client)
  16. self.indicesV.delete("test_idxV")
  17. self.indicesE.delete("test_idxE")
  18. self.vertices = VertexProxy(Vertex,self.client)
  19. self.vertices.index = self.indicesV.get_or_create("test_idxV")
  20. self.edges = EdgeProxy(Edge,self.client)
  21. self.edges.index = self.indicesE.get_or_create("test_idxE")
  22. def test_index(self):
  23. index_name = "test_idxV"
  24. # need to fix this to accept actual data types in POST
  25. ikeys = '[name,location]'
  26. james = self.vertices.create({'name':'James'})
  27. self.vertices.index.put(james._id,'name','James')
  28. self.vertices.index.put(james._id,'location','Dallas')
  29. results = self.vertices.index.lookup('name','James')
  30. results = list(results)
  31. assert len(results) == 1
  32. assert results[0].name == "James"
  33. total_size = self.vertices.index.count('name','James')
  34. assert total_size == 1
  35. i2 = self.indicesV.get(index_name)
  36. assert self.vertices.index.index_name == i2.index_name
  37. self.vertices.index.remove(james._id,'name','James')
  38. james = self.vertices.index.get_unique('name','James')
  39. assert james is None
  40. self.indicesV.delete(index_name)
  41. def test_ascii_encoding_index_lookup(self):
  42. # Fixed for Neo4j Server. Still having issues with Rexster...
  43. # https://github.com/espeed/bulbs/issues/117
  44. # using default index name because that's what create_indexed_vertex() uses
  45. name = u'Aname M\xf6ller' + bulbs.utils.to_string(random.random())
  46. index_name = Vertex.get_index_name(self.vertices.client.config)
  47. self.vertices.client.config.set_logger(ERROR)
  48. self.vertices.index = self.indicesV.get_or_create(index_name)
  49. v1a = self.vertices.create(name=name)
  50. v1b = self.vertices.index.lookup(u"name", name)
  51. assert next(v1b).name == name
  52. def test_ascii_encoding_index_lookup2(self):
  53. # http://stackoverflow.com/questions/23057915/rexster-bulbs-unicode-node-property-node-created-but-not-found
  54. # using default index name because that's what create_indexed_vertex() uses
  55. name = u'Université de Montréal' + bulbs.utils.to_string(random.random())
  56. index_name = Vertex.get_index_name(self.vertices.client.config)
  57. self.vertices.client.config.set_logger(ERROR)
  58. self.vertices.index = self.indicesV.get_or_create(index_name)
  59. v1a = self.vertices.create(name=name)
  60. v1b = self.vertices.index.lookup(u"name", name)
  61. assert next(v1b).name == name