Commit a2cef69a authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Clean API user metadata.

parent df4515a1
Pipeline #118132 passed with stages
in 34 minutes and 58 seconds
......@@ -92,7 +92,7 @@ from .ems import EMSMetadata
from .qcms import QCMSMetadata
from .datamodel import (
Dataset, User, Author, EditableUserMetadata, UserProvidableMetadata, OasisMetadata,
MongoMetadata, EntryMetadata, EntryArchive)
MongoMetadata, EntryMetadata, EntryArchive, user_reference, author_reference)
from .optimade import OptimadeEntry, Species
from .metainfo import m_env
......@@ -43,6 +43,11 @@ _entry_metadata_defaults = {
if quantity.default not in [None, [], False, 0]
_all_author_quantities = [
for quantity in datamodel.EntryMetadata.m_def.all_quantities.values()
if quantity.type in [datamodel.user_reference, datamodel.author_reference]]
def _es_to_entry_dict(hit, required: MetadataRequired) -> Dict[str, Any]:
......@@ -61,6 +66,16 @@ def _es_to_entry_dict(hit, required: MetadataRequired) -> Dict[str, Any]:
entry_dict[key] = value
for author_quantity in _all_author_quantities:
authors = entry_dict.get(author_quantity)
if authors is None:
if isinstance(authors, dict):
authors = [authors]
for author in authors:
if 'email' in author:
return entry_dict
......@@ -227,6 +227,9 @@ def assert_entry_metadata(response_json):
if 'required' not in response_json:
assert 'license' in entry
if 'uploader' in entry:
assert 'email' not in entry['uploader']
def assert_entries_metadata_response(response, status_code=None):
response_json = assert_entries_raw_metadata_response(response, status_code=status_code)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment