Skip to content

Commit cad5d65

Browse files
committed
Update tests
1 parent 6d8dba2 commit cad5d65

6 files changed

Lines changed: 93 additions & 9 deletions

File tree

gene2phenotype_project/gene2phenotype_app/tests/delete_data/test_delete_lgd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class LGDDeleteLGDEndpoint(TestCase):
4545
"gene2phenotype_app/fixtures/lgd_phenotype.json",
4646
"gene2phenotype_app/fixtures/lgd_phenotype_summary.json",
4747
"gene2phenotype_app/fixtures/lgd_variant_type.json",
48+
"gene2phenotype_app/fixtures/lgd_variant_type_publication.json",
4849
"gene2phenotype_app/fixtures/lgd_variant_type_comment.json",
4950
"gene2phenotype_app/fixtures/lgd_variant_type_description.json",
5051
"gene2phenotype_app/fixtures/lgd_variant_consequence.json",

gene2phenotype_project/gene2phenotype_app/tests/delete_data/test_delete_lgd_publication.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
LGDPhenotype,
99
LGDPhenotypeSummary,
1010
LGDVariantType,
11+
LGDVariantTypePublication,
1112
LGDVariantTypeComment,
1213
LGDVariantTypeDescription,
1314
LGDMolecularMechanismEvidence,
@@ -44,6 +45,7 @@ class LGDDeletePublication(TestCase):
4445
"gene2phenotype_app/fixtures/lgd_phenotype.json",
4546
"gene2phenotype_app/fixtures/lgd_phenotype_summary.json",
4647
"gene2phenotype_app/fixtures/lgd_variant_type.json",
48+
"gene2phenotype_app/fixtures/lgd_variant_type_publication.json",
4749
"gene2phenotype_app/fixtures/lgd_variant_type_comment.json",
4850
"gene2phenotype_app/fixtures/lgd_variant_type_description.json",
4951
"gene2phenotype_app/fixtures/lgd_variant_consequence.json",
@@ -232,12 +234,12 @@ def test_lgd_publication_delete(self):
232234
)
233235
self.assertEqual(len(lgd_phenotype_summary), 1)
234236

235-
lgd_variant_type = LGDVariantType.objects.filter(
236-
lgd__stable_id__stable_id="G2P00002",
237+
lgd_variant_type_publications = LGDVariantTypePublication.objects.filter(
238+
lgd_variant_type__lgd__stable_id__stable_id="G2P00002",
237239
publication__pmid=15214012,
238240
is_deleted=1,
239241
)
240-
self.assertEqual(len(lgd_variant_type), 3)
242+
self.assertEqual(len(lgd_variant_type_publications), 3)
241243

242244
lgd_variant_description = LGDVariantTypeDescription.objects.filter(
243245
lgd__stable_id__stable_id="G2P00002",

gene2phenotype_project/gene2phenotype_app/tests/delete_data/test_delete_lgd_variant_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class LGDEditVariantTypesEndpoint(TestCase):
2929
"gene2phenotype_app/fixtures/source.json",
3030
"gene2phenotype_app/fixtures/lgd_publication.json",
3131
"gene2phenotype_app/fixtures/lgd_variant_type.json",
32+
"gene2phenotype_app/fixtures/lgd_variant_type_publication.json",
3233
]
3334

3435
def setUp(self):

gene2phenotype_project/gene2phenotype_app/tests/delete_data/test_delete_lgd_variant_type_description.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class LGDEditVariantTypeDescriptionEndpoint(TestCase):
2929
"gene2phenotype_app/fixtures/source.json",
3030
"gene2phenotype_app/fixtures/lgd_publication.json",
3131
"gene2phenotype_app/fixtures/lgd_variant_type.json",
32+
"gene2phenotype_app/fixtures/lgd_variant_type_publication.json",
3233
"gene2phenotype_app/fixtures/lgd_variant_type_description.json",
3334
]
3435

gene2phenotype_project/gene2phenotype_app/tests/insert_data/test_add_variant_types.py

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from gene2phenotype_app.models import (
77
User,
88
LGDVariantType,
9+
LGDVariantTypePublication,
10+
LGDVariantTypeComment,
911
LocusGenotypeDisease,
1012
OntologyTerm,
1113
)
@@ -33,6 +35,7 @@ class LGDEditVariantTypesTests(TestCase):
3335
"gene2phenotype_app/fixtures/source.json",
3436
"gene2phenotype_app/fixtures/lgd_publication.json",
3537
"gene2phenotype_app/fixtures/lgd_variant_type.json",
38+
"gene2phenotype_app/fixtures/lgd_variant_type_publication.json",
3639
]
3740

3841
def setUp(self):
@@ -233,6 +236,10 @@ def test_readd_soft_deleted_variant_updates_inheritance_flags(self):
233236
inherited=True,
234237
de_novo=True,
235238
unknown_inheritance=True,
239+
is_deleted=1,
240+
)
241+
LGDVariantTypePublication.objects.create(
242+
lgd_variant_type=lgd_variant,
236243
publication_id=3,
237244
is_deleted=1,
238245
)
@@ -263,11 +270,16 @@ def test_readd_soft_deleted_variant_updates_inheritance_flags(self):
263270
self.assertFalse(lgd_variant.inherited)
264271
self.assertFalse(lgd_variant.de_novo)
265272
self.assertFalse(lgd_variant.unknown_inheritance)
273+
self.assertTrue(
274+
LGDVariantTypePublication.objects.filter(
275+
lgd_variant_type=lgd_variant, publication_id=3, is_deleted=0
276+
).exists()
277+
)
266278

