当前位置: 首页>>代码示例>>Python>>正文


Python scoping.scoped_session方法代码示例

本文整理汇总了Python中sqlalchemy.orm.scoping.scoped_session方法的典型用法代码示例。如果您正苦于以下问题:Python scoping.scoped_session方法的具体用法?Python scoping.scoped_session怎么用?Python scoping.scoped_session使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.orm.scoping的用法示例。


在下文中一共展示了scoping.scoped_session方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: apply_filter

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def apply_filter(object_id: str, search_props: Dict[str, Any],
                 triples: Graph, session: scoped_session) -> bool:
    """Check whether objects has properties with query values or not.
    :param object_id: Id of the instance.
    :param search_props: Dictionary of query parameters with property id and values.
    :param triples: All triples.
    :param session: sqlalchemy scoped session.
    :return: True if the instance has properties with given values, False otherwise.
    """
    for prop in search_props:
        # For nested properties
        if isinstance(search_props[prop], dict):
            data = session.query(triples).filter(
                triples.GraphIII.subject == object_id, triples.GraphIII.predicate == prop).one()
            if apply_filter(data.object_, search_props[prop], triples, session) is False:
                return False
        else:
            data = session.query(triples).filter(
                triples.GraphIIT.subject == object_id, triples.GraphIIT.predicate == prop).one()
            terminal = session.query(Terminal).filter(
                Terminal.id == data.object_).one()
            if terminal.value != search_props[prop]:
                return False
    return True 
开发者ID:HTTP-APIs,项目名称:hydrus,代码行数:26,代码来源:crud_helpers.py

示例2: insert_single

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def insert_single(object_: Dict[str, Any], session: scoped_session) -> Any:
    """Insert instance of classes with single objects.
    :param object_: object to be inserted
    :param session: sqlalchemy scoped session
    :return:

    Raises:
        ClassNotFound: If `type_` does not represt a valid/defined RDFClass.
        Instance: If an Instance of type `type_` already exists.

    """
    try:
        rdf_class = session.query(RDFClass).filter(
            RDFClass.name == object_["@type"]).one()
    except NoResultFound:
        raise ClassNotFound(type_=object_["@type"])

    try:
        session.query(Instance).filter(
            Instance.type_ == rdf_class.id).all()[-1]
    except (NoResultFound, IndexError, ValueError):
        return insert(object_, session=session)

    raise InstanceExists(type_=rdf_class.name) 
开发者ID:HTTP-APIs,项目名称:hydrus,代码行数:26,代码来源:crud.py

示例3: delete_single

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def delete_single(type_: str, session: scoped_session) -> None:
    """Delete instance of classes with single objects.
    :param type_: type of object to be deleted
    :param session: sqlalchemy scoped session
    :return: None

    Raises:
        ClassNotFound: If `type_` does not represt a valid/defined RDFClass.
        InstanceNotFound: If no Instance of the class exists.

    """
    try:
        rdf_class = session.query(RDFClass).filter(
            RDFClass.name == type_).one()
    except NoResultFound:
        raise ClassNotFound(type_=type_)

    try:
        instance = session.query(Instance).filter(
            Instance.type_ == rdf_class.id).all()[-1]
    except (NoResultFound, IndexError, ValueError):
        raise InstanceNotFound(type_=rdf_class.name)

    return delete(instance.id, type_, session=session) 
开发者ID:HTTP-APIs,项目名称:hydrus,代码行数:26,代码来源:crud.py

示例4: test_post_block_return_block_id

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def test_post_block_return_block_id(fx_test_client: FlaskClient,
                                    fx_user: User,
                                    fx_session: scoped_session):
    block = Block.create(fx_user, [])
    fx_session.add(block)
    fx_session.commit()
    block2 = Block.create(fx_user, [])
    des = block2.serialize(use_bencode=False,
                           include_suffix=True,
                           include_moves=True,
                           include_hash=True)
    des['id'] = 3
    resp = fx_test_client.post('/blocks', data=json.dumps(des),
                               content_type='application/json')
    assert resp.status_code == 403
    data = json.loads(resp.get_data())
    assert data['result'] == 'failed'
    assert data['message'] == "new block isn't our next block."
    assert data['block_id'] == 2 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:21,代码来源:api_test.py

