mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-13 00:02:57 -04:00
added streaming plugin tests
This commit is contained in:
parent
a650e622ca
commit
1b29e062a0
@ -26,6 +26,7 @@ class HTTPTest < Minitest::Test
|
||||
include Plugins::Multipart
|
||||
include Plugins::Expect
|
||||
include Plugins::RateLimiter
|
||||
include Plugins::Stream
|
||||
|
||||
def test_verbose_log
|
||||
log = StringIO.new
|
||||
|
@ -27,6 +27,7 @@ class HTTPSTest < Minitest::Test
|
||||
include Plugins::Expect
|
||||
include Plugins::RateLimiter
|
||||
include Plugins::Persistent unless RUBY_ENGINE == "jruby" || RUBY_VERSION < "2.3"
|
||||
include Plugins::Stream
|
||||
|
||||
def test_connection_coalescing
|
||||
coalesced_origin = "https://#{ENV["HTTPBIN_COALESCING_HOST"]}"
|
||||
|
42
test/support/requests/plugins/stream.rb
Normal file
42
test/support/requests/plugins/stream.rb
Normal file
@ -0,0 +1,42 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Requests
|
||||
module Plugins
|
||||
module Stream
|
||||
def test_plugin_stream
|
||||
session = HTTPX.plugin(RequestInspector).plugin(:stream)
|
||||
|
||||
uri = build_uri("/get")
|
||||
|
||||
no_stream_response = session.get(uri)
|
||||
stream_response = session.get(uri, stream: true)
|
||||
|
||||
assert session.total_responses.size == 1, "there should be an available response"
|
||||
|
||||
assert no_stream_response.body.to_s == stream_response.body.to_s, "content should be the same"
|
||||
|
||||
assert session.total_responses.size == 2, "there should be 2 available responses"
|
||||
end
|
||||
|
||||
def test_plugin_stream_multiple_responses_error
|
||||
session = HTTPX.plugin(:stream)
|
||||
|
||||
assert_raises(HTTPX::Error, /support only 1 response at a time/) do
|
||||
session.get(build_uri("/stream/2"), build_uri("/stream/3"), stream: true)
|
||||
end
|
||||
end
|
||||
|
||||
def test_plugin_stream_each_line
|
||||
session = HTTPX.plugin(:stream)
|
||||
|
||||
response = session.get(build_uri("/stream/3"), stream: true)
|
||||
lines = response.each_line.each_with_index.map do |line, idx|
|
||||
data = JSON.parse(line)
|
||||
assert data["id"] == idx
|
||||
end
|
||||
|
||||
assert lines.size == 3, "all the lines should have been yielded"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user