Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the WWW-Mechanize CPAN distribution.

Report information
The Basics
Id: 2185
Status: resolved
Priority: 90/
Queue: WWW-Mechanize

People
Owner: Nobody in particular
Requestors: andy [...] petdance.com
Cc: rspier [...] pobox.com
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)

Attachments


Subject: Allow for testing for non-connected tests
CC: rspier [...] pobox.com
Allow users who aren't connected to the net to opt out of the Google tests. Not everyone installing WWW::Mechanize will be attached to the Internet, and the Google tests won't run correctly.
From: book [...] cpan.org
[PETDANCE - Thu Mar 6 11:17:22 2003]: Show quoted text
> Allow users who aren't connected to the net to opt out of the Google
tests. Show quoted text
> > Not everyone installing WWW::Mechanize will be attached to the
Internet, Show quoted text
> and the Google tests won't run correctly.
Hi, Here is a set of patches so that the WWW::Mechanize test suite can run even if the web does not run. The first patch was very easy to write (and work better than my first proposal, which I did without really reading the code). The goal of the first get() in t/page_stack.t is only to have something in the stack. It does not matter if the page returned a 200 or a 500, we just need a response. --- WWW-Mechanize-0.37/t/page_stack.t 2003-03-07 23:36:13.000000000 +0100 +++ WWW-Mechanizet/page_stack.t 2003-03-08 15:33:11.000000000 +0100 @@ -9,7 +9,7 @@ my $t = WWW::Mechanize->new; isa_ok( $t, 'WWW::Mechanize', 'Created object' ); -ok( $t->get("http://www.google.com/intl/en/")->is_success, "Got Google" ); +ok( $t->get("http://www.google.com/intl/en/"), "Got a response" ); is(scalar @{$t->{page_stack}}, 0, "Page stack starts empty"); $t->_push_page_stack(); is(scalar @{$t->{page_stack}}, 1, "Pushed item onto page stack"); The other modified tests use a home made module, t::Utils, that imports the web_ok and start_web functions. There are two ways to run these tests: either only with the dummy web server, or a combination of dummy and (if available) real web server. The choice is made depending on the result of web_ok. I choose to create a dummy web server that would mimic Google. At the beginning of each test, we run web_ok() to check if we can reach google.com, and run the dummy web server if google is not available. The dummy webserver use a very simple hash to send files (taken from google) back to the client. If you want to remove the "live" tests, you can simply remove the if( web_ok() ) test, and simply launch the dummy server. I did some tests under Windows, and it seems to work too (except I hadn't libwww-perl-5.69 installed). I have attached the t/Utils.pm file, as well as all the files that the dummy server uses to simulate Google are stored in the t/google directory. They are attached in the files.tar.gz file. Here are the patches, for the files MANIFEST, t/click.t, t/follow.t, t/form.t, t/get.t, t/page_stack.t: --- WWW-Mechanize-0.37/MANIFEST 2002-09-10 22:06:29.000000000 +0200 +++ WWW-Mechanize/MANIFEST 2003-03-10 16:18:55.000000000 +0100 @@ -1,13 +1,23 @@ Changes -Makefile.PL MANIFEST +Makefile +Makefile.PL README lib/WWW/Mechanize.pm +pm_to_blib t/00.load.t +t/Utils.pm t/add_header.t t/click.t t/follow.t t/form.t t/get.t +t/google/basics.html +t/google/en.html +t/google/foo.html +t/google/help.html +t/google/logo.gif +t/google/news.html +t/google/refinesearch.html t/new.t t/page_stack.t --- WWW-Mechanize-0.37/t/click.t 2003-03-04 22:06:03.000000000 +0100 +++ WWW-Mechanize/t/click.t 2003-03-10 16:21:51.000000000 +0100 @@ -1,6 +1,7 @@ use warnings; use strict; use Test::More tests => 8; +use t::Utils; BEGIN { use_ok( 'WWW::Mechanize' ); @@ -9,7 +10,16 @@ my $t = WWW::Mechanize->new(); isa_ok( $t, 'WWW::Mechanize', 'Created the object' ); -my $response = $t->get( "http://www.google.com/intl/en/"); +my $url = 'http://www.google.com'; +my ($daemon, $pid ); + +if( not web_ok() ) { + ($daemon, $pid ) = start_web( 2 ); + $url = $daemon->url; + $url =~s!/$!!; +} + +my $response = $t->get( "$url/intl/en/" ); isa_ok( $response, 'HTTP::Response', 'Got back a response' ); ok( $response->is_success, 'Got google' ) or die "Can't even fetch google"; ok( $t->is_html ); --- WWW-Mechanize-0.37/t/follow.t 2003-02-04 17:29:18.000000000 +0100 +++ WWW-Mechanize/t/follow.t 2003-03-10 16:21:34.000000000 +0100 @@ -1,7 +1,7 @@ use warnings; use strict; use Test::More tests => 14; -use constant START => 'http://www.google.com/intl/en/'; +use t::Utils; BEGIN { use_ok( 'WWW::Mechanize' ); @@ -11,22 +11,31 @@ isa_ok( $agent, 'WWW::Mechanize', 'Created object' ); $agent->quiet(1); -my $response = $agent->get( START ); +my $url = 'http://www.google.com/intl/en/'; +my ($daemon, $pid ); + +if ( not web_ok() ) { + ( $daemon, $pid ) = start_web(3); + $url = $daemon->url; + $url=~s!/$!/intl/en/!; +} + +my $response = $agent->get( $url ); ok( $response->is_success, 'Got some page' ); -is( $agent->uri, START, 'Got Google' ); +is( $agent->uri, $url, 'Got Google' ); ok(! $agent->follow(99999), "Can't follow too-high-numbered link"); ok($agent->follow(1), "Can follow first link"); -isnt( $agent->uri, START, 'Need to be on a separate page' ); +isnt( $agent->uri, $url, 'Need to be on a separate page' ); ok($agent->back(), "Can go back"); -is( $agent->uri, START, 'Back at the first page' ); +is( $agent->uri, $url, 'Back at the first page' ); ok(! $agent->follow(qr/asdfghjksdfghj/), "Can't follow unlikely named link"); ok($agent->follow("Search"), "Can follow obvious named link"); -isnt( $agent->uri, START, 'Need to be on a separate page' ); +isnt( $agent->uri, $url, 'Need to be on a separate page' ); ok($agent->back(), "Can still go back"); -is( $agent->uri, START, 'Back at the start page again' ); +is( $agent->uri, $url, 'Back at the start page again' ); --- WWW-Mechanize-0.37/t/form.t 2003-02-04 17:44:46.000000000 +0100 +++ WWW-Mechanize/t/form.t 2003-03-10 15:27:32.000000000 +0100 @@ -1,8 +1,7 @@ -#!/usr/bin/perl -T - use warnings; use strict; use Test::More tests => 14; +use t::Utils; use constant START => 'http://www.google.com/intl/en/'; @@ -13,9 +12,19 @@ my $t = WWW::Mechanize->new(); isa_ok( $t, 'WWW::Mechanize' ); $t->quiet(1); -my $response = $t->get(START); + +my $url = 'http://www.google.com/'; +my ($daemon, $pid ); + +if ( not web_ok() ) { + ( $daemon, $pid ) = start_web(1); + $url = $daemon->url; +} + + +my $response = $t->get($url); ok( $response->is_success, "Got a page" ) or die "Can't even get google"; -is( $t->uri, START, 'Got Google' ); +is( $t->uri, $url, 'Got Google' ); my $form_number_1 = $t->form_number(1); ok( $form_number_1, "Can select the first form"); --- WWW-Mechanize-0.37/t/get.t 2003-03-04 22:01:14.000000000 +0100 +++ WWW-Mechanize/t/get.t 2003-03-10 14:41:56.000000000 +0100 @@ -1,6 +1,7 @@ use warnings; use strict; use Test::More tests => 27; +use t::Utils; BEGIN { use_ok( 'WWW::Mechanize' ); @@ -9,33 +10,44 @@ my $agent = WWW::Mechanize->new; isa_ok( $agent, 'WWW::Mechanize', 'Created object' ); -ok($agent->get("http://www.google.com/intl/en/")->is_success, "Get google webpa ge"); +my $url = 'http://www.google.com'; +my ($daemon, $pid ); + +if( not web_ok() ) { + ($daemon, $pid ) = start_web( 6 ); + $url = $daemon->url; + $url =~s!/$!!; +} + + +ok($agent->get("$url/intl/en/")->is_success, "Get google webpage"); isa_ok($agent->uri, "URI", "Set uri"); isa_ok($agent->req, 'HTTP::Request', "req should be a HTTP::Request"); ok( $agent->is_html ); is( $agent->title, "Google" ); ok( $agent->get( '/news/' )->is_success, 'Got the news' ); -is( $agent->uri, 'http://www.google.com/news/', "Got relative OK" ); +is( $agent->uri, "$url/news/", "Got relative OK" ); ok( $agent->is_html ); is( $agent->title, "News and Resources", "Got the right page" ); ok( $agent->get( '../help/' )->is_success, 'Got the help page' ); -is( $agent->uri, 'http://www.google.com/help/', "Got relative OK" ); +is( $agent->uri, "$url/help/", "Got relative OK" ); ok( $agent->is_html ); is( $agent->title, "Google Help Central", "Got the right page" ); ok( $agent->get( 'basics.html' )->is_success, 'Got the basics page' ); -is( $agent->uri, 'http://www.google.com/help/basics.html', "Got relative OK" ); +is( $agent->uri, "$url/help/basics.html", "Got relative OK" ); ok( $agent->is_html ); is( $agent->title, "Google Help" ); like( $agent->content, qr/Basics of Google Search/, "Got the right page" ); ok( $agent->get( './refinesearch.html' )->is_success, 'Got the "refine search" page' ); -is( $agent->uri, 'http://www.google.com/help/refinesearch.html', "Got relative OK" ); +is( $agent->uri, "$url/help/refinesearch.html", "Got relative OK" ); ok( $agent->is_html ); is( $agent->title, "Google Help" ); like( $agent->content, qr/Advanced Search Made Easy/, "Got the right page" ); -ok( $agent->get( "http://www.google.com/images/logo.gif" )- Show quoted text
>is_success, "Got th
e logo" ); +ok( $agent->get( "$url/images/logo.gif" )->is_success, "Got the logo" ); ok( !$agent->is_html ); + --- WWW-Mechanize-0.37/t/page_stack.t 2002-10-24 05:52:55.000000000 +0200 +++ WWW-Mechanize/t/page_stack.t 2003-03-09 22:30:27.000000000 +0100 @@ -9,7 +9,7 @@ my $t = WWW::Mechanize->new; isa_ok( $t, 'WWW::Mechanize', 'Created object' ); -ok( $t->get("http://www.google.com/intl/en/")->is_success, "Got Google" ); +ok( $t->get("http://www.google.com/intl/en/"), "Got a response" ); is(scalar @{$t->{page_stack}}, 0, "Page stack starts empty"); $t->_push_page_stack(); is(scalar @{$t->{page_stack}}, 1, "Pushed item onto page stack"); -- Philippe "BooK" Bruhat We laugh at stupidity because the alternative is to cry over it. (Moral from Groo The Wanderer #71 Epic))
Download files.tar.gz
application/x-gzip-compressed 23.3k

Message body not shown because it is not plain text.

This is now available in 0.45. We don't have all the tests mirrored in non-connected mode, but at least you have the option to skip the live tests.