Skip to content

Commit

Permalink
Support generating VS book reader URLs when start is a page number
Browse files Browse the repository at this point in the history
Support vitalsource:// URLs with the start location specified as a page number
rather than a CFI in `get_book_reader_url`.

I have confirmed with VS [1] that we can rely on the `/page/{number}` launch
URL.

[1] https://vitalsource.slack.com/archives/C01208U1A2F/p1700227038259109
  • Loading branch information
robertknight committed Nov 28, 2023
1 parent 25dd242 commit 88107e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lms/services/vitalsource/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,13 @@ def get_book_reader_url(cls, document_url) -> str:
:param document_url: `vitalsource://` type URL identifying the document
"""
loc = VSBookLocation.from_document_url(document_url)
prefix = f"https://hypothesis.vitalsource.com/books/{loc.book_id}"

return f"https://hypothesis.vitalsource.com/books/{loc.book_id}/cfi/{loc.cfi}"
if loc.cfi:
return f"{prefix}/cfi/{loc.cfi}"
if loc.page:
return f"{prefix}/page/{loc.page}"
return prefix # pragma: nocover

def get_sso_redirect(self, document_url, user_reference: str) -> str:
"""
Expand Down
20 changes: 16 additions & 4 deletions tests/unit/lms/services/vitalsource/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,22 @@ def test_sso_enabled(self, enabled, customer_client, user_lti_param):

assert svc.sso_enabled == bool(enabled and customer_client and user_lti_param)

def test_get_book_reader_url(self, svc):
url = svc.get_book_reader_url("vitalsource://book/bookID/BOOK-ID/cfi/CFI")

assert url == "https://hypothesis.vitalsource.com/books/BOOK-ID/cfi/CFI"
@pytest.mark.parametrize(
"doc_url,reader_url",
[
(
"vitalsource://book/bookID/BOOK-ID/cfi/CFI",
"https://hypothesis.vitalsource.com/books/BOOK-ID/cfi/CFI",
),
(
"vitalsource://book/bookID/BOOK-ID/page/42",
"https://hypothesis.vitalsource.com/books/BOOK-ID/page/42",
),
],
)
def test_get_book_reader_url(self, svc, doc_url, reader_url):
url = svc.get_book_reader_url(doc_url)
assert url == reader_url

def test_get_sso_redirect(self, svc, customer_client):
result = svc.get_sso_redirect(
Expand Down

0 comments on commit 88107e1

Please sign in to comment.