From 8ab4632a890ad5e310c214722e2b629cf771e973 Mon Sep 17 00:00:00 2001 From: Andreas Knab Date: Fri, 19 Jul 2024 15:22:37 +0200 Subject: [PATCH 1/5] Tests for get_where_list and slice table API calls --- .../OmeroWeb/test/integration/test_table.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/components/tools/OmeroWeb/test/integration/test_table.py b/components/tools/OmeroWeb/test/integration/test_table.py index 247e4eaa5d5..3330e90399d 100644 --- a/components/tools/OmeroWeb/test/integration/test_table.py +++ b/components/tools/OmeroWeb/test/integration/test_table.py @@ -237,3 +237,61 @@ def test_table_metadata(self, omero_table_file, django_client, table_data): assert rsp['user_metadata']['test'] == 'value' assert rsp['user_metadata']['my_number'] == 100 + + @pytest.mark.parametrize("query_result", [ + ['query=Well>2', [2, 3, 4], 0], + ['query=Well>2&start=3', [3, 4], 3], + ]) + def test_table_get_where_list(self, omero_table_file, django_client, table_data, query_result): + """ + Test query call returning resulting row numbers + """ + col_types, col_names, rows = table_data + query, expected, start = query_result + request_url = reverse("webgateway_perform_get_where_list", args=[omero_table_file]) + response = get_json(django_client, '%s?%s' % (request_url, query)) + assert response['rows'] == expected + assert response['meta']['partialCount'] == len(expected) + assert response['meta']['rowCount'] == 5 + assert response['meta']['columnCount'] == len(col_types) + assert response['meta']['start'] == start + assert response['meta']['end'] == len(rows) + assert response['meta']['maxCells'] > 0 + + @pytest.mark.parametrize("query_result", [ + ['rows=0-4&columns=0', [[1, 2, 3, 4, 5]], ['Well']], + ['rows=0&columns=0,1', [[1], ['test'], [0.5], [135345.0], [2]], ['Well', 'TestColumn']], + ['rows=0,1&columns=0-1', + [[1, 2], ['test', 'string'], [0.5, 1.0], [135345.0, 345345.121], [2, 4]], + ['Well', 'TestColumn']], + ]) + def test_table_perform_slice(self, omero_table_file, django_client, table_data, query_result): + """ + Test slice call returning table data in columnar format + """ + col_types, col_names, rows = table_data + query, result, columns = query_result + request_url = reverse("webgateway_perform_slice", args=[omero_table_file]) + response = get_json(django_client, '%s?%s' % (request_url, query)) + assert response['columns'] == result + assert response['meta']['columns'] == columns + assert response['meta']['rowCount'] == len(rows) + assert response['meta']['columnCount'] == len(col_types) + assert response['meta']['maxCells'] > 0 + + @pytest.mark.parametrize("query_validity", [ + ['', False], # missing rows and columns + ['rows=0-4', False], # missing columns + ['columns=0-2', False], # missing rows + ['rows=0-4&columns=0-100', False], # columns out of range + ['rows=0-1000000&columns=0-4', False], # too many cells + ['rows=0-100&columns=0-4', True], # all good + ]) + def test_table_perform_slice_errors(self, omero_table_file, django_client, table_data, query_validity): + """ + Test invalid slice calls + """ + query, valid = query_validity + request_url = reverse("webgateway_perform_slice", args=[omero_table_file]) + response = get_json(django_client, '%s?%s' % (request_url, query)) + assert response.has_key('error') != valid From 117498313d441a664e6a57731b70a1fde8df82eb Mon Sep 17 00:00:00 2001 From: Andreas Knab Date: Fri, 19 Jul 2024 15:29:17 +0200 Subject: [PATCH 2/5] Fix flake8 --- .../OmeroWeb/test/integration/test_table.py | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/components/tools/OmeroWeb/test/integration/test_table.py b/components/tools/OmeroWeb/test/integration/test_table.py index 3330e90399d..4ebaf22011e 100644 --- a/components/tools/OmeroWeb/test/integration/test_table.py +++ b/components/tools/OmeroWeb/test/integration/test_table.py @@ -242,13 +242,15 @@ def test_table_metadata(self, omero_table_file, django_client, table_data): ['query=Well>2', [2, 3, 4], 0], ['query=Well>2&start=3', [3, 4], 3], ]) - def test_table_get_where_list(self, omero_table_file, django_client, table_data, query_result): + def test_table_get_where_list( + self, omero_table_file, django_client, table_data, query_result): """ Test query call returning resulting row numbers """ col_types, col_names, rows = table_data query, expected, start = query_result - request_url = reverse("webgateway_perform_get_where_list", args=[omero_table_file]) + request_url = reverse("webgateway_perform_get_where_list", + args=[omero_table_file]) response = get_json(django_client, '%s?%s' % (request_url, query)) assert response['rows'] == expected assert response['meta']['partialCount'] == len(expected) @@ -260,18 +262,22 @@ def test_table_get_where_list(self, omero_table_file, django_client, table_data, @pytest.mark.parametrize("query_result", [ ['rows=0-4&columns=0', [[1, 2, 3, 4, 5]], ['Well']], - ['rows=0&columns=0,1', [[1], ['test'], [0.5], [135345.0], [2]], ['Well', 'TestColumn']], + ['rows=0&columns=0,1', [[1], ['test'], [0.5], [135345.0], [2]], + ['Well', 'TestColumn']], ['rows=0,1&columns=0-1', - [[1, 2], ['test', 'string'], [0.5, 1.0], [135345.0, 345345.121], [2, 4]], + [[1, 2], ['test', 'string'], [0.5, 1.0], [135345.0, 345345.121], + [2, 4]], ['Well', 'TestColumn']], ]) - def test_table_perform_slice(self, omero_table_file, django_client, table_data, query_result): + def test_table_perform_slice( + self, omero_table_file, django_client, table_data, query_result): """ Test slice call returning table data in columnar format """ col_types, col_names, rows = table_data query, result, columns = query_result - request_url = reverse("webgateway_perform_slice", args=[omero_table_file]) + request_url = reverse("webgateway_perform_slice", + args=[omero_table_file]) response = get_json(django_client, '%s?%s' % (request_url, query)) assert response['columns'] == result assert response['meta']['columns'] == columns @@ -287,11 +293,14 @@ def test_table_perform_slice(self, omero_table_file, django_client, table_data, ['rows=0-1000000&columns=0-4', False], # too many cells ['rows=0-100&columns=0-4', True], # all good ]) - def test_table_perform_slice_errors(self, omero_table_file, django_client, table_data, query_validity): + def test_table_perform_slice_errors( + self, omero_table_file, django_client, table_data, + query_validity): """ Test invalid slice calls """ query, valid = query_validity - request_url = reverse("webgateway_perform_slice", args=[omero_table_file]) + request_url = reverse("webgateway_perform_slice", + args=[omero_table_file]) response = get_json(django_client, '%s?%s' % (request_url, query)) assert response.has_key('error') != valid From 374f20d2bf33f35f4888e4149a794f3c4d55ccef Mon Sep 17 00:00:00 2001 From: Andreas Knab Date: Tue, 23 Jul 2024 16:44:43 +0200 Subject: [PATCH 3/5] Fix tests --- components/tools/OmeroWeb/test/integration/test_table.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/components/tools/OmeroWeb/test/integration/test_table.py b/components/tools/OmeroWeb/test/integration/test_table.py index 4ebaf22011e..2bc42d052dc 100644 --- a/components/tools/OmeroWeb/test/integration/test_table.py +++ b/components/tools/OmeroWeb/test/integration/test_table.py @@ -262,11 +262,8 @@ def test_table_get_where_list( @pytest.mark.parametrize("query_result", [ ['rows=0-4&columns=0', [[1, 2, 3, 4, 5]], ['Well']], - ['rows=0&columns=0,1', [[1], ['test'], [0.5], [135345.0], [2]], - ['Well', 'TestColumn']], - ['rows=0,1&columns=0-1', - [[1, 2], ['test', 'string'], [0.5, 1.0], [135345.0, 345345.121], - [2, 4]], + ['rows=0&columns=0,1', [[1], ['test']], ['Well', 'TestColumn']], + ['rows=0,1&columns=0-1', [[1, 2], ['test', 'string']], ['Well', 'TestColumn']], ]) def test_table_perform_slice( @@ -303,4 +300,4 @@ def test_table_perform_slice_errors( request_url = reverse("webgateway_perform_slice", args=[omero_table_file]) response = get_json(django_client, '%s?%s' % (request_url, query)) - assert response.has_key('error') != valid + assert ('error' not in response) == valid From 341639a919094e83b84f22dd628c494885e8ea0b Mon Sep 17 00:00:00 2001 From: Andreas Knab Date: Wed, 24 Jul 2024 09:48:12 +0200 Subject: [PATCH 4/5] Fix tests --- components/tools/OmeroWeb/test/integration/test_table.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/tools/OmeroWeb/test/integration/test_table.py b/components/tools/OmeroWeb/test/integration/test_table.py index 2bc42d052dc..141b0c489b4 100644 --- a/components/tools/OmeroWeb/test/integration/test_table.py +++ b/components/tools/OmeroWeb/test/integration/test_table.py @@ -288,7 +288,11 @@ def test_table_perform_slice( ['columns=0-2', False], # missing rows ['rows=0-4&columns=0-100', False], # columns out of range ['rows=0-1000000&columns=0-4', False], # too many cells - ['rows=0-100&columns=0-4', True], # all good + ['rows=0-100&columns=0-4', False], # rows out of range + ['rows=0-3,-1&columns=0-4', False], # invalid row + ['rows=0,2.5&columns=0-4', False], # invalid row + ['rows=0,X-Y&columns=0-4', False], # invalid row + ['rows=0-3&columns=0-4', True], # all good ]) def test_table_perform_slice_errors( self, omero_table_file, django_client, table_data, From 5f274d9c353628a51e3b531ccf7da7aaafbbcea4 Mon Sep 17 00:00:00 2001 From: Andreas Knab Date: Wed, 24 Jul 2024 14:56:46 +0200 Subject: [PATCH 5/5] Fix URL names --- components/tools/OmeroWeb/test/integration/test_table.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/tools/OmeroWeb/test/integration/test_table.py b/components/tools/OmeroWeb/test/integration/test_table.py index 141b0c489b4..a5cef17a91d 100644 --- a/components/tools/OmeroWeb/test/integration/test_table.py +++ b/components/tools/OmeroWeb/test/integration/test_table.py @@ -249,7 +249,7 @@ def test_table_get_where_list( """ col_types, col_names, rows = table_data query, expected, start = query_result - request_url = reverse("webgateway_perform_get_where_list", + request_url = reverse("webgateway_table_get_where_list", args=[omero_table_file]) response = get_json(django_client, '%s?%s' % (request_url, query)) assert response['rows'] == expected @@ -273,7 +273,7 @@ def test_table_perform_slice( """ col_types, col_names, rows = table_data query, result, columns = query_result - request_url = reverse("webgateway_perform_slice", + request_url = reverse("webgateway_table_slice", args=[omero_table_file]) response = get_json(django_client, '%s?%s' % (request_url, query)) assert response['columns'] == result @@ -301,7 +301,7 @@ def test_table_perform_slice_errors( Test invalid slice calls """ query, valid = query_validity - request_url = reverse("webgateway_perform_slice", + request_url = reverse("webgateway_table_slice", args=[omero_table_file]) response = get_json(django_client, '%s?%s' % (request_url, query)) assert ('error' not in response) == valid