upload fieldbook images test. also test no longer uses simulatec
[sgn.git] / t / lib / SGN / Test / Fixture.pm
blobcaee288aa498610116863e8851399115f01c5eac
2 =head1 NAME
4 SGN::Test::Fixture - use the fixture in unit tests
6 =head1 SYNOPSIS
8 my $f = SGN::Test::Fixture;
10 my $dbh = $f->dbh(); # accesses the fixture db
12 my $bcs_schema = $f->bcs_schema(); # access DBIx::Class BCS schema
14 my $phenome_schema = $f->phenome_schema(); # access DBIx::Class phenome schema
16 my $sgn_schema = $f->sgn_schema(); # access DBIx::Class SGN schema
18 # run tests...
20 my $sample_class = CXGN::SampleClass->new( { dbh => $dbh });
22 is ($sample_class->foo(), 42, "foo test");
24 # etc...
26 =head1 AUTHOR
28 Lukas Mueller <lam87@cornell.edu>
30 =cut
33 package SGN::Test::Fixture;
35 use Moose;
36 use DBI;
37 use DBIx::Class;
38 use Config::Any;
39 use Data::Dumper;
40 use File::Slurp qw | read_file |;
41 use Bio::Chado::Schema;
42 use CXGN::Phenome::Schema;
43 use CXGN::Metadata::Schema;
44 use SGN::Schema;
45 use Catalyst::Authentication::User;
46 use CXGN::People::Person;
48 use warnings;
50 sub BUILD {
51 my $self = shift;
53 if (! -f 'sgn_fixture.conf') {
54 print "ERROR! sgn_fixture.conf does not exist. Abort. Are you running test_fixture.pl ?\n";
55 exit();
58 my $all_config = Config::Any->load_files({
59 files=> ['sgn_fixture.conf'], use_ext=>1
60 });
62 my $config = $all_config->[0]->{'sgn_fixture.conf'};
64 $self->config($config);
66 my $dsn = 'dbi:Pg:database='.$self->config->{dbname}.";host=".$self->config->{dbhost}.";port=5432";
68 $self->dbh(DBI->connect($dsn, $self->config->{dbuser}, $self->config->{dbpass}, { on_connect_do => ['SET search_path TO phenome, public, sgn, metadata' ]} ));
70 $self->bcs_schema(Bio::Chado::Schema->connect($dsn, $self->config->{dbuser}, $self->config->{dbpass}));
72 $self->phenome_schema(CXGN::Phenome::Schema->connect($dsn, $self->config->{dbuser}, $self->config->{dbpass}, { on_connect_do => [ 'SET search_path TO phenome, public, sgn, metadata' ] } ));
74 $self->sgn_schema(SGN::Schema->connect($dsn, $self->config->{dbuser}, $self->config->{dbpass}, { on_connect_do => [ 'SET search_path TO metadata, public, sgn' ] }));
76 $self->metadata_schema(CXGN::Metadata::Schema->connect($dsn, $self->config->{dbuser}, $self->{config}->{dbpass}, { on_connect_do => [ 'SET search_path TO metadata, public, sgn' ] }));
78 #Janedoe in fixture db
79 my $catalyst_user = Catalyst::Authentication::User->new();
80 my $sgn_user = CXGN::People::Person->new($self->dbh, 41);
81 $catalyst_user->set_object($sgn_user);
82 $self->user($catalyst_user);
83 $self->sp_person_id(41);
84 $self->username('janedoe');
87 has 'config' => ( isa => "Ref",
88 is => 'rw',
92 has 'dbh' => (
93 is => 'rw',
96 has 'bcs_schema' => (isa => 'Bio::Chado::Schema',
97 is => 'rw',
100 has 'phenome_schema' => (isa => 'CXGN::Phenome::Schema',
101 is => 'rw',
104 has 'sgn_schema' => (isa => 'SGN::Schema',
105 is => 'rw',
108 has 'metadata_schema' => (isa => 'CXGN::Metadata::Schema',
109 is => 'rw',
112 has 'user' => ( isa => 'Object',
113 is => 'rw',
116 has 'sp_person_id' => ( isa => 'Int',
117 is => 'rw',
120 has 'username' => ( isa => 'Str',
121 is => 'rw',
124 sub dbic_schema {
125 my $self = shift;
126 my $name = shift;
128 if ($name eq 'Bio::Chado::Schema') {
129 return $self->bcs_schema();
131 if ($name eq 'CXGN::Phenome::Schema') {
132 return $self->phenome_schema();
134 if ($name eq 'SGN::Schema') {
135 return $self->sgn_schema();
137 if ($name eq 'CXGN::Metadata::Schema') {
138 return $self->metadata_schema();
141 return undef;
144 sub get_conf {
145 my $self = shift;
146 my $name = shift;
148 return $self->config->{$name};