def test_get_edges(prepare):
    relation1 = prepare.AddRelation(
        AddSchemaRelation(parent_schema_id="1d1cc7a5-9277-48bc-97d3-3d99cfb63000",
                       child_schema_id="1d1cc7a5-9277-48bc-97d3-3d99cfb63001")
    ).relation_id
    relation2 = prepare.AddRelation(
        AddSchemaRelation(parent_schema_id="1d1cc7a5-9277-48bc-97d3-3d99cfb6300c",
                       child_schema_id="1d1cc7a5-9277-48bc-97d3-3d99cfb6300a")
    ).relation_id

    parent = "1d1cc7a5-9277-48bc-97d3-3d99cfb63002"
    child1 = "1d1cc7a5-9277-48bc-97d3-3d99cfb63003"
    child2 = "1d1cc7a5-9277-48bc-97d3-3d99cfb63005"

    prepare.AddEdges(
        ObjectRelations(relations=[
            Edge(relation_id=relation1,
                 parent_object_id=parent,
                 child_object_ids=[child1]),
            Edge(relation_id=relation2,
                 parent_object_id=parent,
                 child_object_ids=[child2])
        ]))

    result = list(
        map(lambda x: (x.relation_id, x.child_object_ids),
            prepare.GetEdges(ObjectIdQuery(object_id=parent)).relations))
    result.sort()

    expected = [(relation1, [child1]), (relation2, [child2])]
    expected.sort()

    assert expected == result
Beispiel #2
0
def test_kafka(prepare):
    stub, kafka_config = prepare
    parent_schema_id = "3fb03807-2c51-43c8-aa57-34f8d2fa0186"
    child_schema_id = "1d1cc7a5-9277-48bc-97d3-3d99cfb633dd"
    relation_id = stub.AddRelation(
        AddSchemaRelation(parent_schema_id=parent_schema_id,
                       child_schema_id=child_schema_id)).relation_id

    parent_object_id = "1d1cc7a5-9277-48bc-97d3-3d99cfb63300"
    child_object_id = "1d1cc7a5-9277-48bc-97d3-3d99cfb63301"
    push_to_kafka(kafka_config, [{
        "relationId": relation_id,
        "parentObjectId": parent_object_id,
        "childObjectIds": [child_object_id]
    }],
                  key='edge',
                  timestamp=1616759706)

    time.sleep(2)

    result = stub.GetEdge(
        RelationIdQuery(relation_id=relation_id,
                        parent_object_id=parent_object_id)).child_object_ids

    assert [child_object_id] == result
def test_get_relations(prepare):
    parent_schema_id = "1d1cc7a5-9277-48bc-97d3-3d99cfb63300"
    relation1 = prepare.AddRelation(
        AddSchemaRelation(parent_schema_id=parent_schema_id,
                       child_schema_id="1d1cc7a5-9277-48bc-97d3-3d99cfb63301")
    ).relation_id
    relation2 = prepare.AddRelation(
        AddSchemaRelation(parent_schema_id=parent_schema_id,
                       child_schema_id="1d1cc7a5-9277-48bc-97d3-3d99cfb63302")
    ).relation_id

    result = list(
        map(
            lambda x: x.relation_id,
            prepare.GetSchemaRelations(
                SchemaId(schema_id=parent_schema_id)).items))

    assert [relation1, relation2] == result
def test_get_relation(prepare):
    parent_schema_id = "3fb03807-2c51-43c8-aa58-3468d26a0186"
    child_schema_id = "1d1cc7a5-9277-48bc-97d3-3d99cfb633ac"
    relation_id = prepare.AddRelation(
        AddSchemaRelation(parent_schema_id=parent_schema_id,
                       child_schema_id=child_schema_id)).relation_id

    result = prepare.GetRelation(
        RelationQuery(relation_id=[relation_id])).items[0].child_schema_id

    assert child_schema_id == result
def test_add_relation(prepare):
    parent_schema_id = "3fb03807-2c51-43c8-aa57-34f8d2fa0186"
    child_schema_id = "1d1cc7a5-9277-48bc-97d3-3d99cfb633dd"
    resp = prepare.AddRelation(
        AddSchemaRelation(parent_schema_id=parent_schema_id,
                       child_schema_id=child_schema_id))
    relations = prepare.GetRelation(Empty())

    result = relations.items[0]

    assert len(relations.items) == 1
    assert result.relation_id == resp.relation_id
    assert result.parent_schema_id == parent_schema_id
    assert result.child_schema_id == child_schema_id
def test_add_get_edge(prepare):
    parent_schema_id = "1d1cc7a5-9277-48bc-97d3-3d99cfb63303"
    child_schema_id = "ed1cc7a5-9277-48bc-97d3-3d99cfb6330c"
    relation = prepare.AddRelation(
        AddSchemaRelation(parent_schema_id=parent_schema_id,
                       child_schema_id=child_schema_id)).relation_id

    parent_object_id = "1d1cc7a5-9277-48bc-97d3-3d99cfb633aa"
    child1 = "1d1cc7a5-9277-48bc-97d3-3d99cfb633a1"
    child2 = "1d1cc7a5-9277-48bc-97d3-3d99cfb633a2"

    prepare.AddEdges(
        ObjectRelations(relations=[
            Edge(relation_id=relation,
                 parent_object_id=parent_object_id,
                 child_object_ids=[child1, child2])
        ]))

    result = prepare.GetEdge(
        RelationIdQuery(relation_id=relation,
                        parent_object_id=parent_object_id)).child_object_ids

    assert result == [child1, child2]