You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by dp...@apache.org on 2020/04/29 17:20:57 UTC

[incubator-superset] branch master updated: tests(engine_specs): full postgres engine coverage (#9682)

This is an automated email from the ASF dual-hosted git repository.

dpgaspar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 527bee5  tests(engine_specs): full postgres engine coverage (#9682)
527bee5 is described below

commit 527bee50513998f7f5fa4e04f07fcadb09847e6b
Author: Daniel Vaz Gaspar <da...@gmail.com>
AuthorDate: Wed Apr 29 18:20:25 2020 +0100

    tests(engine_specs): full postgres engine coverage (#9682)
---
 superset/db_engine_specs/postgres.py    | 10 ++++------
 tests/db_engine_specs/postgres_tests.py | 34 +++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/superset/db_engine_specs/postgres.py b/superset/db_engine_specs/postgres.py
index e99432b..b5f1b2c 100644
--- a/superset/db_engine_specs/postgres.py
+++ b/superset/db_engine_specs/postgres.py
@@ -20,11 +20,11 @@ from typing import Any, List, Optional, Tuple, TYPE_CHECKING
 from pytz import _FixedOffset  # type: ignore
 from sqlalchemy.dialects.postgresql.base import PGInspector
 
-from superset.db_engine_specs.base import BaseEngineSpec, LimitMethod
+from superset.db_engine_specs.base import BaseEngineSpec
 
 if TYPE_CHECKING:
-    # prevent circular imports
-    from superset.models.core import Database  # pylint: disable=unused-import
+    # pylint: disable=unused-import
+    from superset.models.core import Database  # pragma: no cover
 
 
 # Replace psycopg2.tz.FixedOffsetTimezone with pytz, which is serializable by PyArrow
@@ -55,9 +55,7 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
         cursor.tzinfo_factory = FixedOffsetTimezone
         if not cursor.description:
             return []
-        if cls.limit_method == LimitMethod.FETCH_MANY:
-            return cursor.fetchmany(limit)
-        return cursor.fetchall()
+        return super().fetch_data(cursor, limit)
 
     @classmethod
     def epoch_to_dttm(cls) -> str:
diff --git a/tests/db_engine_specs/postgres_tests.py b/tests/db_engine_specs/postgres_tests.py
index d8b1b54..098e918 100644
--- a/tests/db_engine_specs/postgres_tests.py
+++ b/tests/db_engine_specs/postgres_tests.py
@@ -25,6 +25,10 @@ from tests.db_engine_specs.base_tests import DbEngineSpecTestCase
 
 class PostgresTests(DbEngineSpecTestCase):
     def test_get_table_names(self):
+        """
+        DB Eng Specs (postgres): Test get table names
+        """
+
         """ Make sure postgres doesn't try to remove schema name from table name
         ie. when try_remove_schema_from_table_name == False. """
         inspector = mock.Mock()
@@ -38,24 +42,36 @@ class PostgresTests(DbEngineSpecTestCase):
         self.assertListEqual(pg_result_expected, pg_result)
 
     def test_time_exp_literal_no_grain(self):
+        """
+        DB Eng Specs (postgres): Test no grain literal column
+        """
         col = literal_column("COALESCE(a, b)")
         expr = PostgresEngineSpec.get_timestamp_expr(col, None, None)
         result = str(expr.compile(None, dialect=postgresql.dialect()))
         self.assertEqual(result, "COALESCE(a, b)")
 
     def test_time_exp_literal_1y_grain(self):
+        """
+        DB Eng Specs (postgres): Test grain literal column 1 YEAR
+        """
         col = literal_column("COALESCE(a, b)")
         expr = PostgresEngineSpec.get_timestamp_expr(col, None, "P1Y")
         result = str(expr.compile(None, dialect=postgresql.dialect()))
         self.assertEqual(result, "DATE_TRUNC('year', COALESCE(a, b))")
 
     def test_time_ex_lowr_col_no_grain(self):
+        """
+        DB Eng Specs (postgres): Test no grain expr lower case
+        """
         col = column("lower_case")
         expr = PostgresEngineSpec.get_timestamp_expr(col, None, None)
         result = str(expr.compile(None, dialect=postgresql.dialect()))
         self.assertEqual(result, "lower_case")
 
     def test_time_exp_lowr_col_sec_1y(self):
+        """
+        DB Eng Specs (postgres): Test grain expr lower case 1 YEAR
+        """
         col = column("lower_case")
         expr = PostgresEngineSpec.get_timestamp_expr(col, "epoch_s", "P1Y")
         result = str(expr.compile(None, dialect=postgresql.dialect()))
@@ -66,12 +82,18 @@ class PostgresTests(DbEngineSpecTestCase):
         )
 
     def test_time_exp_mixd_case_col_1y(self):
+        """
+        DB Eng Specs (postgres): Test grain expr mixed case 1 YEAR
+        """
         col = column("MixedCase")
         expr = PostgresEngineSpec.get_timestamp_expr(col, None, "P1Y")
         result = str(expr.compile(None, dialect=postgresql.dialect()))
         self.assertEqual(result, "DATE_TRUNC('year', \"MixedCase\")")
 
     def test_convert_dttm(self):
+        """
+        DB Eng Specs (postgres): Test conversion to date time
+        """
         dttm = self.get_dttm()
 
         self.assertEqual(
@@ -83,3 +105,15 @@ class PostgresTests(DbEngineSpecTestCase):
             PostgresEngineSpec.convert_dttm("TIMESTAMP", dttm),
             "TO_TIMESTAMP('2019-01-02 03:04:05.678900', 'YYYY-MM-DD HH24:MI:SS.US')",
         )
+
+        self.assertEqual(PostgresEngineSpec.convert_dttm("DATETIME", dttm), None)
+
+    def test_empty_dbapi_cursor_description(self):
+        """
+        DB Eng Specs (postgres): Test empty cursor description (no columns)
+        """
+        cursor = mock.Mock()
+        # empty description mean no columns, this mocks the following SQL: "SELECT"
+        cursor.description = []
+        results = PostgresEngineSpec.fetch_data(cursor, 1000)
+        self.assertEqual(results, [])