From 5e8373a9827eea1e8a2239d5b97703cd747463d9 Mon Sep 17 00:00:00 2001 From: titima15 Date: Tue, 17 Jan 2023 17:25:58 -0500 Subject: [PATCH] added tests --- lib/CXGN/Pedigree/TargetNumbers.pm | 4 +- .../Controller/AJAX/Cross/CrossingExperiment.pm | 1 - t/data/cross/intercross_upload.csv | 8 +-- t/data/cross/target_numbers.xls | Bin 0 -> 5632 bytes t/data/cross/target_numbers.xlsx | Bin 0 -> 5016 bytes .../CXGN/Uploading/UploadIntercrossData.t | 65 ++++++++++++++++++++- 6 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 t/data/cross/target_numbers.xls create mode 100644 t/data/cross/target_numbers.xlsx diff --git a/lib/CXGN/Pedigree/TargetNumbers.pm b/lib/CXGN/Pedigree/TargetNumbers.pm index 66f7a85a7..80a3bd3b5 100644 --- a/lib/CXGN/Pedigree/TargetNumbers.pm +++ b/lib/CXGN/Pedigree/TargetNumbers.pm @@ -96,10 +96,10 @@ sub get_target_numbers_and_progress { my $target_info = decode_json $prop_value; my %target_numbers_hash = %{$target_info}; - foreach my $female_accession(keys %target_numbers_hash) { + foreach my $female_accession( sort keys %target_numbers_hash) { my $female_details = $target_numbers_hash{$female_accession}; my %female_hash = %{$female_details}; - foreach my $male_accession (keys %female_hash) { + foreach my $male_accession (sort keys %female_hash) { my $seed_target_number = $female_hash{$male_accession}{'target_number_of_seeds'}; my $progeny_target_number = $female_hash{$male_accession}{'target_number_of_progenies'}; my $cross_info = $self->_get_cross_and_info($crossing_experiment_id, $female_accession, $male_accession); diff --git a/lib/SGN/Controller/AJAX/Cross/CrossingExperiment.pm b/lib/SGN/Controller/AJAX/Cross/CrossingExperiment.pm index b2d0a5358..5c7937608 100644 --- a/lib/SGN/Controller/AJAX/Cross/CrossingExperiment.pm +++ b/lib/SGN/Controller/AJAX/Cross/CrossingExperiment.pm @@ -58,7 +58,6 @@ sub upload_target_numbers_POST : Args(0) { my $c = shift; my $schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado'); my $metadata_schema = $c->dbic_schema("CXGN::Metadata::Schema"); - my $phenome_schema = $c->dbic_schema("CXGN::Phenome::Schema"); my $dbh = $c->dbc->dbh; my $target_numbers_experiment_id = $c->req->param('target_numbers_experiment_id'); my $upload = $c->req->upload('target_numbers_file'); diff --git a/t/data/cross/intercross_upload.csv b/t/data/cross/intercross_upload.csv index 53f008d8f..8ae9241d9 100644 --- a/t/data/cross/intercross_upload.csv +++ b/t/data/cross/intercross_upload.csv @@ -1,5 +1,5 @@ crossDbId,femaleObsUnitDbId,maleObsUnitDbId,timestamp,person,experiment,type,fruits,flowers,seeds -transaction_id_0004,UG120001,UG120002,2020-09-05_18_16_01_676,titima,intercross_upload,BIPARENTAL,0,5,0 -transaction_id_0003,UG120002,UG120003,2020-09-05_18_15_10_003,titima,intercross_upload,BIPARENTAL,0,3,0 -transaction_id_0002,UG120002,UG120003,2020-09-02_13_13_19_006,titima,intercross_upload,BIPARENTAL,0,7,0 -transaction_id_0001,UG120001,UG120002,2020-09-01_13_13_19_006,titima,intercross_upload,BIPARENTAL,0,10,0 +transaction_id_0004,UG120001,UG120002,2020-09-05_18_16_01_676,titima,intercross_upload,BIPARENTAL,0,5,10 +transaction_id_0003,UG120002,UG120003,2020-09-05_18_15_10_003,titima,intercross_upload,BIPARENTAL,0,3,5 +transaction_id_0002,UG120002,UG120003,2020-09-02_13_13_19_006,titima,intercross_upload,BIPARENTAL,0,7,20 +transaction_id_0001,UG120001,UG120002,2020-09-01_13_13_19_006,titima,intercross_upload,BIPARENTAL,0,10,25 diff --git a/t/data/cross/target_numbers.xls b/t/data/cross/target_numbers.xls new file mode 100644 index 0000000000000000000000000000000000000000..07d79706e5007bc25eeb8f8e2ac2ffa18252c4bf GIT binary patch literal 5632 zcwX&SYiL|m5T0{)H@SH<*`$e&K9bwmY~GSh1S3+DzN`gnLz<#UA#OG|Y3wE&HVIm> zxJ~UpcWRxu2C91OfH&@XHiCqOaaXV<0Ud2*=#%>Pl)3i@UMayhw>h} zv40*Q?|G)PuUQV=fd3}6Q5e?{S+t+}K_hgMRs(k-Vp89?+qsR^T?^c3=sx zl(Zi^9Ll&8<8p_uppCk7Cm_qjE@pV>vrXUfmdoB>LqvSwo{+fs8F-8aI5zeMLP6_J z!5;A;pxB3T1nDk}6rG1OkKPyQ=W^dA(FbTDt4Rimrd5mhJ}UPzx#tnXRi=v+RGZMRJ5y?Msp+=@2Id0oS{#THj3fF`(fkf@2ihiM|xkAU<#8yU(D>0{V zqGM0RM#_nC4t5lAB!PQS(jIeiJp_`~zkGHoYKc0~ZWD@3#8_ zA-f|G4BCT(z2SZw5Ay|h`=D)ibqoa}J@!yX|8QTY9l=2{5DE9#{U_(k@#3Qg{0;T> z_5S3rAvtV}<2*8{#jVeypjiy0IVg6h!H1SEZr*vtEfg~j1=P#_E9#p`ard-I1w zovqCsB9A72bEurRiOSV!JehD;i$;yyM`Ugh?IavxzP-M(_TD~w(0amt&T0$y1^R2- z?4IFJAX4V@H~4lJBb0p0&T9?y*p{#Lj2L)X?mjrvC~&>GB4u2O@tL}-BXw6}%~dJm z3#fQm_(Ubw2-T`umC#90MMv>&lTOJR5?wCJ7s@HE9JQx*9|Ml zdvIMWP4ZZD70uB+8F@lna_5CL4X-mU*R@jRi%cybGty);(wXR9gd9$RQ*)dl8=c@> z;9L%;M9)3Pu^#t6U*J4ZqW87T=oUSmV+ikYGz`(ma5N0jct>WmiN+0TW!tgGNCGTo zlFl|Z2`^&x+J3B3+o^!#WzfI6AMjW5_InAT9SzImB4hSri%8$ZXfpeFnoA+X{7~#?eq5})?m5$ z3>NU9Ggh!0B72G1O9NM;)P8=s`3z-5PLITO

Sq`}@$F^4=dr6m-j;uw)25YZ#Kn uq0+I>^=YN{?*qQ)j6Jju7J}k~EfKgnf11|t{Wym4ruBo>+W#m0|NjZDg-s~{ literal 0 HcwPel00001 diff --git a/t/data/cross/target_numbers.xlsx b/t/data/cross/target_numbers.xlsx new file mode 100644 index 0000000000000000000000000000000000000000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F-NUzBPngUHipA)x{9AiOyhxTNTC*>EZ;4 zP3+=Iaqvrj@i%Zc=rew#%!y^w>Z-DALGrB(Up7mAZ~1W?+Z$Uo=~S`3)x?M9HUMa} z%5^4jt(SvuZ9Logt)ff@F|M21A`U#n{'success'}, '1'); my $crossing_experiment_rs = $schema->resultset('Project::Project')->find({name =>'intercross_upload'}); my $crossing_experiment_id = $crossing_experiment_rs->project_id(); +#test uploading target numbers +my $target_numbers_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'target_numbers_json', 'project_property')->cvterm_id(); +my $before_uploading_target_numbers_all_projectprop = $schema->resultset("Project::Projectprop")->search({})->count(); +my $before_uploading_target_numbers = $schema->resultset("Project::Projectprop")->search({ project_id => $crossing_experiment_id, type_id => $target_numbers_type_id })->count(); + +for my $extension ("xls", "xlsx") { + my $file = $f->config->{basepath} . "/t/data/cross/target_numbers.$extension"; + my $ua = LWP::UserAgent->new; + my $response = $ua->post( + 'http://localhost:3010/ajax/crossing_experiment/upload_target_numbers', + Content_Type => 'form-data', + Content => [ + "target_numbers_file" => [ + $file, + "target_numbers.$extension", + Content_Type => ($extension eq "xls") ? 'application/vnd.ms-excel' : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + ], + "target_numbers_experiment_id" => $crossing_experiment_id, + "sgn_session_id" => $sgn_session_id + ] + ); + ok($response->is_success); + my $message = $response->decoded_content; + my $message_hash = decode_json $message; + is_deeply($message_hash, { 'success' => 1 }); +} + +my $after_uploading_target_numbers_all_projectprop = $schema->resultset("Project::Projectprop")->search({})->count(); +my $after_uploading_target_numbers = $schema->resultset("Project::Projectprop")->search({ project_id => $crossing_experiment_id, type_id => $target_numbers_type_id })->count(); + +is($after_uploading_target_numbers_all_projectprop, $before_uploading_target_numbers_all_projectprop + 1); +is($after_uploading_target_numbers, $before_uploading_target_numbers + 1); + +#retrieving target number +$mech->post_ok("http://localhost:3010/ajax/crossing_experiment/target_numbers_and_progress/$crossing_experiment_id"); +$response = decode_json $mech->content; +is_deeply($response, { 'data' => [ + ['UG120001','UG120002',50,undef,25,undef,''], + ['UG120002','UG120003',40,undef,20,undef,''] +]}, 'target numbers'); + + +#uploading intercross data my $cross_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, "cross", "stock_type")->cvterm_id(); my $before_uploading_cross = $schema->resultset("Stock::Stock")->search({ type_id => $cross_type_id})->count(); my $before_uploading_stocks = $schema->resultset("Stock::Stock")->search({})->count(); @@ -66,6 +109,25 @@ is($after_uploading_cross, $before_uploading_cross + 2); is($after_uploading_stocks, $before_uploading_stocks + 2); is($after_uploading_relationship, $before_uploading_relationship + 4); +#retrieving target number and progress +$mech->post_ok("http://localhost:3010/ajax/crossing_experiment/target_numbers_and_progress/$crossing_experiment_id"); +$response = decode_json $mech->content; +my $target_data = $response->{'data'}; + +is($target_data->[0]->[0], 'UG120001'); +is($target_data->[0]->[1], 'UG120002'); +is($target_data->[0]->[2], 50); +is($target_data->[0]->[3], 35); +is($target_data->[0]->[4], 25); +is($target_data->[0]->[5], 0); + +is($target_data->[1]->[0], 'UG120002'); +is($target_data->[1]->[1], 'UG120003'); +is($target_data->[1]->[2], 40); +is($target_data->[1]->[3], 25); +is($target_data->[1]->[4], 20); +is($target_data->[1]->[5], 0); + # checking number of crosses in intercross_upload experiment $mech->post_ok("http://localhost:3010/ajax/breeders/trial/$crossing_experiment_id/crosses_and_details_in_trial"); $response = decode_json $mech->content; @@ -75,8 +137,7 @@ my $number_of_crosses = @$crosses; is($number_of_crosses, 2); # checking transactions in intercross_upload_1 -my $intercross_upload_1_id = $schema->resultset('Stock::Stock')->find({name =>'intercross_upload_1'})->stock_id(); - +my $intercross_upload_1_id = $schema->resultset('Stock::Stock')->find({ name => 'intercross_upload_1' })->stock_id(); $mech->post_ok("http://localhost:3010/ajax/cross/transactions/$intercross_upload_1_id"); $response = decode_json $mech->content; my %result = %$response; -- 2.11.4.GIT