Exemple #1
0
class Neo4jIndexTestCase(unittest.TestCase):
    def setUp(self):
        config = Config(NEO4J_URI)
        self.client = Neo4jClient(config)
        self.factory = Factory(self.client)

    def test_gremlin(self):
        # limiting return count so we don't exceed heap size
        resp = self.client.gremlin("g.V[0..9]")
        assert resp.total_size > 5

    def test_query_exact_vertex_index(self):
        index = self.factory.get_index(Vertex, ExactIndex)
        vertices = index.query("name", "Jam*")
        assert len(list(vertices)) > 1

    def test_query_exact_edge_index(self):
        index = self.factory.get_index(Edge, ExactIndex)
        edges = index.query("timestamp", "1*")
        assert len(list(edges)) > 1

    def test_create_unique_vertex(self):
        index = self.factory.get_index(Vertex, ExactIndex)
        k, v = 'key', uuid1().get_hex()
        args = (k, v, {k: v})

        vertex, created = index.create_unique_vertex(*args)
        assert isinstance(vertex, Vertex)
        assert created is True

        vertex, created = index.create_unique_vertex(*args)
        assert isinstance(vertex, Vertex)
        assert created is False
Exemple #2
0
class Neo4jIndexTestCase(unittest.TestCase):
    
    def setUp(self):
        config = Config(NEO4J_URI)
        self.client = Neo4jClient(config)
        self.factory = Factory(self.client)

    def test_gremlin(self):
        # limiting return count so we don't exceed heap size
        resp = self.client.gremlin("g.V[0..9]")
        assert resp.total_size > 5

    def test_query_exact_vertex_index(self):
        index = self.factory.get_index(Vertex, ExactIndex)
        vertices = index.query("name", "Jam*")
        assert len(list(vertices)) > 1

    def test_query_exact_edge_index(self):
        index = self.factory.get_index(Edge, ExactIndex)
        edges = index.query("timestamp", "1*")
        assert len(list(edges)) > 1

    def test_create_unique_vertex(self):
        index = self.factory.get_index(Vertex, ExactIndex)
        k, v = 'key', uuid1().get_hex()
        args = (k, v, {k: v})

        vertex, created = index.create_unique_vertex(*args)
        assert isinstance(vertex, Vertex)
        assert created is True

        vertex, created = index.create_unique_vertex(*args)
        assert isinstance(vertex, Vertex)
        assert created is False
Exemple #3
0
    def __init__(self, config=None):
        self.client = self.client_class(config)
        self.config = self.client.config

        self.factory = Factory(self.client)

        self.vertices = self.build_proxy(Vertex)
        self.edges = self.build_proxy(Edge)
Exemple #4
0
    def __init__(self, config=None):
        self.client = self.client_class(config)
        self.config = self.client.config

        self.factory = Factory(self.client)

        self.vertices = self.build_proxy(Vertex)
        self.edges = self.build_proxy(Edge)
Exemple #5
0
class Neo4jIndexTestCase(unittest.TestCase):
    def setUp(self):
        config = Config(NEO4J_URI)
        self.client = Neo4jClient(config)
        self.factory = Factory(self.client)

    def test_gremlin(self):
        # limiting return count so we don't exceed heap size
        resp = self.client.gremlin("g.V[0..9]")
        assert resp.total_size > 5

    def test_query_exact_vertex_index(self):
        index = self.factory.get_index(Vertex, ExactIndex)
        vertices = index.query("name", "Jam*")
        assert len(list(vertices)) > 1

    def test_query_exact_edge_index(self):
        index = self.factory.get_index(Edge, ExactIndex)
        edges = index.query("timestamp", "1*")
        assert len(list(edges)) > 1
Exemple #6
0
class Neo4jIndexTestCase(unittest.TestCase):
    def setUp(self):
        config = Config(NEO4J_URI)
        self.client = Neo4jClient(config)
        self.factory = Factory(self.client)

    def test_gremlin(self):
        # limiting return count so we don't exceed heap size
        resp = self.client.gremlin("g.V[0..9]")
        assert resp.total_size > 5

    def test_query_exact_vertex_index(self):
        index = self.factory.get_index(Vertex, ExactIndex)
        vertices = index.query("name", "Jam*")
        assert len(list(vertices)) > 1

    def test_query_exact_edge_index(self):
        index = self.factory.get_index(Edge, ExactIndex)
        edges = index.query("timestamp", "1*")
        assert len(list(edges)) > 1
Exemple #7
0
    def __init__(self, config=None):

        #: Client object.
        self.client = self.client_class(config)

        self._factory = Factory(self.client)

        #: Generic VertexProxy object.
        self.vertices = self.build_proxy(Vertex)

        #: Generic EdgeProxy object.
        self.edges = self.build_proxy(Edge)

        #: Config object for convienence
        self.config = self.client.config
