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

ProteinsWebTeam / interpro7-api / 1

18 Jun 2024 09:19AM UTC coverage: 25.541% (-68.5%) from 94.023%
1

push

github

web-flow
Merge pull request #147 from ProteinsWebTeam/set-sortable

sort by in sets

1 of 2 new or added lines in 1 file covered. (50.0%)

6742 existing lines in 50 files now uncovered.

2559 of 10019 relevant lines covered (25.54%)

0.51 hits per line

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

20.74
/webfront/tests/tests_modifiers.py
1
import unittest
2✔
2
import gzip
2✔
3
import json
2✔
4
from webfront.tests.InterproRESTTestCase import InterproRESTTestCase
2✔
5
from rest_framework import status
2✔
6
import ssl
2✔
7

8
ssl._create_default_https_context = ssl._create_unverified_context
2✔
9

10

11
class GroupByModifierTest(InterproRESTTestCase):
2✔
12
    def test_can_get_the_entry_type_groups(self):
2✔
UNCOV
13
        response = self.client.get("/api/entry?group_by=type")
×
UNCOV
14
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
15
        self.assertIn("domain", response.data)
×
UNCOV
16
        self.assertIn("family", response.data)
×
17

18
    def test_can_get_the_entry_type_groups_of_entries_with_proteins(self):
2✔
UNCOV
19
        response = self.client.get("/api/entry/protein?group_by=type")
×
UNCOV
20
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
21
        self.assertIn("domain", response.data)
×
UNCOV
22
        self.assertNotIn("family", response.data)
×
23

24
    def test_can_get_the_entry_type_groups_proteins_by_tax_id(self):
2✔
UNCOV
25
        response = self.client.get("/api/protein?group_by=tax_id")
×
UNCOV
26
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
27
        # Only Mus musculus is a key species
UNCOV
28
        self.assertEqual(
×
29
            {"10090": {"value": 1, "title": "Mus musculus"}}, response.data
30
        )
31

32
    def test_can_group_interpro_entries_with_member_databases(self):
2✔
UNCOV
33
        response = self.client.get("/api/entry/interpro?group_by=member_databases")
×
UNCOV
34
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
35
        self.assertIn("pfam", response.data)
×
UNCOV
36
        self.assertIn("smart", response.data)
×
UNCOV
37
        self.assertIn("profile", response.data)
×
38

39
    def test_wrong_field_for_group_by_should_fail(self):
2✔
UNCOV
40
        self._check_HTTP_response_code(
×
41
            "/api/entry?group_by=entry_type", code=status.HTTP_404_NOT_FOUND
42
        )
43

44
    def test_can_get_the_match_presence_groups(self):
2✔
UNCOV
45
        response = self.client.get("/api/protein?group_by=match_presence")
×
UNCOV
46
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
47
        self.assertIn("match_presence", response.data)
×
UNCOV
48
        self.assertIn("true", response.data["match_presence"])
×
UNCOV
49
        self.assertIn("false", response.data["match_presence"])
×
UNCOV
50
        self.assertEqual(response.data["match_presence"]["true"], 3)
×
UNCOV
51
        self.assertEqual(response.data["match_presence"]["false"], 2)
×
52

53
    def test_can_get_the_fragment_groups(self):
2✔
UNCOV
54
        response = self.client.get("/api/protein?group_by=is_fragment")
×
UNCOV
55
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
56
        self.assertIn("is_fragment", response.data)
×
UNCOV
57
        self.assertIn("true", response.data["is_fragment"])
×
UNCOV
58
        self.assertIn("false", response.data["is_fragment"])
×
UNCOV
59
        self.assertEqual(response.data["is_fragment"]["true"], 1)
×
UNCOV
60
        self.assertEqual(response.data["is_fragment"]["false"], 2)
×
61

62
    def test_can_group_proteomes_by_is_reference(self):
2✔
UNCOV
63
        response = self.client.get(
×
64
            "/api/proteome/uniprot?group_by=proteome_is_reference"
65
        )
