How to use the py2neo.ogm.RelatedTo function in py2neo

To help you get started, we’ve selected a few py2neo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github technige / py2neo / test / integration / test_ogm.py View on Github external
def test_merge(self):
        thing = SimpleThing()
        self.graph.merge(thing)
        self.assertEqual(thing.__node__.graph, self.graph)
        self.assertIsNotNone(thing.__node__.identity)

    def test_push(self):
        thing = SimpleThing()
        self.graph.push(thing)
        self.assertEqual(thing.__node__.graph, self.graph)
        self.assertIsNotNone(thing.__node__.identity)


class A(GraphObject):

    b = RelatedTo("B")


class B(GraphObject):

    a = RelatedFrom("A")


class MutualReferenceTestCase(IntegrationTestCase):

    def test_crossover(self):
        a = A()
        b = B()
        a.b.add(b)
        b.a.add(a)
        self.graph.create(a)
        self.graph.create(b)
github technige / py2neo / test / integration / test_ogm_movies.py View on Github external
def test_can_match_by_id(movie_graph):
    # given
    keanu_0 = Person.match(movie_graph, "Keanu Reeves").first()
    node_id = keanu_0.__node__.identity

    # when

    class PersonById(MovieGraphObject):
        __primarylabel__ = "Person"

        name = Property()
        year_of_birth = Property(key="born")

        acted_in = RelatedTo(Film)
        directed = RelatedTo("Film")
        produced = RelatedTo("test.fixtures.ogm.Film")

    found = list(PersonById.match(movie_graph, node_id))
    assert found
    keanu = found[0]

    # then
    assert keanu.name == "Keanu Reeves"
    assert keanu.year_of_birth == 1964
github tgianko / deemon / deep-modeling / api / datamodel / core.py View on Github external
def __init__(self, projname, dm_type, symbol, s_type, pos):
        super(PTTerminalNode, self).__init__(projname, dm_type)
        self.symbol = symbol
        self.s_type = s_type
        self.pos = pos


class PTNonTerminalNode(BasicNode):
    """ Non terminal node of a parse tree
    """

    dm_type = Property()
    s_type = Property()
    pos = Property()
    HasChild = RelatedTo(["PTTerminalNode", "PTNonTerminalNode", "ParseTree"])  # COMMENT: Here is a ParseTree for Hierarchical parse trees

    def __init__(self, projname, dm_type, s_type, pos):
        super(PTNonTerminalNode, self).__init__(projname, dm_type)

        self.s_type = s_type
        self.pos = pos


"""
 **************************
        DATA FLOW
**************************
"""


class Variable(BasicNode):
github tgianko / deemon / deep-modeling / neo4jmodel / ApplicationDataLevelSession.py View on Github external
def getValue(self):
        return list(self.value)[0].value
 
    def inject(self, graph):
        pass


class SessionElementArrayElement(GraphObject):
    
    __primarykey__ = "uuid"

    projname = Property()
    uuid = Property()

    key = RelatedTo("SessionElementString")
    value = RelatedTo("SessionElementString")

    def __init__(self, key, value, projname=None):
        self.uuid = "{}".format(datetime.datetime.now())
        self.projname = projname
        self.key.add(key)
        self.value.add(value)

    def inject(self, graph):
        graph.push(self)


class SessionElementArray(GraphObject, SessionElement):
    type = SessionElementType.array

    __primarykey__ = "uuid"
github tgianko / deemon / deep-modeling / ast / core.py View on Github external
__primarykey__ = "uuid"

    uuid  = Property()
    
    projname = Property()
    session  = Property()
    user     = Property()
    seq      = Property()
    ts       = Property()

    command  = Property()
    target   = Property()
    value    = Property()

    Command  = RelatedTo("DataValue")
    Target   = RelatedTo("DataValue")
    Value    = RelatedTo("DataValue")
    Next     = RelatedTo("SeleneseCommand")

    Caused   = RelatedTo("HTTPRequest")

    def __init__(self, projname=None, session=None, user=None, seq=None, ts=None, command=None, target=None, value=None):
        self.projname=projname
        self.session = session
        self.user    = user
        self.seq     = seq
        self.ts      = ts
        self.command = command
        self.target  = target
        self.value   = value
        self.uuid     = "{} [{} {}] {}.{}.{}".format(type(self).__name__, seq, ts, projname, session, user)
