From ab27b9d1180b96300480f503da57309bc64016cd Mon Sep 17 00:00:00 2001 From: Anthony Emengo Date: Mon, 14 May 2018 15:47:26 +0100 Subject: [PATCH] Fix template handling in tests for Windows. --- .../tests/test_external_tables_view.py | 35 ++++++---------- .../external_tables/tests/test_properties.py | 2 +- .../tables/tests/test_template_create.py | 10 ++--- .../tests/test_dashboard_templates.py | 34 +++++----------- .../tests/test_explain_plan_templates.py | 21 ++++------ .../tests/test_view_data_templates.py | 40 ++++--------------- 6 files changed, 41 insertions(+), 101 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/databases/external_tables/tests/test_external_tables_view.py b/web/pgadmin/browser/server_groups/servers/databases/external_tables/tests/test_external_tables_view.py index 3658148f7..473378a61 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/external_tables/tests/test_external_tables_view.py +++ b/web/pgadmin/browser/server_groups/servers/databases/external_tables/tests/test_external_tables_view.py @@ -69,9 +69,8 @@ class TestExternalTablesView(BaseTestGenerator): connection=MagicMock(execute_2darray=MagicMock()), execute_2darray_return_value=(True, dict(rows=[])), - expect_render_template_called_with=os.path.join('sql', - '#gpdb#80323#', - 'list.sql'), + expect_render_template_called_with=os.path.join( + 'sql/#gpdb#80323#', 'list.sql'), expected_make_json_response_called_with=dict( data=[], status=200 @@ -93,9 +92,8 @@ class TestExternalTablesView(BaseTestGenerator): connection=MagicMock(execute_2darray=MagicMock()), execute_2darray_return_value=(False, 'Some error message'), - expect_render_template_called_with=os.path.join('sql', - '#gpdb#80323#', - 'list.sql'), + expect_render_template_called_with=os.path.join( + 'sql/#gpdb#80323#', 'list.sql'), expected_internal_server_error_called_with=dict( errormsg='Some error message' ), @@ -127,9 +125,8 @@ class TestExternalTablesView(BaseTestGenerator): ] )), - expect_render_template_called_with=os.path.join('sql', - '#gpdb#80323#', - 'list.sql'), + expect_render_template_called_with=os.path.join( + 'sql/#gpdb#80323#', 'list.sql'), expected_make_json_response_called_with=dict( data=[ { @@ -174,9 +171,8 @@ class TestExternalTablesView(BaseTestGenerator): execute_2darray_return_value=(False, 'Some error message'), expect_render_template_called_with=dict( - template_name_or_list=os.path.join('sql', - '#gpdb#80323#', - 'node.sql'), + template_name_or_list=os.path.join( + 'sql/#gpdb#80323#', 'node.sql'), external_table_id=11 ), expected_internal_server_error_called_with=dict( @@ -201,9 +197,8 @@ class TestExternalTablesView(BaseTestGenerator): execute_2darray_return_value=(True, dict(rows=[])), expect_render_template_called_with=dict( - template_name_or_list=os.path.join('sql', - '#gpdb#80323#', - 'node.sql'), + template_name_or_list=os.path.join( + 'sql/#gpdb#80323#', 'node.sql'), external_table_id=11 ), expected_make_json_response_called_with=dict( @@ -240,9 +235,8 @@ class TestExternalTablesView(BaseTestGenerator): )), expect_render_template_called_with=dict( - template_name_or_list=os.path.join('sql', - '#gpdb#80323#', - 'node.sql'), + template_name_or_list=os.path.join( + 'sql/#gpdb#80323#', 'node.sql'), external_table_id=11 ), expected_make_json_response_called_with=dict( @@ -297,10 +291,7 @@ class TestExternalTablesView(BaseTestGenerator): expect_render_template_called_with=dict( template_name_or_list=os.path.join( - 'sql', - '#gpdb#80323#', - 'get_table_information.sql' - ), + 'sql/#gpdb#80323#', 'get_table_information.sql'), table_oid=11 ), expected_make_response_called_with=dict( diff --git a/web/pgadmin/browser/server_groups/servers/databases/external_tables/tests/test_properties.py b/web/pgadmin/browser/server_groups/servers/databases/external_tables/tests/test_properties.py index 718151b53..288f1b45f 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/external_tables/tests/test_properties.py +++ b/web/pgadmin/browser/server_groups/servers/databases/external_tables/tests/test_properties.py @@ -20,7 +20,7 @@ else: from unittest.mock import MagicMock, patch -class TestExternalTablesView(BaseTestGenerator): +class TestProperties(BaseTestGenerator): scenarios = [ ('#properties When retrieving the properties of a external table ' 'and the table exists, ' diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_template_create.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_template_create.py index b80a90067..71f144d75 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_template_create.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_template_create.py @@ -27,9 +27,7 @@ class TestTemplateCreate(BaseTestGenerator): 'when no primary key is present, ' 'it returns "DISTRIBUTED RANDOMLY"', dict( - template_path=os.path.join( - 'table', 'sql', 'gpdb_5.0_plus', 'create.sql' - ), + template_path='table/sql/gpdb_5.0_plus/create.sql', input_parameters=dict( data=dict() ), @@ -43,8 +41,7 @@ class TestTemplateCreate(BaseTestGenerator): 'when primary key is present, ' 'it returns "DISTRIBUTED BY (attr_primary_key)"', dict( - template_path=os.path.join( - 'table', 'sql', 'gpdb_5.0_plus', 'create.sql'), + template_path='table/sql/gpdb_5.0_plus/create.sql', input_parameters=dict( data=dict( primary_key=[ @@ -69,8 +66,7 @@ class TestTemplateCreate(BaseTestGenerator): 'when distribution is present, ' 'it returns "DISTRIBUTED BY (attr1, attr2, attr4)"', dict( - template_path=os.path.join( - 'table', 'sql', 'gpdb_5.0_plus', 'create.sql'), + template_path='table/sql/gpdb_5.0_plus/create.sql', input_parameters=dict( data=dict( distribution=[1, 2, 4], diff --git a/web/pgadmin/dashboard/tests/test_dashboard_templates.py b/web/pgadmin/dashboard/tests/test_dashboard_templates.py index 205e50b62..dd24bddc9 100644 --- a/web/pgadmin/dashboard/tests/test_dashboard_templates.py +++ b/web/pgadmin/dashboard/tests/test_dashboard_templates.py @@ -61,16 +61,14 @@ DATABASE_ID = 123 _ = MagicMock(side_effect=lambda x: x) -class TestExplainPlanTemplates(BaseTestGenerator): +class TestDashboardTemplates(BaseTestGenerator): scenarios = [ # Server dashboard ( 'Dashboard, when returning the html page with graphs and ' 'server activity related html elements for server dashboard', dict( - template_path=os.path.join( - 'dashboard', 'server_dashboard.html' - ), + template_path='dashboard/server_dashboard.html', input_parameters=dict( sid=SERVER_ID, did=None, @@ -90,9 +88,7 @@ class TestExplainPlanTemplates(BaseTestGenerator): 'Dashboard, when returning the html page with only graphs ' 'related html elements for server dashboard', dict( - template_path=os.path.join( - 'dashboard', 'server_dashboard.html' - ), + template_path='dashboard/server_dashboard.html', input_parameters=dict( sid=SERVER_ID, did=None, @@ -113,9 +109,7 @@ class TestExplainPlanTemplates(BaseTestGenerator): 'Dashboard, when returning the html page with only server ' 'activity related html elements for server dashboard', dict( - template_path=os.path.join( - 'dashboard', 'server_dashboard.html' - ), + template_path='dashboard/server_dashboard.html', input_parameters=dict( sid=SERVER_ID, did=None, @@ -137,9 +131,7 @@ class TestExplainPlanTemplates(BaseTestGenerator): 'graphs nor server activity related html elements for server ' 'dashboard', dict( - template_path=os.path.join( - 'dashboard', 'server_dashboard.html' - ), + template_path='dashboard/server_dashboard.html', input_parameters=dict( sid=SERVER_ID, did=None, @@ -160,9 +152,7 @@ class TestExplainPlanTemplates(BaseTestGenerator): 'Dashboard, when returning the html page with graphs and ' 'database activity related html elements for database dashboard', dict( - template_path=os.path.join( - 'dashboard', 'database_dashboard.html' - ), + template_path='dashboard/database_dashboard.html', input_parameters=dict( sid=SERVER_ID, did=DATABASE_ID, @@ -182,9 +172,7 @@ class TestExplainPlanTemplates(BaseTestGenerator): 'Dashboard, when returning the html page with only ' 'graphs related html elements for database dashboard', dict( - template_path=os.path.join( - 'dashboard', 'database_dashboard.html' - ), + template_path='dashboard/database_dashboard.html', input_parameters=dict( sid=SERVER_ID, did=DATABASE_ID, @@ -205,9 +193,7 @@ class TestExplainPlanTemplates(BaseTestGenerator): 'Dashboard, when returning the html page with only ' 'database activity related html elements for database dashboard', dict( - template_path=os.path.join( - 'dashboard', 'database_dashboard.html' - ), + template_path='dashboard/database_dashboard.html', input_parameters=dict( sid=SERVER_ID, did=DATABASE_ID, @@ -229,9 +215,7 @@ class TestExplainPlanTemplates(BaseTestGenerator): 'graphs nor database activity related html elements for database ' 'dashboard', dict( - template_path=os.path.join( - 'dashboard', 'database_dashboard.html' - ), + template_path='dashboard/database_dashboard.html', input_parameters=dict( sid=SERVER_ID, did=DATABASE_ID, diff --git a/web/pgadmin/tools/sqleditor/tests/test_explain_plan_templates.py b/web/pgadmin/tools/sqleditor/tests/test_explain_plan_templates.py index c8c32cfc6..c2bbcdd24 100644 --- a/web/pgadmin/tools/sqleditor/tests/test_explain_plan_templates.py +++ b/web/pgadmin/tools/sqleditor/tests/test_explain_plan_templates.py @@ -23,8 +23,7 @@ class TestExplainPlanTemplates(BaseTestGenerator): 'when passing all parameters,' 'it returns the explain plan with all parameters', dict( - template_path=os.path.join('sqleditor', 'sql', 'default', - 'explain_plan.sql'), + template_path='sqleditor/sql/default/explain_plan.sql', input_parameters=dict( sql='SELECT * FROM places', format='xml', @@ -45,8 +44,7 @@ class TestExplainPlanTemplates(BaseTestGenerator): 'when not all parameters are present,' 'it returns the explain plan with the present parameters', dict( - template_path=os.path.join('sqleditor', 'sql', 'default', - 'explain_plan.sql'), + template_path='sqleditor/sql/default/explain_plan.sql', input_parameters=dict( sql='SELECT * FROM places', format='json', @@ -63,8 +61,7 @@ class TestExplainPlanTemplates(BaseTestGenerator): 'when timing is present,' 'it returns the explain plan with timing', dict( - template_path=os.path.join('sqleditor', 'sql', '9.2_plus', - 'explain_plan.sql'), + template_path='sqleditor/sql/9.2_plus/explain_plan.sql', input_parameters=dict( sql='SELECT * FROM places', format='json', @@ -82,8 +79,7 @@ class TestExplainPlanTemplates(BaseTestGenerator): 'when summary is present,' 'it returns the explain plan with summary', dict( - template_path=os.path.join('sqleditor', 'sql', '10_plus', - 'explain_plan.sql'), + template_path='sqleditor/sql/10_plus/explain_plan.sql', input_parameters=dict( sql='SELECT * FROM places', format='yaml', @@ -103,8 +99,7 @@ class TestExplainPlanTemplates(BaseTestGenerator): 'when all parameters are present,' 'it returns the explain without parameters', dict( - template_path=os.path.join('sqleditor', 'sql', 'gpdb_5.0_plus', - 'explain_plan.sql'), + template_path='sqleditor/sql/gpdb_5.0_plus/explain_plan.sql', input_parameters=dict( sql='SELECT * FROM places', format='json', @@ -119,8 +114,7 @@ class TestExplainPlanTemplates(BaseTestGenerator): 'when analyze is true,' 'it returns the explain analyze', dict( - template_path=os.path.join('sqleditor', 'sql', 'gpdb_5.0_plus', - 'explain_plan.sql'), + template_path='sqleditor/sql/gpdb_5.0_plus/explain_plan.sql', input_parameters=dict( sql='SELECT * FROM places', analyze=True @@ -134,8 +128,7 @@ class TestExplainPlanTemplates(BaseTestGenerator): 'when analyze is false,' 'it returns the only explain', dict( - template_path=os.path.join('sqleditor', 'sql', 'gpdb_5.0_plus', - 'explain_plan.sql'), + template_path='sqleditor/sql/gpdb_5.0_plus/explain_plan.sql', input_parameters=dict( sql='SELECT * FROM places', analyze=False diff --git a/web/pgadmin/tools/sqleditor/tests/test_view_data_templates.py b/web/pgadmin/tools/sqleditor/tests/test_view_data_templates.py index 5d02af2b2..7c39420ff 100644 --- a/web/pgadmin/tools/sqleditor/tests/test_view_data_templates.py +++ b/web/pgadmin/tools/sqleditor/tests/test_view_data_templates.py @@ -35,10 +35,7 @@ class TestViewDataTemplates(BaseTestGenerator): ( 'When inserting and selecting table data with only PK', dict( - insert_template_path=os.path.join('sqleditor', - 'sql', - 'default', - 'insert.sql'), + insert_template_path='sqleditor/sql/default/insert.sql', insert_parameters=dict( data_to_be_saved=data_to_be_saved, primary_keys=None, @@ -54,10 +51,7 @@ class TestViewDataTemplates(BaseTestGenerator): ' (%(id)s::integer, ' '%(text)s::text)' ' returning id;', - select_template_path=os.path.join('sqleditor', - 'sql', - 'default', - 'select.sql'), + select_template_path='sqleditor/sql/default/select.sql', select_parameters=dict( object_name='test_table', nsp_name='test_schema', @@ -71,10 +65,7 @@ class TestViewDataTemplates(BaseTestGenerator): ( 'When inserting and selecting table data with multiple PK', dict( - insert_template_path=os.path.join('sqleditor', - 'sql', - 'default', - 'insert.sql'), + insert_template_path='sqleditor/sql/default/insert.sql', insert_parameters=dict( data_to_be_saved=data_to_be_saved, primary_keys=None, @@ -90,10 +81,7 @@ class TestViewDataTemplates(BaseTestGenerator): ' VALUES (%(id)s::integer,' ' %(text)s::text)' ' returning id, text;', - select_template_path=os.path.join('sqleditor', - 'sql', - 'default', - 'select.sql'), + select_template_path='sqleditor/sql/default/select.sql', select_parameters=dict( object_name='test_table', nsp_name='test_schema', @@ -109,10 +97,7 @@ class TestViewDataTemplates(BaseTestGenerator): ( 'When inserting and selecting table data with PK and OID', dict( - insert_template_path=os.path.join('sqleditor', - 'sql', - 'default', - 'insert.sql'), + insert_template_path='sqleditor/sql/default/insert.sql', insert_parameters=dict( data_to_be_saved=data_to_be_saved, primary_keys=None, @@ -128,10 +113,7 @@ class TestViewDataTemplates(BaseTestGenerator): ' (%(id)s::integer, ' '%(text)s::text) ' 'returning oid;', - select_template_path=os.path.join('sqleditor', - 'sql', - 'default', - 'select.sql'), + select_template_path='sqleditor/sql/default/select.sql', select_parameters=dict( object_name='test_table', nsp_name='test_schema', @@ -145,10 +127,7 @@ class TestViewDataTemplates(BaseTestGenerator): ( 'When inserting and selecting table data with only OID', dict( - insert_template_path=os.path.join('sqleditor', - 'sql', - 'default', - 'insert.sql'), + insert_template_path='sqleditor/sql/default/insert.sql', insert_parameters=dict( data_to_be_saved=data_to_be_saved, primary_keys=None, @@ -164,10 +143,7 @@ class TestViewDataTemplates(BaseTestGenerator): ' (%(id)s::integer,' ' %(text)s::text)' ' returning oid;', - select_template_path=os.path.join('sqleditor', - 'sql', - 'default', - 'select.sql'), + select_template_path='sqleditor/sql/default/select.sql', select_parameters=dict( object_name='test_table', nsp_name='test_schema',