From f95140338bacea9afcc6f23de190b7f786211de1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Wa=C5=9Bko?= Date: Fri, 8 Dec 2023 15:16:29 +0100 Subject: [PATCH] add a conversion, add one more edge case test --- .../0.0.0-dev/src/Network/URI_With_Query.enso | 3 +++ test/Tests/src/Network/Http_Spec.enso | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/URI_With_Query.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/URI_With_Query.enso index 3be7d50aab1c..0fa4c1cb7be0 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/URI_With_Query.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/URI_With_Query.enso @@ -125,3 +125,6 @@ build_java_uri_with_parameters java_uri java_params = Panic.catch URISyntaxException (URIHelpers.addQueryParameters java_uri java_params) caught_panic-> message = caught_panic.payload.getMessage Error.throw (Syntax_Error.Error "Unable to collapse to a URI: "+message) + +## PRIVATE +URI.from (that : URI_With_Query) = that.to_uri diff --git a/test/Tests/src/Network/Http_Spec.enso b/test/Tests/src/Network/Http_Spec.enso index c789c6814ae0..1a8c4bd5c5e4 100644 --- a/test/Tests/src/Network/Http_Spec.enso +++ b/test/Tests/src/Network/Http_Spec.enso @@ -9,6 +9,7 @@ import Standard.Base.Network.HTTP.Response.Response import Standard.Base.Network.HTTP.Request_Body.Request_Body import Standard.Base.Network.HTTP.Request_Error import Standard.Base.Network.Proxy.Proxy +import Standard.Base.Network.URI_With_Query.URI_With_Query import Standard.Base.Runtime.Context from Standard.Base.Network.HTTP import resolve_headers @@ -104,7 +105,7 @@ spec = } response . should_equal expected_response - uri_response = url_get.to_uri.fetch + uri_response = url_get.to URI . fetch uri_response . should_equal expected_response Test.specify "Can perform a HEAD" <| @@ -354,17 +355,29 @@ spec = r1.catch.status_code.code . should_equal 405 r1.catch.to_display_text . should_contain "status 405" - r2 = Data.post (base_url_with_slash + "some/unknown/path") + uri2 = URI.from (base_url_with_slash + "some/unknown/path") + r2 = Data.post uri2 r2.should_fail_with HTTP_Error r2.catch.should_be_a HTTP_Error.Status_Error r2.catch.status_code.code . should_equal 404 r2.catch.message . should_contain "

404 Not Found

" + r2.catch.uri . should_equal uri2 r3 = HTTP.new.request (Request.new (HTTP_Method.Custom "BREW_COFFEE") (base_url_with_slash + "get")) r3.should_fail_with HTTP_Error r3.catch.should_be_a HTTP_Error.Status_Error r3.catch.status_code.code . should_equal 400 + # Also test the URI_With_Query variant + uri4 = uri2.add_query_argument "a" "b" . add_query_argument "c" "d" + uri4.should_be_a URI_With_Query + r4 = uri4.fetch + r4.should_fail_with HTTP_Error + r4.catch.should_be_a HTTP_Error.Status_Error + r4.catch.status_code.code . should_equal 404 + # The error may not necessarily store the URI_With_Query but a raw URI: + r4.catch.uri . should_equal (URI.from uri4) + Test.specify "Cannot perform POST when output context is disabled" <| Context.Output.with_disabled <| Data.post url_post (Request_Body.Text "hello world") . should_fail_with Forbidden_Operation