Business-Shipping
view release on metacpan or search on metacpan
t/310-UPS_Online-basic.t view on Meta::CPAN
#!/bin/env perl
# UPS_Online RateRequest suite of tests.
use strict;
use warnings;
use Test::More;
use Carp;
use Data::Dumper;
use Business::Shipping;
plan skip_all => 'Required modules not installed'
unless Business::Shipping::Config::calc_req_mod('UPS_Online');
plan skip_all => 'No credentials'
unless $ENV{UPS_USER_ID}
and $ENV{UPS_PASSWORD}
and $ENV{UPS_ACCESS_KEY};
plan skip_all => 'Slow tests. Set TEST_SLOW to run.'
unless $ENV{TEST_SLOW};
plan 'no_plan';
$::debug = 0;
my $standard_method
= new Business::Shipping->rate_request('shipper' => 'UPS');
ok(defined $standard_method, 'UPS standard object construction');
my $other_method = new Business::Shipping::UPS_Online::RateRequest;
ok(defined $other_method, 'UPS alternate object construction');
my $package_one = new Business::Shipping::UPS_Online::Package;
ok(defined $package_one, 'UPS package object construction');
#goto wwe_uk;
sub debug {
print STDERR $_[0] . "\n" if $::debug;
}
sub test {
my (%args) = @_;
my $shipment = Business::Shipping->rate_request(
'shipper' => 'Online::UPS',
'user_id' => $ENV{UPS_USER_ID},
'password' => $ENV{UPS_PASSWORD},
'access_key' => $ENV{UPS_ACCESS_KEY},
'cache' => 0,
);
$shipment->submit(%args) or confess $shipment->user_error();
return $shipment;
}
sub simple_test {
my (%args) = @_;
my $shipment = test(%args);
$shipment->submit() or die $shipment->user_error();
my $total_charges = $shipment->total_charges();
my $msg = "UPS Simple Test: "
. (
$args{weight}
? $args{weight} . " pounds"
: ($args{pounds} . "lbs and " . $args{ounces} . "ounces")
)
. " to "
. ($args{to_city} ? $args{to_city} . " " : '')
. $args{to_zip} . " via "
. $args{service} . " = "
. ($total_charges ? '$' . $total_charges : "undef");
ok($total_charges, $msg);
}
###########################################################################
## Should fail on missing user_id or password
( run in 0.626 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )