diff options
author | franck cuny <franck@lumberjaph.net> | 2009-11-26 18:11:34 +0100 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2009-11-26 18:11:34 +0100 |
commit | b8b8bb3d166081a02c85ce4cb4f7c28aca2f2166 (patch) | |
tree | e9aa3575e0c521c96510dd22bbf10c2f16405c9c | |
parent | add error (diff) | |
download | moosex-net-api-b8b8bb3d166081a02c85ce4cb4f7c28aca2f2166.tar.gz |
add more tests
-rw-r--r-- | t/02_fail.t | 13 | ||||
-rw-r--r-- | t/03_identica.t | 26 | ||||
-rw-r--r-- | t/lib/FakeAPI.pm | 38 | ||||
-rw-r--r-- | t/lib/FakeAPIFail.pm | 21 | ||||
-rw-r--r-- | t/lib/FakeAPIFail2.pm | 24 | ||||
-rw-r--r-- | t/lib/Identica.pm | 24 |
6 files changed, 146 insertions, 0 deletions
diff --git a/t/02_fail.t b/t/02_fail.t new file mode 100644 index 0000000..f73cad9 --- /dev/null +++ b/t/02_fail.t @@ -0,0 +1,13 @@ +use strict; +use warnings; +use Test::More; +use Test::Exception; +use lib ('t/lib'); + +dies_ok { require FakeAPIFail } +"... can't declare a required param that have not been declared"; + +dies_ok {require FakeAPIFail2 } +"... can't declare a required param that have not been declared"; + +done_testing; diff --git a/t/03_identica.t b/t/03_identica.t new file mode 100644 index 0000000..d50f9b8 --- /dev/null +++ b/t/03_identica.t @@ -0,0 +1,26 @@ +use strict; +use warnings; +use lib ('t/lib'); + +use Test::More; +use Identica; +use YAML::Syck; +use Try::Tiny; + +BEGIN { + plan skip_all => + 'set $ENV{IDENTICA_USER} and $ENV{IDENTICA_PWD} for this test' + unless $ENV{IDENTICA_USER} && $ENV{IDENTICA_PWD}; +} + +my ($obj, $res); + +ok $obj = Identica->new( + api_username => $ENV{IDENTICA_USER}, + api_password => $ENV{IDENTICA_PWD} +); + +ok $res = $obj->public_timeline; +ok $res = $obj->update_status( status => 'this is a test' ); + +done_testing(); diff --git a/t/lib/FakeAPI.pm b/t/lib/FakeAPI.pm new file mode 100644 index 0000000..0496351 --- /dev/null +++ b/t/lib/FakeAPI.pm @@ -0,0 +1,38 @@ +package FakeAPI; +use Moose; +use MooseX::Net::API; + +net_api_declare fake_api => ( + base_url => 'http://identi.ca/api', + format => 'json', + format_mode => 'append', + require_authentication => 0, +); + +net_api_method foo => ( + description => 'this does foo', + method => 'GET', + path => '/foo/', + code => sub { my $self = shift; $self->get_foo }, + params => [qw/bar/], +); + +net_api_method bar => ( + description => 'this does bar', + method => 'GET', + path => '/bar/', + params => [qw/bar baz/], + required => [qw/baz/], +); + +net_api_method baz => ( + description => 'this one does baztwo', + method => 'BAZ', + path => '/baz/', + params => [qw/foo bla/], + required => [qw/bla/], +); + +sub get_foo { return 1; } + +1; diff --git a/t/lib/FakeAPIFail.pm b/t/lib/FakeAPIFail.pm new file mode 100644 index 0000000..80f1efa --- /dev/null +++ b/t/lib/FakeAPIFail.pm @@ -0,0 +1,21 @@ +package FakeAPI; +use Moose; +use MooseX::Net::API; + +has api_base_url => ( + is => 'ro', + isa => 'Str', + default => 'http://identi.ca/api', +); + +has format => ( is => 'ro', isa => 'Str', default => 'json', ); +format_query 'format' => ( mode => 'content-type' ); + +net_api_method foo => ( + description => 'this does foo', + method => 'GET', + path => '/foo/', + required => [qw/bar/], +); + +1; diff --git a/t/lib/FakeAPIFail2.pm b/t/lib/FakeAPIFail2.pm new file mode 100644 index 0000000..8ec10c8 --- /dev/null +++ b/t/lib/FakeAPIFail2.pm @@ -0,0 +1,24 @@ +package FakeAPI; +use Moose; +use MooseX::Net::API; + +has api_base_url => ( + is => 'ro', + isa => 'Str', + default => 'http://identi.ca/api', +); + +has format => ( is => 'ro', isa => 'Str', default => 'json', ); +format_query 'format' => ( mode => 'content-type' ); + +net_api_method baz => ( + description => 'this one does baztwo', + method => 'BAZ', + path => '/baz/', + params => [qw/foo/], + required => [qw/bla/], +); + +sub get_foo { return 1; } + +1; diff --git a/t/lib/Identica.pm b/t/lib/Identica.pm new file mode 100644 index 0000000..3772d03 --- /dev/null +++ b/t/lib/Identica.pm @@ -0,0 +1,24 @@ +package Identica; +use Moose; +use MooseX::Net::API; + +has [qw/api_username api_password/] => ( is => 'ro', isa => 'Str' ); + +net_api_declare identica => ( + base_url => 'http://identi.ca/api', + format => 'json', + format_mode => 'append', + authentication => 1, +); +net_api_method public_timeline => ( + path => '/statuses/public_timeline', + method => 'GET', +); + +net_api_method update_status => ( + path => '/statuses/update', + method => 'POST', + params => [qw/status/], + required => [qw/status/], + params_in_url => 1, +); |