Ejemplo n.º 1
0
def test_get_rest_flattened():
    client = RoutesClient(credentials=ga_credentials.AnonymousCredentials(),)

    # Mock the http request call within the method and fake a response.
    with mock.patch.object(Session, "request") as req:
        # Designate an appropriate value for the returned response.
        return_value = compute.Route()

        # Wrap the value into a proper Response obj
        json_return_value = compute.Route.to_json(return_value)
        response_value = Response()
        response_value.status_code = 200
        response_value._content = json_return_value.encode("UTF-8")
        req.return_value = response_value

        # Call the method with a truthy value for each flattened field,
        # using the keyword arguments to the method.
        client.get(
            project="project_value", route="route_value",
        )

        # Establish that the underlying call was made with the expected
        # request object values.
        assert len(req.mock_calls) == 1
        _, http_call, http_params = req.mock_calls[0]
        body = http_params.get("data")
        assert "project_value" in http_call[1] + str(body)
        assert "route_value" in http_call[1] + str(body)
Ejemplo n.º 2
0
def test_get_rest_flattened_error():
    client = RoutesClient(credentials=ga_credentials.AnonymousCredentials(),)

    # Attempting to call a method with both a request object and flattened
    # fields is an error.
    with pytest.raises(ValueError):
        client.get(
            compute.GetRouteRequest(), project="project_value", route="route_value",
        )
Ejemplo n.º 3
0
def test_get_rest(transport: str = "rest", request_type=compute.GetRouteRequest):
    client = RoutesClient(
        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = request_type()

    # Mock the http request call within the method and fake a response.
    with mock.patch.object(Session, "request") as req:
        # Designate an appropriate value for the returned response.
        return_value = compute.Route(
            creation_timestamp="creation_timestamp_value",
            description="description_value",
            dest_range="dest_range_value",
            id="id_value",
            kind="kind_value",
            name="name_value",
            network="network_value",
            next_hop_gateway="next_hop_gateway_value",
            next_hop_ilb="next_hop_ilb_value",
            next_hop_instance="next_hop_instance_value",
            next_hop_ip="next_hop_ip_value",
            next_hop_network="next_hop_network_value",
            next_hop_peering="next_hop_peering_value",
            next_hop_vpn_tunnel="next_hop_vpn_tunnel_value",
            priority=898,
            self_link="self_link_value",
            tags=["tags_value"],
            warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)],
        )

        # Wrap the value into a proper Response obj
        json_return_value = compute.Route.to_json(return_value)
        response_value = Response()
        response_value.status_code = 200
        response_value._content = json_return_value.encode("UTF-8")
        req.return_value = response_value
        response = client.get(request)

    # Establish that the response is the type that we expect.
    assert isinstance(response, compute.Route)
    assert response.creation_timestamp == "creation_timestamp_value"
    assert response.description == "description_value"
    assert response.dest_range == "dest_range_value"
    assert response.id == "id_value"
    assert response.kind == "kind_value"
    assert response.name == "name_value"
    assert response.network == "network_value"
    assert response.next_hop_gateway == "next_hop_gateway_value"
    assert response.next_hop_ilb == "next_hop_ilb_value"
    assert response.next_hop_instance == "next_hop_instance_value"
    assert response.next_hop_ip == "next_hop_ip_value"
    assert response.next_hop_network == "next_hop_network_value"
    assert response.next_hop_peering == "next_hop_peering_value"
    assert response.next_hop_vpn_tunnel == "next_hop_vpn_tunnel_value"
    assert response.priority == 898
    assert response.self_link == "self_link_value"
    assert response.tags == ["tags_value"]
    assert response.warnings == [
        compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)
    ]