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
17 changes: 13 additions & 4 deletions src/mavedb/routers/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ async def update_experiment(
item.raw_read_identifiers = raw_read_identifiers

if item_update.keywords:
keywords: list[ExperimentControlledKeywordAssociation] = []
all_labels_none = all(k.keyword.label is None for k in item_update.keywords)
if all_labels_none is False:
# Users may choose part of keywords from dropdown menu. Remove not chosen keywords from the list.
Expand All @@ -467,10 +468,18 @@ async def update_experiment(
validate_keyword_list(filtered_keywords)
except ValidationError as e:
raise HTTPException(status_code=422, detail=str(e))
try:
await item.set_keywords(db, filtered_keywords)
except Exception as e:
raise HTTPException(status_code=500, detail=f"Invalid keywords: {str(e)}")
for upload_keyword in filtered_keywords:
try:
description = upload_keyword.description
controlled_keyword = search_keyword(db, upload_keyword.keyword.key, upload_keyword.keyword.label)
experiment_controlled_keyword = ExperimentControlledKeywordAssociation(
controlled_keyword=controlled_keyword,
description=description,
)
keywords.append(experiment_controlled_keyword)
except ValueError as e:
raise HTTPException(status_code=422, detail=str(e))
item.keyword_objs = keywords

item.modified_by = user_data.user

Expand Down
62 changes: 57 additions & 5 deletions tests/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@
"special": False,
"description": "Description",
},
{"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
{"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
{
"key": "Phenotypic Assay Mechanism",
"label": "Other",
Expand All @@ -442,6 +442,13 @@
"special": False,
"description": "Description",
},
{
"key": "Phenotypic Assay Profiling Strategy",
"label": "Shotgun sequencing",
"code": None,
"special": False,
"description": "Description",
},
]

TEST_KEYWORDS = [
Expand Down Expand Up @@ -470,7 +477,7 @@
},
},
{
"keyword": {"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
"keyword": {"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
"description": "Details of delivery method",
},
]
Expand All @@ -492,7 +499,7 @@
"methodText": "Methods",
"keywords": [
{
"keyword": {"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
"keyword": {"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
"description": "Details of delivery method",
},
],
Expand Down Expand Up @@ -572,7 +579,7 @@
"keywords": [
{
"recordType": "ExperimentControlledKeyword",
"keyword": {"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
"keyword": {"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
"description": "Details of delivery method",
},
],
Expand All @@ -587,6 +594,51 @@
"numScoreSets": 0, # NOTE: This is context-dependent and may need overriding per test
}

TEST_EXPERIMENT_WITH_UPDATE_KEYWORD_RESPONSE = {
"recordType": "Experiment",
"title": "Test Experiment Title",
"shortDescription": "Test experiment",
"abstractText": "Abstract",
"methodText": "Methods",
"createdBy": {
"recordType": "User",
"firstName": TEST_USER["first_name"],
"lastName": TEST_USER["last_name"],
"orcidId": TEST_USER["username"],
},
"modifiedBy": {
"recordType": "User",
"firstName": TEST_USER["first_name"],
"lastName": TEST_USER["last_name"],
"orcidId": TEST_USER["username"],
},
"creationDate": date.today().isoformat(),
"modificationDate": date.today().isoformat(),
"scoreSetUrns": [],
"contributors": [],
"keywords": [
{
"recordType": "ExperimentControlledKeyword",
"keyword": {
"key": "Phenotypic Assay Profiling Strategy",
"label": "Shotgun sequencing",
"special": False,
"description": "Description"
},
"description": "Details of phenotypic assay profiling strategy",
},
],
"doiIdentifiers": [],
"primaryPublicationIdentifiers": [],
"secondaryPublicationIdentifiers": [],
"rawReadIdentifiers": [],
# keys to be set after receiving response
"urn": None,
"experimentSetUrn": None,
"officialCollections": [],
"numScoreSets": 0, # NOTE: This is context-dependent and may need overriding per test
}

TEST_EXPERIMENT_WITH_KEYWORD_HAS_DUPLICATE_OTHERS_RESPONSE = {
"recordType": "Experiment",
"title": "Test Experiment Title",
Expand Down Expand Up @@ -622,7 +674,7 @@
},
{
"recordType": "ExperimentControlledKeyword",
"keyword": {"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
"keyword": {"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
"description": "Description",
},
],
Expand Down
Loading