예제 #1
0
def test_put_not_owner(client, dashboard_id: int):
    login(client, "gamma")
    payload = {
        "value": "new value",
    }
    resp = client.put(f"api/v1/dashboard/{dashboard_id}/filter_state/{key}/",
                      json=payload)
    assert resp.status_code == 403
예제 #2
0
def test_put_bad_request(client, dashboard_id: int):
    login(client, "admin")
    payload = {
        "value": 1234,
    }
    resp = client.put(f"api/v1/dashboard/{dashboard_id}/filter_state/{key}",
                      json=payload)
    assert resp.status_code == 400
예제 #3
0
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
예제 #4
0
def test_post(client, dashboard_id: int):
    login(client, "admin")
    payload = {
        "value": value,
    }
    resp = client.post(f"api/v1/dashboard/{dashboard_id}/filter_state",
                       json=payload)
    assert resp.status_code == 201
예제 #5
0
def test_put_bad_request_non_json_string(client, dashboard_id: int):
    login(client, "admin")
    payload = {
        "value": "foo",
    }
    resp = client.put(
        f"api/v1/dashboard/{dashboard_id}/filter_state/{KEY}", json=payload
    )
    assert resp.status_code == 400
예제 #6
0
def test_put(client, dashboard_id: int):
    login(client, "admin")
    payload = {
        "value": UPDATED_VALUE,
    }
    resp = client.put(
        f"api/v1/dashboard/{dashboard_id}/filter_state/{KEY}", json=payload
    )
    assert resp.status_code == 200
예제 #7
0
def test_put_access_denied(client, chart_id: int, dataset_id: int):
    login(client, "gamma")
    payload = {
        "dataset_id": dataset_id,
        "chart_id": chart_id,
        "form_data": UPDATED_FORM_DATA,
    }
    resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
    assert resp.status_code == 404
예제 #8
0
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
예제 #9
0
def test_post_access_denied(client, chart_id: int, dataset_id: int):
    login(client, "gamma")
    payload = {
        "dataset_id": dataset_id,
        "chart_id": chart_id,
        "form_data": form_data,
    }
    resp = client.post("api/v1/explore/form_data", json=payload)
    assert resp.status_code == 404
예제 #10
0
def test_put_not_owner(client, chart_id: int, dataset_id: int):
    login(client, "gamma")
    payload = {
        "dataset_id": dataset_id,
        "chart_id": chart_id,
        "form_data": "new form_data",
    }
    resp = client.put(f"api/v1/explore/form_data/{key}", json=payload)
    assert resp.status_code == 404
예제 #11
0
def test_post_bad_request(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
예제 #12
0
def test_put_not_owner(client, chart_id: int, datasource: SqlaTable):
    login(client, "gamma")
    payload = {
        "datasource_id": datasource.id,
        "datasource_type": datasource.type,
        "chart_id": chart_id,
        "form_data": UPDATED_FORM_DATA,
    }
    resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
    assert resp.status_code == 404
예제 #13
0
def test_put_bad_request(client, chart_id: int, datasource: SqlaTable):
    login(client, "admin")
    payload = {
        "datasource_id": datasource.id,
        "datasource_type": datasource.type,
        "chart_id": chart_id,
        "form_data": 1234,
    }
    resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
    assert resp.status_code == 400
예제 #14
0
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
예제 #15
0
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()
예제 #16
0
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()
예제 #17
0
def test_put_bad_request_non_json_string(client, chart_id: int,
                                         dataset_id: int):
    login(client, "admin")
    payload = {
        "dataset_id": dataset_id,
        "chart_id": chart_id,
        "form_data": "foo",
    }
    resp = client.put(f"api/v1/explore/form_data/{KEY}", json=payload)
    assert resp.status_code == 400
예제 #18
0
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
예제 #19
0
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()
예제 #20
0
    def test_dashboards_without_filtersets__200(self, dashboard_id: int,
                                                client: FlaskClient[Any]):
        # arrange
        login(client, "admin")

        # act
        response = call_get_filter_sets(client, dashboard_id)

        # assert
        assert response.status_code == 200
        assert response.is_json and response.json["count"] == 0
예제 #21
0
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()
예제 #22
0
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()
예제 #23
0
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
예제 #24
0
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()
예제 #25
0
    def test_with_dashboard_not_exists__404(
        self,
        not_exists_dashboard: int,
        client: FlaskClient[Any],
    ):
        # arrange
        login(client, "admin")

        # act
        response = call_get_filter_sets(client, not_exists_dashboard)

        # assert
        assert response.status_code == 404
    def test_with_dashboard_exists_filterset_not_exists__200(
        self,
        dashboard_id: int,
        filtersets: Dict[str, List[FilterSet]],
        client: FlaskClient[Any],
    ):
        # arrange
        login(client, "admin")
        filter_set_id = max(collect_all_ids(filtersets)) + 1

        response = call_delete_filter_set(client, {"id": filter_set_id}, dashboard_id)
        # assert
        assert response.status_code == 200
예제 #27
0
def test_delete_not_owner(client, chart_id: int, dataset_id: int,
                          admin_id: int):
    another_key = "another_key"
    another_owner = admin_id + 1
    entry: TemporaryExploreState = {
        "owner": another_owner,
        "dataset_id": dataset_id,
        "chart_id": chart_id,
        "form_data": form_data,
    }
    cache_manager.explore_form_data_cache.set(another_key, entry)
    login(client, "admin")
    resp = client.delete(f"api/v1/explore/form_data/{another_key}")
    assert resp.status_code == 403
예제 #28
0
def test_put_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": "new form_data",
    }
    resp = client.put(f"api/v1/explore/form_data/{key}?tab_id=1", json=payload)
    data = json.loads(resp.data.decode("utf-8"))
    first_key = data.get("key")
    resp = client.put(f"api/v1/explore/form_data/{key}?tab_id=1", json=payload)
    data = json.loads(resp.data.decode("utf-8"))
    second_key = data.get("key")
    assert first_key == second_key
예제 #29
0
def test_post_same_key_for_same_tab_id(client, dashboard_id: int):
    login(client, "admin")
    payload = {
        "value": value,
    }
    resp = client.post(
        f"api/v1/dashboard/{dashboard_id}/filter_state?tab_id=1", 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?tab_id=1", json=payload)
    data = json.loads(resp.data.decode("utf-8"))
    second_key = data.get("key")
    assert first_key == second_key
예제 #30
0
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