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


Python testing.FlaskClient方法代码示例

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


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

示例1: test_cli_runner

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [as 别名]
def test_cli_runner(self, **kwargs):
        """Create a CLI runner for testing CLI commands.
        See :ref:`testing-cli`.

        Returns an instance of :attr:`test_cli_runner_class`, by default
        :class:`~flask.testing.FlaskCliRunner`. The Flask app object is
        passed as the first argument.

        .. versionadded:: 1.0
        """
        cls = self.test_cli_runner_class

        if cls is None:
            from flask.testing import FlaskCliRunner as cls

        return cls(self, **kwargs) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:app.py

示例2: _find_error_handler

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [as 别名]
def _find_error_handler(self, e):
        """Return a registered error handler for an exception in this order:
        blueprint handler for a specific code, app handler for a specific code,
        blueprint handler for an exception class, app handler for an exception
        class, or ``None`` if a suitable handler is not found.
        """
        exc_class, code = self._get_exc_class_and_code(type(e))

        for name, c in (
            (request.blueprint, code), (None, code),
            (request.blueprint, None), (None, None)
        ):
            handler_map = self.error_handler_spec.setdefault(name, {}).get(c)

            if not handler_map:
                continue

            for cls in exc_class.__mro__:
                handler = handler_map.get(cls)

                if handler is not None:
                    return handler 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:app.py

示例3: test_post_block_return_block_id

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [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

示例4: test_post_node

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [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

示例5: test_post_node_connection_error

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [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

示例6: test_post_node_status_not_200

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [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

示例7: test_prevent_hack_and_slash_when_dead

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [as 别名]
def test_prevent_hack_and_slash_when_dead(
        fx_test_client: FlaskClient, fx_session: Session, fx_user: User,
        fx_private_key: PrivateKey, fx_novice_status: typing.Dict[str, str],
):
    move = fx_user.create_novice(fx_novice_status)
    Block.create(fx_user, [move])

    assert fx_user.avatar().dead is False
    while fx_user.avatar().hp > 0:
        move = fx_user.hack_and_slash()
        Block.create(fx_user, [move])
    assert fx_user.avatar().dead is True

    response = fx_test_client.post('/session_moves', data={
        'name': 'hack_and_slash'
    })
    assert response.status_code == 302 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:19,代码来源:game_test.py

示例8: test_client

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [as 别名]
def test_client(self):
        """Creates a test client for this application.  For information
        about unit testing head over to :ref:`testing`.

        The test client can be used in a `with` block to defer the closing down
        of the context until the end of the `with` block.  This is useful if
        you want to access the context locals for testing::

            with app.test_client() as c:
                rv = c.get('/?vodka=42')
                assert request.args['vodka'] == '42'

        .. versionchanged:: 0.4
           added support for `with` block usage for the client.
        """
        from flask.testing import FlaskClient
        return FlaskClient(self, self.response_class, use_cookies=True) 
开发者ID:hhstore,项目名称:annotated-py-projects,代码行数:19,代码来源:app.py

示例9: client

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [as 别名]
def client(app: Flask) -> FlaskClient:
    return app.test_client() 
开发者ID:Kartones,项目名称:flask-calendar,代码行数:4,代码来源:conftest.py

示例10: test_login_credentials

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [as 别名]
def test_login_credentials(client: FlaskClient, username: str, password: str, success: bool) -> None:
    response = client.post("/do_login", data=dict(username=username, password=password))
    assert response.status_code == 302
    if success:
        assert response.headers["Location"] == "http://localhost/"
    else:
        assert response.headers["Location"] == "http://localhost/login" 
开发者ID:Kartones,项目名称:flask-calendar,代码行数:9,代码来源:test_app.py

示例11: test_session_id_cookie_set_when_logged_in

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [as 别名]
def test_session_id_cookie_set_when_logged_in(client: FlaskClient, username: str, password: str, success: bool) -> None:
    response = client.post("/do_login", data=dict(username=username, password=password))
    assert response.status_code == 302
    cookie = next((c for c in client.cookie_jar), None)
    if cookie is not None:
        assert success and cookie.name == SESSION_ID
    else:
        assert not success and cookie is None 
开发者ID:Kartones,项目名称:flask-calendar,代码行数:10,代码来源:test_app.py

示例12: test_redirects_to_calendar_when_logged_in

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [as 别名]
def test_redirects_to_calendar_when_logged_in(client: FlaskClient) -> None:
    client.post("/do_login", data=dict(username="a_username", password="a_password"))
    response = client.get("/")
    assert response.status_code == 302
    assert response.headers["Location"] == "http://localhost/sample/" 
开发者ID:Kartones,项目名称:flask-calendar,代码行数:7,代码来源:test_app.py

示例13: _find_error_handler

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [as 别名]
def _find_error_handler(self, e):
        """Finds a registered error handler for the request’s blueprint.
        Otherwise falls back to the app, returns None if not a suitable
        handler is found.
        """
        exc_class, code = self._get_exc_class_and_code(type(e))

        def find_handler(handler_map):
            if not handler_map:
                return
            for cls in exc_class.__mro__:
                handler = handler_map.get(cls)
                if handler is not None:
                    # cache for next time exc_class is raised
                    handler_map[exc_class] = handler
                    return handler

        # try blueprint handlers
        handler = find_handler(self.error_handler_spec
                               .get(request.blueprint, {})
                               .get(code))
        if handler is not None:
            return handler

        # fall back to app handlers
        return find_handler(self.error_handler_spec[None].get(code)) 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:28,代码来源:app.py

示例14: test_post_node_400

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [as 别名]
def test_post_node_400(fx_test_client: FlaskClient):
    res = fx_test_client.post('/nodes', data={})
    assert res.status_code == 400
    data = json.loads(res.get_data())
    assert data['result'] == 'failed'
    assert data['message'] == 'Invalid parameter.'

    url = 'http://test.neko'
    res = fx_test_client.post('/nodes', data=json.dumps({'url': url}))
    assert res.status_code == 400
    data = json.loads(res.get_data())
    assert data['result'] == 'failed'
    assert data['message'] == 'Invalid parameter.' 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:15,代码来源:api_test.py

示例15: test_get_moves_no_result

# 需要导入模块: from flask import testing [as 别名]
# 或者: from flask.testing import FlaskClient [as 别名]
def test_get_moves_no_result(fx_test_client: FlaskClient):
    res = fx_test_client.get('/moves/0')
    assert res.status_code == 404 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:5,代码来源:api_test.py


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