Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: make tabbed dashboard a little more complex #19966

Merged
merged 4 commits into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/superset-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Superset CLI tests

on:
push:
branches-ignore:
- "dependabot/npm_and_yarn/**"
pull_request:
types: [synchronize, opened, reopened, ready_for_review]

jobs:
test-load-examples:
if: github.event.pull_request.draft == false
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.9]
env:
PYTHONPATH: ${{ github.workspace }}
SUPERSET_CONFIG: tests.integration_tests.superset_test_config
REDIS_PORT: 16379
SUPERSET__SQLALCHEMY_DATABASE_URI: postgresql+psycopg2://superset:superset@127.0.0.1:15432/superset
services:
postgres:
image: postgres:14-alpine
env:
POSTGRES_USER: superset
POSTGRES_PASSWORD: superset
ports:
# Use custom ports for services to avoid accidentally connecting to
# GitHub action runner's default installations
- 15432:5432
redis:
image: redis:5-alpine
ports:
- 16379:6379
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v2
with:
persist-credentials: false
submodules: recursive
- name: Check if python changes are present
id: check
env:
GITHUB_REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
continue-on-error: true
run: ./scripts/ci_check_no_file_changes.sh python
- name: Setup Python
if: steps.check.outcome == 'failure'
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: 'requirements/testing.txt'
- name: Install dependencies
if: steps.check.outcome == 'failure'
uses: ./.github/actions/cached-dependencies
with:
run: |
apt-get-install
pip-upgrade
pip install wheel
pip install -r requirements/testing.txt
setup-postgres
- name: superset init
if: steps.check.outcome == 'failure'
run: |
pip install -e .
superset db upgrade
superset load_test_users
- name: superset load_examples
if: steps.check.outcome == 'failure'
run: |
# load examples without test data
superset load_examples --load-big-data
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function resize(selector: string) {
return {
to(cordX: number, cordY: number) {
cy.get(selector)
.trigger('mousedown', { which: 1 })
.trigger('mousedown', { which: 1, force: true })
.trigger('mousemove', { which: 1, cordX, cordY, force: true })
.trigger('mouseup', { which: 1, force: true });
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Dashboard edit markdown', () => {

cy.get('[data-test="dashboard-markdown-editor"]').contains('Test resize');

cy.get('@component-background-first').click('right');
cy.get('[data-test="nav-list"]:first').click('right', { force: true });
cy.get('[data-test="dashboard-component-chart-holder"]')
.find('.ace_content')
.should('not.exist');
Expand Down
1 change: 0 additions & 1 deletion superset/charts/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ class ChartEntityResponseSchema(Schema):
slice_name = fields.String(description=slice_name_description)
cache_timeout = fields.Integer(description=cache_timeout_description)
changed_on = fields.String(description=changed_on_description)
modified = fields.String()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By catch, this field returns invalid strings:
Xnip2022-05-05_14-16-49

description = fields.String(description=description_description)
description_markeddown = fields.String(
description=description_markeddown_description
Expand Down
7 changes: 3 additions & 4 deletions superset/cli/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def load_examples_run(
if load_test_data:
print("Loading [Tabbed dashboard]")
examples.load_tabbed_dashboard(only_metadata)

if not load_test_data:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha!

else:
print("Loading [Random long/lat data]")
examples.load_long_lat_data(only_metadata, force)

Expand Down Expand Up @@ -105,8 +104,8 @@ def load_examples_run(
help="Force load data even if table already exists",
)
def load_examples(
load_test_data: bool,
load_big_data: bool,
load_test_data: bool = False,
load_big_data: bool = False,
only_metadata: bool = False,
force: bool = False,
) -> None:
Expand Down
4 changes: 2 additions & 2 deletions superset/examples/big_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
sqlalchemy.sql.sqltypes.FLOAT(),
sqlalchemy.sql.sqltypes.DATE(),
sqlalchemy.sql.sqltypes.TIME(),
sqlalchemy.sql.sqltypes.DATETIME(),
sqlalchemy.sql.sqltypes.TIMESTAMP(),
]


Expand Down Expand Up @@ -72,5 +72,5 @@ def load_big_data() -> None:
add_data(columns=columns, num_rows=10, table_name=f"small_table_{i}")

print("Creating table with long name")
name = "".join(random.choices(string.ascii_letters + string.digits, k=64))
name = "".join(random.choices(string.ascii_letters + string.digits, k=60))
add_data(columns=columns, num_rows=10, table_name=name)
2 changes: 1 addition & 1 deletion superset/examples/birth_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ def create_dashboard(slices: List[Slice]) -> Dashboard:
# pylint: enable=line-too-long
# dashboard v2 doesn't allow add markup slice
dash.slices = [slc for slc in slices if slc.viz_type != "markup"]
update_slice_ids(pos, dash.slices)
update_slice_ids(pos)
dash.dashboard_title = "USA Births Names"
dash.position_json = json.dumps(pos, indent=4)
dash.slug = "births"
Expand Down
23 changes: 15 additions & 8 deletions superset/examples/deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"CHART-3afd9d70": {
"meta": {
"chartId": 66,
"sliceName": "Deck.gl Scatterplot",
"width": 6,
"height": 50
},
Expand All @@ -43,6 +44,7 @@
"CHART-2ee7fa5e": {
"meta": {
"chartId": 67,
"sliceName": "Deck.gl Screen grid",
"width": 6,
"height": 50
},
Expand All @@ -53,6 +55,7 @@
"CHART-201f7715": {
"meta": {
"chartId": 68,
"sliceName": "Deck.gl Hexagons",
"width": 6,
"height": 50
},
Expand All @@ -63,6 +66,7 @@
"CHART-d02f6c40": {
"meta": {
"chartId": 69,
"sliceName": "Deck.gl Grid",
"width": 6,
"height": 50
},
Expand All @@ -73,6 +77,7 @@
"CHART-2673431d": {
"meta": {
"chartId": 70,
"sliceName": "Deck.gl Polygons",
"width": 6,
"height": 50
},
Expand All @@ -83,6 +88,7 @@
"CHART-85265a60": {
"meta": {
"chartId": 71,
"sliceName": "Deck.gl Arcs",
"width": 6,
"height": 50
},
Expand All @@ -93,6 +99,7 @@
"CHART-2b87513c": {
"meta": {
"chartId": 72,
"sliceName": "Deck.gl Path",
"width": 6,
"height": 50
},
Expand Down Expand Up @@ -204,7 +211,7 @@ def load_deck_dash() -> None: # pylint: disable=too-many-statements

print("Creating Scatterplot slice")
slc = Slice(
slice_name="Scatterplot",
slice_name="Deck.gl Scatterplot",
viz_type="deck_scatter",
datasource_type="table",
datasource_id=tbl.id,
Expand Down Expand Up @@ -239,7 +246,7 @@ def load_deck_dash() -> None: # pylint: disable=too-many-statements
}
print("Creating Screen Grid slice")
slc = Slice(
slice_name="Screen grid",
slice_name="Deck.gl Screen grid",
viz_type="deck_screengrid",
datasource_type="table",
datasource_id=tbl.id,
Expand Down Expand Up @@ -275,7 +282,7 @@ def load_deck_dash() -> None: # pylint: disable=too-many-statements
}
print("Creating Hex slice")
slc = Slice(
slice_name="Hexagons",
slice_name="Deck.gl Hexagons",
viz_type="deck_hex",
datasource_type="table",
datasource_id=tbl.id,
Expand Down Expand Up @@ -312,7 +319,7 @@ def load_deck_dash() -> None: # pylint: disable=too-many-statements
}
print("Creating Grid slice")
slc = Slice(
slice_name="Grid",
slice_name="Deck.gl Grid",
viz_type="deck_grid",
datasource_type="table",
datasource_id=tbl.id,
Expand Down Expand Up @@ -401,7 +408,7 @@ def load_deck_dash() -> None: # pylint: disable=too-many-statements

print("Creating Polygon slice")
slc = Slice(
slice_name="Polygons",
slice_name="Deck.gl Polygons",
viz_type="deck_polygon",
datasource_type="table",
datasource_id=polygon_tbl.id,
Expand Down Expand Up @@ -451,7 +458,7 @@ def load_deck_dash() -> None: # pylint: disable=too-many-statements

print("Creating Arc slice")
slc = Slice(
slice_name="Arcs",
slice_name="Deck.gl Arcs",
viz_type="deck_arc",
datasource_type="table",
datasource_id=db.session.query(table)
Expand Down Expand Up @@ -503,7 +510,7 @@ def load_deck_dash() -> None: # pylint: disable=too-many-statements

print("Creating Path slice")
slc = Slice(
slice_name="Path",
slice_name="Deck.gl Path",
viz_type="deck_path",
datasource_type="table",
datasource_id=db.session.query(table)
Expand All @@ -525,7 +532,7 @@ def load_deck_dash() -> None: # pylint: disable=too-many-statements
dash.published = True
js = POSITION_JSON
pos = json.loads(js)
update_slice_ids(pos, slices)
slices = update_slice_ids(pos)
dash.position_json = json.dumps(pos, indent=4)
dash.dashboard_title = title
dash.slug = slug
Expand Down
25 changes: 16 additions & 9 deletions superset/examples/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,24 @@ def get_examples_folder() -> str:
return os.path.join(app.config["BASE_DIR"], "examples")


def update_slice_ids(layout_dict: Dict[Any, Any], slices: List[Slice]) -> None:
charts = [
def update_slice_ids(pos: Dict[Any, Any]) -> List[Slice]:
ktmud marked this conversation as resolved.
Show resolved Hide resolved
"""Update slice ids in position_json and return the slices found."""
slice_components = [
component
for component in layout_dict.values()
if isinstance(component, dict) and component["type"] == "CHART"
for component in pos.values()
if isinstance(component, dict) and component.get("type") == "CHART"
]
sorted_charts = sorted(charts, key=lambda k: k["meta"]["chartId"])
for i, chart_component in enumerate(sorted_charts):
if i < len(slices):
chart_component["meta"]["chartId"] = int(slices[i].id)
chart_component["meta"]["uuid"] = str(slices[i].uuid)
slices = {}
for name in set(component["meta"]["sliceName"] for component in slice_components):
slc = db.session.query(Slice).filter_by(slice_name=name).first()
if slc:
slices[name] = slc
for component in slice_components:
slc = slices.get(component["meta"]["sliceName"])
if slc:
component["meta"]["chartId"] = slc.id
component["meta"]["uuid"] = str(slc.uuid)
return list(slices.values())


def merge_slice(slc: Slice) -> None:
Expand Down
9 changes: 2 additions & 7 deletions superset/examples/misc_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

from superset import db
from superset.models.dashboard import Dashboard
from superset.models.slice import Slice

from .helpers import misc_dash_slices, update_slice_ids
from .helpers import update_slice_ids

DASH_SLUG = "misc_charts"

Expand Down Expand Up @@ -211,11 +210,7 @@ def load_misc_dashboard() -> None:
"""
)
pos = json.loads(js)
slices = (
db.session.query(Slice).filter(Slice.slice_name.in_(misc_dash_slices)).all()
)
slices = sorted(slices, key=lambda x: x.id)
update_slice_ids(pos, slices)
slices = update_slice_ids(pos)
dash.dashboard_title = "Misc Charts"
dash.position_json = json.dumps(pos, indent=4)
dash.slug = DASH_SLUG
Expand Down
Loading