Astro-SpaceTrack

 view release on metacpan or  search on metacpan

t/query_spacetrack.t  view on Meta::CPAN

use strict;
use warnings;

use Astro::SpaceTrack;
use HTTP::Response;
use Test::More 0.96;	# For subtest

use lib qw{ inc };
use My::Module::Test;

my $desired_content_interface = 2;
# my $rslt;
my $space_track_domain = 'www.space-track.org';
my $st;

# Things to search for.
# NOTE that if these are changed, the corresponding canned data must be
# regenerated with tools/capture.
my $search_date = '2012-06-13';
my $start_epoch = '2012/04/01';

if ( $ENV{SPACETRACK_TEST_LIVE} ) {
    diag 'live test against space track. be aware of their usage guidelines';
    my $skip;
    $skip = site_check( $space_track_domain )	# To make sure we have account
	and plan skip_all	=> $skip;

    $st = Astro::SpaceTrack->new(
	identity	=> ! $ENV{SPACETRACK_USER},
	verify_hostname	=> VERIFY_HOSTNAME,
    );

} else {
    require Mock::LWP::UserAgent;
    Mock::LWP::UserAgent->install_mock();
    note <<'EOD';
Testing against canned data. Set environment variable
SPACETRACK_TEST_LIVE to test against the actual Space Track web site,
and be aware of their usage guidelines.
EOD

    $st = Astro::SpaceTrack->new(
	username	=> 'bogua',
	password	=> 'equally bogus',
	verify_hostname	=> VERIFY_HOSTNAME,
    );
}

$st->set( space_track_version => $desired_content_interface );

## my $username = $st->getv( 'username' );
## my $password = $st->getv( 'password' );

SKIP: {

    is_success( $st, 'login', 'Log in to Space-Track' )
	or skip 'Not logged in', 1;

    my $rslt = HTTP::Response->new();

    not_defined( $st->content_type(), 'Content type should be undef' )
	or diag( 'content_type is ', $st->content_type() );

    not_defined( $st->content_source(), 'Content source should be undef' )
	or diag( 'content_source is ', $st->content_source() );

    not_defined( $st->content_interface(),
	    'Content interface should be undef' )
	or diag 'content_interface is ', $st->content_interface();

    not_defined( $st->content_type( $rslt ), 'Result type should be undef' )
	or diag( 'content_type is ', $st->content_type( $rslt ) );

    not_defined( $st->content_source( $rslt ),
	    'Result source should be undef' )
	or diag( 'content_source is ', $st->content_source( $rslt ) );

    not_defined( $st->content_interface( $rslt ),
	    'Result interface should be undef' )
	or diag 'content_interface is ', $st->content_interface( $rslt );

    is_error( $st, spacetrack => 'fubar',
	404, 'Fetch a non-existent catalog entry' );

    SKIP: {
	is_success_or_skip( $st, spacetrack => 'inmarsat',
	    'Fetch a catalog entry', 3 );

	is $st->content_type(), 'orbit', "Content type is 'orbit'";

	is $st->content_source(), 'spacetrack',
	    "Content source is 'spacetrack'";

	is $st->content_interface(), $desired_content_interface,
	    "Content version is $desired_content_interface";
    }

    SKIP: {
	is_success_or_skip( $st, retrieve => 25544,
	    'Retrieve ISS orbital elements', 3 );

	is $st->content_type(), 'orbit', "Content type is 'orbit'";

	is $st->content_source(), 'spacetrack',
	    "Content source is 'spacetrack'";

	is $st->content_interface(), $desired_content_interface,
	    "Content version is $desired_content_interface";
    }

    SKIP: {
	is_success_or_skip( $st, file => 't/file.dat',
	    'Retrieve orbital elements specified by file', 3 );

	is $st->content_type(), 'orbit', "Content type is 'orbit'";

	is $st->content_source(), 'spacetrack',
	    "Content source is 'spacetrack'";

	is $st->content_interface(), $desired_content_interface,
	    "Content version is $desired_content_interface";
    }

    SKIP: {
	is_success_or_skip( $st, retrieve => '25544-25546',
	    'Retrieve a range of orbital elements', 3 );

	is $st->content_type(), 'orbit', "Content type is 'orbit'";

	is $st->content_source(), 'spacetrack',
	    "Content source is 'spacetrack'";

	is $st->content_interface(), $desired_content_interface,
	    "Content version is $desired_content_interface";
    }

    SKIP: {
	is_success_or_skip( $st, search_name => 'zarya',



( run in 1.880 second using v1.01-cache-2.11-cpan-39bf76dae61 )