UNCOV
66
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
67
        self.assertIn("proteome_is_reference", response.data)
×
UNCOV
68
        self.assertIn("true", response.data["proteome_is_reference"])
×
UNCOV
69
        self.assertIn("false", response.data["proteome_is_reference"])
×
UNCOV
70
        self.assertEqual(response.data["proteome_is_reference"]["true"], 2)
×
UNCOV
71
        self.assertEqual(response.data["proteome_is_reference"]["false"], 1)
×
72

73

74
class FilterByFieldModifierTest(InterproRESTTestCase):
2✔
75
    def test_can_filter_pfam_by_integrated(self):
2✔
UNCOV
76
        acc = "IPR003165"
×
UNCOV
77
        response = self.client.get("/api/entry/pfam?integrated=" + acc)
×
UNCOV
78
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
79
        self.assertIn("count", response.data)
×
UNCOV
80
        self.assertEqual(response.data["count"], 1)
×
UNCOV
81
        self.assertIn("results", response.data)
×
UNCOV
82
        for result in response.data["results"]:
×
UNCOV
83
            self.assertEqual(result["metadata"]["integrated"].lower(), acc.lower())
×
84

85
    def test_fails_filtering_interpro_by_integrated(self):
2✔
UNCOV
86
        self._check_HTTP_response_code(
×
87
            "/api/entry/interpro?integrated=IPR003165", code=status.HTTP_204_NO_CONTENT
88
        )
89

90
    def test_can_filter_smart_by_type(self):
2✔
UNCOV
91
        entry_types = ["family", "domain"]
×
UNCOV
92
        for entry_type in entry_types:
×
UNCOV
93
            response = self.client.get("/api/entry/smart?type=" + entry_type)
×
UNCOV
94
            self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
95
            self.assertIn("count", response.data)
×
UNCOV
96
            self.assertEqual(response.data["count"], 1)
×
UNCOV
97
            self.assertIn("results", response.data)
×
UNCOV
98
            for result in response.data["results"]:
×
UNCOV
99
                self.assertEqual(result["metadata"]["type"], entry_type)
×
100

101
    def test_can_filter_proteins_by_match_presence(self):
2✔
UNCOV
102
        options = ["true", "false"]
×
UNCOV
103
        for option in options:
×
UNCOV
104
            response = self.client.get(
×
105
                "/api/protein/uniprot?extra_fields=counters&match_presence=" + option
106
            )
UNCOV
107
            self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
108
            self.assertIn("results", response.data)
×
UNCOV
109
            for result in response.data["results"]:
×
UNCOV
110
                entries = result["extra_fields"]["counters"]["entries"]
×
UNCOV
111
                if option == "true":
×
UNCOV
112
                    self.assertGreater(entries, 0)
×
113
                else:
UNCOV
114
                    self.assertEqual(entries, 0)
×
115

116
    def test_can_filter_proteins_by_is_fragment(self):
2✔
UNCOV
117
        urls = ["protein/uniprot", "protein/uniprot/entry"]
×
UNCOV
118
        for url in urls:
×
UNCOV
119
            options = [True, False]
×
UNCOV
120
            for option in options:
×
UNCOV
121
                response = self.client.get(
×
122
                    "/api/{}?extra_fields=is_fragment&is_fragment={}".format(
123
                        url, option
124
                    )
125
                )
UNCOV
126
                self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
127
                self.assertIn("results", response.data)
×
UNCOV
128
                for result in response.data["results"]:
×
UNCOV
129
                    is_fragment = result["extra_fields"]["is_fragment"]
×
UNCOV
130
                    self.assertEqual(is_fragment, option)
×
131

132

133
class FilterByContainsFieldModifierTest(InterproRESTTestCase):
2✔
134
    def test_can_filter_pfam_by_signature_in(self):
2✔
UNCOV
135
        db = "pfam"
×
UNCOV
136
        response = self.client.get("/api/entry/interpro?signature_in=" + db)
×
UNCOV
137
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
138
        self.assertIn("count", response.data)
