Skip to content

Commit

Permalink
Refs #1. Completed tests for GET Dashboards API.
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Mar 1, 2024
1 parent 48e6ad1 commit fd7bf40
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion API/user/QueryDashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get(self):
else:
return gettext('Must specify at least one id parameter or "globals"'), 400

# # Convert to json and return
# Convert to json and return
dashboards_json = [dash.to_json(minimal=request_args['list'], latest=not request_args['all_versions'])
for dash in dashboards]
return dashboards_json
Expand Down
26 changes: 26 additions & 0 deletions tests/api/user/test_QueryDashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ def test_get_site_dashboard_by_uuid(self):
self._check_json(response.json[0])
self.assertEqual(self._dashboards["site"]["id"], response.json[0]['id_dashboard'])

# Test to get all versions
response = self._get_with_user_token_auth(self.test_client, token=self._users[user],
params={'uuid': self._dashboards["site"]["uuid"],
'all_versions': True})
if user == "noaccess":
self.assertEqual(403, response.status_code)
else:
self.assertEqual(200, response.status_code)
self.assertEqual(1, len(response.json))
self._check_json(response.json[0])
self.assertEqual(2, len(response.json[0]['versions']))
self.assertEqual(self._dashboards["site"]["id"], response.json[0]['id_dashboard'])

def test_get_project_dashboard_by_id(self):
with self.app_context():
for user in self._users:
Expand Down Expand Up @@ -100,6 +113,19 @@ def test_get_project_dashboard_by_id(self):
self._check_json(response.json[0])
self.assertEqual(self._dashboards["project_global"]["id"], response.json[0]['id_dashboard'])

# Check with list = true
response = self._get_with_user_token_auth(self.test_client, token=self._users[user],
params={'id_dashboard':
self._dashboards["project_global"]["id"],
'list': True})
if user == "noaccess" or user == "projectadmin": # Project admin has access to projet 1, but not 2.
self.assertEqual(403, response.status_code)
else:
self.assertEqual(200, response.status_code)
self.assertEqual(1, len(response.json))
self._check_json(response.json[0], minimal=True)
self.assertEqual(self._dashboards["project_global"]["id"], response.json[0]['id_dashboard'])

def test_get_project_dashboard_by_uuid(self):
with self.app_context():
for user in self._users:
Expand Down

0 comments on commit fd7bf40

Please sign in to comment.