Commit 2bbd8d4b authored by Patrick van der Leer's avatar Patrick van der Leer
Browse files

Improved test coverage

parent 8abcd72e
Pipeline #291 passed with stage
in 7 minutes and 15 seconds
......@@ -105,7 +105,7 @@ def configure_extensions(app):
ext.login_manager.init_app(app)
ext.scheduler.init_app(app)
if app.config['DEBUG_TB_ENABLED']:
if app.config['DEBUG_TB_ENABLED']: # pragma: no cover
from flask_debugtoolbar import DebugToolbarExtension
debug_toolbar = DebugToolbarExtension()
debug_toolbar.init_app(app)
......@@ -113,7 +113,7 @@ def configure_extensions(app):
return None
def configure_scheduler(app):
def configure_scheduler(app): # pragma: no cover
from eBookHub.jobs import process_blackhole_job
# can not use current_app due to out of context so passing it along
try:
......@@ -152,13 +152,13 @@ def configure_logging(app):
# if app.debug or not app.config['FILE_LOGGING']:
# return
if "GUNICORN_LOGGING" in app.config.keys() and app.config['GUNICORN_LOGGING']:
if "GUNICORN_LOGGING" in app.config.keys() and app.config['GUNICORN_LOGGING']: # pragma: no cover
gunicorn_error_logger = logging.getLogger('gunicorn.error')
app.logger.handlers.extend(gunicorn_error_logger.handlers)
# http://flask.pocoo.org/docs/errorhandling/
loglvl = logging.INFO
if app.debug:
if app.debug: # pragma: no cover
loglvl = logging.DEBUG
app.logger.setLevel(loglvl)
......
from flask import current_app
from flask_script import Manager
from eBookHub.managers.source.goodreads import goodreads_manager
source_manager = Manager(current_app, usage="Source lookups")
source_manager.add_command('goodreads', goodreads_manager)
__all__ = [
"source_manager"
]
......@@ -5,9 +5,6 @@ from eBookHub.extensions import goodreads_client
goodreads_manager = Manager(current_app, usage="Goodreads lookup")
source_manager = Manager(current_app, usage="Source lookups")
source_manager.add_command('goodreads', goodreads_manager)
@goodreads_manager.command
@goodreads_manager.option('-i', '--id', dest='id', default=None)
......@@ -46,5 +43,5 @@ def search_author(q=None): # pragma: no cover
__all__ = [
"source_manager"
"goodreads_manager"
]
class InternalCompareEngine(object):
our_data = {}
ext_data = []
def __init__(self, our_data):
if isinstance(our_data, object):
our_data = dict(our_data)
self.our_data = our_data
def add_ext_data(self, data):
self.ext_data.append(data)
def set_ext_data(self, data):
if not isinstance(data, list):
data = list(data)
self.ext_data = data
def compare(self):
data = self.our_data
# for now, just get the first one
for book in self.ext_data:
if 'isbn_10' in data.keys() and book.isbn_10 is not None:
if data['isbn_10'] != book.isbn_10:
# isbn mismatch
continue
if 'isbn_13' in data.keys() and book.isbn_13 is not None:
if data['isbn_13'] != book.isbn_13:
# isbn mismatch
continue
data['isbn_10'] = book.isbn_10
data['isbn_13'] = book.isbn_13
data['published_year'] = book.published_year
data['publisher'] = book.publisher
return data
......@@ -14,15 +14,55 @@ class TestApi(MyTestCase, TestCase):
def test_login(self):
assert isinstance(self.client, FlaskClient)
rv = self.client.post(
url_for("auth.login")
)
self.assert400(rv)
rv = self.client.post(
url_for("auth.login"),
data=json.dumps({
"email": "abc"
}),
content_type='application/json'
)
self.assert400(rv)
rv = self.client.post(
url_for("auth.login"),
data=json.dumps({
"password": "abc"
}),
content_type='application/json'
)
self.assert400(rv)
rv = self.client.post(
url_for("auth.login"),
data=json.dumps({
"email": "abc",
"password": "abc"
}),
content_type='application/json'
)
self.assert200(rv)
rv = self.client_login()
self.assert200(rv)
content = rv.json
self.assertTrue(content.get("login"))
rv = self.client.get(url_for("api.user.current"))
self.assert200(rv)
rv = self.client.get(url_for("auth.refresh"))
self.assert200(rv)
rv = self.client.get(url_for("api.user.current"))
self.assert200(rv)
rv = self.client.get(url_for("auth.logout"))
self.assert200(rv)
......
......@@ -65,6 +65,12 @@ class ModelTestCase(MyTestCase):
inst.save()
inst.delete()
def test_update(self):
"""Save and update model from factory"""
inst = self.factory()
inst.save()
inst.update(id=inst.id+1)
def test_soft_delete(self):
"""Save and softdelete model from factory"""
inst = self.factory().save()
......
......@@ -17,3 +17,13 @@ class GoodreadsSourceTestCase(MyTestCase, TestCase):
def test_process_file_function(self):
process_file(self.line)
def test_search_book_isbn(self):
goodreads_client.search_isbn("1234567890")
goodreads_client.search_isbn("1234567890123")
def test_search_book_title(self):
goodreads_client.search_title("test")
def test_search_author(self):
goodreads_client.search_author("test")
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