×
UNCOV
139
        self.assertEqual(response.data["count"], 1)
×
UNCOV
140
        self.assertIn("results", response.data)
×
UNCOV
141
        for result in response.data["results"]:
×
UNCOV
142
            self.assertIn(db, result["metadata"]["member_databases"])
×
143

144

145
@unittest.skip
2✔
146
class SortByModifierTest(InterproRESTTestCase):
2✔
147
    def test_can_sort_pfam_by_accession(self):
2✔
148
        response = self.client.get("/api/entry/pfam?sort_by=accession")
×
149
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
150
        self.assertIn("results", response.data)
×
151
        payload_accs = [r["metadata"]["accession"] for r in response.data["results"]]
×
152
        self.assertEqual(payload_accs, sorted(payload_accs))
×
153

154
    def test_can_sort_pfam_by_integrated_and_reverse_sorting(self):
2✔
155
        response = self.client.get("/api/entry/pfam?sort_by=integrated")
×
156
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
157
        self.assertIn("results", response.data)
×
158
        payload_accs = [r["metadata"]["integrated"] for r in response.data["results"]]
×
159
        response = self.client.get("/api/entry/pfam?sort_by=-integrated")
×
160
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
161
        self.assertIn("results", response.data)
×
162
        payload_accs_rev = [
×
163
            r["metadata"]["integrated"] for r in response.data["results"]
164
        ]
165
        self.assertEqual(payload_accs_rev, list(reversed(payload_accs)))
×
166

167

168
class InterProStatusModifierTest(InterproRESTTestCase):
2✔
169
    def test_can_apply_interpro_status(self):
2✔
UNCOV
170
        mdbs = ["profile", "smart", "pfam"]
×
UNCOV
171
        for db in mdbs:
×
UNCOV
172
            response = self.client.get("/api/entry/" + db)
×
UNCOV
173
            self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
174
            self.assertIn("results", response.data)
×
UNCOV
175
            unintegrated = len(
×
176
                [
177
                    r["metadata"]["integrated"]
178
                    for r in response.data["results"]
179
                    if r["metadata"]["integrated"] is None
180
                ]
181
            )
UNCOV
182
            response2 = self.client.get("/api/entry/" + db + "?interpro_status")
×
UNCOV
183
            self.assertEqual(response2.status_code, status.HTTP_200_OK)
×
UNCOV
184
            self.assertEqual(response2.data["unintegrated"], unintegrated)
×
UNCOV
185
            self.assertEqual(
×
186
                response2.data["integrated"],
187
                len(response.data["results"]) - unintegrated,
188
            )
189

190

191
class IDAModifiersTest(InterproRESTTestCase):
2✔
192
    def test_ida_modifier(self):
2✔
UNCOV
193
        response = self.client.get("/api/entry/interpro/IPR001165?ida")
×
UNCOV
194
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
195
        self.assertIn("results", response.data)
×
UNCOV
196
        self.assertIn("count", response.data)
×
UNCOV
197
        self.assertEqual(response.data["count"], len(response.data["results"]))
×
198

199
    def test_filter_by_ida_modifier(self):
2✔
UNCOV
200
        response = self.client.get("/api/protein/uniprot?ida=50134")
×
UNCOV
201
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
202
        self.assertIn("results", response.data)
×
UNCOV
203
        self.assertIn("count", response.data)
×
UNCOV
204
        self.assertEqual(response.data["count"], 1)
×
UNCOV
205
        self.assertEqual(
×
206
            "a1cuj5", response.data["results"][0]["metadata"]["accession"].lower()
207
        )
208

209

