in reply to Stories from the front

making sure that a valid page (HTTP code is 200) gets returned

Unfortunately, you can't rely on a response code of 200 always indicating success - some web servers (I've heard) return that code even for a failed request. I think (I'm open to correction) your best bet is to check that the returned data is 'good' in some way, e.g.

my $mech = WWW::Mechanize->new; $mech->get( $page ); is( $mech->title(), "Alex's Wacky Widgets", "page GET success" );

or, with Test::WWW::Mechanize, which you might like to check out:

$mech->title_is( "Alex's Wacky Widgets" );

Life is denied by lack of attention,
whether it be to cleaning windows
or trying to write a masterpiece...
-- Nadia Boulanger

Replies are listed 'Best First'.
Re^2: Stories from the front
by talexb (Chancellor) on Jan 05, 2009 at 01:03 UTC
      Unfortunately, you can't rely on a response code of 200 always indicating success - some web servers (I've heard) return that code even for a failed request.

    It turns out that I'm testing a web application that I'm maintaining -- so the application is well behaved in that regard. I check that the status was OK, and also check that the content is what I was expecting.

    And I expect to get a 200 Status even on a page that returns something like 'User not found' -- that isn't a protocol error, it's an application error. I also expect to get a 404 on a 'page not found' error, but for pages that are part of a package that may not be installed, that's OK. What I think you're describing is conflating an application error with a protocol error, which I don't think is right.

    And now I know to read the part of the module deltas that say something like "This may break your code" much more closely. :)

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re^2: Stories from the front
by mr_mischief (Monsignor) on Jan 05, 2009 at 14:52 UTC
    If your web server gives 200 as a response when the page is not present or the user is not authorized, then you need to use a different web server package. There are standards for these things for a reason. As talexb said already, don't confuse application conditions with protocol conditions.

      You are, of course, both correct... If you distinguish between application errors and protocol errors (talexb), then the solution to inappropriate response codes (protocol errors) is indeed to get a new web server (mr_mischief).

      Also, I shouldn't have passed on second-hand advice when I don't know the source. Sorry.


      Life is denied by lack of attention,
      whether it be to cleaning windows
      or trying to write a masterpiece...
      -- Nadia Boulanger