Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Mar 17, 2022
1 parent 4ad7e9b commit 8b7cabd
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 3 deletions.
2 changes: 1 addition & 1 deletion superset/initialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def init_views(self) -> None:
)
from superset.views.datasource.views import Datasource
from superset.views.dynamic_plugins import DynamicPluginsView
from superset.views.import_export.api import ImportExportRestApi
from superset.views.importexport.api import ImportExportRestApi
from superset.views.key_value import KV
from superset.views.log.api import LogRestApi
from superset.views.log.views import LogModelView
Expand Down
File renamed without changes.
21 changes: 19 additions & 2 deletions tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import Iterator

import pytest
from flask.testing import FlaskClient
from pytest_mock import MockFixture
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
Expand Down Expand Up @@ -52,20 +53,36 @@ def app(mocker: MockFixture, session: Session) -> Iterator[SupersetApp]:

app.config.from_object("superset.config")
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://"
app.config["FAB_ADD_SECURITY_VIEWS"] = False
# app.config["FAB_ADD_SECURITY_VIEWS"] = False

app_initializer = app.config.get("APP_INITIALIZER", SupersetAppInitializer)(app)
app_initializer.init_app()

# patch session
mocker.patch(
"superset.security.SupersetSecurityManager.get_session", return_value=session,
"superset.security.SupersetSecurityManager.get_session",
return_value=session,
)
mocker.patch("superset.db.session", session)

yield app


@pytest.fixture
def client(app: SupersetApp) -> FlaskClient:
test_client = app.test_client()
response = test_client.post(
"/security/login/",
data=dict(username="admin", password="general"),
follow_redirects=True,
)
print("BETO")
print(response.data)
print(response.status_code)
print("GOO")
return app.test_client()


@pytest.fixture
def app_context(app: SupersetApp) -> Iterator[None]:
"""
Expand Down
16 changes: 16 additions & 0 deletions tests/unit_tests/views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
16 changes: 16 additions & 0 deletions tests/unit_tests/views/importexport/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
41 changes: 41 additions & 0 deletions tests/unit_tests/views/importexport/api_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from flask.testing import FlaskClient
from freezegun import freeze_time
from pytest_mock import MockFixture


def test_export_assets(mocker: MockFixture, client: FlaskClient) -> None:
"""
Test exporting all assets.
"""
# pylint: disable=invalid-name
ExportAssetsCommand = mocker.patch(
"superset.views.importexport.api.ExportAssetsCommand"
)
ExportAssetsCommand().run.return_value = [
(
"metadata.yaml",
"version: 1.0.0\ntype: assets\ntimestamp: '2022-01-01T00:00:00+00:00'\n",
),
("databases/example.yaml", "<DATABASE CONTENTS>"),
]
with freeze_time("2022-01-01T00:00:00Z"):
response = client.get("/api/v1/assets/export/")
print(response.json)
assert response.status_code == 200

0 comments on commit 8b7cabd

Please sign in to comment.