Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_filter_related_owners(self):
"""
Dashboard API: Test dashboard get filter related owners
"""
self.login(username="admin")
argument = {"filter": "a"}
uri = "api/v1/dashboard/related/owners?{}={}".format(
"q", prison.dumps(argument)
)
rv = self.client.get(uri)
self.assertEqual(rv.status_code, 200)
response = json.loads(rv.data.decode("utf-8"))
expected_response = {
"count": 2,
"result": [
{"text": "admin user", "value": 1},
{"text": "alpha user", "value": 5},
],
}
self.assertEqual(response, expected_response)
def test_api_database(self):
self.login("admin")
self.create_fake_db()
arguments = {
"keys": [],
"filters": [{"col": "expose_in_sqllab", "opr": "eq", "value": True}],
"order_column": "database_name",
"order_direction": "asc",
"page": 0,
"page_size": -1,
}
url = "api/v1/database/?{}={}".format("q", prison.dumps(arguments))
self.assertEqual(
{"examples", "fake_db_100"},
{r.get("database_name") for r in self.get_json_resp(url)["result"]},
)
self.delete_fake_db()
"databaseasync/api/read?_flt_0_expose_in_sqllab=1&"
"_oc_DatabaseAsync=database_name&_od_DatabaseAsync=asc"
)
self.login(username="gamma")
databases_json = self.client.get(OLD_FLASK_GET_SQL_DBS_REQUEST).json
self.assertEquals(databases_json["count"], 1)
arguments = {
"keys": ["none"],
"filters": [{"col": "expose_in_sqllab", "opr": "eq", "value": True}],
"order_columns": "database_name",
"order_direction": "asc",
"page": 0,
"page_size": -1,
}
NEW_FLASK_GET_SQL_DBS_REQUEST = f"/api/v1/database/?q={prison.dumps(arguments)}"
self.login(username="gamma")
databases_json = self.client.get(NEW_FLASK_GET_SQL_DBS_REQUEST).json
self.assertEquals(databases_json["count"], 1)
self.logout()
def kibana7_disover_global_state(from_time, to_time):
return prison.dumps( {
'filters': [],
'refreshInterval': {
'pause': True,
'value': 0
},
'time': {
'from': from_time,
'to': to_time
}
def kibana6_disover_global_state(from_time, to_time):
return prison.dumps( {
'refreshInterval': {
'pause': True,
'value': 0
},
'time': {
'from': from_time,
'mode': 'absolute',
'to': to_time
}
'type': 'phrase'
},
'type': 'phrase',
'value': str(query_value)
},
'query': {
'match': {
query_key: {
'query': query_value,
'type': 'phrase'
}
}
}
} )
return prison.dumps( {
'columns': columns,
'filters': app_filters,
'index': index,
'interval': 'auto'
} )
def wraps(self, *args, **kwargs):
value = request.args.get(API_URI_RIS_KEY, None)
kwargs["rison"] = dict()
if value:
try:
kwargs["rison"] = prison.loads(value)
except prison.decoder.ParserException:
if current_app.config.get("FAB_API_ALLOW_JSON_QS", True):
# Rison failed try json encoded content
try:
kwargs["rison"] = json.loads(
urllib.parse.parse_qs(f"{API_URI_RIS_KEY}={value}").get(
API_URI_RIS_KEY
)[0]
)
except Exception:
return self.response_400(
message="Not a valid rison/json argument"
)
else:
return self.response_400(message="Not a valid rison argument")
if schema:
def wraps(self, *args, **kwargs):
value = request.args.get(API_URI_RIS_KEY, None)
kwargs["rison"] = dict()
if value:
try:
kwargs["rison"] = prison.loads(value)
except prison.decoder.ParserException:
if current_app.config.get("FAB_API_ALLOW_JSON_QS", True):
# Rison failed try json encoded content
try:
kwargs["rison"] = json.loads(
urllib.parse.parse_qs(f"{API_URI_RIS_KEY}={value}").get(
API_URI_RIS_KEY
)[0]
)
except Exception:
return self.response_400(
message="Not a valid rison/json argument"
)
else:
return self.response_400(message="Not a valid rison argument")
if schema:
try: