def test_post_different_key_for_no_tab_id(client, dashboard_id: int): login(client, "admin") payload = { "value": INITIAL_VALUE, } resp = client.post(f"api/v1/dashboard/{dashboard_id}/filter_state", json=payload) data = json.loads(resp.data.decode("utf-8")) first_key = data.get("key") resp = client.post(f"api/v1/dashboard/{dashboard_id}/filter_state", json=payload) data = json.loads(resp.data.decode("utf-8")) second_key = data.get("key") assert first_key != second_key
def test_post_same_key_for_same_tab_id(client, chart_id: int, dataset_id: int): login(client, "admin") payload = { "dataset_id": dataset_id, "chart_id": chart_id, "form_data": json.dumps({"test": "initial value"}), } resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload) data = json.loads(resp.data.decode("utf-8")) first_key = data.get("key") resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload) data = json.loads(resp.data.decode("utf-8")) second_key = data.get("key") assert first_key == second_key
def test_post_different_key_for_no_tab_id(client, chart_id: int, dataset_id: int): login(client, "admin") payload = { "dataset_id": dataset_id, "chart_id": chart_id, "form_data": INITIAL_FORM_DATA, } resp = client.post("api/v1/explore/form_data", json=payload) data = json.loads(resp.data.decode("utf-8")) first_key = data.get("key") resp = client.post("api/v1/explore/form_data", json=payload) data = json.loads(resp.data.decode("utf-8")) second_key = data.get("key") assert first_key != second_key
def test_post_same_key_for_same_context(client, chart_id: int, dataset_id: int): login(client, "admin") payload = { "dataset_id": dataset_id, "chart_id": chart_id, "form_data": UPDATED_FORM_DATA, } resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload) data = json.loads(resp.data.decode("utf-8")) first_key = data.get("key") resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload) data = json.loads(resp.data.decode("utf-8")) second_key = data.get("key") assert first_key == second_key
def test_post_bad_request_non_json_string(client, dashboard_id: int): login(client, "admin") payload = { "value": "foo", } resp = client.post(f"api/v1/dashboard/{dashboard_id}/filter_state", json=payload) assert resp.status_code == 400
def test_post(client, dashboard_id: int): login(client, "admin") payload = { "value": INITIAL_VALUE, } resp = client.post(f"api/v1/dashboard/{dashboard_id}/filter_state", json=payload) assert resp.status_code == 201
def test_post_access_denied(mock_raise_for_dashboard_access, client, dashboard_id: int): login(client, "admin") mock_raise_for_dashboard_access.side_effect = DashboardAccessDeniedError() resp = client.post(f"api/v1/dashboard/{dashboard_id}/permalink", json=STATE) assert resp.status_code == 403
def test_post_different_key_for_different_tab_id(client, chart_id: int, datasource: SqlaTable): login(client, "admin") payload = { "datasource_id": datasource.id, "datasource_type": datasource.type, "chart_id": chart_id, "form_data": json.dumps({"test": "initial value"}), } resp = client.post("api/v1/explore/form_data?tab_id=1", json=payload) data = json.loads(resp.data.decode("utf-8")) first_key = data.get("key") resp = client.post("api/v1/explore/form_data?tab_id=2", json=payload) data = json.loads(resp.data.decode("utf-8")) second_key = data.get("key") assert first_key != second_key
def test_post_access_denied(mock_raise_for_dashboard_access, client, dashboard_id: int): login(client, "admin") mock_raise_for_dashboard_access.side_effect = DashboardAccessDeniedError() payload = { "value": INITIAL_VALUE, } resp = client.post(f"api/v1/dashboard/{dashboard_id}/filter_state", json=payload) assert resp.status_code == 403
def test_post_bad_request_non_string(client, chart_id: int, dataset_id: int): login(client, "admin") payload = { "dataset_id": dataset_id, "chart_id": chart_id, "form_data": 1234, } resp = client.post("api/v1/explore/form_data", json=payload) assert resp.status_code == 400
def test_post(client, chart_id: int, dataset_id: int): login(client, "admin") payload = { "dataset_id": dataset_id, "chart_id": chart_id, "form_data": INITIAL_FORM_DATA, } resp = client.post("api/v1/explore/form_data", json=payload) assert resp.status_code == 201
def test_post(client, form_data): login(client, "admin") resp = client.post(f"api/v1/explore/permalink", json={"formData": form_data}) assert resp.status_code == 201 data = json.loads(resp.data.decode("utf-8")) key = data["key"] url = data["url"] assert key in url db.session.query(KeyValueEntry).filter_by(uuid=key).delete() db.session.commit()
def test_post_access_denied(client, chart_id: int, datasource: SqlaTable): login(client, "gamma") payload = { "datasource_id": datasource.id, "datasource_type": datasource.type, "chart_id": chart_id, "form_data": INITIAL_FORM_DATA, } resp = client.post("api/v1/explore/form_data", json=payload) assert resp.status_code == 404
def test_post(client, dashboard_id: int): login(client, "admin") resp = client.post(f"api/v1/dashboard/{dashboard_id}/permalink", json=STATE) assert resp.status_code == 201 data = json.loads(resp.data.decode("utf-8")) key = data["key"] url = data["url"] assert key in url db.session.query(KeyValueEntry).filter_by(uuid=key).delete() db.session.commit()
def test_post(client, form_data: Dict[str, Any], permalink_salt: str): login(client, "admin") resp = client.post(f"api/v1/explore/permalink", json={"formData": form_data}) assert resp.status_code == 201 data = json.loads(resp.data.decode("utf-8")) key = data["key"] url = data["url"] assert key in url id_ = decode_permalink_id(key, permalink_salt) db.session.query(KeyValueEntry).filter_by(id=id_).delete() db.session.commit()
def test_post_bad_request_non_json_string(client, chart_id: int, datasource: SqlaTable): login(client, "admin") payload = { "datasource_id": datasource.id, "datasource_type": datasource.type, "chart_id": chart_id, "form_data": "foo", } resp = client.post("api/v1/explore/form_data", json=payload) assert resp.status_code == 400
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, 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(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_post_invalid_schema(client): login(client, "admin") resp = client.post(f"api/v1/explore/permalink", json={"abc": 123}) assert resp.status_code == 400
def test_post_access_denied(client, form_data): login(client, "gamma") resp = client.post(f"api/v1/explore/permalink", json={"formData": form_data}) assert resp.status_code == 404
def test_post_invalid_schema(client, dashboard_id: int): login(client, "admin") resp = client.post( f"api/v1/dashboard/{dashboard_id}/permalink", json={"foo": "bar"} ) assert resp.status_code == 400