This is an automated email from the git hooks/post-receive script. js pushed a commit to branch master in repository libcatmandu-perl.
commit bda77da35ab82f9b073f4ee1466a584a08112dab Author: Patrick Hochstenbach <patrick.hochstenb...@ugent.be> Date: Thu Dec 10 16:28:58 2015 +0100 Extra tests --- Build.PL | 4 ++-- cpanfile | 1 + lib/Catmandu/Importer.pm | 3 ++- t/Catmandu-Importer.t | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ t/Catmandu-Util.t | 5 ++++- 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/Build.PL b/Build.PL index 3cf9dc3..55948f9 100644 --- a/Build.PL +++ b/Build.PL @@ -1,5 +1,5 @@ -# This file was automatically generated by Dist::Zilla::Plugin::ModuleBuild v5.041. +# This file was automatically generated by Dist::Zilla::Plugin::ModuleBuild v5.039. use strict; use warnings; @@ -15,7 +15,7 @@ my %module_build_args = ( }, "dist_abstract" => "a data toolkit", "dist_author" => [ - "Nicolas Steenlant, C<< <nicolas.steenlant at ugent.be> >>" + "Nicolas Steenlant <nicolas.steenlant\@ugent.be>" ], "dist_name" => "Catmandu", "dist_version" => "0.9505", diff --git a/cpanfile b/cpanfile index 8085d93..f32c7d9 100644 --- a/cpanfile +++ b/cpanfile @@ -6,6 +6,7 @@ on 'test', sub { requires 'Test::More', '0.99'; requires 'Test::Pod', 0; requires 'Log::Any::Test', '1.03'; + requires 'Test::LWP::UserAgent' , 0; }; requires 'App::Cmd', '0.33'; diff --git a/lib/Catmandu/Importer.pm b/lib/Catmandu/Importer.pm index 807814e..c9d9df9 100644 --- a/lib/Catmandu/Importer.pm +++ b/lib/Catmandu/Importer.pm @@ -46,6 +46,7 @@ has variables => (is => 'ro', predicate => 1); has fh => (is => 'ro', lazy => 1, builder => 1); has encoding => (is => 'ro', builder=> 1); has data_path => (is => 'ro'); +has user_agent => (is => 'ro'); has http_method => (is => 'lazy'); has http_headers => (is => 'lazy'); has http_agent => (is => 'ro', predicate => 1); @@ -53,7 +54,7 @@ has http_max_redirect => (is => 'ro', predicate => 1); has http_timeout => (is => 'ro', predicate => 1); has http_verify_hostname => (is => 'ro', default => sub { 1 }); has http_body => (is => 'ro', predicate => 1); -has _http_client => (is => 'ro', lazy => 1, builder => '_build_http_client', init_arg => undef); +has _http_client => (is => 'ro', lazy => 1, builder => '_build_http_client', init_arg => 'user_agent'); sub _build_encoding { ':utf8'; diff --git a/t/Catmandu-Importer.t b/t/Catmandu-Importer.t index 9fb0f84..6604c34 100644 --- a/t/Catmandu-Importer.t +++ b/t/Catmandu-Importer.t @@ -5,6 +5,8 @@ use warnings; use v5.10.1; use Test::More; use Test::Exception; +use Test::LWP::UserAgent; +use HTTP::Response; my $pkg; BEGIN { @@ -57,5 +59,52 @@ is_deeply $i->to_array, [[{a=>1},{b=>2},{c=>3}],[{d=>4},{e=>5},{f=>6}]]; $i = T::DataPathImporter->new(data_path => 'abc.*'); is_deeply $i->to_array, [{a=>1},{b=>2},{c=>3},{d=>4},{e=>5},{f=>6}]; +$i = T::Importer->new( user_agent => user_agent() , file => 'http://demo.org/' ); +is $i->readall , "test123" , "read from http (file)"; + +$i = T::Importer->new( user_agent => user_agent() , file => 'http://demo.org/{id}' , variables => { id => 1234} ); +is $i->file , "http://demo.org/1234"; +is $i->readall , "test1234" , "read from http (file + variables)"; + +$i = T::Importer->new( user_agent => user_agent() , file => 'http://demo.org/{id}' , variables => { id => [qw(red green blue)]}); +is $i->file , "http://demo.org/red,green,blue"; +is $i->readall , "RED-GREEN-BLUE" , "read from http (file + variables list)"; + done_testing; +sub user_agent { + my $ua = Test::LWP::UserAgent->new(agent => 'Test/1.0'); + + $ua->map_response( + qr{^http://demo.org/$}, + HTTP::Response->new( + '200' , + 'OK' , + [ 'Content-Type' => 'text/plain'] , + 'test123' + ) + ); + + $ua->map_response( + qr{^http://demo.org/1234$}, + HTTP::Response->new( + '200' , + 'OK' , + [ 'Content-Type' => 'text/plain'] , + 'test1234' + ) + ); + + $ua->map_response( + qr{^http://demo.org/red,green,blue$}, + HTTP::Response->new( + '200' , + 'OK' , + [ 'Content-Type' => 'text/plain'] , + 'RED-GREEN-BLUE' + ) + ); + + $ua; +} + diff --git a/t/Catmandu-Util.t b/t/Catmandu-Util.t index 6a31585..6924915 100644 --- a/t/Catmandu-Util.t +++ b/t/Catmandu-Util.t @@ -393,7 +393,10 @@ is Catmandu::Util::capitalize("école") , "École" , 'capitalize'; is Catmandu::Util::human_number(64354) , "64,354" , 'human_number'; +is Catmandu::Util::human_byte_size(10) , "10 bytes" , 'human_byte_size'; +is Catmandu::Util::human_byte_size(10005) , "10.01 KB" , 'human_byte_size'; is Catmandu::Util::human_byte_size(10005000) , "10.01 MB" , 'human_byte_size'; +is Catmandu::Util::human_byte_size(10005000000) , "10.01 GB" , 'human_byte_size'; is Catmandu::Util::human_content_type('application/x-dos_ms_excel') , 'Excel' , 'human_content_type'; @@ -401,4 +404,4 @@ is Catmandu::Util::xml_declaration() , qq(<?xml version="1.0" encoding="UTF-8"?> is Catmandu::Util::xml_escape("<>'&") , '<>'&' , 'xml_escape'; -done_testing 531; \ No newline at end of file +done_testing 534; \ No newline at end of file -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-perl.git _______________________________________________ Pkg-perl-cvs-commits mailing list Pkg-perl-cvs-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits