diff options
Diffstat (limited to 'test/python/test_search.py')
| -rw-r--r-- | test/python/test_search.py | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/test/python/test_search.py b/test/python/test_search.py index bfd1d38..aea1e20 100644 --- a/test/python/test_search.py +++ b/test/python/test_search.py @@ -49,6 +49,10 @@ class Gn3StubHandler(http.server.BaseHTTPRequestHandler): with open(SEROTONIN_FIXTURE, "rb") as fixture: body = fixture.read() self.send_response(http.client.OK) + elif "alcohol" in query.get("query", [""])[0] and query.get("page") == ["2"]: + # Past the end: an unsorted /search forwards `page` to gn3. + body = b"[]" + self.send_response(http.client.OK) elif "boom" in query.get("query", [""])[0]: body = b'{"error": "gn3 exploded"}' self.send_response(http.client.INTERNAL_SERVER_ERROR) @@ -176,7 +180,7 @@ class SearchTest(ServerTestCase): lods = [hit["lod"] for hit in hits] self.assertEqual(lods, sorted(lods, reverse=True)) for hit in hits: - self.assertAlmostEqual(hit["lod"], hit["lrs"] / 4.61) + self.assertAlmostEqual(hit["lod"], hit["lrs"] / 4.604) male_midbrain = [ hit @@ -189,7 +193,7 @@ class SearchTest(ServerTestCase): if "5-hydroxytryptamine (5-HT, serotonin) level" in hit["description"] ) self.assertEqual(serotonin["name"], "17985") - self.assertAlmostEqual(serotonin["lod"], 2.603, places=3) + self.assertAlmostEqual(serotonin["lod"], 2.6063, places=4) self.assertAlmostEqual(serotonin["additive"], -1.3041, places=4) self.assertEqual(serotonin["geno_chr"], "16") @@ -197,14 +201,16 @@ class SearchTest(ServerTestCase): # has the higher LOD: "serotonin" is ambiguous between the two. top = male_midbrain[0] self.assertEqual(top["name"], "17994") - self.assertAlmostEqual(top["lod"], 3.577, places=3) + self.assertAlmostEqual(top["lod"], 3.5819, places=4) self.assertAlmostEqual(top["additive"], 233.99, places=2) # The peak marker's name comes from PublishXRef (needs a live # MariaDB); without one `locus` is null and the above still holds. + self.assertEqual(serotonin["pubmed_id"], 24102824) if database_reachable(): self.assertEqual(serotonin["locus"], "rsm10000012461") self.assertEqual(top["locus"], "rsm10000013922") + self.assertEqual(serotonin["abbreviation"], "5HT_MB_M") def test_search_orders_ascending(self): self.require_auth() @@ -218,6 +224,32 @@ class SearchTest(ServerTestCase): self.assertEqual(lrs[0], min_lrs) self.assertEqual(lrs, sorted(lrs)) + def test_search_pages(self): + # Unsorted, `page` is forwarded to gn3 (the stub's page 2 is + # empty); sorted, pages come from the ranked list (the recorded + # 119 serotonin hits: 100, then 19, then none). + self.require_auth() + + status, body = self.get("/search?q=alcohol&page=2") + self.assertEqual(status, http.client.OK) + self.assertEqual(body["data"], []) + + sorted_uri = ( + "/search?q=serotonin%20AND%20midbrain%20AND%20group:BXD" + "&sort=lod&limit=100" + ) + _, page1 = self.get(sorted_uri) + _, page2 = self.get(sorted_uri + "&page=2") + _, page3 = self.get(sorted_uri + "&page=3") + self.assertEqual(len(page1["data"]), 100) + self.assertEqual(len(page2["data"]), 19) + self.assertEqual(page3["data"], []) + self.assertGreaterEqual(page1["data"][-1]["lod"], page2["data"][0]["lod"]) + + status, body = self.get("/search?q=alcohol&page=0") + self.assertEqual(status, http.client.BAD_REQUEST) + self.assertIn("page", body["detail"]) + def test_search_forwards_gn3_parse_errors(self): self.require_auth() |
