3 t/integration/api/sequence.t - integration tests for API sequence URLs
7 Tests for sequence API URLs
21 use SGN::Test::Data qw/ create_test /;
22 use SGN::Test::WWW::Mechanize skip_cgi => 1;
24 my $mech = SGN::Test::WWW::Mechanize->new;
26 my $residue = 'AATTCCGG' x 3;
27 my $poly_cvterm = create_test('Cv::Cvterm', { name => 'polyfonebone' });
28 my $poly_feature = create_test('Sequence::Feature', {
32 my $poly_featureloc = create_test('Sequence::Featureloc', { feature => $poly_feature });
33 my $poly_feature_2 = create_test('Sequence::Feature', {
35 residues => reverse( $residue ),
38 for my $base ( '/api/v1/sequence/download/single/', '/gmodrpc/v1.1/fetch/seq/' ) {
40 my $length = length($poly_feature->name . $residue) + 3;
41 $mech->get_ok( $base . $poly_feature->name . '.fasta');
42 $mech->content_contains( '>' . $poly_feature->name );
43 $mech->content_contains( $residue );
44 is( $mech->content_type, 'application/x-fasta', 'right content type');
45 is( $length, length($mech->content), 'got the expected content length');
48 # 6 = 10 - 5 + 1 = # of chars in requested sequence
49 my $length = length($poly_feature->name.':5..10' ) + 3 + 6;
50 $mech->get_ok('/api/v1/sequence/download/single/' . $poly_feature->name . '.fasta?5..10');
51 $mech->content_contains( '>' . $poly_feature->name . ':5..10' );
52 $mech->content_like( qr/^CCGGAA$/m );
53 is( $mech->content_type, 'application/x-fasta', 'right content type');
54 is( $length, length($mech->content), 'got the expected content length');
57 # 6 = 10 - 5 + 1 = # of chars in requested sequence
58 my $length = length($poly_feature->name.':5..10' ) + 3 + 6;
59 $mech->get_ok('/api/v1/sequence/download/single/' . $poly_feature->feature_id . '.fasta?5..10');
60 $mech->content_contains( '>' . $poly_feature->name . ':5..10' );
61 $mech->content_like( qr/^CCGGAA$/m );
62 is( $mech->content_type, 'application/x-fasta', 'right content type');
63 is( $length, length($mech->content), 'got the expected content length');
66 $mech->get_ok('/api/v1/sequence/download/single/' . $poly_feature->name . '.ace?10..5', 'fetched in ace format');
67 $mech->content_contains( '"'. $poly_feature->name . ':10..5"' );
68 $mech->content_like( qr/^TTCCGG$/m );
69 is( $mech->content_type, 'text/plain', 'right content type');
72 # 6 = 10 - 5 + 1 = # of chars in requested sequence
73 my $length = length($poly_feature->name.':5..10' ) + 3 + 6;
74 $mech->get_ok('/api/v1/sequence/download/single/' . $poly_feature->feature_id . '.fasta?5..10');
75 $mech->content_contains( '>' . $poly_feature->name . ':5..10' );
76 $mech->content_like( qr/^CCGGAA$/m );
77 is( $mech->content_type, 'application/x-fasta', 'right content type');
78 is( $length, length($mech->content), 'got the expected content length')
79 or diag $mech->content;
82 $mech->get_ok('/api/v1/sequence/download/multi?s=' . $poly_feature->feature_id . '&s=' . $poly_feature_2->name .'&format=tab' );
83 is $mech->content, sprintf(<<'EOT',$poly_feature->name,$poly_feature_2->name), 'right content for tab-delimited fetch';
84 %s AATTCCGGAATTCCGGAATTCCGG
85 %s AATTCCGGAATTCCGGAATTCCGG
89 $mech->get("/api/v1/sequence/download/single/JUNK.fasta");
90 is( $mech->status, 404, 'feature not found' );
92 $mech->get("/api/v1/sequence/download/multi?s=" . $poly_feature->feature_id . '&s=JUNK');
93 is( $mech->status, 200, 'multi api query succeeds if any identifiers are valid');
95 $mech->get("/api/v1/sequence/download/multi?s=" . $poly_feature->feature_id);
96 is( $mech->status, 200, 'multi api query succeeds if given single id');
98 $mech->get("/api/v1/sequence/download/multi?s=JUNK");
99 is( $mech->status, 404, 'multi api query with only a single invalid id = 404');