[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[2924] trunk



Revision: 2924
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2924&view=rev
Author:   einhverfr
Date:     2010-02-28 18:34:09 +0000 (Sun, 28 Feb 2010)

Log Message:
-----------
DB tests now pass fully on new db, and this is a part of the test suite

Modified Paths:
--------------
    trunk/README.tests
    trunk/sql/Pg-database.sql
    trunk/sql/modules/Employee.sql
    trunk/sql/modules/Person.sql
    trunk/sql/modules/test/Account.sql
    trunk/sql/modules/test/Base.sql
    trunk/sql/modules/test/Payment.sql
    trunk/sql/modules/test/Reconciliation.sql
    trunk/t/40-dbsetup.t
    trunk/t/43-dbtest.t

Added Paths:
-----------
    trunk/t/89-dropdb.t

Modified: trunk/README.tests
===================================================================
--- trunk/README.tests	2010-02-28 06:38:39 UTC (rev 2923)
+++ trunk/README.tests	2010-02-28 18:34:09 UTC (rev 2924)
@@ -2,7 +2,9 @@
 00 - 09: General base checks
 10 - 39: Module checks, no LSMB database required
      40: Set up test LSMB database
-41 - 59: Operational checks, LSMB database required
+     41: Addons setup.  Addons should use 41.x notation where x is the run
+         needed to properly install.
+42 - 59: Operational checks, LSMB database required
 60 - 88: Interface checks
      89: Clean up test LSMB database
 90 - 99: Packaging checks
@@ -35,7 +37,7 @@
 ENVIRONMENT VARIABLES USED:
 
 Environment Variables which control which tests are run (set to true to enable):
-LSMB_TEST_DB runs database tests
+ LSMB_TEST_DB runs database tests
 LSMB_TEST_LWP runs LWP tests
 
 Variables to set credentials:
@@ -43,5 +45,18 @@
 LSMB_USER and LSMB_PASS for LWP tests
 
 Variables to configure test suites:
-PGDATABASE directs to the database (or company element in LWP tests)
+   PGDATABASE directs to the database (or company element in LWP tests)
 LSMB_BASE_URL directs LWP tests to the main LSMB instance being tested. 
+
+If you wish to make a new db for tests, you must set the following environment 
+variables:
+
+   LSMB_NEW_DB is the name of the new db.  If this database cannot be created, 
+               the tests will bail out.
+PG_CONTRIB_DIR is the address of the directory where Pg contrib scripts are 
+               located.  You can find it by searching for tablefunc.sql.
+
+Additionally, if LSMB_INSTALL_DB is set, the database will NOT be removed after
+test cases are run.  This can be a useful way of installing the for production
+use, though currently an admin user is not created in this process and would
+need to be created manually.

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2010-02-28 06:38:39 UTC (rev 2923)
+++ trunk/sql/Pg-database.sql	2010-02-28 18:34:09 UTC (rev 2924)
@@ -1,3 +1,5 @@
+CREATE LANGUAGE PLPGSQL; -- separate transaction since may already exist
+
 begin;
 CREATE SEQUENCE id;
 -- As of 1.3 there is no central db anymore. --CT
@@ -408,6 +410,8 @@
   approved_at timestamp
 );
 
+CREATE INDEX transactions_locked_by_i ON transactions(locked_by);
+
 COMMENT on TABLE transactions IS 
 $$ This table tracks basic transactions across AR, AP, and GL related tables.  
 It provies a referential integrity enforcement mechanism for the financial data

Modified: trunk/sql/modules/Employee.sql
===================================================================
--- trunk/sql/modules/Employee.sql	2010-02-28 06:38:39 UTC (rev 2923)
+++ trunk/sql/modules/Employee.sql	2010-02-28 18:34:09 UTC (rev 2924)
@@ -1,73 +1,42 @@
 -- VERSION 1.3.0
 
 
