mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fix template paths for Windows. Fixes #3139
Joint work from Joao and Murtuza.
This commit is contained in:
@@ -133,7 +133,7 @@ class ExternalTablesView(PGChildNodeView):
|
|||||||
did=kwargs['database_id']
|
did=kwargs['database_id']
|
||||||
)
|
)
|
||||||
self.sql_template_path = compile_template_path(
|
self.sql_template_path = compile_template_path(
|
||||||
'sql/',
|
'sql',
|
||||||
self.manager.server_type,
|
self.manager.server_type,
|
||||||
self.manager.sversion
|
self.manager.sversion
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#
|
#
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pgadmin.browser.server_groups.servers.databases.external_tables import \
|
from pgadmin.browser.server_groups.servers.databases.external_tables import \
|
||||||
@@ -68,7 +69,9 @@ class TestExternalTablesView(BaseTestGenerator):
|
|||||||
connection=MagicMock(execute_2darray=MagicMock()),
|
connection=MagicMock(execute_2darray=MagicMock()),
|
||||||
execute_2darray_return_value=(True, dict(rows=[])),
|
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(
|
expected_make_json_response_called_with=dict(
|
||||||
data=[],
|
data=[],
|
||||||
status=200
|
status=200
|
||||||
@@ -90,7 +93,9 @@ class TestExternalTablesView(BaseTestGenerator):
|
|||||||
connection=MagicMock(execute_2darray=MagicMock()),
|
connection=MagicMock(execute_2darray=MagicMock()),
|
||||||
execute_2darray_return_value=(False, 'Some error message'),
|
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(
|
expected_internal_server_error_called_with=dict(
|
||||||
errormsg='Some error message'
|
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(
|
expected_make_json_response_called_with=dict(
|
||||||
data=[
|
data=[
|
||||||
{
|
{
|
||||||
@@ -167,7 +174,9 @@ class TestExternalTablesView(BaseTestGenerator):
|
|||||||
execute_2darray_return_value=(False, 'Some error message'),
|
execute_2darray_return_value=(False, 'Some error message'),
|
||||||
|
|
||||||
expect_render_template_called_with=dict(
|
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
|
external_table_id=11
|
||||||
),
|
),
|
||||||
expected_internal_server_error_called_with=dict(
|
expected_internal_server_error_called_with=dict(
|
||||||
@@ -192,7 +201,9 @@ class TestExternalTablesView(BaseTestGenerator):
|
|||||||
execute_2darray_return_value=(True, dict(rows=[])),
|
execute_2darray_return_value=(True, dict(rows=[])),
|
||||||
|
|
||||||
expect_render_template_called_with=dict(
|
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
|
external_table_id=11
|
||||||
),
|
),
|
||||||
expected_make_json_response_called_with=dict(
|
expected_make_json_response_called_with=dict(
|
||||||
@@ -229,7 +240,9 @@ class TestExternalTablesView(BaseTestGenerator):
|
|||||||
)),
|
)),
|
||||||
|
|
||||||
expect_render_template_called_with=dict(
|
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
|
external_table_id=11
|
||||||
),
|
),
|
||||||
expected_make_json_response_called_with=dict(
|
expected_make_json_response_called_with=dict(
|
||||||
@@ -283,8 +296,11 @@ class TestExternalTablesView(BaseTestGenerator):
|
|||||||
)),
|
)),
|
||||||
|
|
||||||
expect_render_template_called_with=dict(
|
expect_render_template_called_with=dict(
|
||||||
template_name_or_list='sql/#gpdb#80323#/'
|
template_name_or_list=os.path.join(
|
||||||
'get_table_information.sql',
|
'sql',
|
||||||
|
'#gpdb#80323#',
|
||||||
|
'get_table_information.sql'
|
||||||
|
),
|
||||||
table_oid=11
|
table_oid=11
|
||||||
),
|
),
|
||||||
expected_make_response_called_with=dict(
|
expected_make_response_called_with=dict(
|
||||||
|
|||||||
@@ -117,20 +117,26 @@ class FakeApp(Flask):
|
|||||||
self.jinja_env.filters['qtTypeIdent'] = driver.qtTypeIdent
|
self.jinja_env.filters['qtTypeIdent'] = driver.qtTypeIdent
|
||||||
self.jinja_loader = ChoiceLoader([
|
self.jinja_loader = ChoiceLoader([
|
||||||
FileSystemLoader(
|
FileSystemLoader(
|
||||||
os.path.dirname(
|
os.path.join(os.path.dirname(
|
||||||
os.path.realpath(__file__)) + '/../templates/'
|
os.path.realpath(__file__)
|
||||||
|
), os.pardir, 'templates')
|
||||||
),
|
),
|
||||||
FileSystemLoader(
|
FileSystemLoader(
|
||||||
os.path.dirname(
|
os.path.join(
|
||||||
os.path.realpath(__file__)) + '/../../templates/'
|
os.path.dirname(
|
||||||
|
os.path.realpath(__file__)
|
||||||
|
), os.pardir, os.pardir, 'templates')
|
||||||
),
|
),
|
||||||
FileSystemLoader(
|
FileSystemLoader(
|
||||||
os.path.dirname(
|
os.path.join(os.path.dirname(
|
||||||
os.path.realpath(__file__)) + '/../../types/templates/'
|
os.path.realpath(__file__)),
|
||||||
|
os.pardir, os.pardir, 'types', 'templates')
|
||||||
),
|
),
|
||||||
FileSystemLoader(
|
FileSystemLoader(
|
||||||
os.path.dirname(
|
os.path.join(os.path.dirname(
|
||||||
os.path.realpath(__file__)) + '/../../../../templates/'
|
os.path.realpath(__file__)),
|
||||||
|
os.pardir, os.pardir, os.pardir, os.pardir,
|
||||||
|
'templates')
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,10 +11,12 @@ import os
|
|||||||
|
|
||||||
def compile_template_name(
|
def compile_template_name(
|
||||||
template_prefix, template_file_name, server_type, version):
|
template_prefix, template_file_name, server_type, version):
|
||||||
return os.path.join(
|
|
||||||
compile_template_path(template_prefix, server_type, version),
|
# Template path concatenation should be same as
|
||||||
template_file_name
|
# 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):
|
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)
|
version_path = '#{0}#{1}#'.format(server_type, version)
|
||||||
else:
|
else:
|
||||||
version_path = '#{0}#'.format(version)
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user