Hi Hackers,
Attached you can find the patch that corrects the rm - 3306.
Also adds some tests around the behavior of the wrapping function of the
table controller.
Thanks
Anthony & Joao
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_utils.py
index e69de29b..a4dd5b69 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_utils.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_utils.py
@@ -0,0 +1,72 @@
+##########################################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2018, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+##########################################################################
+import sys
+from pgadmin.browser.server_groups.servers.databases.schemas.tables import \
+ BaseTableView
+from pgadmin.utils.route import BaseTestGenerator
+
+if sys.version_info < (3, 3):
+ from mock import patch, MagicMock
+else:
+ from unittest.mock import patch, MagicMock
+
+
+class TestBaseView(BaseTableView):
+ @BaseTableView.check_precondition
+ def test(self, did, sid):
+ pass
+
+
+class TestUtils(BaseTestGenerator):
+ scenarios = [
+ ('Test wrapping function', dict(test='wrap'))
+ ]
+
+ def runTest(self):
+ if self.test == 'wrap':
+ self.__wrap_tests()
+
+ def __wrap_tests(self):
+ subject = TestBaseView(cmd='something')
+ with patch('pgadmin.browser.server_groups.servers.databases.schemas'
+ '.tables.utils.get_driver') as get_driver_mock:
+ get_driver_mock.return_value = MagicMock(
+ connection_manager=MagicMock(
+ return_value=MagicMock(
+ connection=MagicMock(),
+ db_info={
+ 1: dict(datlastsysoid=False)
+ },
+ version=10,
+ server_type='gpdb'
+ )
+ ),
+ qtIndent=MagicMock(),
+ qtTypeIdent=MagicMock()
+ )
+ subject.test(did=1, sid=2)
+ self.assertEqual(
+ subject.table_template_path, 'table/sql/#gpdb#10#')
+ self.assertEqual(
+ subject.data_type_template_path, 'datatype/sql/#gpdb#10#')
+ self.assertEqual(
+ subject.check_constraint_template_path,
+ 'check_constraint/sql/#gpdb#10#')
+ self.assertEqual(
+ subject.exclusion_constraint_template_path,
+ 'exclusion_constraint/sql/#gpdb#10#')
+ self.assertEqual(
+ subject.foreign_key_template_path,
+ 'foreign_key/sql/#gpdb#10#')
+ self.assertEqual(
+ subject.index_template_path,
+ 'index/sql/#gpdb#10#')
+ self.assertEqual(
+ subject.trigger_template_path,
+ 'trigger/sql/#gpdb#10#')
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py
index 732ff55d..3dc07493 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py
@@ -22,6 +22,7 @@ from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \
parse_priv_to_db
from pgadmin.browser.utils import PGChildNodeView
from pgadmin.utils import IS_PY2
+from pgadmin.utils.compile_template_name import compile_template_path
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
@@ -106,38 +107,36 @@ class BaseTableView(PGChildNodeView):
ver = self.manager.version
server_type = self.manager.server_type
# Set the template path for the SQL scripts
- self.table_template_path = 'table/sql/' + (
- '#{0}#{1}#'.format(server_type, ver)
- if server_type == 'gpdb' else
- '#{0}#'.format(ver)
- )
- self.data_type_template_path = 'datatype/sql/' + (
- '#{0}#{1}#'.format(server_type, ver) if
- server_type == 'gpdb' else'#{0}#'.format(ver)
- )
+ self.table_template_path = compile_template_path('table/sql',
+ server_type, ver)
+ self.data_type_template_path = compile_template_path(
+ 'datatype/sql',
+ server_type, ver)
self.partition_template_path = \
'partition/sql/{0}/#{0}#{1}#'.format(server_type, ver)
# Template for Column ,check constraint and exclusion
# constraint node
self.column_template_path = 'column/sql/#{0}#'.format(ver)
- self.check_constraint_template_path = \
- 'check_constraint/sql/#{0}#'.format(ver)
- self.exclusion_constraint_template_path = \
- 'exclusion_constraint/sql/#{0}#'.format(ver)
+ self.check_constraint_template_path = compile_template_path(
+ 'check_constraint/sql', server_type, ver)
+ self.exclusion_constraint_template_path = compile_template_path(
+ 'exclusion_constraint/sql', server_type, ver)
# Template for PK & Unique constraint node
self.index_constraint_template_path = 'index_constraint/sql'
# Template for foreign key constraint node
- self.foreign_key_template_path = \
- 'foreign_key/sql/#{0}#'.format(ver)
+ self.foreign_key_template_path = compile_template_path(
+ 'foreign_key/sql', server_type, ver)
# Template for index node
- self.index_template_path = 'index/sql/#{0}#'.format(ver)
+ self.index_template_path = compile_template_path(
+ 'index/sql', server_type, ver)
# Template for trigger node
- self.trigger_template_path = 'trigger/sql/#{0}#'.format(ver)
+ self.trigger_template_path = compile_template_path(
+ 'trigger/sql', server_type, ver)
# Template for rules node
self.rules_template_path = 'rules/sql'
diff --git a/web/pgadmin/utils/compile_template_name.py b/web/pgadmin/utils/compile_template_name.py
index 30fd89b6..68b8425e 100644
--- a/web/pgadmin/utils/compile_template_name.py
+++ b/web/pgadmin/utils/compile_template_name.py
@@ -6,7 +6,6 @@
# This software is released under the PostgreSQL Licence
#
##########################################################################
-import os
def compile_template_name(
diff --git a/web/pgadmin/utils/tests/test_compile_template_name.py b/web/pgadmin/utils/tests/test_compile_template_name.py
index b7836ccb..d6ee1288 100644
--- a/web/pgadmin/utils/tests/test_compile_template_name.py
+++ b/web/pgadmin/utils/tests/test_compile_template_name.py
@@ -10,11 +10,7 @@ from pgadmin.utils.compile_template_name import compile_template_name
from pgadmin.utils.route import BaseTestGenerator
-class StartRunningQueryTest(BaseTestGenerator):
- """
- Check that the apply_explain_plan_weapper_if_needed method works as
- intended
- """
+class TestCompileTemplateName(BaseTestGenerator):
scenarios = [
(
'When server is Postgres and version is 10, it returns the path '