summaryrefslogtreecommitdiffstats
path: root/tests/test_web.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2021-06-11 15:03:32 -0700
committerBryan Newbold <bnewbold@archive.org>2021-06-11 15:03:32 -0700
commit3bae05c4a4cd7d6d9b892b952b7ca35454319479 (patch)
tree83831f45e209ab208c87c443312323279dff3484 /tests/test_web.py
parent20d6a40ae5450dbec11e8774cc61f1f1abad1ead (diff)
downloadfatcat-scholar-3bae05c4a4cd7d6d9b892b952b7ca35454319479.tar.gz
fatcat-scholar-3bae05c4a4cd7d6d9b892b952b7ca35454319479.zip
update access redirect URL endpoints
Diffstat (limited to 'tests/test_web.py')
-rw-r--r--tests/test_web.py39
1 files changed, 20 insertions, 19 deletions
diff --git a/tests/test_web.py b/tests/test_web.py
index ee11ee6..7da5880 100644
--- a/tests/test_web.py
+++ b/tests/test_web.py
@@ -125,11 +125,8 @@ def test_basic_work_landing_page(client: Any, mocker: Any) -> None:
def test_basic_access_redirect(client: Any, mocker: Any) -> None:
- """
- NOTE: DEPRECATED
- """
- with open("tests/files/elastic_fulltext_search.json") as f:
+ with open("tests/files/elastic_fulltext_get.json") as f:
elastic_resp = json.loads(f.read())
es_raw = mocker.patch(
@@ -141,7 +138,7 @@ def test_basic_access_redirect(client: Any, mocker: Any) -> None:
]
rv = client.get(
- "/access-redirect/f81f84e23c9ba5d364c70f01fa26e645d29c0427.pdf",
+ "/work/2x5qvct2dnhrbctqa2q2uyut6a/access/wayback/https://www.federalreserve.gov/econresdata/feds/2015/files/2015118pap.pdf",
allow_redirects=False,
)
assert rv.status_code == 302
@@ -150,39 +147,43 @@ def test_basic_access_redirect(client: Any, mocker: Any) -> None:
== "https://web.archive.org/web/20200206164725id_/https://www.federalreserve.gov/econresdata/feds/2015/files/2015118pap.pdf"
)
+ # check that URL is validated
rv = client.get(
- "/access-redirect/aaaaaaaaaaaaaaaaaaaaaa01fa26e645d29c0427.pdf",
+ "/work/2x5qvct2dnhrbctqa2q2uyut6a/access/wayback/https://www.federalreserve.gov/econresdata/feds/2015/files/2015118pap.pdf.DUMMY",
allow_redirects=False,
)
assert rv.status_code == 404
-def test_access_redirects(client: Any, mocker: Any) -> None:
+def test_access_redirect_encoding(client: Any, mocker: Any) -> None:
- # tricky "URL encoding in archive.org path" case
- rv = client.get(
- "/access/ia_file/crossref-pre-1909-scholarly-works/10.1016%252Fs0140-6736%252802%252912493-7.zip/10.1016%252Fs0140-6736%252802%252912928-x.pdf",
- allow_redirects=False,
- )
- assert rv.status_code == 302
- assert (
- rv.headers["Location"]
- == "https://archive.org/download/crossref-pre-1909-scholarly-works/10.1016%252Fs0140-6736%252802%252912493-7.zip/10.1016%252Fs0140-6736%252802%252912928-x.pdf"
+ with open("tests/files/elastic_get_work_a6gvpil4brdgzhqyaog3ftngqe.json") as f:
+ elastic_ia_resp = json.loads(f.read())
+ with open("tests/files/elastic_get_work_ao5l3ykgbvg2vfpqe2y5qold5y.json") as f:
+ elastic_wayback_resp = json.loads(f.read())
+
+ es_raw = mocker.patch(
+ "elasticsearch.connection.Urllib3HttpConnection.perform_request"
)
+ es_raw.side_effect = [
+ (200, {}, json.dumps(elastic_ia_resp)),
+ (200, {}, json.dumps(elastic_wayback_resp)),
+ ]
+ # tricky "URL encoding in archive.org path" case
rv = client.get(
- "/access/wayback/20170814015956/https://epub.uni-regensburg.de/21901/1/lorenz73.pdf",
+ "/work/a6gvpil4brdgzhqyaog3ftngqe/access/ia_file/crossref-pre-1909-scholarly-works/10.1016%252Fs0140-6736%252802%252912493-7.zip/10.1016%252Fs0140-6736%252802%252912928-x.pdf",
allow_redirects=False,
)
assert rv.status_code == 302
assert (
rv.headers["Location"]
- == "https://web.archive.org/web/20170814015956id_/https://epub.uni-regensburg.de/21901/1/lorenz73.pdf"
+ == "https://archive.org/download/crossref-pre-1909-scholarly-works/10.1016%252Fs0140-6736%252802%252912493-7.zip/10.1016%252Fs0140-6736%252802%252912928-x.pdf"
)
# spaces ("%20" vs "+")
rv = client.get(
- "/access/wayback/20170811115414/http://sudjms.net/issues/5-4/pdf/8)A%20comparison%20study%20of%20histochemical%20staining%20of%20various%20tissues%20after.pdf",
+ "/work/ao5l3ykgbvg2vfpqe2y5qold5y/access/wayback/http://sudjms.net/issues/5-4/pdf/8)A%20comparison%20study%20of%20histochemical%20staining%20of%20various%20tissues%20after.pdf",
allow_redirects=False,
)
assert rv.status_code == 302