memory_express.t (1841B)
1 use strict; 2 use PS::UserAgent; 3 use PS::MemoryExpress; 4 use Log::Log4perl qw(:easy); 5 use Test; 6 7 BEGIN { plan tests => 17 } 8 9 Log::Log4perl->easy_init($INFO); 10 11 my $ua = PS::UserAgent->new(); 12 my $me = PS::MemoryExpress->new(); 13 14 # Search for a Seagate hard drive I know about 15 # 16 my $search_url = $me->create_search("Seagate", "ST8000AS0002"); 17 my $resp = $ua->get_dom($search_url); 18 ok($resp->is_success); 19 20 # Check that the object is working 21 my ($obj_resp) = $me->find_product_page($resp); 22 ok($obj_resp->base, $resp->base); 23 24 # Make sure the part number we scrape is correct 25 my $part_num = $me->scrape_part_num($resp); 26 ok($part_num, "ST8000AS0002"); 27 28 # Make sure the price we scrape is at least close to correct 29 my ($price, @others) = $me->scrape_price($resp); 30 ok($price); 31 ok(@others == 0); 32 ok($price > 200.0); 33 ok($price < 400.0); 34 35 my $descr = $me->scrape_description($resp); 36 ok($descr, "8TB Archive HDD, SATA III w/ 128MB Cache"); 37 38 39 # Search for something I know has multiple results 40 # 41 my $search_url = $me->create_search("Seagate", "ST8000"); 42 $resp = $ua->get_dom($search_url); 43 ok($resp->is_success); 44 45 # The returned URI should have been the search results page 46 ok($resp->base =~ /.*\/Search\/.*/); 47 48 # Searching for the above product yields two results 49 my ($obj_resp, @others) = $me->find_product_page($resp); 50 ok($obj_resp->base =~ /.*\/Products\/.*/); 51 ok(@others, 1); 52 ok($obj_resp->is_success); 53 54 55 # Search for something that returns 0 results 56 # 57 my $search_url = $me->create_search("", "some nonexistent product here"); 58 $resp = $ua->get_dom($search_url); 59 ok($resp->is_success); 60 61 ok($resp->base =~ /.*\/Search\/.*/); 62 63 my ($obj_resp) = $me->find_product_page($resp); 64 ok( !defined $obj_resp ); 65 66 # Check we get the no results found error 67 ok( $resp->decoded_content, 68 "/We're sorry, but there are no products with the specified search parameters./");