Skip to content
Snippets Groups Projects
Verified Commit 3fa3ea91 authored by Martin Weise's avatar Martin Weise
Browse files
parent 419e6c9e
No related branches found
No related tags found
2 merge requests!395Library,!394Grafana
......@@ -236,7 +236,8 @@ def update_dashboard(uid: str):
logging.debug(f'endpoint update dashboard, uid={uid}')
try:
database: Database = Database.model_validate(request.json)
except ValidationError:
except ValidationError as e:
logging.error(f'Model malformed: {e}')
return Response(ApiError(status='BAD_REQUEST', message='Invalid database format',
code='error.database.malformed').model_dump_json(), 400, headers)
try:
......
......@@ -121,3 +121,99 @@ class JwtTest(unittest.TestCase):
'database_name': 'some_database',
'owner_username': 'foobar'}))
self.assertEqual(201, response.status_code)
def test_create_dashboard_exists_fails(self):
with app.test_client() as test_client:
headers = {'Authorization': f'Bearer {self.token(["system"])}',
'Content-Type': 'application/json'}
json_payload = dict({'is_public': True,
'is_schema_public': True,
'database_name': 'some_database',
'owner_username': 'foobar'})
# mock
test_client.post('/api/dashboard', headers=headers, json=json_payload)
# test
response = test_client.post('/api/dashboard', headers=headers, json=json_payload)
self.assertEqual(409, response.status_code)
def test_update_dashboard_no_auth_fails(self):
with app.test_client() as test_client:
headers = {'Authorization': f'Bearer {self.token(["system"])}',
'Content-Type': 'application/json'}
json_payload = dict({'is_public': True,
'is_schema_public': True,
'database_name': 'some_database',
'owner_username': 'foobar'})
# mock
response = test_client.post('/api/dashboard', headers=headers, json=json_payload)
# test
response = test_client.put(f"/api/dashboard/{response.json['uid']}")
self.assertEqual(401, response.status_code)
def test_update_dashboard_no_body_fails(self):
with app.test_client() as test_client:
headers = {'Authorization': f'Bearer {self.token(["system"])}',
'Content-Type': 'application/json'}
json_payload = dict({'is_public': True,
'is_schema_public': True,
'database_name': 'some_database',
'owner_username': 'foobar'})
# mock
response = test_client.post('/api/dashboard', headers=headers, json=json_payload)
# test
response = test_client.put(f"/api/dashboard/{response.json['uid']}",
headers=headers)
self.assertEqual(400, response.status_code)
def test_update_dashboard_empty_body_fails(self):
with app.test_client() as test_client:
headers = {'Authorization': f'Bearer {self.token(["system"])}',
'Content-Type': 'application/json'}
json_payload = dict({'is_public': True,
'is_schema_public': True,
'database_name': 'some_database',
'owner_username': 'foobar'})
# mock
response = test_client.post('/api/dashboard', headers=headers, json=json_payload)
# test
response = test_client.put(f"/api/dashboard/{response.json['uid']}", headers=headers, json={})
self.assertEqual(400, response.status_code)
def test_update_dashboard_malformed_body_fails(self):
with app.test_client() as test_client:
headers = {'Authorization': f'Bearer {self.token(["system"])}',
'Content-Type': 'application/json'}
json_payload = dict({'is_public': True,
'is_schema_public': True,
'database_name': 'some_database',
'owner_username': 'foobar'})
# mock
response = test_client.post('/api/dashboard', headers=headers, json=json_payload)
# test
response = test_client.put(f"/api/dashboard/{response.json['uid']}", headers=headers,
json=dict({'is_public': True}))
self.assertEqual(400, response.status_code)
def test_update_dashboard_succeeds(self):
with app.test_client() as test_client:
headers = {'Authorization': f'Bearer {self.token(["system"])}',
'Content-Type': 'application/json'}
json_payload = dict({'is_public': True,
'is_schema_public': True,
'database_name': 'some_database',
'owner_username': 'foobar'})
# mock
response = test_client.post('/api/dashboard', headers=headers, json=json_payload)
req.dashboard_uid = response.json['uid']
# test
response = test_client.put(f"/api/dashboard/{response.json['uid']}", headers=headers,
json=req.model_dump())
self.assertEqual(202, response.status_code)
def test_update_dashboard_not_found_fails(self):
with app.test_client() as test_client:
headers = {'Authorization': f'Bearer {self.token(["system"])}',
'Content-Type': 'application/json'}
# test
response = test_client.put(f"/api/dashboard/idonotexist", headers=headers, json=req.model_dump())
self.assertEqual(404, response.status_code)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment