summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-06-07 10:22:47 +0200
committerfranck cuny <franck@lumberjaph.net>2010-06-07 10:25:25 +0200
commit2f7b37a44c9a7ce0f334253a809c6cb6deac5e40 (patch)
tree4fcc4969fd1e841faeb454af4db3450ce92ef0b9
parentadd moose (diff)
downloadnet-backtype-2f7b37a44c9a7ce0f334253a809c6cb6deac5e40.tar.gz
update tests
-rw-r--r--t/00_compile.t4
-rw-r--r--t/01_basic.t46
2 files changed, 34 insertions, 16 deletions
diff --git a/t/00_compile.t b/t/00_compile.t
index 6912701..f6505b6 100644
--- a/t/00_compile.t
+++ b/t/00_compile.t
@@ -1,4 +1,4 @@
 use strict;
-use Test::More tests => 1;
+use Test::More tests => 2;
 
-BEGIN { use_ok 'Net::Backtype' }
+BEGIN { use_ok 'Net::Backtype'; use_ok 'Net::Backtweet'; }
diff --git a/t/01_basic.t b/t/01_basic.t
index 2b6fda2..44c56f7 100644
--- a/t/01_basic.t
+++ b/t/01_basic.t
@@ -1,24 +1,42 @@
 use strict;
 use warnings;
 use Test::More;
+
+use HTTP::Response;
 use Net::Backtype;
 use Net::Backtweet;
 
-BEGIN {
-    plan skip_all => 'set $ENV{BACKTYPE_KEY} for this test'
-        unless $ENV{BACKTYPE_KEY};
-}
-
-my $obj = Net::Backtweet->new;
-ok $obj, '... object created';
-my $method = $obj->meta->find_method_by_name('user_comments');
-ok $method->meta->has_attribute('method'), '... got method as attribute';
-is $method->method, 'GET', '... method is GET';
+ok my $backtype = Net::Backtype->new, 'object backtype created';
+_add_handler($backtype);
 
-my $res = $obj->backtweet_search(
-    key => $ENV{BACKTYPE_KEY},
+ok my $res = $backtype->comments_search(
+    key => 's3kr3tk3y',
     q   => 'http://lumberjaph.net'
-);
+  ),
+  'got result for backtype query';
+
+ok my $backtweet = Net::Backtweet->new, 'object backtweet created';
+_add_handler($backtweet);
+
+ok $res = $backtweet->stats_by_url(
+    key => 's3kr3tk3y',
+    q   => 'http://lumberjaph.net',
+  ),
+  'got result for backtweet query';
+
+sub _add_handler {
+    my $object = shift;
+    $object->api_useragent->add_handler(
+        'request_send' => sub {
+            my $request  = shift;
+            my $response = HTTP::Response->new(200);
+            $response->header('Content-Type' => 'application/json');
+            $response->content(
+                '{"startindex" : 1, "itemsperpage" : 25, "since_ts" : 1275874078, "totalresults" : "500"}'
+            );
+            $response;
+        }
+    );
+}
 
-cmp_ok scalar @{ $res->{tweets} }, '>=', 1, '... got more than one result';
 done_testing;