def test_get_missing_chart(client, chart, permalink_salt: str) -> None: from superset.key_value.models import KeyValueEntry chart_id = 1234 entry = KeyValueEntry( resource=KeyValueResource.EXPLORE_PERMALINK, value=pickle.dumps({ "chartId": chart_id, "datasourceId": chart.datasource.id, "datasourceType": DatasourceType.TABLE, "formData": { "slice_id": chart_id, "datasource": f"{chart.datasource.id}__{chart.datasource.type}", }, }), ) db.session.add(entry) db.session.commit() key = encode_permalink_key(entry.id, permalink_salt) login(client, "admin") resp = client.get(f"api/v1/explore/permalink/{key}") assert resp.status_code == 404 db.session.delete(entry) db.session.commit()
def test_get_missing_chart(client, chart): from superset.key_value.models import KeyValueEntry key = 1234 uuid_key = "e2ea9d19-7988-4862-aa69-c3a1a7628cb9" entry = KeyValueEntry( id=int(key), uuid=UUID("e2ea9d19-7988-4862-aa69-c3a1a7628cb9"), resource="explore_permalink", value=pickle.dumps( { "chartId": key, "datasetId": chart.datasource.id, "formData": { "slice_id": key, "datasource": f"{chart.datasource.id}__{chart.datasource.type}", }, } ), ) db.session.add(entry) db.session.commit() login(client, "admin") resp = client.get(f"api/v1/explore/permalink/{uuid_key}") assert resp.status_code == 404 db.session.delete(entry) db.session.commit()
def test_get(client, form_data): login(client, "admin") resp = client.post(f"api/v1/explore/permalink", json={"formData": form_data}) data = json.loads(resp.data.decode("utf-8")) key = data["key"] resp = client.get(f"api/v1/explore/permalink/{key}") assert resp.status_code == 200 result = json.loads(resp.data.decode("utf-8")) assert result["state"]["formData"] == form_data db.session.query(KeyValueEntry).filter_by(uuid=key).delete() db.session.commit()
def test_get(client, dashboard_id: int): login(client, "admin") resp = client.post(f"api/v1/dashboard/{dashboard_id}/permalink", json=STATE) data = json.loads(resp.data.decode("utf-8")) key = data["key"] resp = client.get(f"api/v1/dashboard/permalink/{key}") assert resp.status_code == 200 result = json.loads(resp.data.decode("utf-8")) assert result["dashboardId"] == str(dashboard_id) assert result["state"] == STATE db.session.query(KeyValueEntry).filter_by(uuid=key).delete() db.session.commit()
def test_get(client, form_data: Dict[str, Any], permalink_salt: str) -> None: login(client, "admin") resp = client.post(f"api/v1/explore/permalink", json={"formData": form_data}) data = json.loads(resp.data.decode("utf-8")) key = data["key"] resp = client.get(f"api/v1/explore/permalink/{key}") assert resp.status_code == 200 result = json.loads(resp.data.decode("utf-8")) assert result["state"]["formData"] == form_data id_ = decode_permalink_id(key, permalink_salt) db.session.query(KeyValueEntry).filter_by(id=id_).delete() db.session.commit()
def test_get_dataset_access_denied(mock_can_access_datasource, client): mock_can_access_datasource.side_effect = DatasetAccessDeniedError() login(client, "admin") resp = client.get(f"api/v1/explore/form_data/{KEY}") assert resp.status_code == 403
def test_get_access_denied(client): login(client, "gamma") resp = client.get(f"api/v1/explore/form_data/{KEY}") assert resp.status_code == 404
def test_get(client): login(client, "admin") resp = client.get(f"api/v1/explore/form_data/{KEY}") assert resp.status_code == 200 data = json.loads(resp.data.decode("utf-8")) assert INITIAL_FORM_DATA == data.get("form_data")
def test_get_key_not_found(client): login(client, "admin") resp = client.get(f"api/v1/explore/form_data/unknown-key") assert resp.status_code == 404
def test_get_access_denied(mock_raise_for_dashboard_access, client, dashboard_id): login(client, "admin") mock_raise_for_dashboard_access.side_effect = DashboardAccessDeniedError() resp = client.get(f"api/v1/dashboard/{dashboard_id}/filter_state/{KEY}") assert resp.status_code == 403
def test_get(client, dashboard_id: int): login(client, "admin") resp = client.get(f"api/v1/dashboard/{dashboard_id}/filter_state/{KEY}") assert resp.status_code == 200 data = json.loads(resp.data.decode("utf-8")) assert INITIAL_VALUE == data.get("value")
def test_get_dashboard_not_found(client): login(client, "admin") resp = client.get(f"api/v1/dashboard/{-1}/filter_state/{KEY}") assert resp.status_code == 404
def test_get_key_not_found(client, dashboard_id: int): login(client, "admin") resp = client.get(f"api/v1/dashboard/{dashboard_id}/filter_state/unknown-key/") assert resp.status_code == 404