-CREATE OR REPLACE FUNCTION employee__save(
-    in_entity int, in_startdate date, in_enddate date,
-	in_role text, in_sales boolean, in_dob date, 
-    in_managerid integer, in_employeenumber text
-)
-returns int AS $$
+CREATE OR REPLACE FUNCTION employee__save 
+(in_entity_id int, in_start_date date, in_end_date date, in_dob date, 
+	in_role text, in_ssn text, in_sales bool, in_manager_id int, 
+        in_employee_number text)
+RETURNS int AS $$
+DECLARE out_id INT;
+BEGIN
+	UPDATE entity_employee 
+	SET startdate = coalesce(in_start_date, now()::date),
+		enddate = in_end_date,
+		dob = in_dob,
+		role = in_role,
+		ssn = in_ssn,
+		manager_id = in_manager_id,
+		employeenumber = in_employee_number,
+		person_id = (select id FROM person 
+			WHERE entity_id = in_entity_id)
+	WHERE entity_id = in_entity_id;
 
-    DECLARE
-        e_ent entity_employee;
-        e entity;
-        p person;
-        t_startdate date;
-    BEGIN
-        IF in_startdate IS NULL THEN
-             t_startdate := now()::date;
-        ELSE
-             t_startdate := in_startdate;
-        END IF;
+	out_id = in_entity_id;
 
-        select * into e from entity where id = in_entity;
-        
-        IF NOT FOUND THEN
-            RAISE EXCEPTION 'No entity found for ID %', in_entity;
-        END IF;
-        
-        select * into p from person where entity_id = in_entity;
-        
-        IF NOT FOUND THEN
-            RAISE EXCEPTION 'No person found for ID %', in_entity;
-        END IF;
-        
-        -- Okay, we're good. Check to see if we update or insert.
-        
-        select * into e_ent from entity_employee where 
-            entity_id = in_entity;
-            
-        IF NOT FOUND THEN
-            -- insert.
-            
-            INSERT INTO entity_employee (entity_id, startdate, 
-                enddate, role, sales, manager_id, employeenumber, dob)
-            VALUES (in_entity, t_startdate, in_enddate, in_role, 
-                in_sales, in_managerid, in_employeenumber, in_dob);
-            
-            return in_entity;
-        ELSE
-        
-            -- update
-            
-            UPDATE entity_employee
-            SET
-                startdate = t_startdate,
-                enddate = in_enddate,
-                role = in_role,
-                sales = in_sales,
-                manager_id = in_managerid,
-                employeenumber = in_employeenumber,
-                dob = in_dob
-            WHERE
-                entity_id = in_entity;
-                
-            return in_entity;
-        END IF;
-    END;
+	IF NOT FOUND THEN
+		INSERT INTO entity_employee 
+			(startdate, enddate, dob, role, ssn, manager_id, 
+				employeenumber, entity_id, person_id)
+		VALUES
+			(coalesce(in_start_date, now()::date), in_end_date, 
+                                in_dob, in_role, in_ssn,
+				in_manager_id, in_employee_number, in_entity_id,
+				(SELECT id FROM person 
+				WHERE entity_id = in_entity_id));
+		RETURN in_entity_id;
+	END IF;
+END;
+$$ LANGUAGE PLPGSQL;
 
-$$ language 'plpgsql';
-
 create view employees as
     select 
         s.salutation,

Modified: trunk/sql/modules/Person.sql
===================================================================
--- trunk/sql/modules/Person.sql	2010-02-28 06:38:39 UTC (rev 2923)
+++ trunk/sql/modules/Person.sql	2010-02-28 18:34:09 UTC (rev 2924)
@@ -50,40 +50,6 @@
 END;
 $$ language plpgsql;
 
-CREATE OR REPLACE FUNCTION employee__save 
-(in_entity_id int, in_start_date date, in_end_date date, in_dob date, 
-	in_role text, in_ssn text, in_sales bool, in_manager_id int, in_employee_number text)
-RETURNS int AS $$
-DECLARE out_id INT;
-BEGIN
-	UPDATE entity_employee 
-	SET startdate = in_start_date,
-		enddate = in_end_date,
-		dob = in_dob,
-		role = in_role,
-		ssn = in_ssn,
-		manager_id = in_manager_id,
-		employeenumber = in_employee_number,
-		person_id = (select id FROM person 
-			WHERE entity_id = in_entity_id)
-	WHERE entity_id = in_entity_id;
-
-	out_id = in_entity_id;
-
-	IF NOT FOUND THEN
-		INSERT INTO entity_employee 
-			(startdate, enddate, dob, role, ssn, manager_id, 
-				employeenumber, entity_id, person_id)
-		VALUES
-			(in_start_date, in_end_date, in_dob, in_role, in_ssn,
-				in_manager_id, in_employee_number, in_entity_id,
-				(SELECT id FROM person 
-				WHERE entity_id = in_entity_id));
-		RETURN in_entity_id;
-	END IF;
-END;
-$$ LANGUAGE PLPGSQL;
-
 CREATE OR REPLACE FUNCTION person__list_locations(in_entity_id int)
 RETURNS SETOF location_result AS
 $$