210
class ExtraFieldsModifierTest(InterproRESTTestCase):
2✔
211
    fields = {
2✔
212
        "entry": [
213
            "entry_id",
214
            "accession",
215
            "type",
216
            "name",
217
            "short_name",
218
            "source_database",
219
            "member_databases",
220
            "go_terms",
221
            "description",
222
            "wikipedia",
223
            "literature",
224
            "hierarchy",
225
            "cross_references",
226
            "entry_date",
227
        ],
228
        "protein": [
229
            "accession",
230
            "identifier",
231
            "organism",
232
            "name",
233
            "description",
234
            "sequence",
235
            "length",
236
            "proteome",
237
            "gene",
238
            "go_terms",
239
            "evidence_code",
240
            "source_database",
241
            "structure",
242
            "is_fragment",
243
            "tax_id",
244
        ],
245
        "structure": [
246
            "accession",
247
            "name",
248
            "experiment_type",
249
            "release_date",
250
            "literature",
251
            "chains",
252
            "source_database",
253
            "resolution",
254
        ],
255
        "taxonomy": [
256
            "accession",
257
            "scientific_name",
258
            "full_name",
259
            "lineage",
260
            "rank",
261
            "children",
262
        ],
263
        "proteome": ["accession", "strain", "is_reference", "assembly"],
264
        "set": ["accession", "name", "description", "source_database", "relationships"],
265
    }
266
    list_url = {
2✔
267
        "entry": "/entry/interpro",
268
        "protein": "/protein/uniprot",
269
        "structure": "/structure/pdb",
270
        "taxonomy": "/taxonomy/uniprot",
271
        "proteome": "/proteome/uniprot",
272
        "set": "/set/pfam",
273
    }
274

275
    def test_extra_fields(self):
2✔
UNCOV
276
        for endpoint in self.fields:
×
UNCOV
277
            for field in self.fields[endpoint]:
×
UNCOV
278
                url = "/api{}?extra_fields={}".format(self.list_url[endpoint], field)
×
UNCOV
279
                response = self.client.get(url)
×
UNCOV
280
                self.assertEqual(response.status_code, status.HTTP_200_OK, url)
×
UNCOV
281
                self.assertIn("results", response.data)
×
UNCOV
282
                for result in response.data["results"]:
×
UNCOV
283
                    self.assertIn("extra_fields", result)
×
UNCOV
284
                    self.assertIn(field, result["extra_fields"])
×
UNCOV
285
            url = "/api{}?extra_fields=ERROR".format(self.list_url[endpoint])
×
UNCOV
286
            response = self.client.get(url)
×
UNCOV
287
            self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
×
288

289
    def test_extra_fields_together(self):
2✔
UNCOV
290
        for endpoint in self.fields:
×
UNCOV
291
            url = "/api{}?extra_fields={}".format(
×
292
                self.list_url[endpoint], ",".join(self.fields[endpoint])
293
            )
UNCOV
294
            response = self.client.get(url)
×
UNCOV
295
            self.assertEqual(response.status_code, status.HTTP_200_OK, url)
×
UNCOV
296
            self.assertIn("results", response.data)
×
UNCOV
297
            for field in self.fields[endpoint]:
×
UNCOV
298
                for result in response.data["results"]:
×
UNCOV
299
                    self.assertIn("extra_fields", result)
×
UNCOV
300
                    self.assertIn(field, result["extra_fields"])
×
UNCOV
301
            url = "/api{}?extra_fields=name,ERROR".format(self.list_url[endpoint])
×
UNCOV
302
            response = self.client.get(url)
×
UNCOV
303
            self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
×
304

305
    def test_extra_fields_with_other_endpoint(self):
2✔
UNCOV
306
        for endpoint in self.fields:
×
UNCOV
307
            other_ep = [ep for ep in self.fields if ep != endpoint]
×
UNCOV
308
            for ep in other_ep:
×
UNCOV
309
                for field in self.fields[endpoint]:
×
UNCOV
310
                    url = "/api{}/{}?extra_fields={}".format(
×
311
                        self.list_url[endpoint], ep, field
312
                    )
UNCOV
313
                    response = self.client.get(url)
×
UNCOV
314
                    if response.status_code == status.HTTP_200_OK:
×
UNCOV
315
                        self.assertIn("results", response.data)
×
UNCOV
316
                        for result in response.data["results"]:
