You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2023/08/09 00:10:03 UTC

[superset] branch upload_gsheets updated: Add tests

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

beto pushed a commit to branch upload_gsheets
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/upload_gsheets by this push:
     new 565f7e6890 Add tests
565f7e6890 is described below

commit 565f7e689071f6ae5d0d00b002018dd610093dc3
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Tue Aug 8 17:09:51 2023 -0700

    Add tests
---
 tests/unit_tests/db_engine_specs/test_gsheets.py | 30 ++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tests/unit_tests/db_engine_specs/test_gsheets.py b/tests/unit_tests/db_engine_specs/test_gsheets.py
index 042e486642..c9ee39ffc5 100644
--- a/tests/unit_tests/db_engine_specs/test_gsheets.py
+++ b/tests/unit_tests/db_engine_specs/test_gsheets.py
@@ -19,9 +19,11 @@
 
 import json
 
+import pandas as pd
 from pytest_mock import MockFixture
 
 from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
+from superset.sql_parse import Table
 
 
 class ProgrammingError(Exception):
@@ -307,3 +309,31 @@ def test_unmask_encrypted_extra_when_new_is_none() -> None:
     new = None
 
     assert GSheetsEngineSpec.unmask_encrypted_extra(old, new) is None
+
+
+def test_upload_new(mocker: MockFixture) -> None:
+    """
+    Test file upload when the table does not exist.
+    """
+    from superset.db_engine_specs.gsheets import GSheetsEngineSpec
+
+    mocker.patch("superset.db_engine_specs.gsheets.db")
+    get_adapter_for_table_name = mocker.patch(
+        "superset.db_engine_specs.gsheets.get_adapter_for_table_name"
+    )
+    get_adapter_for_table_name()._get_session().post().json.return_value = {
+        "spreadsheetId": 1,
+        "spreadsheetUrl": "https://docs.example.org",
+        "sheets": [{"properties": {"title": "sample_data"}}],
+    }
+
+    database = mocker.MagicMock()
+    database.get_extra.return_value = {}
+
+    df = pd.DataFrame([1, "foo", 3.0])
+    table = Table("sample_data")
+
+    GSheetsEngineSpec.df_to_sql(database, table, df, {})
+    assert database.extra == json.dumps(
+        {"engine_params": {"catalog": {"sample_data": "https://docs.example.org"}}}
+    )