3 use Test::More tests => 34;
5 use Digest::SHA qw/sha1_hex/;
9 use SGN::Test::Data qw/ create_test /;
10 use aliased 'SGN::Test::WWW::Mechanize' => 'Mech', skip_cgi => 1;
12 use_ok 'SGN::Controller::Bulk';
16 my $poly_cvterm = create_test('Cv::Cvterm', { name => 'polypeptide' });
17 my $poly_feature = create_test('Sequence::Feature', { type => $poly_cvterm });
19 # TODO: these tests depend on live data.
20 $mech->with_test_level( local => sub {
21 # do it twice to test for bugs relating to the cache directory getting removed
27 $mech->with_test_level( local => sub {
28 $mech->get('/tools/bulk/tabs/feature_tab');
29 $mech->submit_form_ok({
30 form_name => "bulk_feature",
34 }, "submit bulk_feature with a single invalid identifier");
35 $mech->content_unlike(qr/Caught exception/);
36 $mech->content_contains('Your query did not contain any valid identifiers. Please try again.');
39 $mech->with_test_level( local => sub {
40 $mech->get('/tools/bulk/tabs/feature_tab');
41 $mech->submit_form_ok({
42 form_name => "bulk_feature",
46 }, "submit bulk_feature with no valid identifiers");
47 $mech->content_unlike(qr/Caught exception/);
48 $mech->content_contains('Your query did not contain any valid identifiers. Please try again.');
51 $mech->with_test_level( local => sub {
52 $mech->get('/tools/bulk/tabs/feature_tab');
53 $mech->submit_form_ok({
54 form_name => "bulk_feature",
56 ids => "\nSGN-E398616 ",
58 }, "submit bulk_feature form with leading+trailing whitespace");
59 $mech->content_unlike(qr/Caught exception/);
61 $mech->get('/tools/bulk/tabs/feature_tab');
62 $mech->submit_form_ok({
63 form_name => "bulk_feature",
65 ids => "\nSGN-E398616 BLARG",
67 }, "submit bulk_feature form with invalid identifiers");
68 $mech->content_contains('Your query was successful.');
69 $mech->content_contains('A total of 1 matching features were found for 2 identifiers provided');
72 $mech->with_test_level( local => sub {
73 $mech->get('/tools/bulk/tabs/feature_tab');
74 $mech->submit_form_ok({
75 form_name => "bulk_feature",
77 # NOTE: no trailing whitespace, to test for colliding identifiers
79 feature_file => [ [ undef, 'ids.txt', Content => "AP009263\n" ] ],
81 }, "submit bulk_feature form with file upload and textarea");
82 my $sha1 = sha1_hex(<<ID_LIST);
87 my @flinks = $mech->find_all_links( url_regex => qr{/bulk/feature/download/$sha1\.fasta} );
89 cmp_ok(@flinks, '==', 1, "found one FASTA download link for $sha1.fasta");
90 $mech->links_ok( \@flinks );
92 for my $url (map { $_->url } (@flinks)) {
94 my $length = length($mech->content);
95 cmp_ok($length, '>', 0,"$url has a content length $length > 0");
96 $mech->content_unlike(qr/Caught exception/);
101 $mech->with_test_level( local => sub {
102 # attempt to post an empty list
103 $mech->post('/bulk/feature/submit/', { ids => "" } );
104 $mech->content_like(qr/At least one identifier must be given/);
109 sub submit_bulk_form {
124 $mech->get_ok('/tools/bulk/tabs/feature_tab');
125 $mech->submit_form_ok({
126 form_name => "bulk_feature",
130 }, "submit bulk_feature form");
131 $mech->content_like(qr/Download as/);
133 my $sha1 = sha1_hex($ids);
134 my @flinks = $mech->find_all_links( url_regex => qr{/bulk/feature/download/$sha1\.fasta} );
136 cmp_ok(@flinks, '==', 1, "found one FASTA download link for $sha1.fasta");
137 $mech->links_ok( \@flinks );
139 for my $url (map { $_->url } (@flinks)) {
141 my $length = length($mech->content);
142 cmp_ok($length, '>', 0,"$url has a content length $length > 0");
143 $mech->content_unlike(qr/Caught exception/);
146 @flinks = grep { $_ =~ qr{$sha1} } $mech->find_all_links(url_regex => qr{/bulk/feature/download/.*\.fasta} );
148 cmp_ok(@flinks, '==', 0, "found no other fasta download links") or diag("Unexpected fasta download links" . Dumper [ map {$_->url} @flinks ]);