Exemple #8
0
 def setUp(self):
     config = Config(NEO4J_URI)
     self.client = Neo4jClient(config)
     self.factory = Factory(self.client)
Exemple #9
0
class Graph(object):
    """
    Abstract base class for the server-specific Graph implementations. 

    :param config: Optional Config object. Defaults to the default config.
    :type config: Config
        
    :cvar client_class: Client class.
    :cvar default_index: Default index class.

    :ivar client: Client object.
    :ivar config: Config object.
    :ivar vertices: VertexProxy object.
    :ivar edges: EdgeProxy object.

    Example:

    >>> from bulbs.neo4jserver import Graph
    >>> g = Graph()
    >>> james = g.vertices.create(name="James")
    >>> julie = g.vertices.create(name="Julie")
    >>> g.edges.create(james, "knows", julie)

    """    
    # The Client class to use for this Graph.
    client_class = Client

    # The default Index class.
    default_index = Index

    def __init__(self, config=None):
        self.client = self.client_class(config)
        self.config = self.client.config

        self.factory = Factory(self.client)

        self.vertices = self.build_proxy(Vertex)
        self.edges = self.build_proxy(Edge)

    @property
    def V(self):
        """
        Returns a list of all the vertices in the graph.

        :rtype: list or None

        """
        resp = self.client.get_all_vertices()
        if resp.total_size > 0:
            vertices = initialize_elements(self.client, resp)
            return list(vertices)
   
    @property
    def E(self):
        """
        Returns a list of all the edges in the graph.

        :rtype: list or None

        """
        resp = self.client.get_all_edges()
        if resp.total_size > 0:
            edges = initialize_elements(self.client, resp)
            return list(edges)
        
    def add_proxy(self, proxy_name, element_class, index_class=None):
        """
        Adds an element proxy to the Graph object for the element class.

        :param proxy_name: Attribute name to use for the proxy.
        :type proxy_name: str

        :param element_class: Element class managed by this proxy.
        :type element_class: Element

        :param index_class: Index class for Element's primary index. 
            Defaults to default_index.
        :type index_class: Index

        :rtype: None

        """
        proxy = self.build_proxy(element_class, index_class)
        self.client.registry.add_proxy(proxy_name, proxy)
        setattr(self, proxy_name, proxy)
    
    def build_proxy(self, element_class, index_class=None):
        """
        Returns an element proxy built to specifications.

        :param element_class: Element class managed by this proxy.
        :type element_class: Element

        :param index_class: Optional Index class for Element's primary index. 
            Defaults to default_index.
        :type index_class: Index

        :rtype: Element proxy

        """
        if not index_class:
            index_class = self.default_index
        return self.factory.build_element_proxy(element_class, index_class)

    def load_graphml(self, uri):
        """
        Loads a GraphML file into the database and returns the response.

        :param uri: URI of the GraphML file.
        :type uri: str

        :rtype: Response

        """
        raise NotImplementedError
        
    def get_graphml(self):
        """
        Returns a GraphML file representing the entire database.

        :rtype: Response

        """
        raise NotImplementedError

    def warm_cache(self):
        """
        Warms the server cache by loading elements into memory.

        :rtype: Response

        """
        raise NotImplementedError

    def clear(self):
        """Deletes all the elements in the graph.

        :rtype: Response

        .. admonition:: WARNING 

           This will delete all your data!

        """
        raise NotImplementedError
