diff --git a/web/pgadmin/browser/server_groups/servers/databases/external_tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/external_tables/__init__.py index 137c6c446..37bbee333 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/external_tables/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/external_tables/__init__.py @@ -133,7 +133,7 @@ class ExternalTablesView(PGChildNodeView): did=kwargs['database_id'] ) self.sql_template_path = compile_template_path( - 'sql/', + 'sql', self.manager.server_type, self.manager.sversion ) 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 acedc61bf..3658148f7 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 @@ -7,6 +7,7 @@ # ########################################################################## +import os import sys from pgadmin.browser.server_groups.servers.databases.external_tables import \ @@ -68,7 +69,9 @@ class TestExternalTablesView(BaseTestGenerator): connection=MagicMock(execute_2darray=MagicMock()), execute_2darray_return_value=(True, dict(rows=[])), - expect_render_template_called_with='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 @@ -90,7 +93,9 @@ class TestExternalTablesView(BaseTestGenerator): connection=MagicMock(execute_2darray=MagicMock()), execute_2darray_return_value=(False, 'Some error message'), - expect_render_template_called_with='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' ), @@ -122,7 +127,9 @@ class TestExternalTablesView(BaseTestGenerator): ] )), - expect_render_template_called_with='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=[ { @@ -167,7 +174,9 @@ class TestExternalTablesView(BaseTestGenerator): execute_2darray_return_value=(False, 'Some error message'), expect_render_template_called_with=dict( - template_name_or_list='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( @@ -192,7 +201,9 @@ class TestExternalTablesView(BaseTestGenerator): execute_2darray_return_value=(True, dict(rows=[])), expect_render_template_called_with=dict( - template_name_or_list='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( @@ -229,7 +240,9 @@ class TestExternalTablesView(BaseTestGenerator): )), expect_render_template_called_with=dict( - template_name_or_list='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( @@ -283,8 +296,11 @@ class TestExternalTablesView(BaseTestGenerator): )), expect_render_template_called_with=dict( - template_name_or_list='sql/#gpdb#80323#/' - 'get_table_information.sql', + template_name_or_list=os.path.join( + '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/schemas/tables/tests/test_template_create.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_template_create.py index 25d589253..b80a90067 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 @@ -117,20 +117,26 @@ class FakeApp(Flask): self.jinja_env.filters['qtTypeIdent'] = driver.qtTypeIdent self.jinja_loader = ChoiceLoader([ FileSystemLoader( - os.path.dirname( - os.path.realpath(__file__)) + '/../templates/' + os.path.join(os.path.dirname( + os.path.realpath(__file__) + ), os.pardir, 'templates') ), FileSystemLoader( - os.path.dirname( - os.path.realpath(__file__)) + '/../../templates/' + os.path.join( + os.path.dirname( + os.path.realpath(__file__) + ), os.pardir, os.pardir, 'templates') ), FileSystemLoader( - os.path.dirname( - os.path.realpath(__file__)) + '/../../types/templates/' + os.path.join(os.path.dirname( + os.path.realpath(__file__)), + os.pardir, os.pardir, 'types', 'templates') ), FileSystemLoader( - os.path.dirname( - os.path.realpath(__file__)) + '/../../../../templates/' + os.path.join(os.path.dirname( + os.path.realpath(__file__)), + os.pardir, os.pardir, os.pardir, os.pardir, + 'templates') ), ] ) diff --git a/web/pgadmin/utils/compile_template_name.py b/web/pgadmin/utils/compile_template_name.py index 1e0b94fa6..30fd89b67 100644 --- a/web/pgadmin/utils/compile_template_name.py +++ b/web/pgadmin/utils/compile_template_name.py @@ -11,10 +11,12 @@ import os def compile_template_name( template_prefix, template_file_name, server_type, version): - return os.path.join( - compile_template_path(template_prefix, server_type, version), - template_file_name - ) + + # Template path concatenation should be same as + # Ref: ../pgadmin4/web/pgadmin/utils/versioned_template_loader.py +54 + # to avoid path mismatch in windows + return compile_template_path(template_prefix, server_type, version) + \ + '/' + template_file_name def compile_template_path(template_prefix, server_type, version): @@ -22,4 +24,8 @@ def compile_template_path(template_prefix, server_type, version): version_path = '#{0}#{1}#'.format(server_type, version) else: version_path = '#{0}#'.format(version) - return os.path.join(template_prefix, version_path) + + # Template path concatenation should be same as + # Ref: ../pgadmin4/web/pgadmin/utils/versioned_template_loader.py +54 + # to avoid path mismatch in windows + return template_prefix + '/' + version_path