Skip to content

Commit

Permalink
Move tests
Browse files Browse the repository at this point in the history
  • Loading branch information
geido committed Feb 16, 2023
1 parent 298badc commit 031e452
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
30 changes: 0 additions & 30 deletions tests/integration_tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,36 +757,6 @@ def test_templated_sql_json(self):
data = self.run_sql(sql, "fdaklj3ws")
self.assertEqual(data["data"][0]["test"], "2")

@pytest.mark.usefixtures("load_birth_names_data")
def test_templated_sql_forbidden(self):
self.login(username="gamma");

data = self.run_sql(
"""
SELECT * FROM {{ table_name }} LIMIT 1;
""",
client_id="client_id_1",
database_name="examples",
template_params=json.dumps({"table_name": "birth_names"}),
raise_on_error=True
)
assert data["errors"][0]["error_type"] == "GENERIC_BACKEND_ERROR"

@pytest.mark.usefixtures("load_birth_names_data")
def test_templated_sql_success(self):
self.login(username="admin");

data = self.run_sql(
"""
SELECT * FROM {{ table_name }} LIMIT 1;
""",
client_id="client_id_1",
database_name="examples",
template_params=json.dumps({"table_name": "birth_names"}),
raise_on_error=True
)
assert data["status"] == "success"

@mock.patch(
"tests.integration_tests.superset_test_custom_template_processors.datetime"
)
Expand Down
32 changes: 32 additions & 0 deletions tests/integration_tests/sqllab_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,38 @@ def test_sql_json_parameter_error(self):
"undefined_parameters": ["stat"],
}

@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
@mock.patch.dict(
"superset.extensions.feature_flag_manager._feature_flags",
{"ENABLE_TEMPLATE_PROCESSING": True},
clear=True,
)
def test_sql_json_parameter_authorized(self):
self.login("admin")

data = self.run_sql(
"SELECT name FROM {{ table }} LIMIT 10",
"3",
template_params=json.dumps({"table": "birth_names"}),
)
assert data["status"] == "success"

@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
@mock.patch.dict(
"superset.extensions.feature_flag_manager._feature_flags",
{"ENABLE_TEMPLATE_PROCESSING": True},
clear=True,
)
def test_sql_json_parameter_forbidden(self):
self.login("gamma")

data = self.run_sql(
"SELECT name FROM {{ table }} LIMIT 10",
"4",
template_params=json.dumps({"table": "birth_names"}),
)
assert data["errors"][0]["error_type"] == "GENERIC_BACKEND_ERROR"

@mock.patch("superset.sql_lab.get_query")
@mock.patch("superset.sql_lab.execute_sql_statement")
def test_execute_sql_statements(self, mock_execute_sql_statement, mock_get_query):
Expand Down

0 comments on commit 031e452

Please sign in to comment.