diff schema/manage_users_tests.sql @ 185:a9d9c2b1d08c

Add database function to create role and user profile
author Tom Gottfried <tom@intevation.de>
date Thu, 19 Jul 2018 16:37:52 +0200
parents
children 5dc8e734487a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schema/manage_users_tests.sql	Thu Jul 19 16:37:52 2018 +0200
@@ -0,0 +1,56 @@
+BEGIN;
+--
+-- pgTAP test script for user management functions
+--
+SELECT plan(5); -- Give number of tests that have to be run
+
+SET search_path TO public, gemma, gemma_waterway, gemma_fairway;
+
+--
+-- Run tests as system_admin
+--
+SET SESSION AUTHORIZATION sys_admin;
+
+SELECT lives_ok($$
+    SELECT create_user(
+        'waterway_user', 'test1', 'secret', 'AT', NULL, 'test1')
+    $$,
+    'New waterway user can be added');
+
+SELECT throws_ok($$
+    SELECT create_user(
+        'invalid', 'test2', 'secret', 'AT', NULL, 'test2')
+    $$,
+    42704, NULL,
+    'Valid role name has to be provided');
+
+SELECT throws_ok($$
+    SELECT create_user(
+        'waterway_user', NULL, 'secret', 'AT', NULL, 'test3')
+    $$,
+    23502, NULL,
+    'username is mandatory');
+-- Though other arguments are mandatory, too, there are no explicit tests
+
+SELECT throws_ok($$
+    SELECT create_user(
+        'waterway_user', 'waterway_user', 'secret', 'AT', NULL, 'test4')
+    $$,
+    23505, NULL,
+    'No duplicate user name is allowed');
+
+SELECT throws_ok($$
+    SELECT create_user(
+        'waterway_user', 'test2', 'secret', 'AT', NULL, 'xxx')
+    $$,
+    23505, NULL,
+    'No duplicate e-mail adress is allowed');
+
+--
+-- finish tests
+--
+SELECT * FROM finish();
+
+-- Rollback because we don't want test roles to stay in the cluster, which
+-- would make tests not repeatable
+ROLLBACK;