×
UNCOV
317
                            self.assertIn("extra_fields", result)
×
UNCOV
318
                            self.assertIn(field, result["extra_fields"])
×
319
                    else:
UNCOV
320
                        self.assertEqual(
×
321
                            response.status_code, status.HTTP_204_NO_CONTENT
322
                        )
UNCOV
323
                url = "/api{}/{}?extra_fields=name,ERROR".format(
×
324
                    self.list_url[endpoint], ep
325
                )
UNCOV
326
                response = self.client.get(url)
×
UNCOV
327
                self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
×
328

329
    accession = {
2✔
330
        "entry": "IPR003165",
331
        "protein": "a1cuj5",
332
        "structure": "1jm7",
333
        "taxonomy": "2579",
334
        "proteome": "up000006701",
335
        "set": "cl0001",
336
    }
337

338
    def test_counters_as_extra_fields(self):
2✔
UNCOV
339
        for endpoint1, path1 in self.list_url.items():
×
UNCOV
340
            for endpoint2, path2 in self.list_url.items():
×
UNCOV
341
                if endpoint1 == endpoint2:
×
UNCOV
342
                    continue
×
UNCOV
343
                url = f"/api{path1}{path2}/{self.accession[endpoint2]}?extra_fields=counters"
×
UNCOV
344
                response = self.client.get(url)
×
UNCOV
345
                if response.status_code == status.HTTP_200_OK:
×
UNCOV
346
                    self.assertIn("results", response.data)
×
UNCOV
347
                    for result in response.data["results"]:
×
UNCOV
348
                        self.assertIn("extra_fields", result)
×
UNCOV
349
                        self.assertIn("counters", result["extra_fields"])
×
UNCOV
350
                        self.assertGreater(
×
351
                            len(result["extra_fields"]["counters"].keys()), 1
352
                        )
353
                else:
UNCOV
354
                    self.assertEqual(
×
355
                        response.status_code,
356
                        status.HTTP_204_NO_CONTENT,
357
                        f"ERROR CODE [{response.status_code}]: {url}",
358
                    )
359

360
    def test_granular_counters_as_extra_fields(self):
2✔
UNCOV
361
        counters_to_ask = [
×
362
            ["entry"],
363
            ["protein"],
364
            ["entry", "protein"],
365
        ]
UNCOV
366
        for endpoint1, path1 in self.list_url.items():
×
UNCOV
367
            for endpoint2, path2 in self.list_url.items():
×
UNCOV
368
                for counters in counters_to_ask:
×
UNCOV
369
                    if (
×
370
                        endpoint1 == endpoint2
371
                        or endpoint1 in counters
372
                        or endpoint2 in counters
373
                    ):
UNCOV
374
                        continue
×
UNCOV
375
                    url = f"/api{path1}{path2}/{self.accession[endpoint2]}?extra_fields=counters:{'-'.join(counters)}"
×
UNCOV
376
                    response = self.client.get(url)
×
UNCOV
377
                    if response.status_code == status.HTTP_200_OK:
×
UNCOV
378
                        self.assertIn("results", response.data)
×
UNCOV
379
                        for result in response.data["results"]:
×
UNCOV
380
                            self.assertIn("extra_fields", result)
×
UNCOV
381
                            self.assertIn("counters", result["extra_fields"])
×
382
                            # It should be equal to the counters requested
UNCOV
383
                            self.assertEqual(
×
384
                                len(result["extra_fields"]["counters"].keys()),
385
                                len(counters),
386
                            )
387
                    else:
UNCOV
388
                        self.assertEqual(
×
389
                            response.status_code,
390
                            status.HTTP_204_NO_CONTENT,
391
                            f"ERROR CODE [{response.status_code}]: {url}",
392
                        )
393

394

395
class ExtraFeaturesModifierTest(InterproRESTTestCase):
2✔
396
    def test_extra_features_modifier_is_different_than_acc_protein(self):
2✔
UNCOV
397
        response1 = self.client.get("/api/protein/uniprot/a1cuj5")