示例5: test_post_node

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def test_post_node(fx_test_client: FlaskClient, fx_session: scoped_session):
    url = 'http://test.neko'
    assert not fx_session.query(Node).first()
    with Mocker() as m:
        m.get(url + '/ping', text='pong')
        res = fx_test_client.post(
            '/nodes',
            data=json.dumps({'url': url}),
            content_type='application/json'
        )
        assert res.status_code == 200
        assert json.loads(res.get_data())['result'] == 'success'
        node = fx_session.query(Node).filter(
            Node.url == url
        ).first()
        assert node
        assert node.last_connected_at 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:19,代码来源:api_test.py

示例6: test_post_node_connection_error

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def test_post_node_connection_error(fx_test_client: FlaskClient,
                                    fx_session: scoped_session):
    url = 'http://test.neko'
    assert not fx_session.query(Node).first()
    with Mocker() as m:
        m.get(url + '/ping', exc=ConnectionError)
        res = fx_test_client.post(
            '/nodes',
            data=json.dumps({'url': url}),
            content_type='application/json'
        )
        assert res.status_code == 403
        data = json.loads(res.get_data())
        assert data['result'] == 'failed'
        assert data['message'] == f'Connection to node {url} was failed.'
        assert not fx_session.query(Node).filter(
            Node.url == url
        ).first() 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:20,代码来源:api_test.py

示例7: test_post_node_status_not_200

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def test_post_node_status_not_200(fx_test_client: FlaskClient,
                                  fx_session: scoped_session,
                                  code: int):
    url = 'http://test.neko'
    assert not fx_session.query(Node).first()
    with Mocker() as m:
        m.get(url + '/ping', text='pong', status_code=code)
        res = fx_test_client.post(
            '/nodes',
            data=json.dumps({'url': url}),
            content_type='application/json'
        )
        assert res.status_code == 403
        data = json.loads(res.get_data())
        assert data['result'] == 'failed'
        assert data['message'] == f'Connection to node {url} was failed.'
        assert not fx_session.query(Node).filter(
            Node.url == url
        ).first() 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:21,代码来源:api_test.py

示例8: test_broadcast_node

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def test_broadcast_node(
        fx_server: WSGIServer,
        fx_session: scoped_session,
        fx_other_server: WSGIServer,
        fx_other_session: Session,
):
    now = datetime.datetime.utcnow()
    node = Node(url=fx_server.url,
                last_connected_at=now)
    node2 = Node(url=fx_other_server.url,
                 last_connected_at=datetime.datetime.utcnow())
    fx_session.add(node)
    fx_session.commit()
    fx_other_session.add(node2)
    fx_other_session.commit()
    assert not fx_session.query(Node).filter(Node.url == node2.url).first()
    multicast(serialized={'url': fx_other_server.url},
              broadcast=broadcast_node)
    assert fx_session.query(Node).filter(Node.url == node2.url).first()
    assert node.last_connected_at > now 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:22,代码来源:broadcast_test.py

示例9: broadcast_node_failed

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def broadcast_node_failed(fx_session: scoped_session,
                          fx_other_session: Session, error):
    now = datetime.datetime.utcnow()
    node = Node(url='http://test.neko',
                last_connected_at=now)
    node2 = Node(url='http://other.neko',
                 last_connected_at=datetime.datetime.utcnow())
    fx_session.add(node)
    fx_session.commit()
    fx_other_session.add(node2)
    fx_other_session.commit()
    assert not fx_session.query(Node).filter(Node.url == node2.url).first()
    with Mocker() as m:
        m.post('http://test.neko', exc=error)
        multicast(serialized={'url': fx_other_server.url},
                  broadcast=broadcast_node)
    assert not fx_session.query(Node).filter(Node.url == node2.url).first()
    assert node.last_connected_at == now 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:20,代码来源:broadcast_test.py

示例10: test_broadcast_block_my_node

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def test_broadcast_block_my_node(fx_session: scoped_session, fx_user: User):
    block = Block.create(fx_user, [])
    url = 'http://test.neko'
    now = datetime.datetime.utcnow()
    node = Node(url=url, last_connected_at=now)
    fx_session.add(node)
    fx_session.flush()
    with Mocker() as m:
        m.post('http://test.neko/blocks', text='success')
        expected = serialized = block.serialize(
            use_bencode=False,
            include_suffix=True,
            include_moves=True,
            include_hash=True
        )
        multicast(serialized=serialized, my_node=node,
                  broadcast=broadcast_block)
        expected['sent_node'] = url
        assert node.last_connected_at > now
        assert node.last_connected_at > now
        # check request.json value
        assert m.request_history[0].json() == expected 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:24,代码来源:broadcast_test.py

