<commit_before>use strict;
use warnings;
use Test::More;
use Data::Dumper;

BEGIN {
    $ENV{SGN_SKIP_CGI} = 1; #< don't need to compile all the CGIs
    use_ok 'Catalyst::Test', 'SGN';
    use_ok 'SGN::Controller::Organism';
}


my $controller = SGN->controller('Organism');

my $schema = SGN->dbic_schema('Bio::Chado::Schema','sgn_chado');

SKIP: {

    my $organism = $schema->resultset('Organism::Organism')
                          ->search({ species => 'Solanum lycopersicum' },
                                   { rows => 1 }
                                  )
                          ->single;

    skip 'no organism to test on', 3 unless $organism;

    my $summary = $controller->species_data_summary_cache->thaw( $organism->organism_id );

    is( lc( $summary->{'Common Name'}), 'tomato', 'got common name from summary cache' );

}

my $sol100 = $controller->organism_sets->{sol100}{resultset};
isa_ok( $sol100, 'DBIx::Class::ResultSet', 'got sol100 organism resultset' );

# find an organism that is in the solanaceae but not part of sol100
my $solanaceae = $controller->organism_sets->{Solanaceae}{resultset};
isa_ok( $sol100, 'DBIx::Class::ResultSet', 'got solanaceae resultset' );

my $test_organism = $solanaceae
    ->search({ 'organism.organism_id' => { -not_in => $sol100->get_column('organism_id')->as_query }},
             { rows => 1, }
            )
    ->single;

SKIP: {
    skip 'could not find an organism to test with', 0 unless $test_organism;

    diag "using test organism ".$test_organism->species;
}

done_testing;
<commit_msg>tests for sol100 organism adding<commit_after>use strict;
use warnings;
use Test::More;
use Data::Dumper;

use FindBin;
use lib "$FindBin::RealBin/lib";

BEGIN {
    use_ok 'SGN::Test::WWW::Mechanize';
    use_ok 'SGN::Controller::Organism';
}


my $controller = SGN->controller('Organism');

my $schema = SGN->dbic_schema('Bio::Chado::Schema','sgn_chado');

SKIP: {

    my $organism = $schema->resultset('Organism::Organism')
                          ->search({ species => 'Solanum lycopersicum' },
                                   { rows => 1 }
                                  )
                          ->single;

    skip 'no organism to test on', 3 unless $organism;

    my $summary = $controller->species_data_summary_cache->thaw( $organism->organism_id );

    is( lc( $summary->{'Common Name'}), 'tomato', 'got common name from summary cache' );

}

my $sol100 = $controller->organism_sets->{sol100}{resultset};
isa_ok( $sol100, 'DBIx::Class::ResultSet', 'got sol100 organism resultset' );

# find an organism that is in the solanaceae but not part of sol100
my $solanaceae = $controller->organism_sets->{Solanaceae}{resultset};
isa_ok( $sol100, 'DBIx::Class::ResultSet', 'got solanaceae resultset' );

my $test_organism = $solanaceae
    ->search({ 'organism.organism_id' => { -not_in => $sol100->get_column('organism_id')->as_query }},
             { rows => 1, }
            )
    ->single;
diag "using test organism ".$test_organism->species;

SKIP: {
    skip 'could not find an organism to test with', 0 unless $test_organism;

    my $mech = SGN::Test::WWW::Mechanize->new;
    $mech->get_ok( '/organism/sol100/view' );
    $mech->content_contains('SOL100 Organisms');
    $mech->content_contains('presents a summary');
    $mech->content_contains('click on an organism name');
    $mech->content_lacks('Add to Tree','not logged in, does not have a form for adding an organism');
    $mech->while_logged_in( user_type => 'curator', sub {
        $mech->get_ok( '/organism/sol100/view' );
        $mech->content_contains( 'Authorized user', 'now says authorized user' );
        $mech->content_contains( 'Add a SOL100 organism', 'now has an adding form' );
        $mech->submit_form_ok({
            form_name => 'sol100_add_form',
            fields    => { species => $test_organism->species },
           }, 'submitted add organism form');
    });

    my $props = $test_organism->search_related('organismprops',{ 'type.name' => 'sol100'},{ join => 'type'} );
    is( $props->count, 1, 'test organism has been added to sol100' );
    is( $props->single->value, 1, 'has value one' );
    $props->delete;
}

done_testing;

{'fraction_non_alphanumeric': 0.15523380014241633, 'fraction_numerical': 0.018276762402088774, 'mean_word_length': 3.1599210266535045, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 72, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6577665', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1362, 'n_words': 335}