Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
0x43
eBookHub-backend
Commits
4620a2ee
Commit
4620a2ee
authored
Mar 20, 2019
by
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
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
4620a2ee
...
...
@@ -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
...
...
eBookHub/source/google.py
View file @
4620a2ee
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'
,
[])
)
...
...
tests/sources/cache/.gitkeep
0 → 100644
View file @
4620a2ee
tests/sources/test_google_books.py
View file @
4620a2ee
# -*- 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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment