Ejemplo n.º 1
0
def test_delete_edgeLabel_by_name():
    """
    根据name查看edgeLabel
    """
    init_graph()
    body = {
        "name": "link",
        "source_label": "person_name",
        "target_label": "person_name",
        "frequency": "SINGLE",
        "properties": ["name"],
        "sort_keys": [],
        "nullable_keys": ["name"],
        "enable_label_index": True,
        "user_data": {
            "super": "animal"
        }
    }
    code, res = Schema().create_edgeLabel(body, auth=auth)
    assert code == 201
    assert res['status'] == 'CREATED'
    assert res['properties'] == ['name']

    # eliminate property && userdata
    code, res = Schema().delete_edgeLabel("link", auth=auth)
    print(code, res)
    assert 202

    res = get_task_res(res['task_id'], 60, auth=auth)
    print(res)
Ejemplo n.º 2
0
def test_eliminate_edgeLabel_userdata():
    """
    添加 property、userdata
    """
    init_graph()
    body = {
        "name": "link",
        "source_label": "person_name",
        "target_label": "person_name",
        "frequency": "SINGLE",
        "properties": ["name"],
        "sort_keys": [],
        "nullable_keys": ["name"],
        "enable_label_index": True,
        "user_data": {
            "super": "animal"
        }
    }
    code, res = Schema().create_edgeLabel(body, auth=auth)
    assert code == 201
    assert res['status'] == 'CREATED'
    assert res['properties'] == ['name']

    # eliminate property && userdata
    property_name = "link"
    append_body = {"name": property_name, "user_data": {"super": "animal"}}
    code, res = Schema().update_edgeLabel(property_name,
                                          {"action": "eliminate"},
                                          append_body,
                                          auth=auth)
    print(code, res)
    assert 200
    assert res['name'] == 'link'
    assert 'super' not in res['user_data']
Ejemplo n.º 3
0
def test_get_edgeLabel_all():
    """
    查看所有edgeLabel
    """
    init_graph()
    body = {
        "name": "link",
        "source_label": "person_name",
        "target_label": "person_name",
        "frequency": "SINGLE",
        "properties": ["name"],
        "sort_keys": [],
        "nullable_keys": ["name"],
        "enable_label_index": True,
        "user_data": {
            "super": "animal"
        }
    }
    code, res = Schema().create_edgeLabel(body, auth=auth)
    assert code == 201
    assert res['status'] == 'CREATED'
    assert res['properties'] == ['name']

    # eliminate property && userdata
    code, res = Schema().get_edgeLabel(auth=auth)
    print(code, res)
    assert 200
    assert len(res['edgelabels']) == 1
    assert res['edgelabels'][0]['name'] == 'link'
Ejemplo n.º 4
0
def test_eliminate_userdata():
    """
    移除 userdata
    """
    init_graph()
    body = {
        "name": "age",
        "data_type": "INT",
        "cardinality": "SINGLE",
        "user_data": {
            "min": 0,
            "max": 100
        }
    }
    code, res = Schema().create_property(body, auth=auth)
    print(code, res)
    assert code == 201
    assert res['data_type'] == 'INT'

    body = {"name": "age", "user_data": {"min": 0}}
    code, res = Schema().deal_property_userdata("age", {"action": "eliminate"},
                                                body,
                                                auth=auth)
    print(code, res)
    assert code == 200
    assert "min" not in res["user_data"]
    assert res["user_data"]["max"] == 100
Ejemplo n.º 5
0
def test_update_vertexlabel_eliminate_userdata():
    """
    ID为主键类型
    """
    init_graph()
    property_name = 'test'
    # append property && userdata
    append_body = {
        "name": property_name,
        "properties": ["city"],
        "nullable_keys": ["city"],
        "user_data": {
            "super": "animal"
        }
    }
    code, res = Schema().update_vertexLabel(property_name,
                                            {"action": "append"},
                                            append_body,
                                            auth=auth)
    print(code, res)
    assert code == 200
    assert res['properties'] == ['name', 'city']
    assert res['user_data']['super'] == 'animal'

    # eliminate
    eliminate_body = {"name": property_name, "user_data": {"super": "animal"}}
    code, res = Schema().update_vertexLabel(property_name,
                                            {"action": "eliminate"},
                                            eliminate_body,
                                            auth=auth)
    print(code, res)
    assert code == 200
    assert 'super' not in res['user_data']
Ejemplo n.º 6
0
def test_delete_property_by_name():
    """
    通过name删除属性
    """
    init_graph()
    body = {"name": "age", "data_type": "INT", "cardinality": "SINGLE"}
    code, res = Schema().create_property(body, auth=auth)
    print(code, res)
    assert code == 201
    assert res['data_type'] == 'INT'

    code, res = Schema().delete_property_by_name('age', auth=auth)
    print(code, res)
    assert code == 204