示例11: test_broadcast_block_same_node

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def test_broadcast_block_same_node(fx_session: scoped_session, fx_user: User):
    block = Block.create(fx_user, [])
    url = 'http://test.neko'
    now = datetime.datetime.utcnow()
    node = Node(url=url, last_connected_at=now)
    fx_session.add(node)
    fx_session.flush()
    multicast(
        serialized=block.serialize(
            use_bencode=False,
            include_suffix=True,
            include_moves=True,
            include_hash=True
        ),
        sent_node=node,
        broadcast=broadcast_block,
    )
    assert node.last_connected_at == now 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:20,代码来源:broadcast_test.py

示例12: test_broadcast_block_raise_exception

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def test_broadcast_block_raise_exception(
        fx_session: scoped_session, fx_user: User,
        error: typing.Union[ConnectionError, Timeout]
):
    block = Block.create(fx_user, [])
    url = 'http://test.neko'
    now = datetime.datetime.utcnow()
    node = Node(url=url, last_connected_at=now)
    fx_session.add(node)
    fx_session.flush()
    with Mocker() as m:
        m.post('http://test.neko/blocks', exc=error)
        multicast(
            serialized=block.serialize(
                use_bencode=False,
                include_suffix=True,
                include_moves=True,
                include_hash=True
            ),
            broadcast=broadcast_block,
        )
        assert node.last_connected_at == now 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:24,代码来源:broadcast_test.py

示例13: test_broadcast_move

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def test_broadcast_move(
        fx_server: WSGIServer,
        fx_session: scoped_session,
        fx_other_server: WSGIServer,
        fx_other_session: Session,
        fx_user: User,
        fx_novice_status: typing.Mapping[str, str],
):
    now = datetime.datetime.utcnow()
    node = Node(url=fx_server.url,
                last_connected_at=now)
    node2 = Node(url=fx_other_server.url,
                 last_connected_at=datetime.datetime.utcnow())
    move = fx_user.create_novice(fx_novice_status)
    fx_session.add_all([node, node2, move])
    fx_session.commit()
    assert not fx_other_session.query(Move).get(move.id)
    serialized = move.serialize(
        use_bencode=False,
        include_signature=True,
        include_id=True,
    )
    multicast(serialized=serialized, broadcast=broadcast_move)
    assert fx_other_session.query(Move).get(move.id)
    assert node.last_connected_at > now 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:27,代码来源:broadcast_test.py

示例14: test_broadcast_move_my_node

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def test_broadcast_move_my_node(fx_session: scoped_session,
                                fx_user: User,
                                fx_novice_status: typing.Mapping[str, str]):
    url = 'http://test.neko'
    now = datetime.datetime.utcnow()
    node = Node(url=url, last_connected_at=now)
    move = fx_user.create_novice(fx_novice_status)
    fx_session.add_all([node, move])
    fx_session.commit()
    with Mocker() as m:
        m.post('http://test.neko/moves', json={'result': 'success'})
        expected = serialized = move.serialize(
            use_bencode=False,
            include_signature=True,
            include_id=True,
        )
        multicast(serialized=serialized, my_node=node,
                  broadcast=broadcast_move)
        expected['sent_node'] = 'http://test.neko'
        assert node.last_connected_at > now
        # check request.json value
        assert m.request_history[0].json() == expected 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:24,代码来源:broadcast_test.py

示例15: broadcast_move_failed

# 需要导入模块: from sqlalchemy.orm import scoping [as 别名]
# 或者: from sqlalchemy.orm.scoping import scoped_session [as 别名]
def broadcast_move_failed(fx_session: scoped_session,
                          fx_user: User,
                          fx_novice_status: typing.Mapping[str, str],
                          error):
    now = datetime.datetime.utcnow()
    move = fx_user.create_novice(fx_novice_status)
    node = Node(url='http://test.neko',
                last_connected_at=now)
    fx_session.add_all([node, move])
    fx_session.commit()
    with Mocker() as m:
        serialized = move.serialize(
            use_bencode=False,
            include_signature=True,
            include_id=True,
        )
        m.post('http://test.neko', exc=error)
        multicast(serialized=serialized, broadcast=broadcast_move)
    assert node.last_connected_at == now 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:21,代码来源:broadcast_test.py


注:本文中的sqlalchemy.orm.scoping.scoped_session方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。