10 use SGN::Test::Data qw/create_test/;
11 use Test::Most tests => 5;
13 use SGN::Test::Fixture;
18 my $tempdir = File::Temp->newdir;
19 my $context = SGN::Context->new;
21 # make a mock context to munge the configuration for stuff to go into a tempdir
22 my $mock_context = Test::MockObject->new;
24 static_datasets_path => "$tempdir",
25 image_dir => 'images',
26 basepath => "$tempdir",
27 tempfiles_subdir => 'temp',
28 static_datasets_url => 'fake_static_datasets_url',
30 $mock_context->mock( 'get_conf', sub { $config->{$_[1]} or die "$_[1] conf var not mocked" } );
31 $mock_context->mock( 'config', sub { $config } );
32 $mock_context->mock( 'dbc', sub { $context->dbc } );
33 $mock_context->mock( 'test_mode', sub {1} );
35 my $organism = create_test( 'Organism::Organism', {} );
36 my $image = SGN::Image->new(undef, $organism->organism_id, $mock_context );
38 # The SGN::Image api will probably be changed in the future so that no dbh needs
41 isa_ok($image, 'SGN::Image');
43 lives_ok( sub { $image->process_image("t/data/tv_test_1.png", "organism", $organism->organism_id) }, 'process_image lives' );
45 my $url = $image->get_image_url('medium');
46 like($url, qr!^/fake_static_datasets_url/images/[a-f\d\/]+/medium\.jpg$!, 'getting a medium image');
48 can_ok( $image, qw/get_organisms get_stocks get_experiments get_loci process_image config associate_experiment/);
50 # we can't use $image->hard_delete because that connects as web_usr which doesn't
51 # have permissions to delete images
54 #my $dbh = SGN::Context->new->dbc('sgn_test')->dbh;
55 my $dbh = SGN::Test::Fixture->new()->dbh();
56 my $oid = $organism->organism_id;
57 my $iid = $image->get_image_id;
58 $dbh->do("delete from metadata.md_image_organism where organism_id = ?", undef, $organism->organism_id ) if $organism;
59 $dbh->do("delete from metadata.md_image where image_id = ?",undef,$image->get_image_id) if $image;