Ejemplo n.º 7
0
def test_create_search_vertex_indexlabel_int_error():
    """
    int类型的属性 & search索引 & vertexlabel
    """
    init_graph()
    query = "graph.schema().propertyKey('name').asText().ifNotExist().create();" \
            "graph.schema().propertyKey('age').asInt().ifNotExist().create();" \
            "graph.schema().propertyKey('date').asDate().ifNotExist().create();" \
            "graph.schema().vertexLabel('person').properties('name', 'age')" \
            ".primaryKeys('name').ifNotExist().create();"\
            "graph.schema().edgeLabel('knows').sourceLabel('person').targetLabel('person')" \
            ".properties('date').ifNotExist().create()"
    code, res = Gremlin().gremlin_post(query, auth=auth)
    assert code == 200

    body = {
        "name": "searchByAgeByVertex",
        "base_type": "VERTEX_LABEL",
        "base_value": "person",
        "index_type": "SEARCH",
        "fields": ["age"]
    }
    code, res = Schema().create_index(body, auth=auth)
    print(code, res)
    assert code == 400
    assert res[
        'message'] == "Search index can only build on text property, but got INT(age)"
Ejemplo n.º 8
0
def test_delete_indexlabel():
    """
    删除索引
    :return:
    """
    init_graph()
    query = "graph.schema().propertyKey('name').asText().ifNotExist().create();" \
            "graph.schema().propertyKey('age').asInt().ifNotExist().create();" \
            "graph.schema().propertyKey('date').asDate().ifNotExist().create();" \
            "graph.schema().vertexLabel('person').properties('name', 'age')" \
            ".primaryKeys('name').ifNotExist().create();" \
            "graph.schema().edgeLabel('knows').sourceLabel('person').targetLabel('person')" \
            ".properties('date').ifNotExist().create();" \
            "graph.schema().indexLabel('rangeByAgeByVertex').onV('person').by('age').range().ifNotExist().create();"
    code, res = Gremlin().gremlin_post(query, auth=auth)
    assert code == 200

    index_name = 'rangeByAgeByVertex'
    code, res = Schema().delete_index(index_name, auth=auth)
    print(code, res)
    assert code == 202
    task_id = res['task_id']
    result = get_task_res(task_id, 120, auth=auth)
    if result:
        assert 1
Ejemplo n.º 9
0
def test_create_secondary_vertex_indexlabel():
    """
    int类型的属性 & secondary索引 & vertexlabel
    """
    init_graph()
    query = "graph.schema().propertyKey('name').asText().ifNotExist().create();" \
            "graph.schema().propertyKey('age').asInt().ifNotExist().create();" \
            "graph.schema().propertyKey('date').asDate().ifNotExist().create();" \
            "graph.schema().vertexLabel('person').properties('name', 'age')" \
            ".primaryKeys('name').ifNotExist().create();"\
            "graph.schema().edgeLabel('knows').sourceLabel('person').targetLabel('person')" \
            ".properties('date').ifNotExist().create()"
    code, res = Gremlin().gremlin_post(query, auth=auth)
    assert code == 200

    body = {
        "name": "secondaryByAgeByVertex",
        "base_type": "VERTEX_LABEL",
        "base_value": "person",
        "index_type": "SECONDARY",
        "fields": ["age"]
    }
    code, res = Schema().create_index(body, auth=auth)
    print(code, res)
    assert code == 202
    task_id = res['task_id']
    result = get_task_res(task_id, 120, auth=auth)
    if result:
        assert 1
Ejemplo n.º 10
0
def test_update_vertexlabel_append_properties_userdata():
    """
    ID为主键类型
    """
    property_name = 'test'
    body = {
        "name": property_name,
        "properties": ["city"],
        "nullable_keys": ["city"],
        "user_data": {
            "super": "animal"
        }
    }
    if init_graph():
        code, res = Schema().update_vertexLabel(property_name,
                                                {"action": "append"},
                                                body,
                                                auth=auth)
        print(code, res)
        assert code == 200
        assert res['properties'] == ['name', 'city']
        assert res['user_data']['super'] == 'animal'
    else:
        print('环境初始化失败')
        assert 0
Ejemplo n.º 11
0
def test_get_all_property():
    """
    获取所有属性
    """
    init_graph()
    body = {"name": "age", "data_type": "INT", "cardinality": "SINGLE"}
    code, res = Schema().create_property(body, auth=auth)
    print(code, res)
    assert code == 201
    assert res['data_type'] == 'INT'

    code, res = Schema().get_all_properties(auth=auth)
    print(code, res)
    assert code == 200
    assert len(res['propertykeys']) == 1
    assert res['propertykeys'][0]['name'] == 'age'