×
UNCOV
398
        self.assertEqual(response1.status_code, status.HTTP_200_OK)
×
UNCOV
399
        response2 = self.client.get("/api/protein/uniprot/a1cuj5?extra_features")
×
UNCOV
400
        self.assertEqual(response2.status_code, status.HTTP_200_OK)
×
UNCOV
401
        self.assertNotEquals(response1.data, response2.data)
×
402

403
    def test_extra_features_modifier(self):
2✔
UNCOV
404
        response2 = self.client.get("/api/protein/uniprot/a1cuj5?extra_features")
×
UNCOV
405
        self.assertEqual(response2.status_code, status.HTTP_200_OK)
×
UNCOV
406
        self.assertIn("TMhelix", response2.data)
×
UNCOV
407
        self.assertIn("locations", response2.data["TMhelix"])
×
408

409

410
class IsoformsModifiersTest(InterproRESTTestCase):
2✔
411
    def test_isoform_modifier(self):
2✔
UNCOV
412
        response = self.client.get("/api/protein/uniprot/a1cuj5?isoforms")
×
UNCOV
413
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
414
        self.assertIn("results", response.data)
×
UNCOV
415
        self.assertIn("count", response.data)
×
UNCOV
416
        self.assertEqual(response.data["count"], len(response.data["results"]))
×
UNCOV
417
        self.assertGreater(response.data["count"], 0)
×
418

419
    def test_isoform_detail_modifier(self):
2✔
UNCOV
420
        response = self.client.get("/api/protein/uniprot/a1cuj5?isoforms=a1cuj5-2")
×
UNCOV
421
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
422
        self.assertIn("accession", response.data)
×
UNCOV
423
        self.assertIn("features", response.data)
×
424

425
    def test_isoform_detail_wrong_acc_modifier(self):
2✔
UNCOV
426
        response = self.client.get("/api/protein/uniprot/a1cuj5?isoforms=wrong")
×
UNCOV
427
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
×
428

429

430
class LatestEntriesModifiersTest(InterproRESTTestCase):
2✔
431
    def test_can_read_entry_interpro_new_entries(self):
2✔
UNCOV
432
        response = self.client.get("/api/entry/interpro?latest_entries")
×
UNCOV
433
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
434
        self.assertEqual(len(response.data["results"]), 1)
×
UNCOV
435
        self._check_is_list_of_objects_with_key(response.data["results"], "metadata")
×
UNCOV
436
        self.assertEqual(
×
437
            response.data["results"][0]["metadata"]["accession"], "IPR003165"
438
        )
439

440

441
class EntryAnnotationModifiersTest(InterproRESTTestCase):
2✔
442
    def test_annotation_modifier_hmm(self):
2✔
UNCOV
443
        response = self.client.get("/api/entry/pfam/pf02171?annotation=hmm")
×
UNCOV
444
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
445
        self.assertEqual(response["content-type"], "application/gzip")
×
446

447
    def test_annotation_modifier_logo(self):
2✔
UNCOV
448
        response = self.client.get("/api/entry/pfam/pf02171?annotation=logo")
×
UNCOV
449
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
450
        self.assertEqual(response["content-type"], "application/json")
×
UNCOV
451
        data = json.loads(response.content)
×
UNCOV
452
        self.assertIn("ali_map", data)
×
UNCOV
453
        self.assertEqual(302, len(data["ali_map"]))
×
454

455
    def test_annotation_modifier_pfam_alignment(self):
2✔
UNCOV
456
        response = self.client.get("/api/entry/pfam/pf02171?annotation=alignment:seed")
×
UNCOV
457
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
458
        self.assertEqual(response["content-type"], "text/plain")
×
459

460
    def test_annotation_modifier_interpro_alignment(self):
2✔
UNCOV
461
        response = self.client.get(
×
462
            "/api/entry/interpro/ipr003165?annotation=alignment:seed"
463
        )
UNCOV
464
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
465
        self.assertEqual(response["content-type"], "text/plain")
