Commit 4620a2ee authored by Patrick van der Leer's avatar Patrick van der Leer
Browse files

Refs #14 - attempt at adding cache to the google lookup and between containers

parent 1153a5c1
Pipeline #319 passed with stage
in 6 minutes and 29 seconds
......@@ -9,6 +9,10 @@ before_script:
- pip install tox
# - pip install -r requirements-test.txt
cache:
paths:
- tests/sources/cache
python35:
image: python:3.5
stage: test
......
import json
import httplib2
from googleapiclient.discovery import build, Resource
from googleapiclient.http import HttpMockSequence
from eBookHub import cache
from eBookHub.parser.exceptions import NoResultsException
......@@ -15,34 +13,22 @@ class GoogleBooksClient(SourceAbstract):
def init_app(self, app=None):
super().init_app(app)
if app.testing:
resp_raw = json.dumps({
"kind": "books#volumes",
"totalItems": 0,
})
http = HttpMockSequence([({'status': '200'}, resp_raw) for _ in range(10)])
self.client = build(
'books',
'v1',
http=http,
developerKey=app.config.get("GOOGLE_BOOKS_DEV_KEY")
)
else:
import httplib2
httplib2.Http(cache=".cache")
self.client = build(
'books',
'v1',
http=httplib2.Http(cache=".cache"),
developerKey=app.config.get("GOOGLE_BOOKS_DEV_KEY")
)
self.build(app.config.get("GOOGLE_BOOKS_DEV_KEY"), http=httplib2.Http(cache=".cache"))
assert isinstance(self.client, Resource)
def build(self, developer_key, http=None):
self.client = build(
'books',
'v1',
http=http,
developerKey=developer_key
)
return self.client
@cache.memoize()
def search(self, q):
return self.parse_search_result(
self.client.volumes().list(
# source='public',
q=q
).execute().get('items', [])
)
......
# -*- coding: utf-8 -*-
import glob
import os
from flask_testing import TestCase
from httplib2 import Http
from eBookHub.source import google_books_client
from eBookHub.jobs.blackhole import process_file
......@@ -11,6 +15,13 @@ from tests.base import MyTestCase
class GoogleBooksSourceTestCase(MyTestCase, TestCase):
line = 'Eriksson, Jerker & Sundquist, Hakan Axlander - [Kihlberg & Zetterlund 01] Het kraaienmeisje.epub'
def setUp(self):
super().setUp()
google_books_client.build(
self.app.config.get("GOOGLE_BOOKS_DEV_KEY"),
http=Http(cache=os.path.join(os.path.dirname(__file__), "cache"))
)
def test_process_file(self):
parser = FilenameParser()
book_data_raw = parser.parse(self.line)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment