mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-12-05 00:02:12 -05:00
regressions for bugs fixed in 0.14.2 and 0.14.1
This commit is contained in:
parent
c9427ca21f
commit
dbea29cca8
32
regression_tests/bug_0_14_1_test.rb
Normal file
32
regression_tests/bug_0_14_1_test.rb
Normal file
@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
require "support/http_helpers"
|
||||
|
||||
class Bug_0_14_1_Test < Minitest::Test
|
||||
include HTTPHelpers
|
||||
|
||||
def test_multipart_can_have_arbitrary_conntent_type
|
||||
uri = "https://#{httpbin}/post"
|
||||
|
||||
response = HTTPX.plugin(:multipart)
|
||||
.post(uri, form: {
|
||||
image: {
|
||||
content_type: "image/png",
|
||||
body: File.new(fixture_file_path),
|
||||
},
|
||||
})
|
||||
verify_status(response, 200)
|
||||
body = json_body(response)
|
||||
verify_header(body["headers"], "Content-Type", "multipart/form-data")
|
||||
# can't really test the filename, but if it's in the files field,
|
||||
# then it was a file upload
|
||||
verify_uploaded_image(body, "image", "image/png")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def origin(orig = httpbin)
|
||||
"http://#{orig}"
|
||||
end
|
||||
end
|
||||
32
regression_tests/bug_0_14_2_test.rb
Normal file
32
regression_tests/bug_0_14_2_test.rb
Normal file
@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
require "support/http_helpers"
|
||||
|
||||
class Bug_0_14_2_Test < Minitest::Test
|
||||
include HTTPHelpers
|
||||
|
||||
def test_multipart_can_have_arbitrary_filename
|
||||
uri = "https://#{httpbin}/post"
|
||||
|
||||
response = HTTPX.plugin(:multipart)
|
||||
.post(uri, form: {
|
||||
image: {
|
||||
filename: "weird-al-jankovic",
|
||||
body: File.new(fixture_file_path),
|
||||
},
|
||||
})
|
||||
verify_status(response, 200)
|
||||
body = json_body(response)
|
||||
verify_header(body["headers"], "Content-Type", "multipart/form-data")
|
||||
# can't really test the filename, but if it's in the files field,
|
||||
# then it was a file upload
|
||||
verify_uploaded_image(body, "image", "image/jpeg")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def origin(orig = httpbin)
|
||||
"http://#{orig}"
|
||||
end
|
||||
end
|
||||
@ -64,4 +64,31 @@ module ResponseHelpers
|
||||
raise "unexpected expectation (#{expectation})"
|
||||
end
|
||||
end
|
||||
|
||||
# test files
|
||||
|
||||
def verify_uploaded_image(body, key, mime_type, skip_verify_data: false)
|
||||
assert body.key?("files"), "there were no files uploaded"
|
||||
assert body["files"].key?(key), "there is no image in the file"
|
||||
# checking mime-type is a bit leaky, as httpbin displays the base64-encoded data
|
||||
return if skip_verify_data
|
||||
|
||||
assert body["files"][key].start_with?("data:#{mime_type}"), "data was wrongly encoded (#{body["files"][key][0..64]})"
|
||||
end
|
||||
|
||||
def fixture
|
||||
File.read(fixture_file_path, encoding: Encoding::BINARY)
|
||||
end
|
||||
|
||||
def fixture_name
|
||||
File.basename(fixture_file_path)
|
||||
end
|
||||
|
||||
def fixture_file_name
|
||||
"image.jpg"
|
||||
end
|
||||
|
||||
def fixture_file_path
|
||||
File.join("test", "support", "fixtures", fixture_file_name)
|
||||
end
|
||||
end
|
||||
|
||||
@ -219,31 +219,6 @@ module Requests
|
||||
assert check_error[retries_response], "expected #{retries_response} to be an error response"
|
||||
assert retries_session.calls == 1, "expect request to be retried 1 time (was #{retries_session.calls})"
|
||||
end
|
||||
|
||||
def fixture
|
||||
File.read(fixture_file_path, encoding: Encoding::BINARY)
|
||||
end
|
||||
|
||||
def fixture_name
|
||||
File.basename(fixture_file_path)
|
||||
end
|
||||
|
||||
def fixture_file_name
|
||||
"image.jpg"
|
||||
end
|
||||
|
||||
def fixture_file_path
|
||||
File.join("test", "support", "fixtures", fixture_file_name)
|
||||
end
|
||||
|
||||
def verify_uploaded_image(body, key, mime_type, skip_verify_data: false)
|
||||
assert body.key?("files"), "there were no files uploaded"
|
||||
assert body["files"].key?(key), "there is no image in the file"
|
||||
# checking mime-type is a bit leaky, as httpbin displays the base64-encoded data
|
||||
return if skip_verify_data
|
||||
|
||||
assert body["files"][key].start_with?("data:#{mime_type}"), "data was wrongly encoded (#{body["files"][key][0..64]})"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user