×
466

467
    # TODO This test should fail but doesn't
468
    # def test_annotation_wrong_acc_modifier(self):
469
    #     response = self.client.get("/api/entry/pfam/pf00001?annotation=hmm")
470
    #     self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
471

472

473
class ValueForFieldModifiersTest(InterproRESTTestCase):
2✔
474
    def test_interactions_modifier(self):
2✔
UNCOV
475
        response = self.client.get("/api/entry/interpro/IPR001165?interactions")
×
UNCOV
476
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
477
        self.assertIn("interactions", response.data)
×
UNCOV
478
        self.assertIsInstance(response.data["interactions"], list)
×
UNCOV
479
        self.assertEqual(1, len(response.data["interactions"]))
×
480

481
    def test_no_interactions_modifier(self):
2✔
UNCOV
482
        response = self.client.get("/api/entry/interpro/IPR003165?interactions")
×
UNCOV
483
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
×
484

485
    def test_pathways_modifier(self):
2✔
UNCOV
486
        response = self.client.get("/api/entry/interpro/IPR001165?pathways")
×
UNCOV
487
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
488
        self.assertIn("pathways", response.data)
×
UNCOV
489
        self.assertIsInstance(response.data["pathways"], object)
×
UNCOV
490
        self.assertIn("reactome", response.data["pathways"])
×
UNCOV
491
        self.assertEqual(2, len(response.data["pathways"]["reactome"]))
×
492

493
    def test_no_pathways_modifier(self):
2✔
UNCOV
494
        response = self.client.get("/api/entry/interpro/IPR003165?pathways")
×
UNCOV
495
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
×
496

497
    def test_taxa_modifier(self):
2✔
UNCOV
498
        response = self.client.get("/api/entry/interpro/IPR003165?taxa")
×
UNCOV
499
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
500
        self.assertIn("taxa", response.data)
×
UNCOV
501
        self.assertIsInstance(response.data["taxa"], object)
×
UNCOV
502
        self.assertIn("children", response.data["taxa"])
×
UNCOV
503
        self.assertEqual(1, len(response.data["taxa"]["children"]))
×
504

505
    def test_no_taxa_modifier(self):
2✔
UNCOV
506
        response = self.client.get("/api/entry/interpro/IPR001165?taxa")
×
UNCOV
507
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
×
508

509

510
class TaxonomyScientificNameModifierTest(InterproRESTTestCase):
2✔
511
    def test_scientific_name_modifier(self):
2✔
UNCOV
512
        response = self.client.get("/api/taxonomy/uniprot/?scientific_name=Bacteria")
×
UNCOV
513
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
514
        self.assertIn("metadata", response.data)
×
UNCOV
515
        self.assertIn("accession", response.data["metadata"])
×
UNCOV
516
        self.assertIn("counters", response.data["metadata"])
×
UNCOV
517
        self.assertEqual("2", response.data["metadata"]["accession"])
×
UNCOV
518
        self.assertEqual(2, response.data["metadata"]["counters"]["entries"])
×
UNCOV
519
        self.assertEqual(2, response.data["metadata"]["counters"]["proteins"])
×
520

521
    def test_scientific_name_modifier_member_database_filter(self):
2✔
UNCOV
522
        response = self.client.get(
×
523
            "/api/taxonomy/uniprot/entry/interpro?scientific_name=Bacteria"
524
        )
UNCOV
525
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
526
        self.assertIn("metadata", response.data)
×
UNCOV
527
        self.assertIn("accession", response.data["metadata"])
×
UNCOV
528
        self.assertIn("counters", response.data["metadata"])
×
UNCOV
529
        self.assertEqual("2", response.data["metadata"]["accession"])
×
UNCOV
530
        self.assertEqual(5, response.data["metadata"]["counters"]["entries"])
×
UNCOV
531
        self.assertEqual(10, response.data["metadata"]["counters"]["proteins"])
×
532

533

534
class ResidueModifierTest(InterproRESTTestCase):
2✔
535
    def test_residue_modifier_is_different_than_acc_protein(self):
