diff --git a/swh/deposit/api/deposit_status.py b/swh/deposit/api/deposit_status.py --- a/swh/deposit/api/deposit_status.py +++ b/swh/deposit/api/deposit_status.py @@ -26,10 +26,10 @@ 'summary': , 'fields': , }], - 'archive': { + 'archive': [{ 'summary': , - 'fields': [], - } + 'fields': , + }] } @@ -45,19 +45,24 @@ return None msg = [] - if 'metadata' in status_detail: - for data in status_detail['metadata']: - fields = ', '.join(data['fields']) - msg.append('- %s (%s)\n' % (data['summary'], fields)) - - for key in ['url', 'archive']: - if key in status_detail: - _detail = status_detail[key] - fields = _detail.get('fields') - suffix_msg = '' - if fields: - suffix_msg = ' (%s)' % ', '.join(fields) - msg.append('- %s%s\n' % (_detail['summary'], suffix_msg)) + for key in ['metadata', 'archive']: + _detail = status_detail.get(key) + print('key', key, 'detail', _detail) + if _detail: + for data in _detail: + suffix_msg = '' + fields = data.get('fields') + if fields: + suffix_msg = ' (%s)' % ', '.join(fields) + msg.append('- %s%s\n' % (data['summary'], suffix_msg)) + + _detail = status_detail.get('url') + if _detail: + fields = _detail.get('fields') + suffix_msg = '' + if fields: + suffix_msg = ' (%s)' % ', '.join(fields) + msg.append('- %s%s\n' % (_detail['summary'], suffix_msg)) if not msg: return None diff --git a/swh/deposit/api/private/deposit_check.py b/swh/deposit/api/private/deposit_check.py --- a/swh/deposit/api/private/deposit_check.py +++ b/swh/deposit/api/private/deposit_check.py @@ -59,7 +59,7 @@ if not check: errors.append({ 'summary': error_message, - 'fields': archive_request.id + 'fields': [archive_request.id] }) if not errors: diff --git a/swh/deposit/tests/api/test_deposit_status.py b/swh/deposit/tests/api/test_deposit_status.py --- a/swh/deposit/tests/api/test_deposit_status.py +++ b/swh/deposit/tests/api/test_deposit_status.py @@ -143,16 +143,16 @@ 'fields': ['name or title', 'url or badurl'] } ], - 'archive': { + 'archive': [{ 'summary': 'Unreadable archive', - 'fields': ['1', '2'], - }, + 'fields': ['1'], + }], } expected_status_detail = '''- Mandatory fields missing (url, title) - Alternate fields missing (name or title, url or badurl) +- Unreadable archive (1) - At least one url field must be compatible with the client's domain name. The following url fields failed the check (blahurl, testurl) -- Unreadable archive (1, 2) ''' # noqa actual_status_detail = convert_status_detail(status_detail) @@ -172,9 +172,21 @@ 'fields': ['name'], }, ], + 'archive': [ + { + 'summary': 'Invalid archive', + 'fields': ['2'], + }, + { + 'summary': 'Unsupported archive', + 'fields': ['1'], + } + ], } expected_status_detail = '''- Mandatory fields missing (name) +- Invalid archive (2) +- Unsupported archive (1) - At least one compatible url field. Failed (testurl) '''