當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。