Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions python/tests/test_workspace_suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ def test_existing_cell_addition_has_zero_cell_delta_and_explicit_apply(self):
self.assertEqual(response.status_code, 200, response.get_json())
self.assertEqual(response.get_json()['protocol']['counts']['epochs'], 3)
self.assertEqual(self.suggestions()['suggestions'][0]['status'], 'applied')
approved = self.suggestions()['approved_history']
self.assertEqual(len(approved), 1)
self.assertEqual(approved[0]['candidate_revision_uuid'], suggestion['candidate_revision_uuid'])
# A newer proposal must not erase the previous approval from the log.
row = copy.deepcopy(self.case.suggestion_rows.rows[0])
row['suggestion_uuid'] = str(uuid.uuid4())
row['summary']['candidate_revision_uuid'] = str(uuid.uuid4())
row['summary']['created_at'] = '2099-01-01T00:00:00+00:00'
self.case.suggestion_rows.insert1(row)
after = self.suggestions()
self.assertNotEqual(after['suggestions'][0]['candidate_revision_uuid'], suggestion['candidate_revision_uuid'])
self.assertEqual(after['approved_history'][0]['candidate_revision_uuid'], suggestion['candidate_revision_uuid'])


def test_candidate_failure_does_not_relabel_committed_import_as_failed(self):
with patch.object(self.case.service, 'explore_preview', side_effect=ValueError('Unsupported new metadata')):
Expand Down
18 changes: 17 additions & 1 deletion python/workspace_suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ def list(self):
else:
status = 'pending'
item['status'] = status
return {'suggestions': list(latest.values()),
approvals = {}
for event in (self.history.Event & {'project_uuid': self.project_uuid, 'action': 'protocol_dataset_bound'}).to_dicts():
payload = event.get('payload') or {}
if payload.get('reason') == 'pre_import_baseline_freeze':
continue
key = (payload.get('protocol_uuid'), payload.get('revision_uuid'))
approvals[key] = event.get('occurred_at')
approved_history = []
seen = set()
for row in rows:
item = copy.deepcopy(row['summary'])
key = (item['protocol_uuid'], item['candidate_revision_uuid'])
if key in approvals and key not in seen:
item.update(status='applied', approved_at=str(approvals[key]))
approved_history.append(item)
seen.add(key)
return {'approved_history': approved_history, 'suggestions': list(latest.values()),
'counts': {status: sum(item['status'] == status for item in latest.values())
for status in ('pending', 'applied', 'superseded', 'stale')}}
Loading
Loading