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
94a182a8
Commit
94a182a8
authored
Mar 19, 2019
by
Patrick van der Leer
Browse files
coverage/unittests
parent
8f525b96
Pipeline
#317
failed with stage
in 6 minutes and 6 seconds
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
eBookHub/__init__.py
View file @
94a182a8
...
...
@@ -25,7 +25,7 @@ def init(config_object=ProdConfig):
with
app
.
app_context
():
configure_extensions
(
app
)
configure_sources
(
app
)
if
not
app
.
testing
:
if
not
app
.
testing
:
# pragma: no cover
configure_scheduler
(
app
)
configure_logging
(
app
)
CORS
(
...
...
@@ -168,7 +168,7 @@ def configure_logging(app):
console
.
setFormatter
(
logging
.
Formatter
(
'%(asctime)s %(levelname)s::%(message)s'
,
'%H:%M:%S'
))
app
.
logger
.
addHandler
(
console
)
if
app
.
config
[
'FILE_LOGGING'
]:
if
app
.
config
[
'FILE_LOGGING'
]:
# pragma: no cover
log_file_handler
=
RotatingFileHandler
(
app
.
config
[
'LOG_PATH'
],
maxBytes
=
app
.
config
[
'LOG_MAX_BYTES'
],
...
...
eBookHub/database.py
View file @
94a182a8
...
...
@@ -19,7 +19,7 @@ SAFRSBase.re_search = re_search
class
PrettyPrint
:
_exclude_from_meta_dump
=
[]
def
__unicode__
(
self
):
def
__unicode__
(
self
):
# pragma: no cover
return
"[%s(%s)]"
%
(
self
.
__class__
.
__name__
,
', '
.
join
(
'%s=%s'
%
(
k
,
self
.
__dict__
[
k
])
for
k
in
sorted
(
self
.
__dict__
)
if
'_sa_'
!=
k
[:
4
]))
...
...
@@ -27,7 +27,7 @@ class PrettyPrint:
if
_visited_objs
is
None
:
_visited_objs
=
[]
def
_serialize
(
obj
,
versions
=
True
):
def
_serialize
(
obj
,
versions
=
True
):
# pragma: no cover
if
isinstance
(
obj
.
__class__
,
DeclarativeMeta
):
# don't re-visit self
if
obj
in
_visited_objs
:
...
...
@@ -79,7 +79,7 @@ class PrettyPrint:
return
_serialize
(
self
)
class
SoftDeleteMixin
(
object
):
class
SoftDeleteMixin
(
object
):
# pragma: no cover
deleted
=
db
.
Column
(
db
.
Boolean
,
default
=
False
)
def
delete
(
self
,
commit
=
True
,
hard_delete
=
False
):
...
...
eBookHub/models/core.py
View file @
94a182a8
...
...
@@ -115,6 +115,8 @@ class BookEdition(Model):
@
staticmethod
def
lookup_by_isbn
(
isbn
):
if
isinstance
(
isbn
,
int
):
isbn
=
str
(
isbn
)
isbn
=
isbn
.
strip
()
if
len
(
isbn
)
==
10
:
return
BookEdition
.
query
.
filter_by
(
isbn_10
=
isbn
)
...
...
eBookHub/source/abstract.py
View file @
94a182a8
...
...
@@ -8,7 +8,7 @@ class SourceAbstract(ABC):
transformer_klass
=
TransformerAbstract
def
__init__
(
self
,
app
=
None
):
if
app
is
not
None
:
if
app
is
not
None
:
# pragma: no cover
self
.
init_app
(
app
)
super
().
__init__
()
...
...
eBookHub/source/goodreads.py
View file @
94a182a8
...
...
@@ -21,7 +21,7 @@ class GoodreadsClient(SourceAbstract):
@
cache
.
memoize
()
def
book_id
(
self
,
eid
):
return
self
.
transform
er
.
convert
_book
(
self
.
client
.
Book
.
show
(
eid
))
return
self
.
transform_book
(
self
.
client
.
Book
.
show
(
eid
))
def
search
(
self
,
q
):
raise
NotImplementedError
...
...
eBookHub/source/google.py
View file @
94a182a8
...
...
@@ -52,6 +52,6 @@ class GoogleBooksClient(SourceAbstract):
elif
len
(
result
)
>
1
:
books
=
[]
for
entry
in
result
:
books
.
append
(
self
.
transform
er
.
convert
_book
(
self
.
book_id
(
entry
[
'id'
])))
books
.
append
(
self
.
transform_book
(
self
.
book_id
(
entry
[
'id'
])))
return
books
return
self
.
transform
er
.
convert
_book
(
self
.
book_id
(
result
[
0
][
'id'
]))
return
self
.
transform_book
(
self
.
book_id
(
result
[
0
][
'id'
]))
eBookHub/source/transformer/goodreads.py
View file @
94a182a8
...
...
@@ -22,7 +22,7 @@ class GoodreadsTransformer(TransformerAbstract):
for
in_key
,
ex_key
in
cls
.
book_mapping
.
items
():
try
:
container
[
in_key
]
=
result
[
ex_key
]
except
(
IndexError
,
KeyError
):
except
(
IndexError
,
KeyError
):
# pragma: no cover
pass
container
[
'authors'
]
=
cls
.
convert_author
(
result
[
'authors'
][
'author'
])
...
...
@@ -36,7 +36,7 @@ class GoodreadsTransformer(TransformerAbstract):
for
in_key
,
ex_key
in
cls
.
author_mapping
.
items
():
try
:
author
[
in_key
]
=
result
[
ex_key
]
except
IndexError
:
except
(
IndexError
,
KeyError
):
# pragma: no cover
pass
return
author
...
...
eBookHub/source/transformer/google.py
View file @
94a182a8
...
...
@@ -24,7 +24,7 @@ class GoogleBooksTransformer(TransformerAbstract):
for
in_key
,
ex_key
in
cls
.
book_mapping
.
items
():
try
:
container
[
in_key
]
=
info
[
ex_key
]
except
(
IndexError
,
KeyError
):
except
(
IndexError
,
KeyError
):
# pragma: no cover
pass
container
[
'authors'
]
=
cls
.
convert_author
(
info
.
get
(
"authors"
))
...
...
tests/models/test_book.py
View file @
94a182a8
...
...
@@ -3,6 +3,7 @@ from flask_testing import TestCase
from
eBookHub.models
import
Book
,
BookEdition
,
BookSerie
from
eBookHub.models.factory
import
BookFactory
,
BookEditionFactory
,
BookSerieFactory
from
eBookHub.validators.exceptions
import
ISBNException
from
tests.base
import
ModelTestCase
...
...
@@ -15,6 +16,16 @@ class BookEditionModelTestCase(ModelTestCase, TestCase):
model
=
BookEdition
factory
=
BookEditionFactory
def
test_lookup_by_isbn
(
self
):
model
=
self
.
model
model
.
lookup_by_isbn
(
"1234567890"
)
model
.
lookup_by_isbn
(
"1234567890123"
)
with
self
.
assertRaises
(
ISBNException
):
model
.
lookup_by_isbn
(
1
)
with
self
.
assertRaises
(
ISBNException
):
model
.
lookup_by_isbn
(
2
)
class
BookSerieModelTestCase
(
ModelTestCase
,
TestCase
):
model
=
BookSerie
...
...
tests/test_config.py
0 → 100644
View file @
94a182a8
# -*- coding: utf-8 -*-
import
glob
import
os
from
unittest
import
TestCase
from
flask.helpers
import
get_debug_flag
from
eBookHub
import
ProdConfig
,
init
from
eBookHub.config
import
TestConfig
,
DevConfig
from
eBookHub.parser.filename
import
FilenameParser
from
eBookHub.utils
import
get_test_flag
,
get_config
class
ConfigTestCase
(
TestCase
):
def
test_production_config
(
self
):
"""Production config"""
app
=
init
(
ProdConfig
)
config
=
app
.
config
self
.
assertEqual
(
config
[
'ENV'
],
'prod'
,
"Wrong env in ProdConfig"
)
self
.
assertFalse
(
config
[
'DEBUG'
],
"Debug is enabled in ProductionEnv"
)
self
.
assertFalse
(
config
[
'DEBUG_TB_ENABLED'
],
"Debug toolbar is enabled in ProductionEnv"
)
self
.
assertFalse
(
config
[
'TESTING'
],
"Testing is enabled in ProductionEnv"
)
def
test_test_config
(
self
):
"""Test config"""
app
=
init
(
TestConfig
)
config
=
app
.
config
self
.
assertEqual
(
config
[
'ENV'
],
'test'
,
"Wrong env in TestConfig"
)
self
.
assertFalse
(
config
[
'DEBUG'
],
"Debug is enabled in TestingEnv"
)
self
.
assertTrue
(
config
[
'TESTING'
],
"Testing is not enabled in TestingEnv"
)
self
.
assertIn
(
"sqlite"
,
config
[
'SQLALCHEMY_DATABASE_URI'
],
"TestConfig contains non sqlite database uri"
)
def
test_dev_config
(
self
):
"""Development config"""
app
=
init
(
DevConfig
)
config
=
app
.
config
self
.
assertEqual
(
config
[
'ENV'
],
'dev'
,
"Wrong env in DevConfig"
)
self
.
assertTrue
(
config
[
'DEBUG'
],
"Debug is not enabled in DevEnv"
)
self
.
assertTrue
(
config
[
'DEBUG_TB_ENABLED'
],
"Debug toolbar is not enabled in DevEnv"
)
self
.
assertFalse
(
config
[
'TESTING'
],
"Testing is enabled in DevEnv"
)
def
test_debug_flag
(
self
):
os
.
environ
[
"FLASK_DEBUG"
]
=
"0"
self
.
assertFalse
(
get_debug_flag
())
os
.
environ
[
"FLASK_DEBUG"
]
=
"1"
self
.
assertTrue
(
get_debug_flag
())
def
test_test_flag
(
self
):
os
.
environ
[
"FLASK_TESTING"
]
=
"0"
self
.
assertFalse
(
get_test_flag
())
os
.
environ
[
"FLASK_TESTING"
]
=
"1"
self
.
assertTrue
(
get_test_flag
())
def
test_get_config
(
self
):
os
.
environ
[
"FLASK_DEBUG"
]
=
"0"
os
.
environ
[
"FLASK_TESTING"
]
=
"0"
self
.
assertEqual
(
ProdConfig
,
get_config
())
os
.
environ
[
"FLASK_DEBUG"
]
=
"1"
os
.
environ
[
"FLASK_TESTING"
]
=
"0"
self
.
assertEqual
(
DevConfig
,
get_config
())
os
.
environ
[
"FLASK_DEBUG"
]
=
"0"
os
.
environ
[
"FLASK_TESTING"
]
=
"1"
self
.
assertEqual
(
TestConfig
,
get_config
())
os
.
environ
[
"FLASK_DEBUG"
]
=
"1"
os
.
environ
[
"FLASK_TESTING"
]
=
"1"
self
.
assertEqual
(
DevConfig
,
get_config
())
tests/test_isbn_validator.py
View file @
94a182a8
...
...
@@ -2,7 +2,7 @@
from
unittest
import
TestCase
from
eBookHub.validators.exceptions
import
ISBNException
from
eBookHub.validators.isbn
import
validate_isbn10
,
validate_isbn13
,
validate_isbn
from
eBookHub.validators.isbn
import
validate_isbn10
,
validate_isbn13
,
validate_isbn
,
is_valid_isbn
class
ISBNTestCase
(
TestCase
):
...
...
@@ -13,14 +13,21 @@ class ISBNTestCase(TestCase):
validate_isbn10
(
self
.
isbn_10_valid
)
def
test_isbn10_fail
(
self
):
self
.
assertRaises
(
ISBNException
,
validate_isbn10
,
123456789
1
)
self
.
assertRaises
(
ISBNException
,
validate_isbn10
,
"
123456789
"
)
def
test_isbn13_success
(
self
):
validate_isbn13
(
self
.
isbn_13_valid
)
def
test_isbn13_fail
(
self
):
self
.
assertRaises
(
ISBNException
,
validate_isbn13
,
12345678912
34
)
self
.
assertRaises
(
ISBNException
,
validate_isbn13
,
"
12345678912
"
)
def
test_isbn_success
(
self
):
validate_isbn
(
self
.
isbn_10_valid
)
validate_isbn
(
self
.
isbn_13_valid
)
def
test_isbn_fail
(
self
):
self
.
assertRaises
(
ISBNException
,
validate_isbn
,
"12345678912"
)
def
test_is_valid_isbn
(
self
):
self
.
assertTrue
(
is_valid_isbn
(
self
.
isbn_13_valid
))
self
.
assertFalse
(
is_valid_isbn
(
"128912"
))
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