Skip to content

Commit 9b82a28

Browse files
authored
Merge pull request #330 from EBI-G2P/update_draft_check_v14
Validate curation draft before update
2 parents 23f15f0 + 5055642 commit 9b82a28

File tree

3 files changed

+100
-11
lines changed

3 files changed

+100
-11
lines changed

gene2phenotype_project/gene2phenotype_app/serializers/curation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,16 @@ class CurationDataSerializer(serializers.ModelSerializer):
4545

4646
def validate_to_save(self, data):
4747
"""
48-
Validate the input data for curation.
48+
Validate the input data to add or save a curation draft.
4949
50-
Validation extension step:
51-
This step is called in AddCurationData of the views.py
52-
The steps of the validation for the save is
53-
- Locus is the minimum requirement needed to save a draft
54-
- Draft does not already exist as a draft
55-
- User has permissions to curate on the selected panel
50+
Validation steps:
51+
- Locus is the minimum requirement needed to save a draft
52+
- Draft does not already exist as a draft
53+
- User has permissions to curate on the selected panels
5654
5755
Args:
58-
data: The data to be validated.
56+
data: The data to be validated. Input format:
57+
{'json_data': {...}, 'status': 'manual'} OR {'json_data': {...}}
5958
6059
Returns:
6160
The validated data.
@@ -290,6 +289,7 @@ def compare_curation_data(self, input_json_data, user_obj):
290289
# remove session_name field from input json and compare input json with existing curation json
291290
input_json_data["json_data"].pop("session_name", None)
292291
data_json.pop("session_name", None)
292+
293293
result = DeepDiff(input_json_data["json_data"], data_json)
294294

295295
if not result:

gene2phenotype_project/gene2phenotype_app/tests/curation/test_update_curation.py

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def setUp(self):
2424
self.url_update_curation = reverse(
2525
"update_curation", kwargs={"stable_id": "G2P00004"}
2626
)
27-
27+
self.url_update_curation_2 = reverse(
28+
"update_curation", kwargs={"stable_id": "G2P00010"}
29+
)
2830
self.url_update_invalid_curation = reverse(
2931
"update_curation", kwargs={"stable_id": "G2P00123"}
3032
)
@@ -327,7 +329,6 @@ def test_update_curation_empty_locus(self):
327329
"""
328330
self.login_user()
329331

330-
# Define the complex data structure
331332
curation_to_update = {
332333
"json_data": {
333334
"allelic_requirement": "",
@@ -358,7 +359,45 @@ def test_update_curation_empty_locus(self):
358359
self.assertEqual(response.status_code, 400)
359360

360361
response_data = response.json()
361-
self.assertEqual(response_data["error"],"Invalid gene ''")
362+
self.assertEqual(response_data["error"], "To save a draft, the minimum requirement is a locus entry. Please save this draft with locus information")
363+
364+
def test_update_curation_invalid_locus(self):
365+
"""
366+
Test call to update curation endpoint with invalid locus field
367+
"""
368+
self.login_user()
369+
370+
curation_to_update = {
371+
"json_data": {
372+
"allelic_requirement": "",
373+
"confidence": "",
374+
"cross_cutting_modifier": [],
375+
"disease": {"cross_references": [], "disease_name": ""},
376+
"locus": "BAAT-21",
377+
"mechanism_evidence": [],
378+
"mechanism_synopsis": [],
379+
"molecular_mechanism": {"name": "", "support": ""},
380+
"panels": [],
381+
"phenotypes": [],
382+
"private_comment": "",
383+
"public_comment": "",
384+
"publications": [],
385+
"session_name": "test session",
386+
"variant_consequences": [],
387+
"variant_descriptions": [],
388+
"variant_types": [],
389+
}
390+
}
391+
392+
response = self.client.put(
393+
self.url_update_curation,
394+
curation_to_update,
395+
content_type="application/json",
396+
)
397+
self.assertEqual(response.status_code, 400)
398+
399+
response_data = response.json()
400+
self.assertEqual(response_data["error"], "Invalid gene 'BAAT-21'")
362401

363402
def test_update_invalid_curation(self):
364403
"""
@@ -396,3 +435,49 @@ def test_update_invalid_curation(self):
396435
content_type="application/json",
397436
)
398437
self.assertEqual(response.status_code, 404)
438+
439+
def test_update_curation_duplicate(self):
440+
"""
441+
Test to update curation that would create a duplicate entry
442+
G2P ID G2P00010 has session name 'test session SRY', this test
443+
tries to update the json content to be the same as session 'test session' (G2P00004)
444+
"""
445+
self.login_user()
446+
447+
curation_to_update = {
448+
"json_data": {
449+
"allelic_requirement": "",
450+
"confidence": "",
451+
"cross_cutting_modifier": [],
452+
"disease": {
453+
"cross_references": [],
454+
"disease_name": ""
455+
},
456+
"locus": "CEP290",
457+
"mechanism_evidence": [],
458+
"mechanism_synopsis": [],
459+
"molecular_mechanism": {
460+
"name": "",
461+
"support": ""
462+
},
463+
"panels": [],
464+
"phenotypes": [],
465+
"private_comment": "",
466+
"public_comment": "",
467+
"publications": [],
468+
"session_name": "test session SRY",
469+
"variant_consequences": [],
470+
"variant_descriptions": [],
471+
"variant_types": []
472+
}
473+
}
474+
475+
response = self.client.put(
476+
self.url_update_curation_2,
477+
curation_to_update,
478+
content_type="application/json",
479+
)
480+
self.assertEqual(response.status_code, 400)
481+
482+
response_data = response.json()
483+
self.assertEqual(response_data["error"], "Data already under curation. Please check session 'test session'")

gene2phenotype_project/gene2phenotype_app/views/curation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ def update(self, request, *args, **kwargs):
287287
status=status.HTTP_400_BAD_REQUEST,
288288
)
289289

290+
# Check if input data (json) is already present for this user
291+
# Do not use 'input_data' because it is a result of json.dumps()
292+
self.serializer_class(context={"user": user}).validate_to_save(request.data)
293+
290294
# Update data - it replaces the data
291295
serializer = CurationDataSerializer(
292296
curation_obj,

0 commit comments

Comments
 (0)