當前位置: 首頁>>代碼示例>>Python>>正文


Python testing.DummyRequest方法代碼示例

本文整理匯總了Python中pyramid.testing.DummyRequest方法的典型用法代碼示例。如果您正苦於以下問題:Python testing.DummyRequest方法的具體用法?Python testing.DummyRequest怎麽用?Python testing.DummyRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyramid.testing的用法示例。


在下文中一共展示了testing.DummyRequest方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_add_explorer_view

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_add_explorer_view() -> None:
    """Test registration of a view serving the Swagger UI."""
    with testConfig() as config:
        config.include("pyramid_openapi3")

        with tempfile.NamedTemporaryFile() as document:
            document.write(MINIMAL_DOCUMENT)
            document.seek(0)

            config.pyramid_openapi3_spec(
                document.name, route="/foo.yaml", route_name="foo_api_spec"
            )

        config.pyramid_openapi3_add_explorer()
        request = config.registry.queryUtility(
            IRouteRequest, name="pyramid_openapi3.explorer"
        )
        view = config.registry.adapters.registered(
            (IViewClassifier, request, Interface), IView, name=""
        )
        response = view(request=DummyRequest(config=config), context=None)
        assert b"<title>Swagger UI</title>" in response.body 
開發者ID:Pylons,項目名稱:pyramid_openapi3,代碼行數:24,代碼來源:test_views.py

示例2: test_explorer_view_missing_spec

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_explorer_view_missing_spec() -> None:
    """Test graceful failure if explorer view is not registered."""
    with testConfig() as config:
        config.include("pyramid_openapi3")
        config.pyramid_openapi3_add_explorer()

        request = config.registry.queryUtility(
            IRouteRequest, name="pyramid_openapi3.explorer"
        )
        view = config.registry.adapters.registered(
            (IViewClassifier, request, Interface), IView, name=""
        )
        with pytest.raises(
            ConfigurationError,
            match="You need to call config.pyramid_openapi3_spec for explorer to work.",
        ):
            view(request=DummyRequest(config=config), context=None) 
開發者ID:Pylons,項目名稱:pyramid_openapi3,代碼行數:19,代碼來源:test_views.py

示例3: test_resources_with_path_prefix_with_trailing_slash

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_resources_with_path_prefix_with_trailing_slash(self):
        from nefertari.resource import add_resource_routes
        add_resource_routes(
            self.config,
            DummyCrudView,
            'message',
            'messages',
            path_prefix='/category/{category_id}/'
        )

        self.assertEqual(
            '/category/2/messages',
            route_path('messages', testing.DummyRequest(), category_id=2)
        )
        self.assertEqual(
            '/category/2/messages/1',
            route_path('message', testing.DummyRequest(), id=1, category_id=2)
        ) 
開發者ID:ramses-tech,項目名稱:nefertari,代碼行數:20,代碼來源:test_resource.py

示例4: test_instance_delay

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_instance_delay(mock_load_config, mock_get_app_queue):
    mock_unused_offers = mock.Mock()
    mock_unused_offers.last_unused_offers = [
        {"reason": ["foo", "bar"]},
        {"reason": ["bar", "baz"]},
        {"reason": []},
    ]
    mock_get_app_queue.return_value = mock_unused_offers

    mock_config = mock.Mock()
    mock_config.format_marathon_app_dict = lambda: {"id": "foo"}
    mock_load_config.return_value = mock_config

    request = testing.DummyRequest()
    request.swagger_data = {"service": "fake_service", "instance": "fake_instance"}

    response = instance.instance_delay(request)
    assert response["foo"] == 1
    assert response["bar"] == 2
    assert response["baz"] == 1 
開發者ID:Yelp,項目名稱:paasta,代碼行數:22,代碼來源:test_instance.py

示例5: test_update_autoscaler_count_marathon

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_update_autoscaler_count_marathon(mock_get_instance_config):
    request = testing.DummyRequest()
    request.swagger_data = {
        "service": "fake_marathon_service",
        "instance": "fake_marathon_instance",
        "json_body": {"desired_instances": 123},
    }

    mock_get_instance_config.return_value = mock.MagicMock(
        get_min_instances=mock.MagicMock(return_value=100),
        get_max_instances=mock.MagicMock(return_value=200),
        spec=MarathonServiceConfig,
    )

    response = autoscaler.update_autoscaler_count(request)
    assert response.json_body["desired_instances"] == 123
    assert response.status_code == 202 
開發者ID:Yelp,項目名稱:paasta,代碼行數:19,代碼來源:test_autoscaler.py

示例6: test_update_autoscaler_count_warning

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_update_autoscaler_count_warning(mock_get_instance_config):
    request = testing.DummyRequest()
    request.swagger_data = {
        "service": "fake_service",
        "instance": "fake_instance",
        "json_body": {"desired_instances": 123},
    }

    mock_get_instance_config.return_value = mock.MagicMock(
        get_min_instances=mock.MagicMock(return_value=10),
        get_max_instances=mock.MagicMock(return_value=100),
        spec=KubernetesDeploymentConfig,
    )

    response = autoscaler.update_autoscaler_count(request)
    assert response.json_body["desired_instances"] == 100
    assert "WARNING" in response.json_body["status"] 
開發者ID:Yelp,項目名稱:paasta,代碼行數:19,代碼來源:test_autoscaler.py

示例7: test_list_services_for_cluster

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_list_services_for_cluster(mock_get_services_for_cluster,):
    fake_services_and_instances = [
        ("fake_service", "fake_instance_a"),
        ("fake_service", "fake_instance_b"),
        ("fake_service", "fake_instance_c"),
    ]
    mock_get_services_for_cluster.return_value = fake_services_and_instances

    request = testing.DummyRequest()

    response = list_services_for_cluster(request)
    assert response["services"] == [
        ("fake_service", "fake_instance_a"),
        ("fake_service", "fake_instance_b"),
        ("fake_service", "fake_instance_c"),
    ] 
開發者ID:Yelp,項目名稱:paasta,代碼行數:18,代碼來源:test_service.py

示例8: test_resources_utilization_nothing_special

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_resources_utilization_nothing_special(
    mock_get_mesos_master, mock_get_resource_utilization_by_grouping
):
    request = testing.DummyRequest()
    request.swagger_data = {"groupings": None, "filter": None}
    mock_mesos_state = mock.Mock()
    mock_master = mock.Mock(
        state=asynctest.CoroutineMock(return_value=mock_mesos_state)
    )
    mock_get_mesos_master.return_value = mock_master

    mock_get_resource_utilization_by_grouping.return_value = {
        frozenset([("superregion", "unknown")]): {
            "total": metastatus_lib.ResourceInfo(cpus=10.0, mem=512.0, disk=100.0),
            "free": metastatus_lib.ResourceInfo(cpus=8.0, mem=312.0, disk=20.0),
        }
    }

    resp = resources_utilization(request)
    body = json.loads(resp.body.decode("utf-8"))

    assert resp.status_int == 200
    assert len(body) == 1
    assert set(body[0].keys()) == {"disk", "mem", "groupings", "cpus", "gpus"} 
開發者ID:Yelp,項目名稱:paasta,代碼行數:26,代碼來源:test_resources.py

示例9: test_update_autoscaler_pause

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_update_autoscaler_pause():
    with mock.patch(
        "paasta_tools.utils.KazooClient", autospec=True
    ) as mock_zk, mock.patch(
        "paasta_tools.api.views.pause_autoscaler.time", autospec=True
    ) as mock_time, mock.patch(
        "paasta_tools.utils.load_system_paasta_config", autospec=True
    ):
        request = testing.DummyRequest()
        request.swagger_data = {"json_body": {"minutes": 100}}
        mock_zk_set = mock.Mock()
        mock_zk_ensure = mock.Mock()
        mock_zk.return_value = mock.Mock(set=mock_zk_set, ensure_path=mock_zk_ensure)

        mock_time.time = mock.Mock(return_value=0)

        response = pause_autoscaler.update_service_autoscaler_pause(request)
        assert mock_zk_ensure.call_count == 1
        mock_zk_set.assert_called_once_with("/autoscaling/paused", b"6000")
        assert response is None 
開發者ID:Yelp,項目名稱:paasta,代碼行數:22,代碼來源:test_pause_autoscaler.py

示例10: test_delete_autoscaler_pause

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_delete_autoscaler_pause():
    with mock.patch(
        "paasta_tools.utils.KazooClient", autospec=True
    ) as mock_zk, mock.patch(
        "paasta_tools.api.views.pause_autoscaler.time", autospec=True
    ) as mock_time, mock.patch(
        "paasta_tools.utils.load_system_paasta_config", autospec=True
    ):
        request = testing.DummyRequest()
        mock_zk_del = mock.Mock()
        mock_zk_ensure = mock.Mock()
        mock_zk.return_value = mock.Mock(delete=mock_zk_del, ensure_path=mock_zk_ensure)

        mock_time.time = mock.Mock(return_value=0)

        response = pause_autoscaler.delete_service_autoscaler_pause(request)
        assert mock_zk_ensure.call_count == 1
        mock_zk_del.assert_called_once_with("/autoscaling/paused")
        assert response is None 
開發者ID:Yelp,項目名稱:paasta,代碼行數:21,代碼來源:test_pause_autoscaler.py

示例11: test_add_formatter

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_add_formatter() -> None:
    """Test registration of a custom formatter."""

    with testConfig() as config:
        request = DummyRequest()

        config.include("pyramid_openapi3")
        config.pyramid_openapi3_add_formatter("foormatter", lambda x: x)

        formatter = request.registry.settings["pyramid_openapi3_formatters"].get(
            "foormatter", None
        )
        assert formatter("foo") == "foo" 
開發者ID:Pylons,項目名稱:pyramid_openapi3,代碼行數:15,代碼來源:test_add_formatter.py

示例12: test_openapi_view

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_openapi_view() -> None:
    """Test registration a an openapi view."""
    with testConfig() as config:
        config.include("pyramid_openapi3")

        with tempfile.NamedTemporaryFile() as document:
            document.write(MINIMAL_DOCUMENT)
            document.seek(0)

            config.pyramid_openapi3_spec(
                document.name, route="/foo.yaml", route_name="foo_api_spec"
            )

        config.add_route("foo", "/foo")
        view_func = lambda *arg: "bar"  # noqa: E731
        config.add_view(openapi=True, renderer="json", view=view_func, route_name="foo")

        request_interface = config.registry.queryUtility(IRouteRequest, name="foo")
        view = config.registry.adapters.registered(
            (IViewClassifier, request_interface, Interface), IView, name=""
        )
        request = DummyRequest(config=config, content_type="text/html")
        request.matched_route = DummyRoute(name="foo", pattern="/foo")
        context = None
        response = view(context, request)

        assert response.json == "bar" 
開發者ID:Pylons,項目名稱:pyramid_openapi3,代碼行數:29,代碼來源:test_views.py

示例13: test_mapped_values_request

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_mapped_values_request() -> None:
    """Test that values are correctly mapped from pyramid's Request."""

    pyramid_request = DummyRequest(path="/foo")
    pyramid_request.matched_route = DummyRoute(name="foo", pattern="/foo")
    pyramid_request.matchdict["foo"] = "bar"
    pyramid_request.headers["X-Foo"] = "Bar"
    pyramid_request.cookies["tasty-foo"] = "tasty-bar"
    pyramid_request.content_type = "text/html"

    assert pyramid_request.application_url == "http://example.com"
    assert pyramid_request.path_info == "/foo"
    assert pyramid_request.method == "GET"

    openapi_request = PyramidOpenAPIRequestFactory.create(pyramid_request)

    assert openapi_request.full_url_pattern == "http://example.com/foo"
    assert openapi_request.method == "get"
    assert openapi_request.body == ""
    assert openapi_request.mimetype == "text/html"
    assert openapi_request.parameters == RequestParameters(
        path={"foo": "bar"},
        query={},
        header={"X-Foo": "Bar"},
        cookie={"tasty-foo": "tasty-bar"},
    ) 
開發者ID:Pylons,項目名稱:pyramid_openapi3,代碼行數:28,代碼來源:test_wrappers.py

示例14: test_no_matched_route

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_no_matched_route() -> None:
    """Test path_pattern when no route is matched."""
    pyramid_request = DummyRequest(path="/foo")
    pyramid_request.matched_route = None
    pyramid_request.content_type = "text/html"

    openapi_request = PyramidOpenAPIRequestFactory.create(pyramid_request)
    assert openapi_request.full_url_pattern == "http://example.com/foo" 
開發者ID:Pylons,項目名稱:pyramid_openapi3,代碼行數:10,代碼來源:test_wrappers.py

示例15: test_mapped_values_response

# 需要導入模塊: from pyramid import testing [as 別名]
# 或者: from pyramid.testing import DummyRequest [as 別名]
def test_mapped_values_response() -> None:
    """Test that values are correctly mapped from pyramid's Response."""
    pyramid_request = DummyRequest()

    assert pyramid_request.response.body == b""
    assert pyramid_request.response.status_code == 200
    assert pyramid_request.response.content_type == "text/html"

    openapi_response = PyramidOpenAPIResponseFactory.create(pyramid_request.response)

    assert openapi_response.data == b""
    assert openapi_response.status_code == 200
    assert openapi_response.mimetype == "text/html" 
開發者ID:Pylons,項目名稱:pyramid_openapi3,代碼行數:15,代碼來源:test_wrappers.py


注:本文中的pyramid.testing.DummyRequest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。