diff options
author | franck cuny <franck@lumberjaph.net> | 2010-06-02 18:57:29 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-06-02 18:57:29 +0200 |
commit | 856c715612f3de54ebc51f348ace42a805b2e31d (patch) | |
tree | 6604b1bfb2050c5a3f5a9227228081e3a707ca40 | |
parent | handle authentication (diff) | |
download | moosex-net-api-856c715612f3de54ebc51f348ace42a805b2e31d.tar.gz |
update tests
-rw-r--r-- | t/02_error.t | 2 | ||||
-rw-r--r-- | t/05_authentication.t | 67 |
2 files changed, 68 insertions, 1 deletions
diff --git a/t/02_error.t b/t/02_error.t index a97158e..3ab5dcc 100644 --- a/t/02_error.t +++ b/t/02_error.t @@ -12,6 +12,6 @@ package main; ok my $t = test::api::missing_api_base_url->new; dies_ok { $t->user } 'die with missing url'; -like $@, qr/api_base_url is missing/, 'missing api_base_url'; +like $@, qr/'api_base_url' have not been defined/, 'missing api_base_url'; done_testing; diff --git a/t/05_authentication.t b/t/05_authentication.t new file mode 100644 index 0000000..e769a53 --- /dev/null +++ b/t/05_authentication.t @@ -0,0 +1,67 @@ +use strict; +use warnings; +use Test::More; + +package test::auth; +use MooseX::Net::API; + +net_api_declare fake_auth => ( + api_base_url => 'http://localhost', + format => 'json', + authentication => 1, + authentication_method => 'my_auth', +); + +net_api_method user => ( + method => 'GET', + path => '/user/', +); + +sub my_auth { + my ($self, $request, $ua, $h) = @_; + $request->header('Authentication' => 1); +} + +package test::auth::simple; +use MooseX::Net::API; + +net_api_declare fake_auth => ( + api_base_url => 'http://localhost', + format => 'json', + authentication => 1, +); + +net_api_method user => ( + method => 'GET', + path => '/user/', +); + +package main; + +ok my $api = test::auth->new, 'object api created'; +$api->api_useragent->add_handler( + request_send => sub { + my $request = shift; + is $request->header('Authentication'), 1, 'authentication header is set'; + my $res = HTTP::Response->new(200); + $res->content('[{"name":"eris"}]'); + $res; + } +); +ok $api->user, 'method user success'; + +ok $api = + test::auth::simple->new(api_username => 'foo', api_password => 'bar'), + 'object api simple created'; +$api->api_useragent->add_handler( + request_send => sub { + my $request = shift; + ok $request->header('authorization'), 'authentication header is set'; + my $res = HTTP::Response->new(200); + $res->content('[{"name":"eris"}]'); + $res; + } +); +ok $api->user, 'method user success'; + +done_testing; |