2✔
UNCOV
536
        response1 = self.client.get("/api/protein/uniprot/a1cuj5")
×
UNCOV
537
        self.assertEqual(response1.status_code, status.HTTP_200_OK)
×
UNCOV
538
        response2 = self.client.get("/api/protein/uniprot/a1cuj5?residues")
×
UNCOV
539
        self.assertEqual(response2.status_code, status.HTTP_200_OK)
×
UNCOV
540
        self.assertNotEquals(response1.data, response2.data)
×
541

542
    def test_residue_modifier(self):
2✔
UNCOV
543
        response2 = self.client.get("/api/protein/uniprot/a1cuj5?residues")
×
UNCOV
544
        self.assertEqual(response2.status_code, status.HTTP_200_OK)
×
UNCOV
545
        self.assertIn("residue", response2.data)
×
UNCOV
546
        self.assertIn("locations", response2.data["residue"])
×
547

548

549
class StructuralModelTest(InterproRESTTestCase):
2✔
550
    def test_model_structure_modifier(self):
2✔
UNCOV
551
        response = self.client.get("/api/entry/pfam/PF17176?model:structure")
×
UNCOV
552
        self.assertEqual(response.status_code, status.HTTP_410_GONE)
×
553

554
    def test_model_contacts_modifier(self):
2✔
UNCOV
555
        response = self.client.get("/api/entry/pfam/PF17176?model:contacts")
×
UNCOV
556
        self.assertEqual(response.status_code, status.HTTP_410_GONE)
×
557

558
    def test_model_lddt_modifier(self):
2✔
UNCOV
559
        response = self.client.get("/api/entry/pfam/PF17176?model:lddt")
×
UNCOV
560
        self.assertEqual(response.status_code, status.HTTP_410_GONE)
×
561

562

563
class SubfamiliesTest(InterproRESTTestCase):
2✔
564
    entries = [
2✔
565
        {"db": "panther", "acc": "PTHR43214", "sf": "PTHR43214:sf24"},
566
        {"db": "cathgene3d", "acc": "G3DSA:1.10.10.10", "sf": "G3DSA:1.10.10.10:1"},
567
    ]
568

569
    def test_subfamilies_counter(self):
2✔
UNCOV
570
        for entry in self.entries:
×
UNCOV
571
            response = self.client.get(f"/api/entry/{entry['db']}/{entry['acc']}")
×
UNCOV
572
            self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
573
            self.assertIn("counters", response.data["metadata"])
×
UNCOV
574
            self.assertEqual(response.data["metadata"]["counters"]["subfamilies"], 1)
×
575

576
    def test_panther_subfamilies(self):
2✔
UNCOV
577
        for entry in self.entries:
×
UNCOV
578
            response = self.client.get(
×
579
                f"/api/entry/{entry['db']}/{entry['acc']}?subfamilies"
580
            )
UNCOV
581
            self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
582
            self.assertEqual(len(response.data["results"]), 1)
×
UNCOV
583
            self.assertEqual(
×
584
                response.data["results"][0]["metadata"]["accession"], entry["sf"]
585
            )
UNCOV
586
            self.assertEqual(
×
587
                response.data["results"][0]["metadata"]["integrated"], entry["acc"]
588
            )
589

590
    def test_no_subfamilies_in_pfam(self):
2✔
UNCOV
591
        response = self.client.get(f"/api/entry/pfam/PF02171")
×
UNCOV
592
        self.assertEqual(response.status_code, status.HTTP_200_OK)
×
UNCOV
593
        self.assertIn("counters", response.data["metadata"])
×
UNCOV
594
        self.assertNotIn("subfamilies", response.data["metadata"]["counters"])
×
UNCOV
595
        response2 = self.client.get(f"/api/entry/pfam/PF02171?subfamilies")
×
UNCOV
596
        self.assertEqual(response2.status_code, status.HTTP_204_NO_CONTENT)
×
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

© 2026 Coveralls, Inc