start fixing test for multi cat phenotype upload.
[sgn.git] / t / unit_fixture / CXGN / BreedersToolbox / Projects.t
blob68039e78ff7b507969b0959ea8fa9be15e34d04e
1 #test all functions in CXGN::BreedersToolbox::Projects
3 use strict;
5 use lib 't/lib';
7 use Test::More;
8 use Data::Dumper;
9 use SGN::Test::Fixture;
10 use CXGN::BreedersToolbox::Projects;
12 my $f = SGN::Test::Fixture->new();
13 my $schema = $f->bcs_schema();
15 my $p = CXGN::BreedersToolbox::Projects->new({schema=>$schema});
17 $f->get_db_stats();
19 my $trial_id = $schema->resultset('Project::Project')->find({name=>'test_trial'})->project_id();
20 ok($p->trial_exists($trial_id));
22 my $projects = $p->get_breeding_programs();
23 #print STDERR Dumper $projects;
24 is_deeply($projects, [
25           [
26             134,
27             'test',
28             'test'
29           ]
30         ], 'test get bps');
32 my $bp_project_id = $p->get_breeding_program_by_name('test');
33 ok($bp_project_id);
35 my ($field_trials, $cross_trials, $genotyping_trials) = $p->get_trials_by_breeding_program($bp_project_id->project_id);
36 my @sorted_field_trials = sort {$a->[0] cmp $b->[0]} @$field_trials;
37 print STDERR Dumper \@sorted_field_trials;
38 is_deeply(\@sorted_field_trials, [
39           [
40             '137',
41             'test_trial',
42             'test trial'
43           ],
44           [
45             '139',
46             'Kasese solgs trial',
47             'This trial was loaded into the fixture to test solgs.'
48           ],
49           [
50             '141',
51             'trial2 NaCRRI',
52             'another trial for solGS'
53           ],
54           [
55             '144',
56             'test_t',
57             'test tets'
58           ],
59           [
60             '165',
61             'CASS_6Genotypes_Sampling_2015',
62             'Copy of trial with postcomposed phenotypes from cassbase.'
63           ]
64         ], 'test get trials');
65 #print STDERR Dumper $cross_trials;
66 =begin
67 my @sorted_cross_trials = sort {$a->[0] cmp $b->[0]} @$cross_trials;
68 #print STDERR Dumper \@sorted_cross_trials;
69 is_deeply(\@sorted_cross_trials, [
70           [
71             '138',
72             'test5',
73             'test5'
74           ],
75           [
76             '145',
77             'cross_test1',
78             'cross_test1'
79           ],
80           [
81             '146',
82             'cross_test4',
83             'cross_test4'
84           ],
85           [
86             '147',
87             'cross_test5',
88             'cross_test5'
89           ],
90           [
91             '148',
92             'cross_test6',
93             'cross_test6'
94           ],
95           [
96             '149',
97             'cross_test2',
98             'cross_test2'
99           ],
100           [
101             '150',
102             'cross_test3',
103             'cross_test3'
104           ],
105           [
106             '151',
107             'TestCross1',
108             'TestCross1'
109           ],
110           [
111             '152',
112             'TestCross2',
113             'TestCross2'
114           ],
115           [
116             '153',
117             'TestCross3',
118             'TestCross3'
119           ],
120           [
121             '154',
122             'TestCross4',
123             'TestCross4'
124           ],
125           [
126             '155',
127             'TestCross5',
128             'TestCross5'
129           ],
130           [
131             '156',
132             'TestCross6',
133             'TestCross6'
134           ],
135           [
136             '157',
137             'TestCross7',
138             'TestCross7'
139           ],
140           [
141             '158',
142             'TestCross8',
143             'TestCross8'
144           ],
145           [
146             '159',
147             'TestCross9',
148             'TestCross9'
149           ],
150           [
151             '160',
152             'TestCross10',
153             'TestCross10'
154           ],
155           [
156             '161',
157             'TestCross11',
158             'TestCross11'
159           ],
160           [
161             '162',
162             'TestCross12',
163             'TestCross12'
164           ],
165           [
166             '163',
167             'TestCross13',
168             'TestCross13'
169           ],
170           [
171             '164',
172             'TestCross14',
173             'TestCross14'
174           ]
175         ], 'test get crosses');
176 =end
178 =cut
180 #print STDERR Dumper $genotyping_trials;
181 is_deeply($genotyping_trials, undef, 'test get geno trials');
183 my $locations = $p->get_location_geojson_data();
184 print STDERR Dumper $locations;
185 is_deeply($locations, [{"geometry"=>{"coordinates"=>[-115.86428,32.61359],"type"=>"Point"},"properties"=>{"Abbreviation"=>undef,"Altitude"=>109,"Code"=>"USA","Country"=>"United States","Id"=>"23","Latitude"=>32.61359,"Longitude"=>-115.86428,"NOAAStationID"=>undef,"Name"=>"test_location","Program"=>"test","Trials"=>"<a href=\"/search/trials?location_id=23\">5 trials</a>","Type"=>undef},"type"=>"Feature"},{"geometry"=>{"coordinates"=>[-76.4735,42.45345],"type"=>"Point"},"properties"=>{"Abbreviation"=>undef,"Altitude"=>274,"Code"=>"USA","Country"=>"United States","Id"=>"24","Latitude"=>42.45345,"Longitude"=>-76.4735,"NOAAStationID"=>undef,"Name"=>"Cornell Biotech","Program"=>"test","Trials"=>"<a href=\"/search/trials?location_id=24\">0 trials</a>","Type"=>undef},"type"=>"Feature"},{"geometry"=>{"coordinates"=>[undef,undef],"type"=>"Point"},"properties"=>{"Abbreviation"=>undef,"Altitude"=>undef,"Code"=>undef,"Country"=>undef,"Id"=>"25","Latitude"=>undef,"Longitude"=>undef,"NOAAStationID"=>undef,"Name"=>"NA","Program"=>undef,"Trials"=>"<a href=\"/search/trials?location_id=25\">0 trials</a>","Type"=>undef},"type"=>"Feature"},{"geometry"=>{"coordinates"=>[undef,undef],"type"=>"Point"},"properties"=>{"Abbreviation"=>undef,"Altitude"=>undef,"Code"=>undef,"Country"=>undef,"Id"=>"26","Latitude"=>undef,"Longitude"=>undef,"NOAAStationID"=>undef,"Name"=>"[Computation]","Program"=>undef,"Trials"=>"<a href=\"/search/trials?location_id=26\">0 trials</a>","Type"=>undef},"type"=>"Feature"}]);
189 #'[{"geometry":{"coordinates":[-115.864,32.6136],"type":"Point"},"properties":{"Abbreviation":null,"Altitude":109,"Code":"USA","Country":"United States","Id":"23","Latitude":32.6136,"Longitude":-115.864,"NOAAStationID":null,"Name":"test_location","Program":"test","Trials":"<a href=\"/search/trials?location_id=23\">5 trials</a>","Type":null},"type":"Feature"},{"geometry":{"coordinates":[-76.4735,42.4534],"type":"Point"},"properties":{"Abbreviation":null,"Altitude":274,"Code":"USA","Country":"United States","Id":"24","Latitude":42.4534,"Longitude":-76.4735,"NOAAStationID":null,"Name":"Cornell Biotech","Program":"test","Trials":"<a href=\"/search/trials?location_id=24\">0 trials</a>","Type":null},"type":"Feature"},{"geometry":{"coordinates":[null,null],"type":"Point"},"properties":{"Abbreviation":null,"Altitude":null,"Code":null,"Country":null,"Id":"25","Latitude":null,"Longitude":null,"NOAAStationID":null,"Name":"NA","Program":null,"Trials":"<a href=\"/search/trials?location_id=25\">0 trials</a>","Type":null},"type":"Feature"}]', 'get locations by bp');
191 my $all_locations = $p->get_all_locations();
192 print STDERR Dumper $all_locations;
193 is(scalar(@$all_locations), 4);
194 is_deeply($all_locations,[
195               [ 26,
196                 '[Computation]',
197                 ],
198           [
199             24,
200             'Cornell Biotech'
201           ],
202           [
203             25,
204             'NA'
205           ],
206           [
207             23,
208             'test_location'
209           ]
210         ], 'get all locations');
212 my $all_locations = $p->get_locations();
213 print STDERR Dumper $all_locations;
214 is_deeply($all_locations, [
215           [
216             24,
217             'Cornell Biotech',
218             '42.45345',
219             '-76.4735',
220             '274',
221             0
222           ],
223           [
224             23,
225             'test_location',
226             '32.61359',
227             '-115.86428',
228             '109',
229             5456
230           ],
231           [
232             25,
233             'NA',
234             undef,
235             undef,
236             undef,
237             0
238           ],
239           [
240             26,
241             '[Computation]',
242             undef,
243             undef,
244             undef,
245             0
246           ]
247         ], 'get all locations');
249 my @all_years = $p->get_all_years();
250 print STDERR Dumper \@all_years;
251 is_deeply(\@all_years, [
252           '2017',
253           '2016',
254           '2015',
255           '2014'
256         ], 'get all years');
258 my $new_bp = CXGN::BreedersToolbox::Projects->new({
259     schema=>$schema,
260     name => 'test_new_bp_to_edit',
261     description => 'test_new_bp_desc_to_edit',
263 my $new_bp_result = $new_bp->store_breeding_program();
264 print STDERR Dumper $new_bp_result;
265 ok($new_bp_result->{success});
267 my $edit_bp = CXGN::BreedersToolbox::Projects->new({
268     schema=>$schema,
269     id => $new_bp_result->{id},
270     name => 'test_new_bp',
271     description => 'test_new_bp_desc',
273 my $edit_bp_result = $edit_bp->store_breeding_program();
274 print STDERR Dumper $edit_bp_result;
275 ok($edit_bp_result->{success});
277 my $bp_projects = $p->get_breeding_program_with_trial($trial_id);
278 #print STDERR Dumper $bp_projects;
279 is_deeply($bp_projects, [
280           [
281             134,
282             'test',
283             'test'
284           ]
285         ], 'get bps');
287 my $gt_protocols = $p->get_gt_protocols();
288 #print STDERR Dumper $gt_protocols;
289 is_deeply($gt_protocols, [
290           [
291             1,
292             'GBS ApeKI genotyping v4'
293           ]
294         ], 'get gt protocols');
296 my $program_id = $schema->resultset('Project::Project')->find({name=>'test_new_bp'})->project_id();
297 ok($p->delete_breeding_program($program_id));
299 $f->clean_up_db();
301 done_testing;