def test_validate_parameters_simple(
    mocker: MockFixture,
    app_context: AppContext,
) -> None:
    from superset.db_engine_specs.gsheets import (
        GSheetsEngineSpec,
        GSheetsParametersType,
    )

    parameters: GSheetsParametersType = {
        "credentials_info": {},
        "catalog": {},
    }
    errors = GSheetsEngineSpec.validate_parameters(parameters)
    assert errors == [
        SupersetError(
            message="URL is required",
            error_type=SupersetErrorType.CONNECTION_MISSING_PARAMETERS_ERROR,
            level=ErrorLevel.WARNING,
            extra={
                "invalid": ["catalog"],
                "name":
                "",
                "url":
                "",
                "issue_codes": [{
                    "code":
                    1018,
                    "message":
                    "Issue 1018 - One or more parameters needed to configure a database are missing.",
                }],
            },
        )
    ]
Ejemplo n.º 2
0
def test_validate_parameters_simple(
    mocker: MockFixture,
    app_context: AppContext,
) -> None:
    from superset.db_engine_specs.gsheets import (
        GSheetsEngineSpec,
        GSheetsParametersType,
    )

    parameters: GSheetsParametersType = {
        "credentials_info": {},
        "catalog": {},
    }
    errors = GSheetsEngineSpec.validate_parameters(parameters)
    assert errors == []
Ejemplo n.º 3
0
def test_validate_parameters_simple(mocker: MockFixture, ) -> None:
    from superset.db_engine_specs.gsheets import (
        GSheetsEngineSpec,
        GSheetsParametersType,
    )

    parameters: GSheetsParametersType = {
        "service_account_info": "",
        "catalog": {},
    }
    errors = GSheetsEngineSpec.validate_parameters(parameters)
    assert errors == [
        SupersetError(
            message="Sheet name is required",
            error_type=SupersetErrorType.CONNECTION_MISSING_PARAMETERS_ERROR,
            level=ErrorLevel.WARNING,
            extra={"catalog": {
                "idx": 0,
                "name": True
            }},
        ),
    ]
Ejemplo n.º 4
0
 def test_extract_errors(self):
     """
     Test that custom error messages are extracted correctly.
     """
     msg = 'SQLError: near "fromm": syntax error'
     result = GSheetsEngineSpec.extract_errors(Exception(msg))
     assert result == [
         SupersetError(
             message=
             'Please check your query for syntax errors near "fromm". Then, try running your query again.',
             error_type=SupersetErrorType.SYNTAX_ERROR,
             level=ErrorLevel.ERROR,
             extra={
                 "engine_name":
                 "Google Sheets",
                 "issue_codes": [{
                     "code":
                     1030,
                     "message":
                     "Issue 1030 - The query has a syntax error.",
                 }],
             },
         )
     ]
def test_validate_parameters_catalog(
    mocker: MockFixture,
    app_context: AppContext,
) -> None:
    from superset.db_engine_specs.gsheets import (
        GSheetsEngineSpec,
        GSheetsParametersType,
    )

    g = mocker.patch("superset.db_engine_specs.gsheets.g")
    g.user.email = "*****@*****.**"

    create_engine = mocker.patch(
        "superset.db_engine_specs.gsheets.create_engine")
    conn = create_engine.return_value.connect.return_value
    results = conn.execute.return_value
    results.fetchall.side_effect = [
        ProgrammingError("The caller does not have permission"),
        [(1, )],
        ProgrammingError("Unsupported table: https://www.google.com/"),
    ]

    parameters: GSheetsParametersType = {
        "credentials_info": {},
        "catalog": {
            "private_sheet": "https://docs.google.com/spreadsheets/d/1/edit",
            "public_sheet":
            "https://docs.google.com/spreadsheets/d/1/edit#gid=1",
            "not_a_sheet": "https://www.google.com/",
        },
    }
    errors = GSheetsEngineSpec.validate_parameters(parameters)  # ignore: type

    assert errors == [
        SupersetError(
            message="URL could not be identified",
            error_type=SupersetErrorType.TABLE_DOES_NOT_EXIST_ERROR,
            level=ErrorLevel.WARNING,
            extra={
                "invalid": ["catalog"],
                "name":
                "private_sheet",
                "url":
                "https://docs.google.com/spreadsheets/d/1/edit",
                "issue_codes": [
                    {
                        "code":
                        1003,
                        "message":
                        "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.",
                    },
                    {
                        "code":
                        1005,
                        "message":
                        "Issue 1005 - The table was deleted or renamed in the database.",
                    },
                ],
            },
        ),
        SupersetError(
            message="URL could not be identified",
            error_type=SupersetErrorType.TABLE_DOES_NOT_EXIST_ERROR,
            level=ErrorLevel.WARNING,
            extra={
                "invalid": ["catalog"],
                "name":
                "not_a_sheet",
                "url":
                "https://www.google.com/",
                "issue_codes": [
                    {
                        "code":
                        1003,
                        "message":
                        "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.",
                    },
                    {
                        "code":
                        1005,
                        "message":
                        "Issue 1005 - The table was deleted or renamed in the database.",
                    },
                ],
            },
        ),
    ]

    create_engine.assert_called_with(
        "gsheets://",
        service_account_info={},
        subject="*****@*****.**",
    )