Modified: trunk/sql/modules/test/Account.sql
===================================================================
--- trunk/sql/modules/test/Account.sql	2010-02-28 06:38:39 UTC (rev 2923)
+++ trunk/sql/modules/test/Account.sql	2010-02-28 18:34:09 UTC (rev 2924)
@@ -8,10 +8,6 @@
 INSERT INTO chart (description, charttype, category, accno)
 VALUES ('TEST testing 2', 'A', 'A', '00002');
 
-INSERT INTO entity (id, control_code, name, entity_class, country_id) 
-values (-100, 'test1', 'test', 3, 242);
-
-
 INSERT INTO entity_credit_account (id, meta_number, entity_id, entity_class, ar_ap_account_id) 
 values (-100, 'test1', -100, 1, -1000);
 

Modified: trunk/sql/modules/test/Base.sql
===================================================================
--- trunk/sql/modules/test/Base.sql	2010-02-28 06:38:39 UTC (rev 2923)
+++ trunk/sql/modules/test/Base.sql	2010-02-28 18:34:09 UTC (rev 2924)
@@ -11,6 +11,8 @@
 INSERT INTO users (entity_id, username)
 SELECT -100, CURRENT_USER;
 
+INSERT INTO entity_employee(entity_id) values (-100);
+
 INSERT INTO entity(name, id, entity_class, control_code, country_id)
 values ('test user 1', -200, 3, 'Test User 1', 242);
 

Modified: trunk/sql/modules/test/Payment.sql
===================================================================
--- trunk/sql/modules/test/Payment.sql	2010-02-28 06:38:39 UTC (rev 2923)
+++ trunk/sql/modules/test/Payment.sql	2010-02-28 18:34:09 UTC (rev 2924)
@@ -11,9 +11,6 @@
 INSERT INTO person(first_name, last_name, entity_id, id)
 VALUES ('test', 'test', -100, -100);
 
-INSERT INTO entity_employee(entity_id)
-VALUES (-100);
-
 INSERT INTO chart (accno, description, charttype, category, link)
 VALUES ('00001', 'testing', 'A', 'L', 'AP');
 INSERT INTO chart (accno, description, charttype, category, link)

Modified: trunk/sql/modules/test/Reconciliation.sql
===================================================================
--- trunk/sql/modules/test/Reconciliation.sql	2010-02-28 06:38:39 UTC (rev 2923)
+++ trunk/sql/modules/test/Reconciliation.sql	2010-02-28 18:34:09 UTC (rev 2924)
@@ -3,11 +3,6 @@
 \i data/Reconciliation.sql
 
 
-INSERT INTO entity (id, control_code, name, entity_class, country_id) values (-50, 'Test User', 'Test User', 3, 242);
-INSERT INTO person (id, entity_id, first_name, last_name) values (-50, -50, 'Test', 'Usr');
-
-INSERT INTO users (id, entity_id, username) values (-50, -50, SESSION_USER);
-
 INSERT INTO test_result(test_name, success)
 SELECT 'check_prefix set', count(*) = 1 
 FROM defaults where setting_key = 'check_prefix';

Modified: trunk/t/40-dbsetup.t
===================================================================
--- trunk/t/40-dbsetup.t	2010-02-28 06:38:39 UTC (rev 2923)
+++ trunk/t/40-dbsetup.t	2010-02-28 18:34:09 UTC (rev 2924)
@@ -1,29 +1,21 @@
 # Database setup tests.
 
 use Test::More;
-use LedgerSMB::Form;
 use strict;
 
