Skip to content

Commit

Permalink
database creation script and test case fixes
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.code.sf.net/p/ledger-smb/code/trunk@3413 4979c152-3d1c-0410-bac9-87ea11338e46
  • Loading branch information
einhverfr committed Jul 2, 2011
1 parent 3893fae commit ea8343d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
15 changes: 4 additions & 11 deletions LedgerSMB/Database.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ sub new {
if ($self->{source_dir}){
$self->{source_dir} =~ s/\/*$/\//;
}
if (isa($args, 'LedgerSMB')){
for (keys %$args){
if ($_ =~ /^_/){
$self->{$_} = $args->{$_};
}
}
}
bless $self, $class;
return $self;
}
Expand All @@ -90,16 +83,16 @@ sub create {

for my $contrib (@contrib_scripts){
my $rc2;
$rc2=system("psql -f $ENV{PG_CONTRIB_DIR}/$contrib.sql >>$temp/dblog");
$rc2=system("psql -f $ENV{PG_CONTRIB_DIR}/$contrib.sql 2>>$temp/dblog");
$rc ||= $rc2
}
if (!system("psql -f $self->{source_dir}sql/Pg-database.sql >> $temp/dblog"
if (!system("psql -f $self->{source_dir}sql/Pg-database.sql 2>>$temp/dblog"
)){
$rc = 1;
}
# TODO Add logging of errors/notices

return !$rc;
return $rc;
}

=item $db->load_modules($loadorder)
Expand Down Expand Up @@ -184,7 +177,7 @@ sub process_roles {
close ROLES;
close TROLES;

$self->exec_script({script => "sql/modules/$rolefile",
$self->exec_script({script => "$temp/lsmb_roles.sql",
log => "$temp/dblog"});
}

Expand Down
12 changes: 6 additions & 6 deletions README.tests
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Environment variables can be used as flags to disable/enable tests >= 40

LSMB_TEST_DB must be set to a defined value if databases are going to be tested.

if LSMB_NEW_DB is set, test 40 (when it is complete) will create a database with
the name from this environment variable, and subsequent database tests will run
against that database. If this is not set, and PGDATABASE is set, tests will
run on that database. If neither are set, the tests will bail out.
if LSMB_NEW_DB is set, test 40 will create a database with the name from this
environment variable, and subsequent database tests will run against that
database. If this is not set, and PGDATABASE is set, tests will run on that
database. If neither are set, the tests will bail out.

Special notes on specific test cases:

Expand Down Expand Up @@ -75,7 +75,7 @@ LSMB_ADMIN_PASSWORD password for admin user

Chart of accounts loading
-------------------------
LSMB_LOAD_COA name of the Chart of Accounts file (minus the extension)
LSMB_LOAD_GIFI name of the GIFI file (minus the extension)
LSMB_LOAD_COA name of the Chart of Accounts file, not including extension
LSMB_LOAD_GIFI name of the GIFI file, not including extension
LSMB_COUNTRY_CODE Country code for administrator and for loading chart of
accounts
29 changes: 15 additions & 14 deletions t/40-dbsetup.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ for my $evar (qw(LSMB_NEW_DB LSMB_TEST_DB PG_CONTRIB_DIR)){
}

if ($run_tests){
plan tests => 35;
plan tests => 10;
$ENV{PGDATABASE} = $ENV{LSMB_NEW_DB};
}

Expand All @@ -49,13 +49,13 @@ if (!$ENV{LSMB_INSTALL_DB}){
close (DBLOCK);
}

ok($db->process_roles('Roles.sql'), 'Roles processed');
is($db->process_roles('Roles.sql'), 0, 'Roles processed');

#Changed the COA and GIFI loading to use this, and move admin user to
#Database.pm --CT

SKIP: {
skip 'No admin info', 4
skip 'No admin info', 5
if (!defined $ENV{LSMB_ADMIN_USERNAME}
or !defined $ENV{LSMB_ADMIN_PASSWORD}
or !defined $ENV{LSMB_COUNTRY_CODE}
Expand All @@ -78,9 +78,8 @@ SKIP: {
last_name => $ENV{LSMB_ADMIN_LNAME},
country_id => $ref->{id},
});
my ($var) = $sth->fetchrow_array();
cmp_ok($var, '>', 0, 'User id retrieved');
$sth->finish;
my $user = LedgerSMB::DBObject::Admin->new({base => $lsmb});
ok($user->save);
$sth = $dbh->prepare("SELECT admin__add_user_to_role(?, ?)");
my $rolename = "lsmb_" . $ENV{PGDATABASE} . "__users_manage";
ok($sth->execute($ENV{LSMB_ADMIN_USERNAME}, $rolename),
Expand All @@ -90,18 +89,20 @@ SKIP: {
};

SKIP: {
skip 'No COA specified', 2 if !defined $ENV{LSMB_LOAD_COA};
ok($db->exec_script('sql/coa/'
. lc($ENV{LSMB_COUNTRY_CODE})
."/chart/$ENV{LSMB_LOAD_COA}.sql"),
skip 'No COA specified', 1 if !defined $ENV{LSMB_LOAD_COA};
is($db->exec_script({script => 'sql/coa/'
. lc($ENV{LSMB_COUNTRY_CODE})
."/chart/$ENV{LSMB_LOAD_COA}.sql"
}), 0,
'Ran Chart of Accounts Script');
}

SKIP: {
skip 'No GIFI specified', 2 if !defined $ENV{LSMB_LOAD_GIFI};
ok($db->exec_script('sql/coa/'
. lc($ENV{LSMB_COUNTRY_CODE})
."/chart/$ENV{LSMB_LOAD_GIFI}.sql"),
skip 'No GIFI specified', 1 if !defined $ENV{LSMB_LOAD_GIFI};
is($db->exec_script({script => 'sql/coa/'
. lc($ENV{LSMB_COUNTRY_CODE})
."/gifi/$ENV{LSMB_LOAD_GIFI}.sql"
}), 0,
'Ran GIFI Script');
}

0 comments on commit ea8343d

Please sign in to comment.