Ejemplo n.º 12
0
def test_create_range_edge_indexlabel():
    """
    int类型的属性 & range索引 & edgelabel
    """
    init_graph()
    query = "graph.schema().propertyKey('name').asText().ifNotExist().create();" \
            "graph.schema().propertyKey('age').asInt().ifNotExist().create();" \
            "graph.schema().propertyKey('date').asDate().ifNotExist().create();" \
            "graph.schema().vertexLabel('person').properties('name', 'age')" \
            ".primaryKeys('name').ifNotExist().create();"\
            "graph.schema().edgeLabel('knows').sourceLabel('person').targetLabel('person')" \
            ".properties('date').ifNotExist().create()"
    code, res = Gremlin().gremlin_post(query, auth=auth)
    assert code == 200

    body = {
        "name": "rangeByDateByEdge",
        "base_type": "EDGE_LABEL",
        "base_value": "knows",
        "index_type": "RANGE",
        "fields": ["date"]
    }
    code, res = Schema().create_index(body, auth=auth)
    print(code, res)
    assert code == 202
    task_id = res['task_id']
    result = get_task_res(task_id, 120, auth=auth)
    if result:
        assert 1
Ejemplo n.º 13
0
def test_create_property_single_boolean():
    """
    boolean类型的属性创建
    """
    init_graph()
    body = {"name": "boolean", "data_type": "BOOLEAN", "cardinality": "SINGLE"}
    code, res = Schema().create_property(body, auth=auth)
    print(code, res)
    assert code == 201
    assert res['data_type'] == 'BOOLEAN'
Ejemplo n.º 14
0
def test_create_property_single_uuid():
    """
    uuid类型的属性创建
    """
    init_graph()

    body = {"name": "uuid", "data_type": "UUID", "cardinality": "SINGLE"}
    code, res = Schema().create_property(body, auth=auth)
    print(code, res)
    assert code == 201
    assert res['data_type'] == 'UUID'
Ejemplo n.º 15
0
def test_create_property_single_time():
    """
    date类型的属性创建
    """
    init_graph()

    body = {"name": "time", "data_type": "DATE", "cardinality": "SINGLE"}
    code, res = Schema().create_property(body, auth=auth)
    print(code, res)
    assert code == 201
    assert res['data_type'] == 'DATE'
Ejemplo n.º 16
0
def test_create_property_list_text():
    """
    text类型set集合的属性创建
    """
    init_graph()

    body = {"name": "name", "data_type": "TEXT", "cardinality": "LIST"}
    code, res = Schema().create_property(body, auth=auth)
    print(code, res)
    assert code == 201
    assert res['data_type'] == 'TEXT'
Ejemplo n.º 17
0
def test_create_property_single_long():
    """
    float类型的属性创建
    """
    init_graph()

    body = {"name": "long", "data_type": "LONG", "cardinality": "SINGLE"}
    code, res = Schema().create_property(body, auth=auth)
    print(code, res)
    assert code == 201
    assert res['data_type'] == 'LONG'
Ejemplo n.º 18
0
def test_get_vertexlabel_by_name():
    """
    通过name查询vertexLabel
    """
    init_graph()
    property_name = "person"
    body = {
        "name": property_name,
        "id_strategy": "DEFAULT",
        "properties": ["name"],
        "primary_keys": ["name"],
        "nullable_keys": [],
        "enable_label_index": True
    }
    code, res = Schema().create_vertexLabel(body, auth=auth)
    assert code == 201

    # get vertexLabel by name
    code, res = Schema().get_vertexLabel_by_name(property_name, auth=auth)
    print(code, res)
    assert code == 200
    assert res['name'] == 'person'
Ejemplo n.º 19
0
def test_get_vertexlabel_all():
    """
    获取vertex label
    """
    init_graph()
    property_name = "person"
    body = {
        "name": property_name,
        "id_strategy": "DEFAULT",
        "properties": ["name"],
        "primary_keys": ["name"],
        "nullable_keys": [],
        "enable_label_index": True
    }
    code, res = Schema().create_vertexLabel(body, auth=auth)
    assert code == 201

    # get all vertexLabel
    code, res = Schema().get_vertexLabel(auth=auth)
    print(code, res)
    assert code == 200
    assert len(res['vertexlabels']) == 2
    assert res['vertexlabels'][0]['name'] == 'test'
    assert res['vertexlabels'][1]['name'] == 'person'
Ejemplo n.º 20
0
def test_delete_vertexlabel_by_name():
    """
    删除vertexLabel 通过name
    """
    init_graph()
    property_name = "person"
    body = {
        "name": property_name,
        "id_strategy": "DEFAULT",
        "properties": ["name"],
        "primary_keys": ["name"],
        "nullable_keys": [],
        "enable_label_index": True
    }
    code, res = Schema().create_vertexLabel(body, auth=auth)
    assert code == 201

    # delete vertexLabel by name
    code, res = Schema().delete_vertexLabel(property_name, auth=auth)
    print(code, res)
    assert code == 202

    res = get_task_res(res['task_id'], 60, auth=auth)
    print(res)
