use an existing logger for screencap
closes FOO-1440 flag=none TEST PLAN: 1) make cutycapt fail with non-200 response 2) log entry gets written Change-Id: Ib9b40536e5a6fa597a3f0a305c2254b4612db2e1 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/256274 Reviewed-by: Jacob Burroughs <jburroughs@instructure.com> Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Ethan Vizitei <evizitei@instructure.com> Product-Review: Ethan Vizitei <evizitei@instructure.com>
This commit is contained in:
parent
d0693ea69c
commit
8ff0a32f86
|
@ -23,7 +23,7 @@ module Services
|
|||
def initialize(config)
|
||||
@config = config.with_indifferent_access
|
||||
end
|
||||
|
||||
|
||||
def snapshot_url_to_file(url, tmpfile)
|
||||
url_params = { url: url }.to_query
|
||||
full_url = "#{@config[:url]}?#{url_params}"
|
||||
|
@ -32,10 +32,9 @@ module Services
|
|||
http_response.read_body do |chunk|
|
||||
tmpfile.write chunk
|
||||
end
|
||||
|
||||
tmpfile.close
|
||||
else
|
||||
logger.error("Snapshot failed with error code #{http_response.code}")
|
||||
Rails.logger.error("Snapshot failed with error code #{http_response.code}")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,9 +39,9 @@ module Services
|
|||
token: 'AN_API_TOKEN'
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
subject { described_class.new(config) }
|
||||
|
||||
|
||||
context ".snapshot_url_to_file" do
|
||||
it 'calls the provided url' do
|
||||
@stub = stub_request(:get, config[:url]).
|
||||
|
@ -49,7 +49,20 @@ module Services
|
|||
to_return(status: 200, body: "IMAGE_GOES_HERE")
|
||||
|
||||
Tempfile.create('example.png') do |f|
|
||||
subject.snapshot_url_to_file("https://www.example.com", f)
|
||||
result = subject.snapshot_url_to_file("https://www.example.com", f)
|
||||
expect(result).to be_truthy
|
||||
end
|
||||
expect(@stub).to have_been_requested.times(1)
|
||||
end
|
||||
|
||||
it 'returns false if it gets a non-200' do
|
||||
@stub = stub_request(:get, config[:url]).
|
||||
with(query: { url: 'https://www.example.com' }).
|
||||
to_return(status: 500, body: "IMAGE_GOES_HERE")
|
||||
|
||||
Tempfile.create('example.png') do |f|
|
||||
result = subject.snapshot_url_to_file("https://www.example.com", f)
|
||||
expect(result).to be_falsey
|
||||
end
|
||||
expect(@stub).to have_been_requested.times(1)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue