Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion openlibrary/plugins/upstream/addbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io
import logging
import re
import urllib
import urllib.parse
from typing import TYPE_CHECKING, Literal, NoReturn, overload

import web
Expand Down Expand Up @@ -967,6 +967,10 @@ def GET(self, key):
if not page:
raise web.notfound()

if page.ocaid:
ia_item_url = f"https://archive.org/details/{urllib.parse.quote(page.ocaid, safe='')}"
raise web.seeother(ia_item_url)

return render_template("books/daisy", page)


Expand Down
50 changes: 50 additions & 0 deletions openlibrary/plugins/upstream/tests/test_addbook.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""py.test tests for addbook"""

import pytest
import web

from openlibrary import accounts
Expand Down Expand Up @@ -489,6 +490,55 @@ def test_moving_edition_to_new_work_copy_when_none(self, monkeypatch):
assert not new_work.subjects


class TestDaisyPage:
def setup_method(self, method):
web.ctx.site = MockSite()

def test_redirects_to_archive_item_for_edition_with_ocaid(self, monkeypatch):
web.ctx.site.save(
{
"type": {"key": "/type/edition"},
"key": "/books/OL1M",
"title": "Accessible Book",
"ocaid": "testitem00archive",
}
)

redirects = []

def seeother(url):
redirects.append(url)
raise RuntimeError("redirect")

monkeypatch.setattr(addbook.web, "seeother", seeother)

with pytest.raises(RuntimeError, match="redirect"):
addbook.daisy().GET("/books/OL1M")
assert redirects == ["https://archive.org/details/testitem00archive"]

def test_redirect_escapes_archive_item_identifier(self, monkeypatch):
web.ctx.site.save(
{
"type": {"key": "/type/edition"},
"key": "/books/OL1M",
"title": "Accessible Book",
"ocaid": "test item/archive",
}
)

redirects = []

def seeother(url):
redirects.append(url)
raise RuntimeError("redirect")

monkeypatch.setattr(addbook.web, "seeother", seeother)

with pytest.raises(RuntimeError, match="redirect"):
addbook.daisy().GET("/books/OL1M")
assert redirects == ["https://archive.org/details/test%20item%2Farchive"]


class TestMakeWork:
def test_make_author_adds_the_correct_key(self):
author_key = "OL123A"
Expand Down