-#util functions
-
-# sub ok_or_die($name, $success)
-# if $success is true, then pass.
-# else bail out.
-
+my $temp = $ENV{TEMP} || '/tmp/';
 my $run_tests = 1;
 for my $evar (qw(LSMB_NEW_DB LSMB_TEST_DB PG_CONTRIB_DIR)){
   if (!defined $ENV{$evar}){
       $run_tests = 0;
+      plan skipall => "$evar not set";
   }
 }
 
 if ($run_tests){
-	plan tests => 5;
+	plan tests => 25;
 	$ENV{PGDATABASE} = $ENV{LSMB_NEW_DB};
 }
-else {
-	plan skip_all => 'Skipping all.  Told not to test db.';
-}
 
 # Manual tests
 open (CREATEDB, '-|', 'createdb');
@@ -33,6 +25,12 @@
 
 close(CREATEDB);
 
+if (!$ENV{LSMB_INSTALL_DB}){
+    open (DBLOCK, '>', "$temp/LSMB_TEST_DB");
+    print DBLOCK $ENV{LSMB_NEW_DB};
+    close (DBLOCK);
+}
+
 my @contrib_scripts = qw(pg_trgm tsearch2 tablefunc);
 
 for my $contrib (@contrib_scripts){
@@ -74,7 +72,8 @@
     $mod =~ s/\s*$//;
     next if $mod eq '';
 
-    open (PSQL, '-|', "psql -f sql/modules/$mod")&& pass("$mod loaded and committed");
+    (open (PSQL, '-|', "psql -f sql/modules/$mod")&& pass("$mod loaded"))
+      || fail("$mod loaded");
     my $test = 0;
     while (my $line = <PSQL>){
         chomp($line);
@@ -84,4 +83,17 @@
     }
     close(PSQL);
 }
-close (LOADORDER)
+close (LOADORDER);
+
+# Roles processing for later permission tests and db install.
+open (PSQL, '|-', "psql");
+
+(open (ROLES, '<', 'sql/modules/Roles.sql') && pass("Roles description found"))
+|| fail("Roles description found");
+
+print PSQL "BEGIN;\n";
+for my $roleline (<ROLES>){
+    $roleline =~ s/<?lsmb dbname ?>/$ENV{LSMB_NEW_DB}/;
+    print PSQL $roleline;
+}
+print PSQL "COMMIT;\n";

Modified: trunk/t/43-dbtest.t
===================================================================
--- trunk/t/43-dbtest.t	2010-02-28 06:38:39 UTC (rev 2923)
+++ trunk/t/43-dbtest.t	2010-02-28 18:34:09 UTC (rev 2924)
@@ -5,7 +5,7 @@
 	plan skip_all => 'Skipping all.  Told not to test db.';
 }
 else {
-	plan tests => 102;
+	plan tests => 99;
 	if (defined $ENV{LSMB_NEW_DB}){
 		$ENV{PGDATABASE} = $ENV{LSMB_NEW_DB};
 	}

Added: trunk/t/89-dropdb.t
===================================================================
--- trunk/t/89-dropdb.t	                        (rev 0)
+++ trunk/t/89-dropdb.t	2010-02-28 18:34:09 UTC (rev 2924)
@@ -0,0 +1,26 @@
+use Test::More;
+use strict;
+
+my $temp = $ENV{TEMP} || '/tmp/';
+my $run_tests = 5;
+for my $evar (qw(LSMB_NEW_DB LSMB_TEST_DB PG_CONTRIB_DIR LSMB_INSTALL_DB)){
+  if (!defined $ENV{$evar}){
+      $run_tests = 0;
+      plan skipall => "$eval not set";
+  }
+}
+
+if ($run_tests){
+	plan tests => 5;
+	$ENV{PGDATABASE} = $ENV{LSMB_NEW_DB};
+}
+
+ok(open (DBLOCK, '<', "$temp/LSMB_TEST_DB"), 'Opened db lock file');
+my $db = <DBLOCK>;
+chomp($db);
+ok(close (DBLOCK), 'Closed db lock file');
+ok(open (DROPDB, '-|', "dropdb -d $db"), 'Opened drop db');
+my $dropvar = <DROPDB>
+chomp($dropvar);
+cmp_ok($dropdb, 'eq', 'DROP DATABASE', 'Database dropped');
+ok(unlink "$temp/LSMB_TEST_DB", 'Removed test db lockfile');


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.