def test_add_unique_node():
    """Test ad unique node."""
    class Foo(BaseModel):
        vertex_label: str = 'foo'
        foo: str

    g = Traversel('g')
    foo = Foo(foo='bar')
    g.add_unique_node(foo)
    assert ("g.V().has('vertex_label', '{vertex_label}')"
            ".has('foo', '{foo}').fold().coalesce(unfold(), addV('{vertex_label}'))"
            ".property('vertex_label', '{vertex_label}').property('foo', '{foo}')"
            .format(**foo.__dict__) == str(g))
def test_add_unique_node_with_key():
    """Test ass unique node with key."""
    class Foo(BaseModel):
        vertex_label: str = 'foo'
        primary_key = ('foo', 'bla')
        foo: str
        bar: str

    g = Traversel('g')
    foo = Foo(foo='bar', bar='zoo')
    g.add_unique_node(foo)
    assert ("g.V()"
            ".has('foo', '{foo}').fold().coalesce(unfold(), addV('{vertex_label}'))"
            ".property('vertex_label', '{vertex_label}').property('foo', '{foo}')"
            ".property('bar', '{bar}')".format(**foo.__dict__) == str(g))
Beispiel #3
0
def _ingest_pcve(pcve):
    g = Traversel() # pylint: disable=invalid-name
    query = str(g.add_unique_node(pcve.dependency)
                .add_unique_node(pcve.version)
                .add_unique_node(pcve.security_event)
                .add_unique_node(pcve.probable_cve)
                .has_version(pcve.dependency, pcve.version)
                .triaged_to(pcve.security_event, pcve.probable_cve)
                .affects(pcve.probable_cve, pcve.version)
                .next())
    return execute_query(query)