Skip to content

Commit

Permalink
fixes after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
kstrz committed Jan 12, 2021
1 parent f7c7b37 commit 623857c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bashlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ cypress-run-all() {
nohup flask run --no-debugger -p $port >"$flasklog" 2>&1 </dev/null &
local flaskProcessId=$!

cypress-run "dashboard/url_params.test.js"
cypress-run "*/**/*"

# Upload code coverage separately so each page can have separate flags
# -c will clean existing coverage reports, -F means add flags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Dashboard form data', () => {
it('should apply url params to slice requests', () => {
const aliases = getChartAliases(dashboard.slices);
// wait and verify one-by-one
cy.wait(aliases, {timeout: 15000}).then(requests =>
cy.wait(aliases, {timeout: 18000}).then(requests =>
Promise.all(
requests.map(async xhr => {
expect(xhr.status).to.eq(200);
Expand Down
4 changes: 4 additions & 0 deletions tests/base_api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
# under the License.
# isort:skip_file
import json
from tests.fixtures.world_bank_dashboard import load_world_bank_dashboard_with_slices

import pytest
from flask_appbuilder.models.sqla.interface import SQLAInterface
import prison

Expand Down Expand Up @@ -66,6 +68,7 @@ def test_open_api_spec(self):


class TestBaseModelRestApi(SupersetTestCase):
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
def test_default_missing_declaration_get(self):
"""
API: Test default missing declaration on get
Expand Down Expand Up @@ -148,6 +151,7 @@ def test_default_missing_declaration_post(self):
}
self.assertEqual(response, expected_response)

@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
def test_default_missing_declaration_put(self):
"""
API: Test default missing declaration on put
Expand Down
25 changes: 17 additions & 8 deletions tests/charts/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,10 @@ def test_delete_bulk_chart_not_owned(self):
db.session.delete(user_alpha2)
db.session.commit()

@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices", "load_birth_names_dashboard_with_slices")
@pytest.mark.usefixtures(
"load_world_bank_dashboard_with_slices",
"load_birth_names_dashboard_with_slices",
)
def test_create_chart(self):
"""
Chart API: Test create chart
Expand Down Expand Up @@ -545,15 +548,18 @@ def test_create_chart_validate_datasource(self):
response, {"message": {"datasource_id": ["Datasource does not exist"]}}
)

@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_update_chart(self):
"""
Chart API: Test update
"""
admin = self.get_user("admin")
gamma = self.get_user("gamma")

chart_id = self.insert_chart("title", [admin.id], 1, admin).id
birth_names_table_id = SupersetTestCase.get_table_by_name("birth_names").id
chart_id = self.insert_chart(
"title", [admin.id], birth_names_table_id, admin
).id
dash_id = db.session.query(Dashboard.id).filter_by(slug="births").first()[0]
chart_data = {
"slice_name": "title1_changed",
"description": "description1",
Expand All @@ -563,14 +569,14 @@ def test_update_chart(self):
"cache_timeout": 1000,
"datasource_id": birth_names_table_id,
"datasource_type": "table",
"dashboards": [1],
"dashboards": [dash_id],
}
self.login(username="admin")
uri = f"api/v1/chart/{chart_id}"
rv = self.put_assert_metric(uri, chart_data, "put")
self.assertEqual(rv.status_code, 200)
model = db.session.query(Slice).get(chart_id)
related_dashboard = db.session.query(Dashboard).get(1)
related_dashboard = db.session.query(Dashboard).filter_by(slug="births").first()
self.assertEqual(model.created_by, admin)
self.assertEqual(model.slice_name, "title1_changed")
self.assertEqual(model.description, "description1")
Expand All @@ -582,7 +588,7 @@ def test_update_chart(self):
self.assertEqual(model.datasource_id, birth_names_table_id)
self.assertEqual(model.datasource_type, "table")
self.assertEqual(model.datasource_name, "birth_names")
self.assertIn(related_dashboard, model.dashboards)
self.assertIn(model.id, [slice.id for slice in related_dashboard.slices])
db.session.delete(model)
db.session.commit()

Expand Down Expand Up @@ -801,7 +807,10 @@ def test_get_charts_changed_on(self):
db.session.delete(chart)
db.session.commit()

@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices", "load_birth_names_dashboard_with_slices")
@pytest.mark.usefixtures(
"load_world_bank_dashboard_with_slices",
"load_birth_names_dashboard_with_slices",
)
def test_get_charts_filter(self):
"""
Chart API: Test get charts filter
Expand Down Expand Up @@ -1012,7 +1021,7 @@ def test_get_time_range(self):
"load_unicode_dashboard_with_slice",
"load_energy_table_with_slice",
"load_world_bank_dashboard_with_slices",
"load_birth_names_dashboard_with_slices"
"load_birth_names_dashboard_with_slices",
)
def test_get_charts_page(self):
"""
Expand Down
9 changes: 6 additions & 3 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
from superset.views.database.views import DatabaseView

from .base_tests import SupersetTestCase
from tests.fixtures.world_bank_dashboard import load_world_bank_dashboard_with_slices

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1223,6 +1224,7 @@ def test_results_msgpack_deserialization(self):
{"FOO": lambda x: 1},
clear=True,
)
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
def test_feature_flag_serialization(self):
"""
Functions in feature flags don't break bootstrap data serialization.
Expand All @@ -1238,13 +1240,14 @@ def test_feature_flag_serialization(self):
.replace("'", "&#39;")
.replace('"', "&#34;")
)

dash_id = db.session.query(Dashboard.id).first()[0]
tbl_id = self.table_ids.get("wb_health_population")
urls = [
"/superset/sqllab",
"/superset/welcome",
"/superset/dashboard/1/",
f"/superset/dashboard/{dash_id}/",
"/superset/profile/admin/",
"/superset/explore/table/1",
f"/superset/explore/table/{tbl_id}",
]
for url in urls:
data = self.get_resp(url)
Expand Down
9 changes: 7 additions & 2 deletions tests/dashboards/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
dataset_metadata_config,
)
from tests.utils.get_dashboards import get_dashboards_ids
from tests.fixtures.world_bank_dashboard import load_world_bank_dashboard_with_slices

DASHBOARDS_FIXTURE_COUNT = 10

Expand Down Expand Up @@ -1102,13 +1103,17 @@ def test_update_dashboard_not_owned(self):
db.session.delete(user_alpha2)
db.session.commit()

@pytest.mark.usefixtures(
"load_world_bank_dashboard_with_slices",
"load_birth_names_dashboard_with_slices",
)
def test_export(self):
"""
Dashboard API: Test dashboard export
"""
self.login(username="admin")
argument = [1, 2]
uri = f"api/v1/dashboard/export/?q={prison.dumps(argument)}"
dashboards_ids = get_dashboards_ids(db, ["world_health", "births"])
uri = f"api/v1/dashboard/export/?q={prison.dumps(dashboards_ids)}"

# freeze time to ensure filename is deterministic
with freeze_time("2020-01-01T00:00:00Z"):
Expand Down
5 changes: 4 additions & 1 deletion tests/dashboards/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,17 @@ def test_export_dashboard_command(self, mock_g1, mock_g2):
"version": "1.0.0",
}

@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
@patch("superset.security.manager.g")
@patch("superset.views.base.g")
def test_export_dashboard_command_no_access(self, mock_g1, mock_g2):
"""Test that users can't export datasets they don't have access to"""
mock_g1.user = security_manager.find_user("gamma")
mock_g2.user = security_manager.find_user("gamma")

example_dashboard = db.session.query(Dashboard).filter_by(id=1).one()
example_dashboard = (
db.session.query(Dashboard).filter_by(slug="world_health").one()
)
command = ExportDashboardsCommand([example_dashboard.id])
contents = command.run()
with self.assertRaises(DashboardNotFoundError):
Expand Down

0 comments on commit 623857c

Please sign in to comment.