Exemple #10
0
class Graph(object):
    """
    Abstract base class for the server-specific Graph implementations. 

    :param config: Optional Config object. Defaults to the default config.
    :type config: Config
        
    :cvar client_class: Client class.
    :cvar default_index: Default index class.

    :ivar client: Client object.
    :ivar config: Config object.
    :ivar vertices: VertexProxy object.
    :ivar edges: EdgeProxy object.

    Example:

    >>> from bulbs.neo4jserver import Graph
    >>> g = Graph()
    >>> james = g.vertices.create(name="James")
    >>> julie = g.vertices.create(name="Julie")
    >>> g.edges.create(james, "knows", julie)

    """
    # The Client class to use for this Graph.
    client_class = Client

    # The default Index class.
    default_index = Index

    def __init__(self, config=None):
        self.client = self.client_class(config)
        self.config = self.client.config

        self.factory = Factory(self.client)

        self.vertices = self.build_proxy(Vertex)
        self.edges = self.build_proxy(Edge)

    @property
    def V(self):
        """
        Returns a list of all the vertices in the graph.

        :rtype: list or None

        """
        resp = self.client.get_all_vertices()
        if resp.total_size > 0:
            vertices = initialize_elements(self.client, resp)
            return list(vertices)

    @property
    def E(self):
        """
        Returns a list of all the edges in the graph.

        :rtype: list or None

        """
        resp = self.client.get_all_edges()
        if resp.total_size > 0:
            edges = initialize_elements(self.client, resp)
            return list(edges)

    def add_proxy(self, proxy_name, element_class, index_class=None):
        """
        Adds an element proxy to the Graph object for the element class.

        :param proxy_name: Attribute name to use for the proxy.
        :type proxy_name: str

        :param element_class: Element class managed by this proxy.
        :type element_class: Element

        :param index_class: Index class for Element's primary index. 
            Defaults to default_index.
        :type index_class: Index

        :rtype: None

        """
        proxy = self.build_proxy(element_class, index_class)
        setattr(self, proxy_name, proxy)

    def build_proxy(self, element_class, index_class=None):
        """
        Returns an element proxy built to specifications.

        :param element_class: Element class managed by this proxy.
        :type element_class: Element

        :param index_class: Optional Index class for Element's primary index. 
            Defaults to default_index.
        :type index_class: Index

        :rtype: Element proxy

        """
        if not index_class:
            index_class = self.default_index
        return self.factory.build_element_proxy(element_class, index_class)

    def load_graphml(self, uri):
        """
        Loads a GraphML file into the database and returns the response.

        :param uri: URI of the GraphML file.
        :type uri: str

        :rtype: Response

        """
        raise NotImplementedError

    def get_graphml(self):
        """
        Returns a GraphML file representing the entire database.

        :rtype: Response

        """
        raise NotImplementedError

    def warm_cache(self):
        """
        Warms the server cache by loading elements into memory.

        :rtype: Response

        """
        raise NotImplementedError

    def clear(self):
        """Deletes all the elements in the graph.

        :rtype: Response

        .. admonition:: WARNING 

           This will delete all your data!

        """
        raise NotImplementedError
Exemple #11
0
 def setUp(self):
     config = Config(NEO4J_URI)
     self.client = Neo4jClient(config)
     self.factory = Factory(self.client)
Exemple #12
0
class Graph(object):
    """
    Abstract base class for the Graph implementations. See the Bulbs 
    Neo4j Server and Rexster documentation for server-specific 
    implementations. 

    :param config: Optional. Defaults to the default config.
    :type config: Config
        
    Example:

    >>> from bulbs.neo4jserver import Graph
    >>> g = Graph()
    >>> james = g.vertices.create(name="James")
    >>> julie = g.vertices.create(name="Julie")
    >>> g.edges.create(james, "knows", julie)

    """    
    #: The Client class to use for this Graph.
    client_class = Client

    #: The default Index class.
    default_index = Index

    def __init__(self, config=None):

        #: Client object.
        self.client = self.client_class(config)

        self._factory = Factory(self.client)

        #: Generic VertexProxy object.
        self.vertices = self.build_proxy(Vertex)

        #: Generic EdgeProxy object.
        self.edges = self.build_proxy(Edge)

        #: Config object for convienence
        self.config = self.client.config


    def add_proxy(self, proxy_name, element_class, index_class=None):
        """
        Adds an element proxy to the Graph object for the element class.

        :param proxy_name: Attribute name to use for the proxy.
        :type proxy_name: str

        :param element_class: Element class managed by this proxy.
        :type element_class: Element

        :param index_class: Index class used for Element's primary index. Defaults to default_index.
        :type index_class: Index

        :rtype: None

        """
        proxy = self.build_proxy(element_class, index_class)
        setattr(self, proxy_name, proxy)
    
    def build_proxy(self, element_class, index_class=None):
        """
        Returns an element proxy built to specifications.

        :param element_class: Element class managed by this proxy.
        :type element_class: Element

        :param index_class: Optional Index class used for Element's primary index. 
            Defaults to default_index.
        :type index_class: Index

        :rtype: Element proxy

        """
        if not index_class:
            index_class = self.default_index
        return self._factory.build_element_proxy(element_class, index_class)

    def load_graphml(self, uri):
        """
        Loads a GraphML file into the database and returns the response.

        :param uri: URI of the GraphML file.
        :type uri: str

        :rtype: Response

        """
        raise NotImplementedError
        
    def save_graphml(self):
        """
        Returns a GraphML file representing the entire database.

        :rtype: Response

        """
        raise NotImplementedError

    def warm_cache(self):
        """
        Warms the server cache by loading elements into memory.

        :rtype: Response

        """
        raise NotImplementedError

    def clear(self):
        """Deletes all the elements in the graph.

        :rtype: Response

        .. admonition:: WARNING 

           This will delete all your data!

        """
        raise NotImplementedError