aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_web.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2021-04-27 20:53:24 -0700
committerBryan Newbold <bnewbold@archive.org>2021-04-27 20:53:26 -0700
commit9907d45e4f54fe70e8e062f47f75197a3ae1b58e (patch)
treed5654721d401a9b96e7ce803b0039e0d140b1cb4 /tests/test_web.py
parente35e99bceff3277afaac8f2d5519aa4f07aabe49 (diff)
downloadfatcat-scholar-9907d45e4f54fe70e8e062f47f75197a3ae1b58e.tar.gz
fatcat-scholar-9907d45e4f54fe70e8e062f47f75197a3ae1b58e.zip
iterate on access redirects and landing page implementation
Small code refactors and minimal test coverage
Diffstat (limited to 'tests/test_web.py')
-rw-r--r--tests/test_web.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/test_web.py b/tests/test_web.py
index df8b832..6c6632d 100644
--- a/tests/test_web.py
+++ b/tests/test_web.py
@@ -101,3 +101,43 @@ def test_basic_search(client: Any, mocker: Any) -> None:
rv = client.get("/zh/search?q=blood")
assert rv.status_code == 200
+
+def test_basic_work_landing_page(client: Any, mocker: Any) -> None:
+
+ with open("tests/files/elastic_fulltext_get.json") as f:
+ elastic_resp = json.loads(f.read())
+
+ es_raw = mocker.patch(
+ "elasticsearch.connection.Urllib3HttpConnection.perform_request"
+ )
+ es_raw.side_effect = [
+ (200, {}, json.dumps(elastic_resp)),
+ (200, {}, json.dumps(elastic_resp)),
+ ]
+
+ rv = client.get("/work/2x5qvct2dnhrbctqa2q2uyut6a")
+ assert rv.status_code == 200
+ assert b"citation_pdf_url" in rv.content
+
+ rv = client.get("/zh/work/2x5qvct2dnhrbctqa2q2uyut6a")
+ assert rv.status_code == 200
+
+def test_basic_access_redirect(client: Any, mocker: Any) -> None:
+
+ with open("tests/files/elastic_fulltext_search.json") as f:
+ elastic_resp = json.loads(f.read())
+
+ es_raw = mocker.patch(
+ "elasticsearch.connection.Urllib3HttpConnection.perform_request"
+ )
+ es_raw.side_effect = [
+ (200, {}, json.dumps(elastic_resp)),
+ (200, {}, json.dumps(elastic_resp)),
+ ]
+
+ rv = client.get("/access-redirect/f81f84e23c9ba5d364c70f01fa26e645d29c0427.pdf", allow_redirects=False)
+ assert rv.status_code == 302
+ assert rv.headers['Location'] == "https://web.archive.org/web/20200206164725id_/https://www.federalreserve.gov/econresdata/feds/2015/files/2015118pap.pdf"
+
+ rv = client.get("/access-redirect/aaaaaaaaaaaaaaaaaaaaaa01fa26e645d29c0427.pdf", allow_redirects=False)
+ assert rv.status_code == 404