commit 2ca0e69b05ef46c6a58ac2c0ecc0b4da45618fa7
parent 665b398abb782ccde9009c2a1e02c4e0713b3bf6
Author: Paco Esteban <paco@onna.be>
Date: Wed, 30 Sep 2015 16:59:35 +0200
Trying to fix internet tests for good;
Diffstat:
4 files changed, 48 insertions(+), 6 deletions(-)
diff --git a/Changes b/Changes
@@ -1,7 +1,8 @@
Revision history for Rarbg-torrentapi
{{$NEXT}}
-
+ - Fixed tests. CPAN Testers sometimes don't have internet connection
+ It seems last fix did not work for all. Using Test::LWP::UserAgent now.
v0.1.3 2015-09-27 12:26:08 CEST
- Fixed tests. CPAN Testers sometimes don't have internet connection
Using Test::RequiresInternet
diff --git a/cpanfile b/cpanfile
@@ -9,5 +9,5 @@ on test => sub {
requires 'Test::More', '0.96';
requires 'Test::Pod', '0';
requires 'JSON', '0';
- requires 'Test::RequiresInternet', '0';
+ requires 'Test::LWP::UserAgent', '0';
};
diff --git a/lib/Rarbg/torrentapi.pm b/lib/Rarbg/torrentapi.pm
@@ -40,7 +40,7 @@ has ranked => (
default => 0
);
-has _mode => (
+has mode => (
is => 'rw',
isa => 'Str',
default => 'list'
@@ -137,7 +137,7 @@ foreach my $method (qw/list search/) {
foreach my $key ( keys %{$args} ) {
$self->$key( $args->{$key} );
}
- $self->_mode("$method");
+ $self->mode("$method");
return $self->_make_request;
}
);
diff --git a/t/basic.t b/t/basic.t
@@ -1,6 +1,6 @@
use strict;
use Test::More;
-use Test::RequiresInternet ( 'torrentapi.org', => 443 );
+use Test::LWP::UserAgent;
BEGIN {
use_ok('Rarbg::torrentapi');
@@ -9,7 +9,48 @@ BEGIN {
can_ok( 'Rarbg::torrentapi',
qw( new search list _renew_token _token_valid _make_request ) );
-my $tapi = new_ok('Rarbg::torrentapi');
+my $test_ua = Test::LWP::UserAgent->new;
+$test_ua->map_response(
+ qr{get_token},
+ HTTP::Response->new(
+ '200',
+ HTTP::Status::status_message('200'),
+ [ 'Content-Type' => 'application/json' ],
+ '{"token":"8q1sjn0yb6"}',
+ ),
+);
+$test_ua->map_response(
+ qr{mode=list},
+ HTTP::Response->new(
+ '200', HTTP::Status::status_message('200'),
+ [ 'Content-Type' => 'application/json' ],
+ '{
+ "torrent_results": [
+ {
+ "category": "Foo Cat",
+ "download": "magnet:?xt=ublablabla",
+ "filename": "myfilename.mp4"
+ },
+ {
+ "category": "Bar category",
+ "download": "magnet:?xt=urn:btih:foobarbaz",
+ "filename": "blahblah.mp3"
+ }
+ ]
+ }',
+ ),
+);
+$test_ua->map_response(
+ qr{mode=search},
+ HTTP::Response->new(
+ '200',
+ HTTP::Status::status_message('200'),
+ [ 'Content-Type' => 'application/json' ],
+ '{ "error": "No results found", "error_code": 20 } ',
+ ),
+);
+my $tapi = Rarbg::torrentapi->new( '_ua' => $test_ua );
+
like( $tapi->_token, qr/\w{10}/, 'Token test' );
diag( "I got token " . $tapi->_token );
ok( $tapi->_token_valid, 'Token time test' );