Ejemplo n.º 6
0
def test_validate_parameters_catalog(mocker, app_context):
    from superset.db_engine_specs.gsheets import GSheetsEngineSpec

    g = mocker.patch("superset.db_engine_specs.gsheets.g")
    g.user.email = "*****@*****.**"

    create_engine = mocker.patch(
        "superset.db_engine_specs.gsheets.create_engine")
    conn = create_engine.return_value.connect.return_value
    results = conn.execute.return_value
    results.fetchall.side_effect = [
        ProgrammingError("The caller does not have permission"),
        [(1, )],
        ProgrammingError("Unsupported table: https://www.google.com/"),
    ]

    parameters = {
        "table_catalog": {
            "private_sheet": "https://docs.google.com/spreadsheets/d/1/edit",
            "public_sheet":
            "https://docs.google.com/spreadsheets/d/1/edit#gid=1",
            "not_a_sheet": "https://www.google.com/",
        },
    }
    errors = GSheetsEngineSpec.validate_parameters(parameters)
    assert errors == [
        SupersetError(
            message=("Unable to connect to spreadsheet private_sheet at "
                     "https://docs.google.com/spreadsheets/d/1/edit"),
            error_type=SupersetErrorType.TABLE_DOES_NOT_EXIST_ERROR,
            level=ErrorLevel.WARNING,
            extra={
                "name":
                "private_sheet",
                "url":
                "https://docs.google.com/spreadsheets/d/1/edit",
                "issue_codes": [
                    {
                        "code":
                        1003,
                        "message":
                        ("Issue 1003 - There is a syntax error in the SQL query. "
                         "Perhaps there was a misspelling or a typo."),
                    },
                    {
                        "code":
                        1005,
                        "message":
                        ("Issue 1005 - The table was deleted or renamed in the "
                         "database."),
                    },
                ],
            },
        ),
        SupersetError(
            message=("Unable to connect to spreadsheet not_a_sheet at "
                     "https://www.google.com/"),
            error_type=SupersetErrorType.TABLE_DOES_NOT_EXIST_ERROR,
            level=ErrorLevel.WARNING,
            extra={
                "name":
                "not_a_sheet",
                "url":
                "https://www.google.com/",
                "issue_codes": [
                    {
                        "code":
                        1003,
                        "message":
                        ("Issue 1003 - There is a syntax error in the SQL query. "
                         "Perhaps there was a misspelling or a typo."),
                    },
                    {
                        "code":
                        1005,
                        "message":
                        ("Issue 1005 - The table was deleted or renamed in the "
                         "database.", ),
                    },
                ],
            },
        ),
    ]
    create_engine.assert_called_with(
        "gsheets://",
        service_account_info=None,
        subject="*****@*****.**",
    )
Ejemplo n.º 7
0
def test_validate_parameters_simple(mocker, app_context):
    from superset.db_engine_specs.gsheets import GSheetsEngineSpec

    parameters = {}
    errors = GSheetsEngineSpec.validate_parameters(parameters)
    assert errors == []