github tgianko / deemon / deep-modeling / ast / core.py View on Github external
__primarykey__ = "uuid"

    uuid  = Property()

    projname = Property()
    
    session  = Property()
    user     = Property()
    seq      = Property()
    ts       = Property()
    
    status      = Property()

    Header      = RelatedTo("HeaderList")
    Body        = RelatedTo("Body") # We can use any other type of node. Apparently this library does not to type enforcement for nodes.
    

    def __init__(self, projname=None, session=None, user=None, seq=None, ts=None, status=None):
        self.projname = projname
        self.session  = session
        self.user     = user
        self.seq      = seq
        self.ts       = ts
        self.status = status
        self.uuid     = "{} [{} {}] {}.{}.{}".format(type(self).__name__, seq, ts, projname, session, user)


class SQLQuery(GraphObject):
    
    __primarykey__ = "uuid"
github tgianko / deemon / deep-modeling / neo4jmodel / ApplicationDataLevelSQL.py View on Github external
class SQLQuery(GraphObject):
    
    __primarykey__ = "uuid"

    uuid = Property()

    projname = Property()
    
    session = Property()
    user = Property()
    seq = Property()
    ts = Property()
    
    sql = Property()

    Statement = RelatedTo("SQLStatement")
    ABSTRACTSTO = RelatedTo("AbstractQuery")

    def __init__(self, projname=None, session=None, user=None,
                 seq=None, ts=None, sql=None):
        self.projname = projname
        self.session = session
        self.user = user
        self.seq = seq
        self.ts = ts
        self.sql = sql
        self.uuid = "{} [{} {}] {}.{}.{}".format(type(self).__name__,
                                                 seq, ts, projname,
                                                 session, user)


class AbstractQuery(GraphObject):
github tgianko / deemon / deep-modeling / neo4jmodel / BrowserActionLevel.py View on Github external
seq = Property()
    ts = Property()
    
    method = Property()
    url = Property()
    
    URL = RelatedTo("URL")
    Header = RelatedTo("HeaderList")
    ABSTRACTSTO = RelatedTo("AbstractHTTPRequest")
# We can use any other type of node.
# Apparently this library does not to type enforcement for nodes.
    Body = RelatedTo("Body")

    Next = RelatedTo("HTTPRequest")
    Transaction = RelatedTo("HTTPResponse")
    Caused = RelatedTo(["SQLQuery", "PHPSession"])

    def __init__(self, projname=None, session=None, user=None,
                 seq=None, ts=None, method=None, url=None):
        self.projname = projname
        self.session = session
        self.user = user
        self.seq = seq
        self.ts = ts
        self.method = method
        self.url = url
        self.uuid = "{} [{} {}] {}.{}.{}".format(type(self).__name__,
                                                 seq, ts, projname,
                                                 session, user)


class AbstractHTTPRequest (GraphObject):
github tgianko / deemon / deep-modeling / neo4jmodel / BrowserActionLevel.py View on Github external
seq, ts, projname,
                                                 session, user)


class URL(GraphObject):

    __primarykey__ = "uuid"

    uuid = Property()

    projname = Property()
    
    url = Property()

    Scheme = RelatedTo("DataValue")
    Netloc = RelatedTo("DataValue")
    Params = RelatedTo("DataValue")
    Fragment = RelatedTo("DataValue")
    Path = RelatedTo("DataValue")
    QueryString = RelatedTo("KeyValuePair")

    def __init__(self, projname=None, url=None):
        self.projname = projname
        self.url = url
        self.uuid = str(uuid4())


class HeaderList(GraphObject):

    __primarykey__ = "uuid"

    uuid = Property()
github tgianko / deemon / deep-modeling / api / datamodel / UserActionLevel.py View on Github external
__primarykey__ = "uuid"

    uuid  = Property()
    
    projname = Property()
    session  = Property()
    user     = Property()
    seq      = Property()
    ts       = Property()

    command  = Property()
    target   = Property()
    value    = Property()

    Command  = RelatedTo("DataValue")
    Target   = RelatedTo("DataValue")
    Value    = RelatedTo("DataValue")
    Next     = RelatedTo("SeleneseCommand")

    Caused   = RelatedTo("HTTPRequest")

    def __init__(self, projname=None, session=None, user=None, seq=None, ts=None, command=None, target=None, value=None):
        self.projname=projname
        self.session = session
        self.user    = user
        self.seq     = seq
        self.ts      = ts
        self.command = command
        self.target  = target
        self.value   = value
        self.uuid     = "{} [{} {}] {}.{}.{}".format(type(self).__name__, seq, ts, projname, session, user)