diff options
author | franck cuny <franck@lumberjaph.net> | 2010-06-03 10:01:01 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-06-03 10:01:01 +0200 |
commit | 3da11a8153d3b42af2f2a250008be6cc52e57b09 (patch) | |
tree | 4da02b541e9f8d35e5f20d63908cd33fe64dc7f8 /t/lib | |
parent | replace remainging with nothing (diff) | |
parent | fix attribute declaration (diff) | |
download | moosex-net-api-3da11a8153d3b42af2f2a250008be6cc52e57b09.tar.gz |
merge
Diffstat (limited to 't/lib')
-rw-r--r-- | t/lib/FakeAPI.pm | 82 | ||||
-rw-r--r-- | t/lib/TestAPI.pm | 49 |
2 files changed, 49 insertions, 82 deletions
diff --git a/t/lib/FakeAPI.pm b/t/lib/FakeAPI.pm deleted file mode 100644 index 0f53157..0000000 --- a/t/lib/FakeAPI.pm +++ /dev/null @@ -1,82 +0,0 @@ -package FakeAPI; -use Moose; -use MooseX::Net::API; -use LWP::UserAgent; -use HTTP::Response; -use JSON::XS; - -net_api_declare demorest => ( - base_url => "http://example.com/", - format => 'json', - format_mode => 'content-type', - authentication => 0, - username => 'foo', - password => 'bar', - useragent => sub { - my ($self) = @_; - my $ua = LWP::UserAgent->new(); - $ua->add_handler( - request_send => sub { - my $request = shift; - my $res = HTTP::Response->new(200, 'OK'); - $res->header('content-type' => 'application/json'); - $res->content(encode_json {status => 1}); - return $res; - } - ); - return $ua; - }, -); - -net_api_method users => ( - description => 'get a list of users', - method => 'GET', - path => '/users/', - expected => [qw/200/], -); - -net_api_method get_user => ( - description => 'fetch information about a specific user', - method => 'GET', - path => '/user/$id', - params => [qw/id/], - required => [qw/id/], - expected => [qw/200 404/], -); - -net_api_method create_user => ( - description => 'create a new user', - method => 'POST', - path => '/user/', - params => [qw/user nickname/], - required => [qw/user nickname/], -); - -net_api_method update_user => ( - description => 'update information about a specific user', - method => 'PUT', - path => '/user/$id', - params => [qw/id nickname/], - required => [qw/id nickname/], -); - -net_api_method delete_user => ( - description => 'terminate an user', - method => 'DELETE', - path => '/user/$id', - params => [qw/id/], - required => [qw/id/], -); - -net_api_method auth_get_user => ( - description => - 'fetch information about a specific user with authentication', - method => 'GET', - path => '/auth_user/$id', - params => [qw/id/], - required => [qw/id/], - expected => [qw/200 404/], - authentication => 1, -); - -1; diff --git a/t/lib/TestAPI.pm b/t/lib/TestAPI.pm new file mode 100644 index 0000000..1e8bf97 --- /dev/null +++ b/t/lib/TestAPI.pm @@ -0,0 +1,49 @@ +package TestAPI; +use MooseX::Net::API; + +use HTTP::Response; + +net_api_declare fake_api => ( + api_base_url => 'http://exemple.com', + format => 'json', +); + +net_api_method users => ( + method => 'GET', + path => '/users/', + expected => [qw/200/], +); + +net_api_method user => ( + method => 'GET', + path => '/user/:user_name', + params => [qw/user_name/], + required => [qw/user_name/], + expected => [qw/200/], +); + +net_api_method add_user => ( + method => 'POST', + path => '/user/', + params => [qw/name dob/], + required => [qw/name/], + expected => [qw/201/], +); + +net_api_method update_user => ( + method => 'PUT', + path => '/user/:name', + params => [qw/name dob/], + required => [qw/name/], + expected => [qw/201/], +); + +net_api_method delete_user => ( + method => 'DELETE', + path => '/user/:name', + params => [qw/name/], + required => [qw/name/], + expected => [qw/204/], +); + +1; |