changeset 1853:cedadd4e3db5

Use dollar quoting to make tested statements more readable
author Tom Gottfried <tom@intevation.de>
date Thu, 17 Jan 2019 11:23:24 +0100
parents 72d6fcb2147d
children 79283856f9cb
files schema/auth_tests.sql
diffstat 1 files changed, 74 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/schema/auth_tests.sql	Thu Jan 17 11:02:03 2019 +0100
+++ b/schema/auth_tests.sql	Thu Jan 17 11:23:24 2019 +0100
@@ -20,20 +20,32 @@
 --
 SET SESSION AUTHORIZATION test_user_at;
 
-SELECT throws_ok('CREATE TABLE test()', 42501, NULL,
-                 'No objects can be created');
+SELECT throws_ok($$
+    CREATE TABLE test()
+    $$,
+    42501, NULL,
+    'No objects can be created');
+
+SELECT isnt_empty($$
+    SELECT * FROM waterway.bottlenecks
+    $$,
+    'Staged data should be visible');
 
-SELECT isnt_empty('SELECT * FROM waterway.bottlenecks',
-                  'Staged data should be visible');
-SELECT is_empty('SELECT * FROM waterway.bottlenecks WHERE NOT staging_done',
-                'Only staged data should be visible');
+SELECT is_empty($$
+    SELECT * FROM waterway.bottlenecks WHERE NOT staging_done
+    $$,
+    'Only staged data should be visible');
 
-SELECT isnt_empty('SELECT * FROM users.templates',
-                  'User should see templates associated to him');
-SELECT is_empty('SELECT * FROM users.templates
-                 JOIN users.user_templates USING (template_name)
-                 WHERE username <> current_user',
-                'User should only see templates associated to him');
+SELECT isnt_empty($$
+    SELECT * FROM users.templates
+    $$,
+    'User should see templates associated to him');
+SELECT is_empty($$
+    SELECT * FROM users.templates
+        JOIN users.user_templates USING (template_name)
+        WHERE username <> current_user
+    $$,
+    'User should only see templates associated to him');
 
 --
 -- Run tests as waterway administrator
@@ -52,47 +64,60 @@
             $2, 'AT', 'AT', 'AT',
             1, 'depth', 'testorganization'
         );
-SELECT lives_ok('EXECUTE bn_insert(
-                     ''test1'',
-                     ST_geomfromtext(''POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))'',
-                         4326))',
-                 'Waterway admin can insert data within his region');
-SELECT throws_ok('EXECUTE bn_insert(
-                      ''test2'',
-                      ST_geomfromtext(''POLYGON((1 0, 1 1, 2 1, 2 0, 1 0))'',
-                          4326))',
-                 42501, NULL,
-                 'Waterway admin cannot insert data outside his region');
+SELECT lives_ok($$
+    EXECUTE bn_insert(
+        'test1',
+        ST_geomfromtext('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))', 4326))
+    $$,
+    'Waterway admin can insert data within his region');
+SELECT throws_ok($$
+    EXECUTE bn_insert(
+        'test2',
+        ST_geomfromtext('POLYGON((1 0, 1 1, 2 1, 2 0, 1 0))', 4326))
+    $$,
+    42501, NULL,
+    'Waterway admin cannot insert data outside his region');
 
 -- template management
-SELECT isnt_empty('SELECT * FROM users.templates
-                   JOIN users.user_templates USING (template_name)
-                   WHERE username <> current_user',
-                  'Waterway admin should see templates of other users');
+SELECT isnt_empty($$
+    SELECT * FROM users.templates
+        JOIN users.user_templates USING (template_name)
+        WHERE username <> current_user
+    $$,
+    'Waterway admin should see templates of other users');
 
-SELECT lives_ok('INSERT INTO users.templates (template_name, template_data)
-                 VALUES (''New AT'', ''\x'');
-                 INSERT INTO users.user_templates
-                 VALUES (''test_user_at'', ''New AT'')',
-                'Waterway admin can add templates for users in his country');
+SELECT lives_ok($$
+    INSERT INTO users.templates (template_name, template_data)
+        VALUES ('New AT', '\x');
+        INSERT INTO users.user_templates
+        VALUES ('test_user_at', 'New AT')
+    $$,
+    'Waterway admin can add templates for users in his country');
 
-SELECT throws_ok('INSERT INTO users.user_templates
-                  VALUES (''waterway_user2'', ''AT'')',
-                 42501, NULL,
-                 'Waterway admin cannot add template for other country');
+SELECT throws_ok($$
+    INSERT INTO users.user_templates VALUES ('waterway_user2', 'AT')
+    $$,
+    42501, NULL,
+    'Waterway admin cannot add template for other country');
 
-SELECT isnt_empty('UPDATE users.templates SET template_data = ''\xDABE''
-                   WHERE template_name = ''AT'' RETURNING *',
-                  'Waterway admin can alter templates for own country');
-
-SELECT is_empty('UPDATE users.templates SET template_data = ''\xDABE''
-                 WHERE template_name = ''RO'' RETURNING *',
-                'Waterway admin cannot alter templates for other country');
+SELECT isnt_empty($$
+    UPDATE users.templates SET template_data = '\xDABE'
+        WHERE template_name = 'AT' RETURNING *
+    $$,
+    'Waterway admin can alter templates for own country');
 
-SELECT isnt_empty('DELETE FROM users.templates WHERE template_name = ''AT''
-                   RETURNING *',
-                  'Waterway admin can delete templates for own country');
+SELECT is_empty($$
+    UPDATE users.templates SET template_data = '\xDABE'
+        WHERE template_name = 'RO' RETURNING *
+    $$,
+    'Waterway admin cannot alter templates for other country');
 
-SELECT is_empty('DELETE FROM users.templates WHERE template_name = ''RO''
-                 RETURNING *',
-                'Waterway admin cannot delete templates for other country');
+SELECT isnt_empty($$
+    DELETE FROM users.templates WHERE template_name = 'AT' RETURNING *
+    $$,
+    'Waterway admin can delete templates for own country');
+
+SELECT is_empty($$
+    DELETE FROM users.templates WHERE template_name = 'RO' RETURNING *
+    $$,
+    'Waterway admin cannot delete templates for other country');