4 SGN::Test::Fixture - use the fixture in unit tests
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
20 my $sample_class = CXGN::SampleClass->new( { dbh => $dbh });
22 is ($sample_class->foo(), 42, "foo test");
28 Lukas Mueller <lam87@cornell.edu>
33 package SGN
::Test
::Fixture
;
40 use File
::Slurp qw
| read_file
|;
41 use Bio
::Chado
::Schema
;
42 use CXGN
::Phenome
::Schema
;
43 use CXGN
::Metadata
::Schema
;
45 use Catalyst
::Authentication
::User
;
46 use CXGN
::People
::Person
;
53 if (! -f
'sgn_fixture.conf') {
54 print "ERROR! sgn_fixture.conf does not exist. Abort. Are you running test_fixture.pl ?\n";
58 my $all_config = Config
::Any
->load_files({
59 files
=> ['sgn_fixture.conf'], use_ext
=>1
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",
96 has
'bcs_schema' => (isa
=> 'Bio::Chado::Schema',
100 has
'phenome_schema' => (isa
=> 'CXGN::Phenome::Schema',
104 has
'sgn_schema' => (isa
=> 'SGN::Schema',
108 has
'metadata_schema' => (isa
=> 'CXGN::Metadata::Schema',
112 has
'user' => ( isa
=> 'Object',
116 has
'sp_person_id' => ( isa
=> 'Int',
120 has
'username' => ( isa
=> 'Str',
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();
148 return $self->config->{$name};