Skip to content

Commit

Permalink
add a conversion, add one more edge case test
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Dec 15, 2023
1 parent addd10b commit f951403
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 15 additions & 2 deletions test/Tests/src/Network/Http_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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" <|
Expand Down Expand Up @@ -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 "<h1>404 Not Found</h1>"
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
Expand Down

0 comments on commit f951403

Please sign in to comment.