Skip to content

Commit bb1e709

Browse files
committed
Make the updating keywords in the editing experiment accept insensible searching and add some controlled keywords tests.
1 parent 326ddb0 commit bb1e709

File tree

3 files changed

+351
-11
lines changed

3 files changed

+351
-11
lines changed

src/mavedb/routers/experiments.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ async def update_experiment(
459459
item.raw_read_identifiers = raw_read_identifiers
460460

461461
if item_update.keywords:
462+
keywords: list[ExperimentControlledKeywordAssociation] = []
462463
all_labels_none = all(k.keyword.label is None for k in item_update.keywords)
463464
if all_labels_none is False:
464465
# Users may choose part of keywords from dropdown menu. Remove not chosen keywords from the list.
@@ -467,10 +468,18 @@ async def update_experiment(
467468
validate_keyword_list(filtered_keywords)
468469
except ValidationError as e:
469470
raise HTTPException(status_code=422, detail=str(e))
470-
try:
471-
await item.set_keywords(db, filtered_keywords)
472-
except Exception as e:
473-
raise HTTPException(status_code=500, detail=f"Invalid keywords: {str(e)}")
471+
for upload_keyword in filtered_keywords:
472+
try:
473+
description = upload_keyword.description
474+
controlled_keyword = search_keyword(db, upload_keyword.keyword.key, upload_keyword.keyword.label)
475+
experiment_controlled_keyword = ExperimentControlledKeywordAssociation(
476+
controlled_keyword=controlled_keyword,
477+
description=description,
478+
)
479+
keywords.append(experiment_controlled_keyword)
480+
except ValueError as e:
481+
raise HTTPException(status_code=422, detail=str(e))
482+
item.keyword_objs = keywords
474483

475484
item.modified_by = user_data.user
476485

tests/helpers/constants.py

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@
427427
"special": False,
428428
"description": "Description",
429429
},
430-
{"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
430+
{"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
431431
{
432432
"key": "Phenotypic Assay Mechanism",
433433
"label": "Other",
@@ -442,6 +442,13 @@
442442
"special": False,
443443
"description": "Description",
444444
},
445+
{
446+
"key": "Phenotypic Assay Profiling Strategy",
447+
"label": "Shotgun sequencing",
448+
"code": None,
449+
"special": False,
450+
"description": "Description",
451+
},
445452
]
446453

447454
TEST_KEYWORDS = [
@@ -470,7 +477,7 @@
470477
},
471478
},
472479
{
473-
"keyword": {"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
480+
"keyword": {"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
474481
"description": "Details of delivery method",
475482
},
476483
]
@@ -492,7 +499,7 @@
492499
"methodText": "Methods",
493500
"keywords": [
494501
{
495-
"keyword": {"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
502+
"keyword": {"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
496503
"description": "Details of delivery method",
497504
},
498505
],
@@ -572,7 +579,7 @@
572579
"keywords": [
573580
{
574581
"recordType": "ExperimentControlledKeyword",
575-
"keyword": {"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
582+
"keyword": {"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
576583
"description": "Details of delivery method",
577584
},
578585
],
@@ -587,6 +594,51 @@
587594
"numScoreSets": 0, # NOTE: This is context-dependent and may need overriding per test
588595
}
589596

597+
TEST_EXPERIMENT_WITH_UPDATE_KEYWORD_RESPONSE = {
598+
"recordType": "Experiment",
599+
"title": "Test Experiment Title",
600+
"shortDescription": "Test experiment",
601+
"abstractText": "Abstract",
602+
"methodText": "Methods",
603+
"createdBy": {
604+
"recordType": "User",
605+
"firstName": TEST_USER["first_name"],
606+
"lastName": TEST_USER["last_name"],
607+
"orcidId": TEST_USER["username"],
608+
},
609+
"modifiedBy": {
610+
"recordType": "User",
611+
"firstName": TEST_USER["first_name"],
612+
"lastName": TEST_USER["last_name"],
613+
"orcidId": TEST_USER["username"],
614+
},
615+
"creationDate": date.today().isoformat(),
616+
"modificationDate": date.today().isoformat(),
617+
"scoreSetUrns": [],
618+
"contributors": [],
619+
"keywords": [
620+
{
621+
"recordType": "ExperimentControlledKeyword",
622+
"keyword": {
623+
"key": "Phenotypic Assay Profiling Strategy",
624+
"label": "Shotgun sequencing",
625+
"special": False,
626+
"description": "Description"
627+
},
628+
"description": "Details of phenotypic assay profiling strategy",
629+
},
630+
],
631+
"doiIdentifiers": [],
632+
"primaryPublicationIdentifiers": [],
633+
"secondaryPublicationIdentifiers": [],
634+
"rawReadIdentifiers": [],
635+
# keys to be set after receiving response
636+
"urn": None,
637+
"experimentSetUrn": None,
638+
"officialCollections": [],
639+
"numScoreSets": 0, # NOTE: This is context-dependent and may need overriding per test
640+
}
641+
590642
TEST_EXPERIMENT_WITH_KEYWORD_HAS_DUPLICATE_OTHERS_RESPONSE = {
591643
"recordType": "Experiment",
592644
"title": "Test Experiment Title",
@@ -622,7 +674,7 @@
622674
},
623675
{
624676
"recordType": "ExperimentControlledKeyword",
625-
"keyword": {"key": "Delivery method", "label": "Other", "special": False, "description": "Description"},
677+
"keyword": {"key": "Delivery Method", "label": "Other", "special": False, "description": "Description"},
626678
"description": "Description",
627679
},
628680
],

0 commit comments

Comments
 (0)