Skip to content

Commit 455c808

Browse files
committed
usage report updated for anlaysis containers
1 parent 124ea0c commit 455c808

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

api/handlers/reporthandler.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -880,10 +880,9 @@ def _build_project_report(self, base_query):
880880
acquisition_ids = [a['_id'] for a in acquisitions]
881881

882882
# For the project and each session and acquisition, create a list of analysis ids
883-
analysis_ids = [an['_id'] for an in p.get('analyses', [])]
884-
analysis_ids.extend([an['_id'] for an in s.get('analyses', []) for s in sessions])
885-
analysis_ids.extend([an['_id'] for an in a.get('analyses', []) for a in acquisitions])
886-
883+
ids = session_ids + acquisition_ids + [p['_id']]
884+
analysis_ids = [an['_id'] for an in config.db.analyses.find({'parent.id': {'$in': ids}})]
885+
887886
report_obj['session_count'] = len(session_ids)
888887

889888
# for each type of container below it will have a slightly modified match query

test/integration_tests/python/test_reports.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,17 @@ def test_usage_report(data_builder, file_form, as_user, as_admin):
284284
assert usage[0]['session_count'] == 1
285285
assert usage[0]['file_mbs'] > 0
286286
assert usage[0]['gear_execution_count'] == 1
287+
288+
# Test if empty project breaks Usage report
289+
group = data_builder.create_group()
290+
r = as_admin.post('/projects', params={'inherit': 'false'}, json={'label': 'project2', 'group': group})
291+
assert r.ok
292+
project = r.json()['_id']
293+
294+
# get project-aggregated usage report
295+
r = as_admin.get('/report/usage', params={'type': 'project'})
296+
assert r.ok
297+
298+
# delete project
299+
r= as_admin.delete('/projects/' + project)
300+
assert r.ok

0 commit comments

Comments
 (0)