267279
def test_reuse_existing_row_with_new_publication_updates_inheritance_flags(self):
268280
"""
269-
Test that converting an existing publication-less row into a
270-
publication-linked row replaces inheritance flags with the latest payload.
281+
Test that adding a publication link to an existing publication-less
282+
variant type replaces inheritance flags with the latest payload.
271283
"""
272284
user = User.objects.get(email="john@test.ac.uk")
273285
refresh = RefreshToken.for_user(user)
@@ -281,7 +293,6 @@ def test_reuse_existing_row_with_new_publication_updates_inheritance_flags(self)
281293
inherited=True,
282294
de_novo=True,
283295
unknown_inheritance=True,
284-
publication=None,
285296
is_deleted=0,
286297
)
287298

@@ -307,7 +318,69 @@ def test_reuse_existing_row_with_new_publication_updates_inheritance_flags(self)
307318
self.assertEqual(response.status_code, 201)
308319

309320
lgd_variant.refresh_from_db()
310-
self.assertEqual(lgd_variant.publication_id, 3)
321+
self.assertTrue(
322+
LGDVariantTypePublication.objects.filter(
323+
lgd_variant_type=lgd_variant, publication_id=3, is_deleted=0
324+
).exists()
325+
)
311326
self.assertFalse(lgd_variant.inherited)
312327
self.assertFalse(lgd_variant.de_novo)
313328
self.assertFalse(lgd_variant.unknown_inheritance)
329+
330+
def test_add_variant_type_with_multiple_publications_no_duplication(self):
331+
"""
332+
Test that adding a variant type supported by more than one publication
333+
creates exactly one LGDVariantType row, one LGDVariantTypePublication
334+
row per publication, and does not duplicate the comment.
335+
"""
336+
user = User.objects.get(email="john@test.ac.uk")
337+
refresh = RefreshToken.for_user(user)
338+
access_token = str(refresh.access_token)
339+
self.client.cookies[settings.SIMPLE_JWT["AUTH_COOKIE"]] = access_token
340+
341+
payload = {
342+
"variant_types": [
343+
{
344+
"comment": "supported by two papers",
345+
"de_novo": False,
346+
"inherited": True,
347+
"primary_type": "protein_changing",
348+
"secondary_type": "stop_gained",
349+
"supporting_papers": ["12451214", "20512146"],
350+
"unknown_inheritance": False,
351+
}
352+
]
353+
}
354+
355+
response = self.client.post(
356+
self.url_add_variant,
357+
payload,
358+
content_type="application/json",
359+
)
360+
self.assertEqual(response.status_code, 201)
361+
362+
stop_gained = OntologyTerm.objects.get(term="stop_gained")
363+
lgd_variant_qs = LGDVariantType.objects.filter(
364+
lgd__stable_id__stable_id="G2P00002",
365+
variant_type_ot=stop_gained,
366+
is_deleted=0,
367+
)
368+
self.assertEqual(len(lgd_variant_qs), 1)
369+
370+
lgd_variant = lgd_variant_qs.first()
371+
lgd_variant_publications = LGDVariantTypePublication.objects.filter(
372+
lgd_variant_type=lgd_variant, is_deleted=0
373+
)
374+
self.assertEqual(len(lgd_variant_publications), 2)
375+
self.assertEqual(
376+
set(lgd_variant_publications.values_list("publication__pmid", flat=True)),
377+
{12451214, 20512146},
378+
)
379+
380+
lgd_variant_comments = LGDVariantTypeComment.objects.filter(
381+
lgd_variant_type=lgd_variant, is_deleted=0
382+
)
383+
self.assertEqual(len(lgd_variant_comments), 1)
384+
self.assertEqual(
385+
lgd_variant_comments.first().comment, "supported by two papers"
386+
)

gene2phenotype_project/gene2phenotype_app/tests/update_data/test_merge_records.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class LGDEditPublicationsEndpoint(TestCase):
4141
"gene2phenotype_app/fixtures/lgd_phenotype.json",
4242
"gene2phenotype_app/fixtures/lgd_variant_consequence.json",
4343
"gene2phenotype_app/fixtures/lgd_variant_type.json",
44+
"gene2phenotype_app/fixtures/lgd_variant_type_publication.json",
4445
"gene2phenotype_app/fixtures/lgd_variant_type_comment.json",
4546
]
4647

@@ -190,11 +191,16 @@ def test_merge_records(self):
190191
stable_id=stable_id_obj.id, is_deleted=0
191192
)
192193
# Check if all variant types were merged correctly
194+
# Note: a variant type is unique per (lgd, variant_type_ot), so the source
195+
# record's "intron_variant" row is skipped during the merge since the
196+
# target record already has one (with a different supporting publication)
193197
lgd_variant_type_list = LGDVariantType.objects.filter(lgd=lgd_obj.id)
194-
self.assertEqual(len(lgd_variant_type_list), 3)
198+
self.assertEqual(len(lgd_variant_type_list), 2)
195199
for variant_type in lgd_variant_type_list:
196200
if (
197-
variant_type.publication.id == 1
201+
variant_type.publications.filter(
202+
publication_id=1, is_deleted=0
203+
).exists()
198204
and variant_type.variant_type_ot.term == "intron_variant"
199205
):
200206
variant_type_comment_list = LGDVariantTypeComment.objects.filter(

0 commit comments

Comments
 (0)