• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ProteinsWebTeam / interpro7-api / 9887981828

11 Jul 2024 08:20AM UTC coverage: 93.827% (-0.2%) from 94.023%
9887981828

Pull #151

github

web-flow
Update webfront/serializers/content_serializers.py

Co-authored-by: Matthias Blum <mat.blum@gmail.com>
Pull Request #151: Replacing `_subset` with `_url` in filter by DB requests

429 of 436 new or added lines in 29 files covered. (98.39%)

6 existing lines in 5 files now uncovered.

9089 of 9687 relevant lines covered (93.83%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.91
/webfront/tests/tests_organism.py
1
from rest_framework import status
1✔
2

3
from webfront.models import Taxonomy
1✔
4
from webfront.tests.InterproRESTTestCase import InterproRESTTestCase
1✔
5

6

7
class TaxonomyFixturesTest(InterproRESTTestCase):
1✔
8
    def test_the_fixtures_are_loaded(self):
1✔
9
        taxa = Taxonomy.objects.all()
1✔
10
        self.assertEqual(taxa.count(), 7)
1✔
11
        names = [t.scientific_name for t in taxa]
1✔
12
        self.assertIn("ROOT", names)
1✔
13
        self.assertNotIn("unicorn", names)
1✔
14

15
    def test_can_get_the_taxonomy_count(self):
1✔
16
        response = self.client.get("/api/taxonomy")
1✔
17
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
18
        self.assertIn("taxa", response.data)
1✔
19
        self.assertIn("uniprot", response.data["taxa"])
1✔
20
        # self.assertIn("proteome", response.data["taxa"])
21

22
    def test_can_read_taxonomy_list(self):
1✔
23
        response = self.client.get("/api/taxonomy/uniprot")
1✔
24
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
25
        self._check_is_list_of_objects_with_key(response.data["results"], "metadata")
1✔
26
        self.assertEqual(len(response.data["results"]), 7)
1✔
27

28
    def test_can_read_taxonomy_id(self):
1✔
29
        response = self.client.get("/api/taxonomy/uniprot/2")
1✔
30
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
31
        self._check_taxonomy_details(response.data["metadata"])
1✔
32

33

34
class TaxonomyProteomeFixturesTest(InterproRESTTestCase):
1✔
35
    def test_can_read_taxonomy_with_proteome_list(self):
1✔
36
        response = self.client.get("/api/taxonomy/uniprot/proteome")
1✔
37
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
38
        self._check_is_list_of_objects_with_key(response.data["results"], "metadata")
1✔
39
        self._check_is_list_of_objects_with_key(response.data["results"], "proteomes")
1✔
40
        self.assertEqual(len(response.data["results"]), 4)
1✔
41

42
    def test_can_read_taxonomy_leaf_id_with_proteome_count(self):
1✔
43
        response = self.client.get("/api/taxonomy/uniprot/40296/proteome")
1✔
44
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
45
        self.assertIn("metadata", response.data)
1✔
46
        self.assertIn("proteomes", response.data)
1✔
47
        self.assertIn("uniprot", response.data["proteomes"])
1✔
48
        self.assertEqual(response.data["proteomes"]["uniprot"], 1)
1✔
49

50
    def test_can_read_taxonomy_leaf_id_with_proteomes(self):
1✔
51
        url = "/api/taxonomy/uniprot/40296/proteome/uniprot"
1✔
52
        self._check_details_url_with_and_without_subset(
1✔
53
            url,
54
            "proteome",
55
            check_metadata_fn=self._check_taxonomy_details,
56
            check_subset_fn=lambda s: self.assertEqual(len(s), 1),
57
        )
58

59
    def test_can_read_taxonomy_node_id_with_proteomes(self):
1✔
60
        url = "/api/taxonomy/uniprot/2579/proteome/uniprot"
1✔
61
        self._check_details_url_with_and_without_subset(
1✔
62
            url,
63
            "proteome",
64
            check_metadata_fn=self._check_taxonomy_details,
65
            check_subset_fn=lambda s: self.assertEqual(len(s), 3),
66
        )
67

68
    def test_can_read_proteome_id_including_tax_id(self):
1✔
69
        lineage = [1, 2, 40296]
1✔
70
        for taxon in lineage:
1✔
71
            response = self.client.get(
1✔
72
                f"/api/taxonomy/uniprot/{taxon}/proteome/uniprot/UP000030104"
73
            )
74
            self.assertEqual(
1✔
75
                response.status_code, status.HTTP_200_OK, f"failed at {str(taxon)}"
76
            )
77
            self.assertIn("proteomes", response.data)
1✔
78
            self.assertEqual(len(response.data["proteomes"]), 1)
1✔
79
            self.assertIn("accession", response.data["proteomes"][0])
1✔
80
            self.assertIn("taxonomy", response.data["proteomes"][0])
1✔
81

82

83
class EntryTaxonomyTest(InterproRESTTestCase):
1✔
84
    def test_can_get_the_taxonomy_count(self):
1✔
85
        response = self.client.get("/api/entry/taxonomy")
1✔
86
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
87
        self._check_entry_count_overview(response.data)
1✔
88
        self._check_taxonomy_count_overview(response.data)
1✔
89

90
    def test_can_get_the_taxonomy_count_on_a_list(self):
1✔
91
        acc = "IPR003165"
1✔
92
        urls = [
1✔
93
            "/api/entry/interpro/taxonomy/",
94
            "/api/entry/pfam/taxonomy/",
95
            "/api/entry/unintegrated/taxonomy/",
96
            "/api/entry/interpro/pfam/taxonomy/",
97
            "/api/entry/unintegrated/pfam/taxonomy/",
98
            f"/api/entry/interpro/{acc}/pfam/taxonomy",
99
        ]
100
        for url in urls:
1✔
101
            response = self.client.get(url)
1✔
102
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
103
            self._check_is_list_of_objects_with_key(
1✔
104
                response.data["results"], "metadata"
105
            )
106
            self._check_is_list_of_objects_with_key(response.data["results"], "taxa")
1✔
107
            for result in response.data["results"]:
1✔
108
                self._check_taxonomy_count_overview(result)
1✔
109

110
    def test_urls_that_return_entry_with_taxonomy_count(self):
1✔
111
        acc = "IPR003165"
1✔
112
        pfam = "PF02171"
1✔
113
        pfam_un = "PF17176"
1✔
114
        urls = [
1✔
115
            f"/api/entry/interpro/{acc}/taxonomy",
116
            f"/api/entry/pfam/{pfam}/taxonomy",
117
            f"/api/entry/pfam/{pfam_un}/taxonomy",
118
            f"/api/entry/interpro/{acc}/pfam/{pfam}/taxonomy",
119
            f"/api/entry/interpro/pfam/{pfam}/taxonomy",
120
            f"/api/entry/unintegrated/pfam/{pfam_un}/taxonomy",
121
        ]
122
        for url in urls:
1✔
123
            response = self.client.get(url)
1✔
124
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
125
            self._check_entry_details(response.data["metadata"])
1✔
126
            self.assertIn(
1✔
127
                "taxa",
128
                response.data,
129
                "'taxa' should be one of the keys in the response",
130
            )
131
            self._check_taxonomy_count_overview(response.data)
1✔
132

133
    def test_can_filter_entry_counter_with_taxonomy_db(self):
1✔
134
        url = "/api/entry/taxonomy/uniprot"
1✔
135
        response = self.client.get(url)
1✔
136
        self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
137
        self.assertIn(
1✔
138
            "taxa",
139
            response.data["entries"]["integrated"],
140
            "'taxa' should be one of the keys in the response",
141
        )
142
        if response.data["entries"]["unintegrated"] != 0:
1✔
143
            self.assertIn(
1✔
144
                "taxa",
145
                response.data["entries"]["unintegrated"],
146
                "'taxa' should be one of the keys in the response",
147
            )
148

149
    def test_can_get_the_taxonomy_list_on_a_list(self):
1✔
150
        acc = "IPR003165"
1✔
151
        urls = [
1✔
152
            "/api/entry/interpro/taxonomy/uniprot",
153
            "/api/entry/unintegrated/taxonomy/uniprot",
154
            f"/api/entry/interpro/{acc}/pfam/taxonomy/uniprot",
155
        ]
156
        for url in urls:
1✔
157
            self._check_list_url_with_and_without_subset(
1✔
158
                url,
159
                "taxonomy",
160
                check_inner_subset_fn=self._check_taxonomy_from_searcher,
161
            )
162

163
    def test_can_get_the_taxonomy_list_on_an_object(self):
1✔
164
        urls = [
1✔
165
            "/api/entry/interpro/IPR003165/taxonomy/uniprot",
166
            "/api/entry/pfam/PF02171/taxonomy/uniprot",
167
            "/api/entry/unintegrated/pfam/PF17176/taxonomy/uniprot",
168
            "/api/entry/interpro/IPR003165/pfam/PF02171/taxonomy/uniprot",
169
        ]
170
        for url in urls:
1✔
171
            self._check_details_url_with_and_without_subset(
1✔
172
                url,
173
                "taxonomy",
174
                check_inner_subset_fn=self._check_taxonomy_from_searcher,
175
                check_metadata_fn=self._check_entry_details,
176
            )
177

178
    def test_can_filter_entry_counter_with_taxonomy_acc(self):
1✔
179
        urls = ["/api/entry/taxonomy/uniprot/2579", "/api/entry/taxonomy/uniprot/40296"]
1✔
180
        for url in urls:
1✔
181
            response = self.client.get(url)
1✔
182
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
183
            self._check_entry_count_overview(response.data)
1✔
184

185
    def test_can_get_the_taxonomy_object_on_a_list(self):
1✔
186
        acc = "IPR003165"
1✔
187
        urls = [
1✔
188
            "/api/entry/interpro/taxonomy/uniprot/2579",
189
            "/api/entry/unintegrated/taxonomy/uniprot/2579",
190
            "/api/entry/unintegrated/taxonomy/uniprot/344612",
191
            f"/api/entry/interpro/{acc}/pfam/taxonomy/uniprot/344612",
192
        ]
193
        for url in urls:
1✔
194
            response = self.client.get(url)
1✔
195
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
196
            self._check_is_list_of_objects_with_key(
1✔
197
                response.data["results"], "metadata"
198
            )
199
            self._check_is_list_of_objects_with_key(response.data["results"], "taxa")
1✔
200
            for result in response.data["results"]:
1✔
201
                for org in result["taxa"]:
1✔
202
                    self._check_taxonomy_from_searcher(org)
1✔
203

204
    def test_can_get_thetaxonomy_object_on_an_object(self):
1✔
205
        urls = [
1✔
206
            "/api/entry/interpro/IPR003165/taxonomy/uniprot/40296",
207
            "/api/entry/unintegrated/pfam/PF17176/taxonomy/uniprot/344612",
208
            "/api/entry/unintegrated/pfam/PF17176/taxonomy/uniprot/1",
209
        ]
210
        for url in urls:
1✔
211
            response = self.client.get(url)
1✔
212
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
213
            self._check_entry_details(response.data["metadata"])
1✔
214
            self.assertIn("taxa", response.data)
1✔
215
            for org in response.data["taxa"]:
1✔
216
                self._check_taxonomy_from_searcher(org)
1✔
217

218

219
class ProteinTaxonomyTest(InterproRESTTestCase):
1✔
220
    def test_can_get_the_taxonomy_count(self):
1✔
221
        response = self.client.get("/api/protein/taxonomy")
1✔
222
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
223
        self._check_taxonomy_count_overview(response.data)
1✔
224
        self._check_protein_count_overview(response.data)
1✔
225

226
    def test_can_get_the_taxonomy_count_on_a_list(self):
1✔
227
        urls = [
1✔
228
            "/api/protein/reviewed/taxonomy/",
229
            "/api/protein/unreviewed/taxonomy/",
230
            "/api/protein/uniprot/taxonomy/",
231
        ]
232
        for url in urls:
1✔
233
            response = self.client.get(url)
1✔
234
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
235
            self._check_is_list_of_objects_with_key(
1✔
236
                response.data["results"], "metadata"
237
            )
238
            self._check_is_list_of_objects_with_key(response.data["results"], "taxa")
1✔
239
            for result in response.data["results"]:
1✔
240
                self._check_taxonomy_count_overview(result)
1✔
241

242
    def test_urls_that_return_protein_with_taxonomy_count(self):
1✔
243
        reviewed = "A1CUJ5"
1✔
244
        unreviewed = "P16582"
1✔
245
        urls = [
1✔
246
            f"/api/protein/uniprot/{reviewed}/taxonomy/",
247
            f"/api/protein/uniprot/{unreviewed}/taxonomy/",
248
            f"/api/protein/reviewed/{reviewed}/taxonomy/",
249
            f"/api/protein/unreviewed/{unreviewed}/taxonomy/",
250
        ]
251
        for url in urls:
1✔
252
            response = self.client.get(url)
1✔
253
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
254
            self._check_protein_details(response.data["metadata"])
1✔
255
            self.assertIn(
1✔
256
                "taxa",
257
                response.data,
258
                "'taxa' should be one of the keys in the response",
259
            )
260
            self._check_taxonomy_count_overview(response.data)
1✔
261

262
    def test_can_filter_protein_counter_with_taxonomy_db(self):
1✔
263
        url = "/api/protein/taxonomy/uniprot"
1✔
264
        response = self.client.get(url)
1✔
265
        self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
266
        self.assertIn(
1✔
267
            "proteins",
268
            response.data["proteins"]["uniprot"],
269
            "'proteins' should be one of the keys in the response",
270
        )
271
        self.assertIn(
1✔
272
            "taxa",
273
            response.data["proteins"]["uniprot"],
274
            "'taxa' should be one of the keys in the response",
275
        )
276
        if "reviewed" in response.data["proteins"]:
1✔
277
            self.assertIn(
1✔
278
                "proteins",
279
                response.data["proteins"]["reviewed"],
280
                "'proteins' should be one of the keys in the response",
281
            )
282
            self.assertIn(
1✔
283
                "taxa",
284
                response.data["proteins"]["reviewed"],
285
                "'taxa' should be one of the keys in the response",
286
            )
287
        if "unreviewed" in response.data["proteins"]:
1✔
288
            self.assertIn(
1✔
289
                "proteins",
290
                response.data["proteins"]["unreviewed"],
291
                "'proteins' should be one of the keys in the response",
292
            )
293
            self.assertIn(
1✔
294
                "taxa",
295
                response.data["proteins"]["unreviewed"],
296
                "'taxa' should be one of the keys in the response",
297
            )
298

299
    def test_can_get_the_taxonomy_list_on_a_list(self):
1✔
300
        urls = [
1✔
301
            "/api/protein/unreviewed/taxonomy/uniprot",
302
            "/api/protein/reviewed/taxonomy/uniprot",
303
            "/api/protein/uniprot/taxonomy/uniprot",
304
        ]
305
        for url in urls:
1✔
306
            self._check_list_url_with_and_without_subset(
1✔
307
                url,
308
                "taxonomy",
309
                check_inner_subset_fn=self._check_taxonomy_from_searcher,
310
            )
311

312
    def test_can_get_the_taxonomy_list_on_an_object(self):
1✔
313
        urls = [
1✔
314
            "/api/protein/uniprot/A0A0A2L2G2/taxonomy/uniprot",
315
            "/api/protein/unreviewed/P16582/taxonomy/uniprot/",
316
            "/api/protein/reviewed/A1CUJ5/taxonomy/uniprot",
317
        ]
318
        for url in urls:
1✔
319
            self._check_details_url_with_and_without_subset(
1✔
320
                url,
321
                "taxonomy",
322
                check_inner_subset_fn=self._check_taxonomy_from_searcher,
323
                check_metadata_fn=self._check_protein_details,
324
            )
325

326
    def test_can_filter_counter_with_taxonomy_acc(self):
1✔
327
        urls = [
1✔
328
            "/api/protein/taxonomy/uniprot/2579",
329
            "/api/protein/taxonomy/uniprot/40296",
330
        ]
331
        for url in urls:
1✔
332
            response = self.client.get(url)
1✔
333
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
334
            self._check_protein_count_overview(response.data)
1✔
335

336
    def test_can_get_the_taxonomy_object_on_a_list(self):
1✔
337
        urls = [
1✔
338
            "/api/protein/reviewed/taxonomy/uniprot/2579",
339
            "/api/protein/uniprot/taxonomy/uniprot/344612",
340
        ]
341
        for url in urls:
1✔
342
            response = self.client.get(url)
1✔
343
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
344
            self._check_is_list_of_objects_with_key(
1✔
345
                response.data["results"], "metadata"
346
            )
347
            self._check_is_list_of_objects_with_key(response.data["results"], "taxa")
1✔
348
            for result in response.data["results"]:
1✔
349
                for org in result["taxa"]:
1✔
350
                    self._check_taxonomy_from_searcher(org)
1✔
351

352
    def test_can_get_the_taxonomy_object_on_an_object(self):
1✔
353
        urls = [
1✔
354
            "/api/protein/uniprot/A0A0A2L2G2/taxonomy/uniprot/40296",
355
            "/api/protein/unreviewed/P16582/taxonomy/uniprot/40296",
356
            "/api/protein/reviewed/A1CUJ5/taxonomy/uniprot/2579",
357
            "/api/protein/reviewed/A1CUJ5/taxonomy/uniprot/344612",
358
        ]
359
        for url in urls:
1✔
360
            response = self.client.get(url)
1✔
361
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
362
            self._check_protein_details(response.data["metadata"])
1✔
363
            self.assertIn("taxa", response.data)
1✔
364
            for org in response.data["taxa"]:
1✔
365
                self._check_taxonomy_from_searcher(org)
1✔
366

367

368
class StructureTaxonomyTest(InterproRESTTestCase):
1✔
369
    def test_can_get_the_taxonomy_count(self):
1✔
370
        response = self.client.get("/api/structure/taxonomy")
1✔
371
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
372
        self._check_taxonomy_count_overview(response.data)
1✔
373
        self._check_structure_count_overview(response.data)
1✔
374

375
    def test_can_get_the_taxonomy_count_on_a_list(self):
1✔
376
        url = "/api/structure/pdb/taxonomy/"
1✔
377
        response = self.client.get(url)
1✔
378
        self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
379
        self._check_is_list_of_objects_with_key(response.data["results"], "metadata")
1✔
380
        self._check_is_list_of_objects_with_key(response.data["results"], "taxa")
1✔
381
        for result in response.data["results"]:
1✔
382
            self._check_taxonomy_count_overview(result)
1✔
383

384
    def test_urls_that_return_structure_with_taxonomy_count(self):
1✔
385
        urls = [
1✔
386
            f"/api/structure/pdb/{pdb}/taxonomy/" for pdb in ["1JM7", "2BKM", "1T2V"]
387
        ]
388
        for url in urls:
1✔
389
            response = self.client.get(url)
1✔
390
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
391
            self._check_structure_details(response.data["metadata"])
1✔
392
            self.assertIn(
1✔
393
                "taxa",
394
                response.data,
395
                "'taxa' should be one of the keys in the response",
396
            )
397
            self._check_taxonomy_count_overview(response.data)
1✔
398

399
    def test_can_filter_structure_counter_with_taxonomy_db(self):
1✔
400
        url = "/api/structure/taxonomy/uniprot"
1✔
401
        response = self.client.get(url)
1✔
402
        self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
403
        self.assertIn(
1✔
404
            "structures",
405
            response.data["structures"]["pdb"],
406
            "'structures' should be one of the keys in the response",
407
        )
408
        self.assertIn(
1✔
409
            "taxa",
410
            response.data["structures"]["pdb"],
411
            "'taxa' should be one of the keys in the response",
412
        )
413

414
    def test_can_get_the_taxonomy_list_on_a_list(self):
1✔
415
        url = "/api/structure/pdb/taxonomy/uniprot"
1✔
416
        self._check_list_url_with_and_without_subset(
1✔
417
            url,
418
            "taxonomy",
419
            check_inner_subset_fn=self._check_taxonomy_from_searcher,
420
        )
421

422
    def test_can_get_the_taxonomy_list_on_an_object(self):
1✔
423
        urls = [
1✔
424
            "/api/structure/pdb/1T2V/taxonomy/uniprot",
425
            "/api/structure/pdb/1JZ8/taxonomy/uniprot",
426
        ]
427
        for url in urls:
1✔
428
            self._check_details_url_with_and_without_subset(
1✔
429
                url,
430
                "taxonomy",
431
                check_inner_subset_fn=self._check_taxonomy_from_searcher,
432
                check_metadata_fn=self._check_structure_details,
433
            )
434

435
    def test_can_filter_counter_with_taxonomy_acc(self):
1✔
436
        urls = [
1✔
437
            "/api/structure/taxonomy/uniprot/2579",
438
            "/api/structure/taxonomy/uniprot/40296",
439
        ]
440
        for url in urls:
1✔
441
            response = self.client.get(url)
1✔
442
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
443
            self._check_structure_count_overview(response.data)
1✔
444

445
    def test_can_get_the_taxonomy_object_on_a_list(self):
1✔
446
        urls = [
1✔
447
            "/api/structure/pdb/taxonomy/uniprot/2",
448
            "/api/structure/pdb/taxonomy/uniprot/2579",
449
        ]
450
        for url in urls:
1✔
451
            response = self.client.get(url)
1✔
452
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
453
            self._check_is_list_of_objects_with_key(
1✔
454
                response.data["results"], "metadata"
455
            )
456
            self._check_is_list_of_objects_with_key(response.data["results"], "taxa")
1✔
457
            for result in response.data["results"]:
1✔
458
                for org in result["taxa"]:
1✔
459
                    self._check_taxonomy_from_searcher(org)
1✔
460

461
    def test_can_get_the_taxonomy_object_on_an_object(self):
1✔
462
        urls = [
1✔
463
            "/api/structure/pdb/1T2V/taxonomy/uniprot/40296",
464
            "/api/structure/pdb/1JZ8/taxonomy/uniprot/1",
465
            "/api/structure/pdb/1JZ8/taxonomy/uniprot/40296",
466
        ]
467
        for url in urls:
1✔
468
            response = self.client.get(url)
1✔
469
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
470
            self._check_structure_details(response.data["metadata"])
1✔
471
            self.assertIn("taxa", response.data)
1✔
472
            for org in response.data["taxa"]:
1✔
473
                self._check_taxonomy_from_searcher(org)
1✔
474

475

476
class SetTaxonomyTest(InterproRESTTestCase):
1✔
477
    def test_can_get_the_taxonomy_count(self):
1✔
478
        response = self.client.get("/api/set/taxonomy")
1✔
479
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
480
        self._check_set_count_overview(response.data)
1✔
481
        self._check_taxonomy_count_overview(response.data)
1✔
482

483
    def test_can_get_the_taxonomy_count_on_a_list(self):
1✔
484
        urls = [
1✔
485
            "/api/set/pfam/taxonomy",
486
            #            "/api/set/kegg/taxonomy",
487
            #            "/api/set/kegg/KEGG01/node/taxonomy",
488
        ]
489
        for url in urls:
1✔
490
            response = self.client.get(url)
1✔
491
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
492
            self._check_is_list_of_objects_with_key(
1✔
493
                response.data["results"], "metadata"
494
            )
495
            self._check_is_list_of_objects_with_key(response.data["results"], "taxa")
1✔
496
            for result in response.data["results"]:
1✔
497
                self._check_taxonomy_count_overview(result)
1✔
498

499
    def test_can_get_the_taxonomy_count_on_a_set(self):
1✔
500
        urls = [
1✔
501
            "/api/set/pfam/CL0001/taxonomy",
502
            #            "/api/set/kegg/KEGG01/taxonomy",
503
            #            "/api/set/kegg/KEGG01/node/KEGG01-1/taxonomy",
504
        ]
505
        for url in urls:
1✔
506
            response = self.client.get(url)
1✔
507
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
508
            self._check_set_details(response.data["metadata"])
1✔
509
            self.assertIn(
1✔
510
                "taxa",
511
                response.data,
512
                "'taxa' should be one of the keys in the response",
513
            )
514
            self._check_taxonomy_count_overview(response.data)
1✔
515

516
    def test_can_filter_set_counter_with_structure_db(self):
1✔
517
        url = "/api/set/taxonomy/uniprot"
1✔
518
        response = self.client.get(url)
1✔
519
        self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
520
        self.assertIsInstance(response.data, dict)
1✔
521
        # if "kegg" in response.data["sets"]:
522
        #     self.assertIn("taxa", response.data["sets"]["kegg"],
523
        #                   "'taxa' should be one of the keys in the response")
524
        #     self.assertIn("sets", response.data["sets"]["kegg"],
525
        #                   "'sets' should be one of the keys in the response")
526
        if "pfam" in response.data["sets"]:
1✔
527
            self.assertIn(
1✔
528
                "taxa",
529
                response.data["sets"]["pfam"],
530
                "'taxa' should be one of the keys in the response",
531
            )
532
            self.assertIn(
1✔
533
                "sets",
534
                response.data["sets"]["pfam"],
535
                "'sets' should be one of the keys in the response",
536
            )
537

538
    def test_can_get_the_set_list_on_a_list(self):
1✔
539
        urls = [
1✔
540
            #            "/api/set/kegg/taxonomy/uniprot",
541
            #            "/api/set/kegg/kegg01/node/taxonomy/uniprot",
542
        ]
543
        for url in urls:
1✔
544
            response = self.client.get(url)
×
NEW
545
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
×
UNCOV
546
            self._check_is_list_of_objects_with_key(
×
547
                response.data["results"], "metadata"
548
            )
549
            self._check_is_list_of_objects_with_key(response.data["results"], "taxa")
×
550
            for result in response.data["results"]:
×
551
                for s in result["taxa"]:
×
552
                    self._check_taxonomy_from_searcher(s)
×
553

554
    def test_can_get_a_list_from_the_set_object(self):
1✔
555
        urls = [
1✔
556
            "/api/set/pfam/Cl0001/taxonomy/uniprot",
557
            #            "/api/set/kegg/kegg01/node/KEGG01-1/taxonomy/uniprot/",
558
        ]
559
        for url in urls:
1✔
560
            self._check_details_url_with_and_without_subset(
1✔
561
                url,
562
                "taxonomy",
563
                check_inner_subset_fn=self._check_taxonomy_from_searcher,
564
                check_metadata_fn=self._check_set_details,
565
            )
566

567
    def test_can_filter_set_counter_with_acc(self):
1✔
568
        urls = [
1✔
569
            "/api/set/taxonomy/uniprot/1",
570
            "/api/set/taxonomy/uniprot/2579",
571
            "/api/set/taxonomy/uniprot/344612",
572
            "/api/set/taxonomy/uniprot/1001583",
573
        ]
574
        for url in urls:
1✔
575
            response = self.client.get(url)
1✔
576
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
577
            self._check_set_count_overview(response.data)
1✔
578

579
    #     def test_can_get_object_on_a_set_list(self):
580
    #         urls = [
581
    # #            "/api/set/kegg/taxonomy/uniprot/2579",
582
    # #            "/api/set/kegg/taxonomy/uniprot/344612",
583
    #             ]
584
    #         for url in urls:
585
    #             response = self.client.get(url)
586
    #             self.assertEqual(response.status_code, status.HTTP_200_OK, "URL : [{}]".format(url))
587
    #             self._check_is_list_of_objects_with_key(response.data["results"], "metadata")
588
    #             self._check_is_list_of_objects_with_key(response.data["results"], "taxa")
589
    #             for result in response.data["results"]:
590
    #                 self._check_set_details(result["metadata"], False)
591
    #                 for st in result["taxa"]:
592
    #                     self._check_taxonomy_from_searcher(st)
593

594
    def test_can_get_an_object_from_the_set_object(self):
1✔
595
        urls = [
1✔
596
            #            "/api/set/kegg/kegg01/taxonomy/uniprot/2",
597
            #            "/api/set/kegg/kegg01/taxonomy/uniprot/40296",
598
            #            "/api/set/kegg/kegg01/node/kegg01-1/taxonomy/uniprot/40296",
599
            "/api/set/pfam/Cl0001/taxonomy/uniprot/344612"
600
        ]
601
        for url in urls:
1✔
602
            response = self.client.get(url)
1✔
603
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
604
            self._check_set_details(response.data["metadata"])
1✔
605
            self.assertIn("taxa", response.data)
1✔
606
            for s in response.data["taxa"]:
1✔
607
                self._check_taxonomy_from_searcher(s)
1✔
608

609

610
class TaxonomyEntryTest(InterproRESTTestCase):
1✔
611
    def test_can_get_the_taxonomy_count(self):
1✔
612
        response = self.client.get("/api/taxonomy/entry")
1✔
613
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
614
        self._check_taxonomy_count_overview(response.data)
1✔
615
        self._check_entry_count_overview(response.data)
1✔
616

617
    def test_can_get_the_entry_count_on_a_list(self):
1✔
618
        url = "/api/taxonomy/uniprot/entry"
1✔
619
        response = self.client.get(url)
1✔
620
        self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
621
        self._check_is_list_of_objects_with_key(response.data["results"], "metadata")
1✔
622
        self._check_is_list_of_objects_with_key(response.data["results"], "entries")
1✔
623
        for result in response.data["results"]:
1✔
624
            self._check_entry_count_overview(result)
1✔
625

626
    def test_a_more_inclusive_taxon_has_more_items(self):
1✔
627
        response1 = self.client.get("/api/taxonomy/uniprot/2579/entry")
1✔
628
        response2 = self.client.get("/api/taxonomy/uniprot/1001583/entry")
1✔
629
        self.assertEqual(response1.status_code, status.HTTP_200_OK)
1✔
630
        self.assertEqual(response2.status_code, status.HTTP_200_OK)
1✔
631
        self.assertGreater(
1✔
632
            response1.data["entries"]["all"], response2.data["entries"]["all"]
633
        )
634

635
    def test_urls_that_return_taxonomy_with_entry_count(self):
1✔
636
        urls = ["/api/taxonomy/uniprot/40296/entry", "/api/taxonomy/uniprot/2/entry"]
1✔
637
        for url in urls:
1✔
638
            response = self.client.get(url)
1✔
639
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
640
            self._check_taxonomy_details(response.data["metadata"])
1✔
641
            self.assertIn(
1✔
642
                "entries",
643
                response.data,
644
                "'entries' should be one of the keys in the response",
645
            )
646
            self._check_entry_count_overview(response.data)
1✔
647

648
    def test_can_filter_taxonomy_counter_with_entry_db(self):
1✔
649
        acc = "IPR003165"
1✔
650
        urls = [
1✔
651
            "/api/taxonomy/entry/interpro",
652
            "/api/taxonomy/entry/pfam",
653
            "/api/taxonomy/entry/unintegrated",
654
            "/api/taxonomy/entry/unintegrated/pfam",
655
            "/api/taxonomy/entry/interpro/pfam",
656
            f"/api/taxonomy/entry/interpro/{acc}/pfam",
657
        ]
658
        for url in urls:
1✔
659
            response = self.client.get(url)
1✔
660
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
661
            self.assertIsInstance(response.data, dict)
1✔
662
            self.assertIn(
1✔
663
                "uniprot",
664
                response.data["taxa"],
665
                "'uniprot' should be one of the keys in the response",
666
            )
667
            self.assertIn(
1✔
668
                "taxa",
669
                response.data["taxa"]["uniprot"],
670
                "'proteome' should be one of the keys in the response",
671
            )
672
            self.assertIn(
1✔
673
                "entries",
674
                response.data["taxa"]["uniprot"],
675
                "'entries' should be one of the keys in the response",
676
            )
677

678
    def test_can_get_a_list_from_the_taxonomy_list(self):
1✔
679
        urls = [
1✔
680
            "/api/taxonomy/uniprot/entry/interpro",
681
            "/api/taxonomy/uniprot/entry/unintegrated",
682
            "/api/taxonomy/uniprot/entry/interpro/pfam",
683
            "/api/taxonomy/uniprot/entry/unintegrated/pfam",
684
            "/api/taxonomy/uniprot/entry/interpro/IPR003165/pfam",
685
        ]
686
        for url in urls:
1✔
687
            self._check_list_url_with_and_without_subset(
1✔
688
                url,
689
                "entry",
690
                check_inner_subset_fn=self._check_entry_from_searcher,
691
                check_metadata_fn=lambda m: self._check_taxonomy_details(m, False),
692
            )
693

694
    def test_can_get_a_list_from_the_taxonomy_object(self):
1✔
695
        urls = [
1✔
696
            "/api/taxonomy/uniprot/40296/entry/interpro",
697
            "/api/taxonomy/uniprot/1/entry/interpro/pfam",
698
            "/api/taxonomy/uniprot/2579/entry/unintegrated/pfam",
699
            "/api/taxonomy/uniprot/344612/entry/unintegrated/pfam",
700
        ]
701
        for url in urls:
1✔
702
            self._check_details_url_with_and_without_subset(
1✔
703
                url,
704
                "entry",
705
                check_inner_subset_fn=self._check_entry_from_searcher,
706
                check_metadata_fn=self._check_taxonomy_details,
707
            )
708

709
    def test_can_filter_taxonomy_counter_with_acc(self):
1✔
710
        acc = "IPR003165"
1✔
711
        pfam = "PF02171"
1✔
712
        pfam_un = "PF17176"
1✔
713
        urls = [
1✔
714
            f"/api/taxonomy/entry/interpro/{acc}",
715
            f"/api/taxonomy/entry/pfam/{pfam}",
716
            f"/api/taxonomy/entry/pfam/{pfam_un}",
717
            f"/api/taxonomy/entry/interpro/{acc}/pfam/{pfam}",
718
            f"/api/taxonomy/entry/interpro/pfam/{pfam}",
719
            f"/api/taxonomy/entry/unintegrated/pfam/{pfam_un}",
720
        ]
721
        for url in urls:
1✔
722
            response = self.client.get(url)
1✔
723
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
724
            self._check_taxonomy_count_overview(response.data)
1✔
725

726
    def test_can_get_object_on_a_taxonomy_list(self):
1✔
727
        acc = "IPR003165"
1✔
728
        pfam = "PF02171"
1✔
729
        pfam_un = "PF17176"
1✔
730
        urls = [
1✔
731
            f"/api/taxonomy/uniprot/entry/interpro/{acc}",
732
            f"/api/taxonomy/uniprot/entry/unintegrated/pfam/{pfam_un}",
733
            f"/api/taxonomy/uniprot/entry/interpro/pfam/{pfam}",
734
            f"/api/taxonomy/uniprot/entry/interpro/IPR003165/pfam/{pfam}",
735
        ]
736
        for url in urls:
1✔
737
            response = self.client.get(url)
1✔
738
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
739
            self._check_is_list_of_objects_with_key(
1✔
740
                response.data["results"], "metadata"
741
            )
742
            self._check_is_list_of_objects_with_key(response.data["results"], "entries")
1✔
743
            for result in response.data["results"]:
1✔
744
                self._check_taxonomy_details(result["metadata"], False)
1✔
745
                for st in result["entries"]:
1✔
746
                    self._check_entry_from_searcher(st)
1✔
747

748
    def test_can_get_an_object_from_the_taxonomy_object(self):
1✔
749
        urls = [
1✔
750
            "/api/taxonomy/uniprot/40296/entry/interpro/ipr003165",
751
            "/api/taxonomy/uniprot/1/entry/interpro/pfam/pf02171",
752
            "/api/taxonomy/uniprot/2579/entry/unintegrated/pfam/pf17176",
753
            "/api/taxonomy/uniprot/344612/entry/unintegrated/pfam/pf17176",
754
        ]
755
        for url in urls:
1✔
756
            response = self.client.get(url)
1✔
757
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
758
            self._check_taxonomy_details(response.data["metadata"], False)
1✔
759
            self.assertIn("entries", response.data)
1✔
760
            for st in response.data["entries"]:
1✔
761
                self._check_entry_from_searcher(st)
1✔
762

763

764
class TaxonomyProteinTest(InterproRESTTestCase):
1✔
765
    def test_can_get_the_taxonomy_count(self):
1✔
766
        response = self.client.get("/api/taxonomy/protein")
1✔
767
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
768
        self._check_taxonomy_count_overview(response.data)
1✔
769
        self._check_protein_count_overview(response.data)
1✔
770

771
    def test_can_get_the_protein_count_on_a_list(self):
1✔
772
        url = "/api/taxonomy/uniprot/protein"
1✔
773
        response = self.client.get(url)
1✔
774
        self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
775
        self._check_is_list_of_objects_with_key(response.data["results"], "metadata")
1✔
776
        self._check_is_list_of_objects_with_key(response.data["results"], "proteins")
1✔
777
        for result in response.data["results"]:
1✔
778
            self._check_protein_count_overview(result)
1✔
779

780
    def test_a_more_inclusive_taxon_has_more_items(self):
1✔
781
        response1 = self.client.get("/api/taxonomy/uniprot/2579/protein")
1✔
782
        response2 = self.client.get("/api/taxonomy/uniprot/1001583/protein")
1✔
783
        self.assertEqual(response1.status_code, status.HTTP_200_OK)
1✔
784
        self.assertEqual(response2.status_code, status.HTTP_200_OK)
1✔
785
        self.assertGreater(
1✔
786
            response1.data["proteins"]["uniprot"], response2.data["proteins"]["uniprot"]
787
        )
788

789
    def test_urls_that_return_taxonomy_with_entry_count(self):
1✔
790
        urls = [
1✔
791
            "/api/taxonomy/uniprot/40296/protein",
792
            "/api/taxonomy/uniprot/2/protein",
793
        ]
794
        for url in urls:
1✔
795
            response = self.client.get(url)
1✔
796
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
797
            self._check_taxonomy_details(response.data["metadata"])
1✔
798
            self.assertIn(
1✔
799
                "proteins",
800
                response.data,
801
                "'proteins' should be one of the keys in the response",
802
            )
803
            self._check_protein_count_overview(response.data)
1✔
804

805
    def test_can_filter_protein_counter_with_taxonomy_db(self):
1✔
806
        urls = [
1✔
807
            "/api/taxonomy/protein/uniprot",
808
            "/api/taxonomy/protein/reviewed",
809
            "/api/taxonomy/protein/unreviewed",
810
        ]
811
        for url in urls:
1✔
812
            response = self.client.get(url)
1✔
813
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
814
            self.assertIsInstance(response.data, dict)
1✔
815
            self.assertIn(
1✔
816
                "uniprot",
817
                response.data["taxa"],
818
                "'uniprot' should be one of the keys in the response",
819
            )
820
            self.assertIn(
1✔
821
                "taxa",
822
                response.data["taxa"]["uniprot"],
823
                "'taxa' should be one of the keys in the response",
824
            )
825
            self.assertIn(
1✔
826
                "proteins",
827
                response.data["taxa"]["uniprot"],
828
                "'proteins' should be one of the keys in the response",
829
            )
830

831
    def test_can_get_a_list_from_the_taxonomy_list(self):
1✔
832
        urls = [
1✔
833
            "/api/taxonomy/uniprot/protein/uniprot",
834
            "/api/taxonomy/uniprot/protein/unreviewed",
835
            "/api/taxonomy/uniprot/protein/reviewed",
836
        ]
837
        for url in urls:
1✔
838
            self._check_list_url_with_and_without_subset(
1✔
839
                url,
840
                "protein",
841
                check_inner_subset_fn=lambda p: self._check_match(
842
                    p, include_coordinates=False
843
                ),
844
                check_metadata_fn=lambda m: self._check_taxonomy_details(m, False),
845
            )
846

847
    def test_can_get_a_list_from_the_taxonomy_object(self):
1✔
848
        urls = [
1✔
849
            "/api/taxonomy/uniprot/40296/protein/uniprot",
850
            "/api/taxonomy/uniprot/1/protein/unreviewed",
851
            "/api/taxonomy/uniprot/2579/protein/reviewed",
852
            "/api/taxonomy/uniprot/344612/protein/reviewed",
853
        ]
854
        for url in urls:
1✔
855
            self._check_details_url_with_and_without_subset(
1✔
856
                url,
857
                "protein",
858
                check_inner_subset_fn=lambda p: self._check_match(
859
                    p, include_coordinates=False
860
                ),
861
                check_metadata_fn=lambda m: self._check_taxonomy_details(m, False),
862
            )
863

864
    def test_can_filter_taxonomy_counter_with_acc(self):
1✔
865
        urls = [
1✔
866
            "/api/taxonomy/protein/uniprot/M5ADK6",
867
            "/api/taxonomy/protein/unreviewed/A0A0A2L2G2",
868
            "/api/taxonomy/protein/reviewed/M5ADK6",
869
        ]
870
        for url in urls:
1✔
871
            response = self.client.get(url)
1✔
872
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
873
            self._check_taxonomy_count_overview(response.data)
1✔
874

875
    def test_can_get_object_on_a_taxonomy_list(self):
1✔
876
        urls = [
1✔
877
            "/api/taxonomy/uniprot/protein/uniprot/P16582",
878
            "/api/taxonomy/uniprot/protein/unreviewed/A0A0A2L2G2",
879
            "/api/taxonomy/uniprot/protein/reviewed/M5ADK6",
880
            "/api/taxonomy/uniprot/protein/reviewed/a1cuj5",
881
        ]
882
        for url in urls:
1✔
883
            response = self.client.get(url)
1✔
884
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
885
            self._check_is_list_of_objects_with_key(
1✔
886
                response.data["results"], "metadata"
887
            )
888
            self._check_is_list_of_objects_with_key(
1✔
889
                response.data["results"], "proteins"
890
            )
891
            for result in response.data["results"]:
1✔
892
                self._check_taxonomy_details(result["metadata"], False)
1✔
893
                for st in result["proteins"]:
1✔
894
                    self._check_match(st, include_coordinates=False)
1✔
895

896
    def test_can_get_an_object_from_the_taxonomy_object(self):
1✔
897
        urls = [
1✔
898
            "/api/taxonomy/uniprot/40296/protein/uniprot/p16582",
899
            "/api/taxonomy/uniprot/1/protein/reviewed/a1cuj5",
900
            "/api/taxonomy/uniprot/2579/protein/reviewed/a1cuj5",
901
            "/api/taxonomy/uniprot/344612/protein/reviewed/a1cuj5",
902
        ]
903
        for url in urls:
1✔
904
            response = self.client.get(url)
1✔
905
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
906
            self._check_taxonomy_details(response.data["metadata"], False)
1✔
907
            self.assertIn("proteins", response.data)
1✔
908
            for st in response.data["proteins"]:
1✔
909
                self._check_match(st, include_coordinates=False)
1✔
910

911

912
class TaxonomyStructureTest(InterproRESTTestCase):
1✔
913
    def test_can_get_the_taxonomy_count(self):
1✔
914
        response = self.client.get("/api/taxonomy/structure")
1✔
915
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
916
        self._check_taxonomy_count_overview(response.data)
1✔
917
        self._check_structure_count_overview(response.data)
1✔
918

919
    def test_can_get_the_protein_count_on_a_list(self):
1✔
920
        url = "/api/taxonomy/uniprot/structure"
1✔
921
        response = self.client.get(url)
1✔
922
        self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
923
        self._check_is_list_of_objects_with_key(response.data["results"], "metadata")
1✔
924
        self._check_is_list_of_objects_with_key(response.data["results"], "structures")
1✔
925
        for result in response.data["results"]:
1✔
926
            self._check_structure_count_overview(result)
1✔
927

928
    def test_a_more_inclusive_taxon_has_more_items(self):
1✔
929
        response1 = self.client.get("/api/taxonomy/uniprot/1/structure")
1✔
930
        response2 = self.client.get("/api/taxonomy/uniprot/1001583/structure")
1✔
931
        self.assertEqual(response1.status_code, status.HTTP_200_OK)
1✔
932
        self.assertEqual(response2.status_code, status.HTTP_200_OK)
1✔
933
        self.assertGreater(
1✔
934
            response1.data["structures"]["pdb"], response2.data["structures"]["pdb"]
935
        )
936

937
    def test_urls_that_return_taxonomy_with_entry_count(self):
1✔
938
        urls = [
1✔
939
            "/api/taxonomy/uniprot/40296/structure",
940
            "/api/taxonomy/uniprot/2/structure",
941
        ]
942
        for url in urls:
1✔
943
            response = self.client.get(url)
1✔
944
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
945
            self._check_taxonomy_details(response.data["metadata"])
1✔
946
            self.assertIn(
1✔
947
                "structures",
948
                response.data,
949
                "'structures' should be one of the keys in the response",
950
            )
951
            self._check_structure_count_overview(response.data)
1✔
952

953
    def test_can_filter_structure_counter_with_taxonomy_db(self):
1✔
954
        url = "/api/taxonomy/structure/pdb"
1✔
955
        response = self.client.get(url)
1✔
956
        self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
957
        self.assertIsInstance(response.data, dict)
1✔
958
        self.assertIn(
1✔
959
            "uniprot",
960
            response.data["taxa"],
961
            "'uniprot' should be one of the keys in the response",
962
        )
963
        self.assertIn(
1✔
964
            "structures",
965
            response.data["taxa"]["uniprot"],
966
            "'structures' should be one of the keys in the response",
967
        )
968
        self.assertIn(
1✔
969
            "taxa",
970
            response.data["taxa"]["uniprot"],
971
            "'taxa' should be one of the keys in the response",
972
        )
973

974
    def test_can_get_a_list_from_the_taxonomy_list(self):
1✔
975
        url = "/api/taxonomy/uniprot/structure/pdb"
1✔
976
        self._check_list_url_with_and_without_subset(
1✔
977
            url,
978
            "structure",
979
            check_metadata_fn=lambda m: self._check_taxonomy_details(m, False),
980
            check_inner_subset_fn=self._check_structure_chain_details,
981
        )
982

983
    def test_can_get_a_list_from_the_taxonomy_object(self):
1✔
984
        urls = [
1✔
985
            "/api/taxonomy/uniprot/40296/structure/pdb",
986
            "/api/taxonomy/uniprot/1/structure/pdb",
987
            "/api/taxonomy/uniprot/2579/structure/pdb",
988
            "/api/taxonomy/uniprot/344612/structure/pdb",
989
        ]
990
        for url in urls:
1✔
991
            self._check_details_url_with_and_without_subset(
1✔
992
                url,
993
                "structure",
994
                check_metadata_fn=lambda m: self._check_taxonomy_details(m, False),
995
                check_inner_subset_fn=self._check_structure_chain_details,
996
            )
997

998
    def test_can_filter_taxonomy_counter_with_acc(self):
1✔
999
        urls = ["/api/taxonomy/structure/pdb/1JM7", "/api/taxonomy/structure/pdb/1JZ8"]
1✔
1000
        for url in urls:
1✔
1001
            response = self.client.get(url)
1✔
1002
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
1003
            self._check_taxonomy_count_overview(response.data)
1✔
1004

1005
    def test_can_get_object_on_a_taxonomy_list(self):
1✔
1006
        urls = [
1✔
1007
            "/api/taxonomy/uniprot/structure/pdb/1JM7",
1008
            "/api/taxonomy/uniprot/structure/pdb/1JZ8",
1009
        ]
1010
        for url in urls:
1✔
1011
            response = self.client.get(url)
1✔
1012
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
1013
            self._check_is_list_of_objects_with_key(
1✔
1014
                response.data["results"], "metadata"
1015
            )
1016
            self._check_is_list_of_objects_with_key(
1✔
1017
                response.data["results"], "structures"
1018
            )
1019
            for result in response.data["results"]:
1✔
1020
                self._check_taxonomy_details(result["metadata"], False)
1✔
1021
                for st in result["structures"]:
1✔
1022
                    self._check_structure_chain_details(st)
1✔
1023

1024
    def test_can_get_an_object_from_the_taxonomy_object(self):
1✔
1025
        urls = [
1✔
1026
            "/api/taxonomy/uniprot/40296/structure/pdb/1t2v",
1027
            "/api/taxonomy/uniprot/1/structure/pdb/1jm7",
1028
            "/api/taxonomy/uniprot/2579/structure/pdb/1jm7",
1029
            "/api/taxonomy/uniprot/344612/structure/pdb/1jm7",
1030
        ]
1031
        for url in urls:
1✔
1032
            response = self.client.get(url)
1✔
1033
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
1034
            self._check_taxonomy_details(response.data["metadata"], False)
1✔
1035
            self.assertIn("structures", response.data)
1✔
1036
            for st in response.data["structures"]:
1✔
1037
                self._check_structure_chain_details(st)
1✔
1038

1039

1040
class TaxonomySetTest(InterproRESTTestCase):
1✔
1041
    def test_can_get_the_taxonomy_count(self):
1✔
1042
        response = self.client.get("/api/taxonomy/set")
1✔
1043
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
1044
        self._check_set_count_overview(response.data)
1✔
1045
        self._check_taxonomy_count_overview(response.data)
1✔
1046

1047
    def test_can_get_the_set_count_on_a_list(self):
1✔
1048
        url = "/api/taxonomy/uniprot/set"
1✔
1049
        response = self.client.get(url)
1✔
1050
        self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
1051
        self._check_is_list_of_objects_with_key(response.data["results"], "metadata")
1✔
1052
        self._check_is_list_of_objects_with_key(response.data["results"], "sets")
1✔
1053
        for result in response.data["results"]:
1✔
1054
            self._check_set_count_overview(result)
1✔
1055

1056
    def test_urls_that_return_taxonomy_with_set_count(self):
1✔
1057
        urls = ["/api/taxonomy/uniprot/1001583/set", "/api/taxonomy/uniprot/1/set"]
1✔
1058
        for url in urls:
1✔
1059
            response = self.client.get(url)
1✔
1060
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
1061
            self._check_taxonomy_details(response.data["metadata"])
1✔
1062
            self.assertIn(
1✔
1063
                "sets",
1064
                response.data,
1065
                "'sets' should be one of the keys in the response",
1066
            )
1067
            self._check_set_count_overview(response.data)
1✔
1068

1069
    def test_can_filter_taxonomy_counter_with_taxonomy_db(self):
1✔
1070
        urls = [
1✔
1071
            "/api/taxonomy/set/pfam",
1072
            #            "/api/taxonomy/set/kegg",
1073
            #            "/api/taxonomy/set/kegg/kegg01/node",
1074
        ]
1075
        for url in urls:
1✔
1076
            response = self.client.get(url)
1✔
1077
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
1078
            self.assertIn(
1✔
1079
                "uniprot",
1080
                response.data["taxa"],
1081
                "'uniprot' should be one of the keys in the response",
1082
            )
1083
            self.assertIn(
1✔
1084
                "taxa",
1085
                response.data["taxa"]["uniprot"],
1086
                "'taxa' should be one of the keys in the response",
1087
            )
1088
            self.assertIn(
1✔
1089
                "sets",
1090
                response.data["taxa"]["uniprot"],
1091
                "'sets' should be one of the keys in the response",
1092
            )
1093

1094
    def test_can_get_the_set_list_on_a_list(self):
1✔
1095
        urls = [
1✔
1096
            "/api/taxonomy/uniprot/set/pfam",
1097
        ]
1098
        for url in urls:
1✔
1099
            self._check_list_url_with_and_without_subset(
1✔
1100
                url,
1101
                "set",
1102
                check_inner_subset_fn=self._check_set_from_searcher,
1103
            )
1104

1105
    def test_can_get_the_set_list_on_a__tax_object(self):
1✔
1106
        urls = [
1✔
1107
            "/api/taxonomy/uniprot/2579/set/pfam",
1108
        ]
1109
        for url in urls:
1✔
1110
            self._check_details_url_with_and_without_subset(
1✔
1111
                url,
1112
                "set",
1113
                check_inner_subset_fn=self._check_set_from_searcher,
1114
                check_metadata_fn=self._check_taxonomy_details,
1115
            )
1116

1117
    def test_can_filter_counter_with_set_acc(self):
1✔
1118
        urls = [
1✔
1119
            "/api/taxonomy/set/pfam/Cl0001",
1120
            #            "/api/taxonomy/set/kegg/kegg01",
1121
            #            "/api/taxonomy/set/kegg/kegg01/node/KEGG01-1",
1122
            #            "/api/taxonomy/set/kegg/kegg01/node/KEGG01-2",
1123
        ]
1124
        for url in urls:
1✔
1125
            response = self.client.get(url)
1✔
1126
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
1127
            self._check_taxonomy_count_overview(response.data)
1✔
1128

1129
    def test_can_get_the_set_object_on_a_list(self):
1✔
1130
        urls = [
1✔
1131
            #            "/api/taxonomy/uniprot/set/kegg/kegg01",
1132
            #            "/api/taxonomy/uniprot/set/kegg/kegg01/node/kegg01-1",
1133
            "/api/taxonomy/uniprot/set/pfam/Cl0001"
1134
        ]
1135
        for url in urls:
1✔
1136
            response = self.client.get(url)
1✔
1137
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
1138
            self._check_is_list_of_objects_with_key(
1✔
1139
                response.data["results"], "metadata"
1140
            )
1141
            self._check_is_list_of_objects_with_key(response.data["results"], "sets")
1✔
1142
            for result in response.data["results"]:
1✔
1143
                for org in result["sets"]:
1✔
1144
                    self._check_set_from_searcher(org)
1✔
1145

1146
    def test_can_get_the_object_on_an_object(self):
1✔
1147
        urls = [
1✔
1148
            #            "/api/taxonomy/uniprot/2/set/kegg/kegg01",
1149
            #            "/api/taxonomy/uniprot/40296/set/kegg/kegg01",
1150
            #            "/api/taxonomy/uniprot/40296/set/kegg/kegg01/node/kegg01-1",
1151
            "/api/taxonomy/uniprot/344612/set/pfam/Cl0001"
1152
        ]
1153
        for url in urls:
1✔
1154
            response = self.client.get(url)
1✔
1155
            self.assertEqual(response.status_code, status.HTTP_200_OK, f"URL : [{url}]")
1✔
1156
            self._check_taxonomy_details(response.data["metadata"])
1✔
1157
            self.assertIn("sets", response.data)
1✔
1158
            for s in response.data["sets"]:
1✔
1159
                self._check_set_from_searcher(s)
1✔
1160

1161

1162
class TaxonomyPerEntryTest(InterproRESTTestCase):
1✔
1163
    def test_can_get_the_root_per_interpro(self):
1✔
1164
        response = self.client.get("/api/taxonomy/uniprot/1?filter_by_entry=IPR001165")
1✔
1165
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
1166
        self._check_taxonomy_details(response.data["metadata"])
1✔
1167
        self.assertEqual(response.data["metadata"]["counters"]["proteins"], 2)
1✔
1168
        self.assertIsInstance(response.data["children"], dict)
1✔
1169

1170
    def test_can_browse_lineage_with_children_key(self):
1✔
1171
        entries = ["IPR001165", "PF17180", "SM00950"]
1✔
1172
        for entry in entries:
1✔
1173
            tax = "1"
1✔
1174
            lineage = ""
1✔
1175
            payload_lineage = ""
1✔
1176
            while tax != "":
1✔
1177
                lineage += f" {tax}"
1✔
1178
                path = f"/api/taxonomy/uniprot/{tax}?filter_by_entry={entry}"
1✔
1179
                response = self.client.get(path)
1✔
1180
                self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
1181
                children = list(response.data["children"].keys())
1✔
1182
                tax = children[0] if len(children) > 0 else ""
1✔
1183
                payload_lineage = response.data["metadata"]["lineage"]
1✔
1184
            self.assertEqual(payload_lineage.strip(), lineage.strip())
1✔
1185

1186
    def test_error_query(self):
1✔
1187
        response = self.client.get("/api/taxonomy/uniprot/1?filter_by_entry=XXX")
1✔
1188
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
1✔
1189

1190

1191
class TaxonomyPerEntryDBTest(InterproRESTTestCase):
1✔
1192
    def test_can_get_the_root_per_interpro(self):
1✔
1193
        response = self.client.get(
1✔
1194
            "/api/taxonomy/uniprot/1?filter_by_entry_db=interpro"
1195
        )
1196
        self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
1197
        self._check_taxonomy_details(response.data["metadata"])
1✔
1198
        self.assertEqual(response.data["metadata"]["counters"]["entries"], 7)
1✔
1199
        self.assertIsInstance(response.data["children"], dict)
1✔
1200

1201
    def test_can_browse_lineage_with_children_key(self):
1✔
1202
        dbs = ["interpro", "pfam", "profile", "smart"]
1✔
1203
        for db in dbs:
1✔
1204
            tax = "1"
1✔
1205
            lineage = ""
1✔
1206
            payload_lineage = ""
1✔
1207
            while tax != "":
1✔
1208
                lineage += f" {tax}"
1✔
1209
                path = f"/api/taxonomy/uniprot/{tax}?filter_by_entry_db={db}"
1✔
1210
                response = self.client.get(path)
1✔
1211
                self.assertEqual(response.status_code, status.HTTP_200_OK)
1✔
1212
                children = list(response.data["children"].keys())
1✔
1213
                tax = children[0] if len(children) > 0 else ""
1✔
1214
                payload_lineage = response.data["metadata"]["lineage"]
1✔
1215
            self.assertEqual(payload_lineage.strip(), lineage.strip())
1✔
1216

1217
    def test_error_query(self):
1✔
1218
        response = self.client.get("/api/taxonomy/uniprot/1?filter_by_entry_db=XXX")
1✔
1219
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc