Ejemplo n.º 1
0
def test_isbnx(monkeypatch):
    site = mock_infobase.MockSite()
    site.save({
        "key": "/books/OL1M",
        "type": {"key": "/type/edition"},
        "isbn_10": ["123456789X"]
    })

    monkeypatch.setattr(web.ctx, "site", site, raising=False)
    json = dynlinks.dynlinks(["isbn:123456789X"], {"format": "json"})
    d = simplejson.loads(json)
    assert d.keys() == ["isbn:123456789X"]
Ejemplo n.º 2
0
def test_dynlinks_ia(monkeypatch):
    monkeypatch_ol(monkeypatch)

    expected_result = {
        "OL2M": {
            "bib_key": "OL2M",
            "info_url": "https://openlibrary.org/books/OL2M/bar",
            "preview": "full",
            "preview_url": "https://archive.org/details/ia-bar"
        }
    }
    json = dynlinks.dynlinks(["OL2M"], {"format": "json"})
    assert simplejson.loads(json) == expected_result
Ejemplo n.º 3
0
def test_dynlinks(monkeypatch):
    monkeypatch_ol(monkeypatch)

    expected_result = {
        "isbn:1234567890": {
            "bib_key": "isbn:1234567890",
            "info_url": "https://openlibrary.org/books/OL1M/foo",
            "preview": "noview",
            "preview_url": "https://openlibrary.org/books/OL1M/foo"
        }
    }

    js = dynlinks.dynlinks(["isbn:1234567890"], {})
    match = re.match('^var _OLBookInfo = ({.*});$', js)
    assert match is not None
    assert simplejson.loads(match.group(1)) == expected_result

    js = dynlinks.dynlinks(["isbn:1234567890"], {"callback": "func"})
    match = re.match('^({.*})$', js)
    assert match is not None
    assert simplejson.loads(match.group(1)) == expected_result

    js = dynlinks.dynlinks(["isbn:1234567890"], {"format": "json"})
    assert simplejson.loads(js) == expected_result
Ejemplo n.º 4
0
def test_dynlinks_details(monkeypatch):
    monkeypatch_ol(monkeypatch)

    expected_result = {
        "OL2M": {
            "bib_key": "OL2M",
            "info_url": "https://openlibrary.org/books/OL2M/bar",
            "preview": "full",
            "preview_url": "https://archive.org/details/ia-bar",
            "details": {
                "key": "/books/OL2M",
                "title": "bar",
                "ocaid": "ia-bar"
            },
        },
    }
    json_data = dynlinks.dynlinks(["OL2M"], {
        "format": "json",
        "details": "true"
    })
    assert json.loads(json_data) == expected_result
Ejemplo n.º 5
0
 def GET(self):
     i = web.input(bibkeys='', callback=None, details="false")
     if web.ctx.path.endswith('.json'):
         i.format = 'json'
     return dynlinks.dynlinks(i.bibkeys.split(","), i)