示例#1
0
def test_full_relationship_create():
    expected_query = ('MATCH (m:`User`)\n'
                      'MATCH (n:`User`)\n'
                      'CREATE (m)-[rel:`KNOWS`]->(n)')
    user_m = Node('User', name=Property(), var='m')
    user_n = user_m.copy(var='n')
    rel = Relationship('KNOWS', user_m, user_n)
    query = Match(user_m) & Match(user_n) & Create(rel)
    assert str(query) == expected_query
    assert len(query.params) == 0
示例#2
0
def test_union_and_union_all():
    n = Node('Person', name='Mr. N', var='n')
    m = n.copy(var='m', name='Mrs. M')
    expected_stmt = [
        'MATCH (n:`Person`)',
        'UNION',
        'MATCH (m:`Person`)',
    ]
    assert str(Match(n) ^ Match(m)) == '\n'.join(expected_stmt)
    expected_stmt[1] += ' ALL'
    assert str(Match(n) | Match(m)) == '\n'.join(expected_stmt)
示例#3
0
def test_full_relationship_create():
    expected_query = (
        'MATCH (m:`User`)\n'
        'MATCH (n:`User`)\n'
        'CREATE (m)-[rel:`KNOWS`]->(n)'
    )
    user_m = Node('User', name=Property(), var='m')
    user_n = user_m.copy(var='n')
    rel = Relationship('KNOWS', user_m, user_n)
    query = Match(user_m) & Match(user_n) & Create(rel)
    assert str(query) == expected_query
    assert len(query.params) == 0
示例#4
0
def test_full_match():
    expected_stmt = [
        'MATCH (m:`Person`)',
        '    WHERE m.name = {m_name}',
        'MATCH (n:`Person`)',
        '    WHERE n.name = {n_name}',
        'MATCH (m)-[rel:`KNOWS`]->(n)',
    ]
    person_m = Node('Person', name='Alice', var='m').bind('name')
    person_n = person_m.copy(name='Bob', var='n')
    knows = Relationship('KNOWS', person_m, person_n)
    match = Match(person_m) & Match(person_n) & Match(knows)
    assert str(match) == '\n'.join(expected_stmt)
    assert len(match.params) == 2
    assert 'm_name' in match.params
    assert match.params['m_name'] == 'Alice'
    assert 'n_name' in match.params
    assert match.params['n_name'] == 'Bob'
    match.return_().order_by(person_n['name']).skip(1).limit(1)
    expected_stmt += [
        'RETURN *',
        'ORDER BY n.name',
        'SKIP 1',
        'LIMIT 1',
    ]
    assert str(match) == '\n'.join(expected_stmt)
    assert len(match.params) == 2
    assert 'm_name' in match.params
    assert match.params['m_name'] == 'Alice'
    assert 'n_name' in match.params
    assert match.params['n_name'] == 'Bob'
    expected_stmt[-3] += ' DESC'
    for _ in range(3):
        match.pop()
    match.order_by(person_n['name'], desc=True).skip(1).limit(1)
    assert str(match) == '\n'.join(expected_stmt)
    assert len(match.params) == 2
    assert 'm_name' in match.params
    assert match.params['m_name'] == 'Alice'
    assert 'n_name' in match.params
    assert match.params['n_name'] == 'Bob'
示例#5
0
def test_optional_match():
    person_m = Node('Person', var='m')
    person_n = person_m.copy(var='n')
    rel = Relationship(None, person_m, person_n)
    match = Match(rel, optional=True)
    assert str(match) == 'OPTIONAL MATCH (m)-[rel]->(n)'
示例#6
0
def test_matching_anonymous_relationship():
    person_m = Node('Person', var='m')
    person_n = person_m.copy(var='n')
    rel = Relationship(None, person_m, person_n)
    match = Match(rel)
    assert str(match) == 'MATCH (m)-[rel]->(n)'