From: Bill Erickson Date: Tue, 16 Oct 2012 20:59:31 +0000 (-0400) Subject: Circulations test data X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=fab460c68cef53a87672374a1ce2a4241f6c573f;p=working%2FEvergreen.git Circulations test data Adds supporting functions for creating circulations test data. Adds 162 test circs across different users and profiles and rules. In time, more samples and variations would be good. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/tests/datasets/sql/env_create.sql b/Open-ILS/tests/datasets/sql/env_create.sql index 9e9c9b4746..313607d00a 100644 --- a/Open-ILS/tests/datasets/sql/env_create.sql +++ b/Open-ILS/tests/datasets/sql/env_create.sql @@ -34,3 +34,71 @@ RETURNS void AS $$ WHERE record > 0 AND label LIKE $4 || '%' AND owning_lib = $2; $$ LANGUAGE SQL; +/** Returns the next (by ID) non-deleted copy */ +CREATE FUNCTION evergreen.next_copy (copy_id BIGINT) RETURNS asset.copy AS $$ + DECLARE copy asset.copy%ROWTYPE; + DECLARE max_id BIGINT; +BEGIN + SELECT INTO max_id max(id) FROM asset.copy; + WHILE TRUE LOOP + copy_id := copy_id + 1; + IF copy_id > max_id THEN + RETURN NULL; + END IF; + SELECT INTO copy * FROM asset.copy WHERE id = copy_id; + IF NOT copy.deleted THEN + RETURN copy; + END IF; + END LOOP; + RETURN NULL; +END; +$$ LANGUAGE PLPGSQL; + + + + +/** + * Creates circulations + */ +CREATE FUNCTION evergreen.populate_circ ( + patron_barcode TEXT, + copy_barcode TEXT, + circ_lib INTEGER, + duration_rule TEXT, + recurring_fine_rule TEXT, + max_fine_rule TEXT, + overdue BOOLEAN +) +RETURNS void AS $$ + INSERT INTO action.circulation ( + usr, target_copy, circ_lib, circ_staff, renewal_remaining, + grace_period, duration, recurring_fine, max_fine, duration_rule, + recurring_fine_rule, max_fine_rule, due_date ) + VALUES ( + (SELECT usr FROM actor.card WHERE barcode = $1), + (SELECT id FROM asset.copy WHERE barcode = $2 AND NOT deleted), + $3, -- circ_lib + 1, -- circ_staff + (SELECT max_renewals FROM config.rule_circ_duration WHERE name = $4), + (SELECT grace_period FROM config.rule_recurring_fine WHERE name = $5), + (SELECT normal FROM config.rule_circ_duration WHERE name = $4), + (SELECT normal FROM config.rule_recurring_fine WHERE name = $5), + (SELECT amount FROM config.rule_max_fine WHERE name = $6), + $4, -- duration_rule + $5, -- recurring_fine_rule + $6, -- max_fine_rule + CASE WHEN $7 THEN -- due_date + (DATE(NOW() - -- subtract duration from now() for overdues + (SELECT normal FROM config.rule_circ_duration WHERE name = $4)) + || ' 23:59:59')::TIMESTAMP -- due_date + ELSE + (DATE(NOW() + + (SELECT normal FROM config.rule_circ_duration WHERE name = $4)) + || ' 23:59:59')::TIMESTAMP -- due_date + END + ); +$$ LANGUAGE SQL; + + + + diff --git a/Open-ILS/tests/datasets/sql/env_destroy.sql b/Open-ILS/tests/datasets/sql/env_destroy.sql index 6680640b89..5795f897de 100644 --- a/Open-ILS/tests/datasets/sql/env_destroy.sql +++ b/Open-ILS/tests/datasets/sql/env_destroy.sql @@ -3,3 +3,6 @@ DROP TABLE marcxml_import; DROP FUNCTION evergreen.populate_call_number(INTEGER, TEXT, TEXT); DROP FUNCTION evergreen.populate_copy(INTEGER, INTEGER, TEXT, TEXT); +DROP FUNCTION evergreen.next_copy (BIGINT); +DROP FUNCTION evergreen.populate_circ + (TEXT, TEXT, INTEGER, TEXT, TEXT, TEXT, BOOLEAN); diff --git a/Open-ILS/tests/datasets/sql/load_all.sql b/Open-ILS/tests/datasets/sql/load_all.sql index 43d95bd3ec..43bbd443c7 100644 --- a/Open-ILS/tests/datasets/sql/load_all.sql +++ b/Open-ILS/tests/datasets/sql/load_all.sql @@ -31,6 +31,9 @@ INSERT INTO biblio.record_entry (marc, last_xact_id) -- load sample staff users \i users_staff_134.sql +-- circs, etc. +\i transactions.sql + -- clean up the env \i env_destroy.sql diff --git a/Open-ILS/tests/datasets/sql/transactions.sql b/Open-ILS/tests/datasets/sql/transactions.sql new file mode 100644 index 0000000000..1e51b3e572 --- /dev/null +++ b/Open-ILS/tests/datasets/sql/transactions.sql @@ -0,0 +1,71 @@ + + +/* NOTE: fine generator should be run after loading to produce billings */ + +/** + * create 3 regular circs w/ varying (stock) rules and 3 overdue + * circs for the fisrt 2 (by ID) users in each profile group. + * target copies start at ID 1 and progress upward by ID from + * there, skipping deleted copies. + * TODO: vary the rules more + */ +DO $$ + DECLARE grp INTEGER; + DECLARE recipient INTEGER; + DECLARE copy asset.copy%ROWTYPE; +BEGIN + copy := evergreen.next_copy(0); + + FOR grp IN SELECT id FROM permission.grp_tree LOOP + FOR recipient IN SELECT id FROM actor.usr + WHERE profile = grp ORDER BY id LIMIT 2 LOOP + + copy := evergreen.next_copy(copy.id); + PERFORM evergreen.populate_circ( + (SELECT barcode FROM actor.card WHERE usr = recipient), + copy.barcode, copy.circ_lib, + 'default', 'default', 'default', FALSE + ); + + copy := evergreen.next_copy(copy.id); + PERFORM evergreen.populate_circ( + (SELECT barcode FROM actor.card WHERE usr = recipient), + copy.barcode, copy.circ_lib, + 'default', 'default', 'overdue_min', FALSE + ); + + copy := evergreen.next_copy(copy.id); + PERFORM evergreen.populate_circ( + (SELECT barcode FROM actor.card WHERE usr = recipient), + copy.barcode, copy.circ_lib, + 'default', 'default', 'overdue_max', FALSE + ); + + -- overdues... + + copy := evergreen.next_copy(copy.id); + PERFORM evergreen.populate_circ( + (SELECT barcode FROM actor.card WHERE usr = recipient), + copy.barcode, copy.circ_lib, + 'default', 'default', 'default', TRUE + ); + + copy := evergreen.next_copy(copy.id); + PERFORM evergreen.populate_circ( + (SELECT barcode FROM actor.card WHERE usr = recipient), + copy.barcode, copy.circ_lib, + 'default', 'default', 'overdue_min', TRUE + ); + + copy := evergreen.next_copy(copy.id); + PERFORM evergreen.populate_circ( + (SELECT barcode FROM actor.card WHERE usr = recipient), + copy.barcode, copy.circ_lib, + 'default', 'default', 'overdue_max', TRUE + ); + + END LOOP; + END LOOP; +END $$; + +