This repository has been archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgreadsimilaraut.t
executable file
·74 lines (49 loc) · 2.75 KB
/
greadsimilaraut.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl -w
# Test cases realized:
# [x]
# [ ]
# [ ]
# [ ]
use diagnostics; # More debugging info
use warnings;
use strict;
use FindBin;
use local::lib "$FindBin::Bin/../lib/local/";
use lib "$FindBin::Bin/../lib/";
use Test::More qw( no_plan );
use List::MoreUtils qw( any firstval );
use_ok( 'Goodscrapes' );
# We should never use caching during real tests:
# We need to test against the most up-to-date markup from Goodreads.com
# Having no cache during development is annoying, tho.
# So we leave a small window:
gsetopt( cache_days => 1 );
print( 'Reading book shelf... ');
my %authors;
my $SIMILAR_AUTHOR_ID = '9876'; # John Milton
greadsimilaraut( author_id => '1734373', # Karl Held
rh_into => \%authors,
on_progress => gmeter( 'similar' ));
print( "\n" );
ok( scalar( keys( %authors )) >= 4, 'At least 4 similar authors' );
ok( exists( $authors{$SIMILAR_AUTHOR_ID} ), 'Expected author found via hash-key = Goodreads author ID' )
or BAIL_OUT( "Cannot test author attributes when expected author is missing." );
my $a = $authors{$SIMILAR_AUTHOR_ID};
isa_ok( $a, 'HASH', 'Author datatype' );
is ( $a->{id}, $SIMILAR_AUTHOR_ID, 'Author has ID' );
is ( $a->{name}, 'John Milton', 'Author has name' );
is ( $a->{url}, "https://www.goodreads.com/author/show/$SIMILAR_AUTHOR_ID", 'Author has URL' );
like( $a->{works_url}, qr/^https:\/\/www\.goodreads\.com\/author\/list\/$SIMILAR_AUTHOR_ID/, 'Author has works URL' );
like( $a->{img_url}, qr/\.jpg$/, 'Author has image URL' );
is ( $a->{is_author}, 1, 'Author has author flag' );
is ( $a->{is_private}, 0, 'Author not private' );
ok ( $a->{is_mainstream}, 'is mainstream author' );
# Not available or scraped yet, otherwise one of the following
# tests will fail and remind me of implementing a correct test:
is ( $a->{name_lf}, $a->{name}, 'N/A: author name != name_lf' ); # "Dick, Philip K."
is ( $a->{residence}, undef, 'N/A: author residence' );
is ( $a->{age}, undef, 'N/A: author age' );
is ( $a->{num_books}, undef, 'N/A: number of author books' );
is ( $a->{is_friend}, undef, 'N/A: author friend status' );
is ( $a->{is_female}, undef, 'N/A: author gender status' );
is ( $a->{is_staff}, undef, 'N/A: is Goodreads author' );