From: Jason Etheridge Date: Mon, 11 Oct 2021 21:52:00 +0000 (-0400) Subject: lp1787968 jacket_upload: tests X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f23fd208955cb039131e0772744396feacc718f9;p=evergreen%2Ftadl.git lp1787968 jacket_upload: tests Signed-off-by: Jason Etheridge Signed-off-by: Michele Morgan --- diff --git a/Open-ILS/src/perlmods/live_t/34-lp1787968-cover-uploader.t b/Open-ILS/src/perlmods/live_t/34-lp1787968-cover-uploader.t new file mode 100644 index 0000000000..66ae4ee398 --- /dev/null +++ b/Open-ILS/src/perlmods/live_t/34-lp1787968-cover-uploader.t @@ -0,0 +1,72 @@ +#!perl +use strict; use warnings; +use Test::More tests => 6; +use OpenILS::Utils::TestUtils; +use OpenILS::Const qw(:const); +use OpenILS::Utils::CStoreEditor qw/:funcs/; +use OpenILS::Utils::Fieldmapper; +use LWP::UserAgent; +use File::Fetch; +use HTTP::Request::Common qw(POST); + +diag("test image uploader"); + +my $U = 'OpenILS::Application::AppUtils'; +my $script = OpenILS::Utils::TestUtils->new(); +$script->bootstrap; + +$script->authenticate({ + username => 'admin', + password => 'demo123', + type => 'staff'}); + +my $authtoken = $script->authtoken; +ok($authtoken, 'Have an authtoken'); + +#
+# +# +# +# +#
+ +my $target = "http://127.0.0.1/jacket-upload"; + +my $ua = new LWP::UserAgent; +my $req = POST( + $target, + Content_Type => 'multipart/form-data', + Content => [ + # we're going for an image parse error + jacket_upload => [ '34-lp1787968-cover-uploader.t' ], + bib_record => 1, + ses => $authtoken + ] +); + +my $response = $ua->request($req); +ok( $response->is_success(), 'HTTP POST was successful'); +ok( $response->content() eq '"parse error"', 'Received expected parse error for non-image upload'); + +$ua = new LWP::UserAgent; +$req = POST( + $target, + Content_Type => 'multipart/form-data', + Content => [ + jacket_upload => [ '../../../web/images/green_check.png' ], + bib_record => 1, + ses => $authtoken + ] +); +$response = $ua->request($req); +ok( $response->is_success(), 'HTTP POST was successful'); +ok( $response->content() eq '1', 'Received expected response for an image upload'); + +my $url = 'http://localhost/opac/extras/ac/jacket/small/r/1'; +my $ff = File::Fetch->new(uri => $url); +my $file = $ff->fetch( to => '/tmp' ) or die $ff->error; +diag("Downloaded $url as $file"); + +my $filetype = `file $file`; +diag($filetype); +ok( $filetype =~ /PNG/, 'Downloaded a PNG file from target location');