start fixing test for multi cat phenotype upload.
[sgn.git] / t / unit_fixture / CXGN / DownloadFieldMapSpreadsheet.t
blobcebd6ac2a2fce7bb7f78cbe69752d45274da2126
1 use strict;
2 use lib 't/lib';
4 use Test::More;
5 use SGN::Test::Fixture;
7 use Data::Dumper;
8 use CXGN::Trial;
9 use CXGN::Trial::TrialLayoutDownload;
10 use Test::WWW::Mechanize;
11 use LWP::UserAgent;
12 use JSON;
14 my $test = SGN::Test::Fixture->new();
15 my $schema = $test->bcs_schema;
17 my $mech = Test::WWW::Mechanize->new;
19 $mech->post_ok('http://localhost:3010/brapi/v1/token', [ "username"=> "janedoe", "password"=> "secretpw", "grant_type"=> "password" ]);
20 my $response = decode_json $mech->content;
21 print STDERR Dumper $response;
22 is($response->{'metadata'}->{'status'}->[2]->{'message'}, 'Login Successfull');
23 my $sgn_session_id = $response->{access_token};
24 print STDERR $sgn_session_id."\n";
26 my $trial_id = $schema->resultset('Project::Project')->find({name=>'test_trial'})->project_id();
28 my $file = $test->config->{basepath}."/t/data/trial/field_coord_upload.csv";
29 my $ua = LWP::UserAgent->new;
30 $response = $ua->post(
31         'http://localhost:3010/ajax/breeders/trial/coordsupload',
32         Content_Type => 'form-data',
33         Content => [
34             trial_coordinates_uploaded_file => [ $file, 'coords_upload', Content_Type => 'application/vnd.ms-excel', ],
35             "trial_coordinates_upload_trial_id"=>$trial_id,
36             "sgn_session_id"=>$sgn_session_id
37         ]
38     );
40 #print STDERR Dumper $response;
41 ok($response->is_success);
42 my $message = $response->decoded_content;
43 my $message_hash = decode_json $message;
44 print STDERR Dumper $message_hash;
46 my $trial_layout_download = CXGN::Trial::TrialLayoutDownload->new({
47     schema => $schema,
48     trial_id => $trial_id,
49     data_level => 'plot_fieldMap',
50     selected_columns => {
51                'accession_name' => 1,
52                'col_number' => 1,
53                'row_number' => 1
54              },
55 });
56 my $output = $trial_layout_download->get_layout_output();
57 my %hash = %{$output->{output}};
58 print STDERR Dumper \%hash;
60 is_deeply(\%hash, {
61           '4' => {
62                    '3' => 'test_accession5',
63                    '1' => 'test_accession3',
64                    '2' => 'test_accession1'
65                  },
66           '2' => {
67                    '3' => 'test_accession4',
68                    '2' => 'test_accession1',
69                    '1' => 'test_accession3'
70                  },
71           '1' => {
72                    '3' => 'test_accession3',
73                    '1' => 'test_accession4',
74                    '2' => 'test_accession5'
75                  },
76           '3' => {
77                    '3' => 'test_accession2',
78                    '2' => 'test_accession1',
79                    '1' => 'test_accession5'
80                  },
81           '5' => {
82                    '2' => 'test_accession4',
83                    '1' => 'test_accession2',
84                    '3' => 'test_accession2'
85                  }
86         });
88 my $trial_layout = CXGN::Trial::TrialLayout->new({
89    schema => $schema,
90    trial_id => $trial_id,
91    experiment_type => 'field_layout'
92 });
93 my $tl = $trial_layout->get_design();
95 #Remove row_number and col_number so tests downstream don't fail
96 foreach (values %$tl) {
97     my $stock = CXGN::Stock->new({
98         schema => $schema,
99         stock_id => $_->{plot_id}
100     });
101     $stock->_remove_stockprop('row_number', $_->{row_number});
102     $stock->_remove_stockprop('col_number', $_->{col_number});
104 $trial_layout->generate_and_cache_layout();
107 done_testing();
109