Ejemplo n.º 21
0
def test_create_vertexlabel_automatic_id():
    """
    ID为主键类型
    """
    body = {
        "name": "person",
        "id_strategy": "AUTOMATIC",
        "properties": ["name", "age"],
        "nullable_keys": [],
        "enable_label_index": True
    }
    if init_graph():
        code, res = Schema().create_vertexLabel(body, auth=auth)
        assert code == 201
        assert res['status'] == 'CREATED'
        assert res['id_strategy'] == 'AUTOMATIC'
    else:
        print('环境初始化失败')
        assert 0
Ejemplo n.º 22
0
def test_create_vertexlabel_primaryKey_id():
    """
    ID为主键类型
    """
    body = {
        "name": "person",
        "id_strategy": "PRIMARY_KEY",
        "properties": ["name"],
        "primary_keys": ["name"],
        "nullable_keys": [],
        "enable_label_index": True
    }
    if init_graph():
        code, res = Schema().create_vertexLabel(body, auth=auth)
        assert code == 201
        assert res['status'] == 'CREATED'
        assert res['id_strategy'] == 'PRIMARY_KEY'
    else:
        print('环境初始化失败')
        assert 0
Ejemplo n.º 23
0
def test_create_vertexlabel_customize_string_id():
    """
    ID为主键类型
    """
    body = {
        "name": "person",
        "id_strategy": "CUSTOMIZE_STRING",
        "properties": ["name", "age"],
        "nullable_keys": [],
        "enable_label_index": True
    }
    if init_graph():
        code, res = Schema().create_vertexLabel(body, auth=auth)
        print(code, res)
        assert code == 201
        assert res['status'] == 'CREATED'
        assert res['id_strategy'] == 'CUSTOMIZE_STRING'
    else:
        print('环境初始化失败')
        assert 0
Ejemplo n.º 24
0
def test_get_indexlabel_by_name():
    """
    根据name查询vertexlabel
    """
    init_graph()
    query = "graph.schema().propertyKey('name').asText().ifNotExist().create();" \
            "graph.schema().propertyKey('age').asInt().ifNotExist().create();" \
            "graph.schema().propertyKey('date').asDate().ifNotExist().create();" \
            "graph.schema().vertexLabel('person').properties('name', 'age')" \
            ".primaryKeys('name').ifNotExist().create();"\
            "graph.schema().edgeLabel('knows').sourceLabel('person').targetLabel('person')" \
            ".properties('date').ifNotExist().create();" \
            "graph.schema().indexLabel('rangeByAgeByVertex').onV('person').by('age').range().ifNotExist().create();"
    code, res = Gremlin().gremlin_post(query, auth=auth)
    assert code == 200

    index_name = 'rangeByAgeByVertex'
    code, res = Schema().get_index_by_name(index_name, auth=auth)
    print(code, res)
    assert code == 200
    assert res['name'] == 'rangeByAgeByVertex'
Ejemplo n.º 25
0
def test_get_all_indexlabels():
    """
    查询所有vertexlabels
    """
    init_graph()
    query = "graph.schema().propertyKey('name').asText().ifNotExist().create();" \
            "graph.schema().propertyKey('age').asInt().ifNotExist().create();" \
            "graph.schema().propertyKey('date').asDate().ifNotExist().create();" \
            "graph.schema().vertexLabel('person').properties('name', 'age')" \
            ".primaryKeys('name').ifNotExist().create();" \
            "graph.schema().edgeLabel('knows').sourceLabel('person').targetLabel('person')" \
            ".properties('date').ifNotExist().create();" \
            "graph.schema().indexLabel('rangeByAgeByVertex').onV('person').by('age').range().ifNotExist().create();"
    code, res = Gremlin().gremlin_post(query, auth=auth)
    assert code == 200

    code, res = Schema().get_index(auth=auth)
    print(code, res)
    assert code == 200
    assert len(res['indexlabels']) == 1
    assert res['indexlabels'][0]['name'] == 'rangeByAgeByVertex'
Ejemplo n.º 26
0
def test_create_edgeLabel_int_link_int():
    """
    无属性
    """
    body = {
        "name": "link",
        "source_label": "person_age",
        "target_label": "person_age",
        "frequency": "SINGLE",
        "properties": [],
        "sort_keys": [],
        "nullable_keys": [],
        "enable_label_index": True
    }
    if init_graph():
        code, res = Schema().create_edgeLabel(body, auth=auth)
        assert code == 201
        assert res['status'] == 'CREATED'
        assert res['properties'] == []
    else:
        print('环境初始化失败')
        assert 0