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

some more of what I did before

parent f6f358cd
Pipeline #289 passed with stage
in 7 minutes and 6 seconds
......@@ -4,6 +4,7 @@ omit = *tests*, *docs*, *managers*
[report]
exclude_lines =
pragma: no cover
@abstract
def __repr__
if self.debug:
if settings.DEBUG
......
......@@ -25,7 +25,8 @@ def init(config_object=ProdConfig):
with app.app_context():
configure_extensions(app)
configure_sources(app)
configure_scheduler(app)
if not app.testing:
configure_scheduler(app)
configure_logging(app)
CORS(
app,
......
from functools import wraps
from flask import Blueprint, jsonify, request, make_response
from flask import Blueprint, jsonify, request
from flask_httpauth import HTTPBasicAuth
from flask_jwt_extended import jwt_refresh_token_required, get_jwt_identity, unset_jwt_cookies, set_access_cookies, \
set_refresh_cookies
......@@ -21,7 +21,6 @@ def login_required(fn):
auth_ = auth.get_auth()
if request.method != 'OPTIONS': # pragma: no cover
password = auth.get_auth_password(auth_)
ff = auth.authenticate(auth_, password)
if not auth.authenticate(auth_, password):
# Clear TCP receive buffer of any pending data
request.data
......
......@@ -121,9 +121,7 @@ class Model(SAFRSBase, db.Model, PrettyPrint):
@classmethod
def create(cls, commit=True, **kwargs):
"""Create a new record and save it the database."""
instance = cls()
for key, value in kwargs.items():
setattr(instance, key, value)
instance = cls(**kwargs)
return instance.save() if commit else instance
def update(self, commit=True, **kwargs):
......@@ -150,10 +148,6 @@ class Model(SAFRSBase, db.Model, PrettyPrint):
"""To prevent IDE from bitching about wrong arguments"""
super().__init__(*arg, **kwargs)
def get_field_names(self):
for p in self.__mapper__.iterate_properties:
yield p.key
__all__ = [
"db",
......
......@@ -6,20 +6,20 @@ database_manager = Manager(current_app, usage="Perform database operations")
@database_manager.command
def drop():
def drop(): # pragma: no cover
"""Drops database tables"""
if prompt_bool("Are you sure you want to lose all your data"):
db.drop_all()
@database_manager.command
def create(default_data=True, sample_data=False):
def create(default_data=True, sample_data=False): # pragma: no cover
"""Creates database tables from sqlalchemy models"""
db.create_all()
@database_manager.command
def recreate(default_data=True, sample_data=False):
def recreate(default_data=True, sample_data=False): # pragma: no cover
"""Recreates database tables (same as issuing 'drop' and then 'create')"""
drop()
create(default_data, sample_data)
......@@ -8,7 +8,7 @@ parser_manager = Manager(current_app, usage="Perform parser tests/operations")
@parser_manager.command
@parser_manager.option('-p', '--path', dest='path', default=None)
def blackhole(path=None):
def blackhole(path=None): # pragma: no cover
if path is None:
app = parser_manager.app
path = app.config['BLACKHOLE_PATH']
......
......@@ -11,7 +11,7 @@ source_manager.add_command('goodreads', goodreads_manager)
@goodreads_manager.command
@goodreads_manager.option('-i', '--id', dest='id', default=None)
def by_id(id=None):
def by_id(id=None): # pragma: no cover
if id is None:
id = prompt("ID")
......@@ -23,7 +23,7 @@ def by_id(id=None):
@goodreads_manager.command
@goodreads_manager.option('-t', '--title', dest='q', default=None)
def search_title(q=None):
def search_title(q=None): # pragma: no cover
if q is None:
q = prompt("Title")
......@@ -35,7 +35,7 @@ def search_title(q=None):
@goodreads_manager.command
@goodreads_manager.option('-a', '--author', dest='q', default=None)
def search_author(q=None):
def search_author(q=None): # pragma: no cover
if q is None:
q = prompt("Author")
......
......@@ -12,7 +12,7 @@ user_manager = Manager(current_app, usage="User operations")
@user_manager.option('-n', '--name', dest='name', default=None)
@user_manager.option('-e', '--email', dest='email', default=None)
@user_manager.option('-p', '--password', dest='password', default=None)
def create(name=None, email=None, password=None):
def create(name=None, email=None, password=None): # pragma: no cover
if name is None:
name = prompt("Name")
if email is None:
......@@ -33,7 +33,7 @@ def create(name=None, email=None, password=None):
print("User created")
def _get_user(id=None, email=None):
def _get_user(id=None, email=None): # pragma: no cover
if id is None and email is None:
choices = (
"ID",
......@@ -64,7 +64,7 @@ def _get_user(id=None, email=None):
@user_manager.option('-id', '--id', dest='id', default=None)
@user_manager.option('-e', '--email', dest='email', default=None)
@user_manager.option('-p', '--password', dest='password', default=None)
def set_password(id=None, email=None, password=None):
def set_password(id=None, email=None, password=None): # pragma: no cover
user = _get_user(id, email)
assert isinstance(user, User)
if password is None:
......@@ -82,7 +82,7 @@ def set_password(id=None, email=None, password=None):
@user_manager.option('-i', '--id', dest='id', default=None)
@user_manager.option('-e', '--email', dest='email', default=None)
@user_manager.option('-f', '--force', dest='force', default=False)
def delete(id=None, email=None, force=False):
def delete(id=None, email=None, force=False): # pragma: no cover
user = _get_user(id, email)
assert isinstance(user, User)
if not force:
......
......@@ -147,7 +147,7 @@ class BookEditionFile(Model):
return os.path.join(get_temp_path(), self.filename)
return os.path.join(get_library_path(), self.filename)
def move_to_temp(self, src=None, dest=None):
def move_to_temp(self, src=None, dest=None): # pragma: no cover
if src is None:
src = get_blackhole_path()
if dest is None:
......@@ -155,7 +155,7 @@ class BookEditionFile(Model):
return os.rename(os.path.join(src, self.filename), os.path.join(dest, self.filename))
def move_to_lib(self, src=None, dest=None):
def move_to_lib(self, src=None, dest=None): # pragma: no cover
if src is None:
if os.path.exists(os.path.join(get_blackhole_path(), self.filename)):
src = get_blackhole_path()
......
......@@ -9,30 +9,30 @@ class SourceAbstract(ABC):
def __init__(self, app=None):
if app is not None:
self.app = app
if not isinstance(self.transformer, TransformerAbstract):
self.transformer = self.transformer_klass()
assert isinstance(self.transformer, TransformerAbstract)
self.init_app(app)
super().__init__()
def init_app(self, app=None):
if app is not None:
self.app = app
if not isinstance(self.transformer, TransformerAbstract):
self.transformer = self.transformer_klass()
assert isinstance(self.transformer, TransformerAbstract)
@abstractmethod
def search_title_and_author(self, title, author):
def search_title_and_author(self, title, author): # pragma: no cover
pass
@abstractmethod
def search_author(self, author):
def search_author(self, author): # pragma: no cover
pass
@abstractmethod
def search_title(self, title):
def search_title(self, title): # pragma: no cover
pass
@abstractmethod
def search_isbn(self, isbn):
def search_isbn(self, isbn): # pragma: no cover
pass
def transform_book(self, result):
......
......@@ -12,7 +12,7 @@ class GoodreadsClient(SourceAbstract):
transformer_klass = GoodreadsTransformer
def init_app(self, app=None):
super().__init__(app)
super().init_app(app)
developer_key = app.config.get("GOODREADS_DEV_KEY")
developer_secret = app.config.get("GOODREADS_DEV_SECRET", None)
self.client = gr.Client(developer_key=developer_key, developer_secret=developer_secret)
......
......@@ -34,6 +34,31 @@ class ModelTestCase(MyTestCase):
"""Test factory instance"""
self.assertEqual(type(self.factory()), self.model)
def test_get_by(self):
"""Get model via get_by"""
inst = self.factory()
inst.save()
retrieved = self.model.get_by(id=inst.id)
assert retrieved == inst
def test_get_all_by(self):
"""Get models via get_all_by"""
inst = self.factory()
inst.save()
retrieved = list(self.model.get_all_by(id=inst.id))
assert retrieved == [inst]
def test_get_or_create(self):
"""Get or create model from factory"""
model = self.model
inst, created = model.get_or_create()
assert isinstance(inst, model)
inst, created = model.get_or_create(id=inst.id)
assert not created
assert isinstance(inst, model)
def test_delete(self):
"""Save and delete model from factory"""
inst = self.factory()
......
......@@ -10,3 +10,11 @@ class UserModelTestCase(ModelTestCase, TestCase):
model = User
factory = UserFactory
def test_get_or_create(self):
"""Get or create model from factory"""
model = self.model
inst, created = model.get_or_create(email="test@example.org")
assert isinstance(inst, model)
inst, created = model.get_or_create(id=inst.id)
assert not created
assert isinstance(inst, model)
# -*- coding: utf-8 -*-
import os
from flask_testing import TestCase
from eBookHub.extensions import goodreads_client
from eBookHub.jobs.blackhole import process_file
from eBookHub.parser.filename import FilenameParser
from eBookHub.jobs.blackhole import process_blackhole_job
from eBookHub.utils import get_blackhole_path
from tests.base import MyTestCase
class GoodreadsSourceTestCase(MyTestCase, TestCase):
class BlackHoleTestCase(MyTestCase, TestCase):
line = 'Eriksson, Jerker & Sundquist, Hakan Axlander - [Kihlberg & Zetterlund 01] Het kraaienmeisje.epub'
def test_process_file(self):
parser = FilenameParser()
book_data_raw = parser.parse(self.line)
goodreads_client.parse(book_data_raw['title'], book_data_raw['authors'])
def test_process_blackhole(self):
path = os.path.join(get_blackhole_path(), self.line)
with open(path, "w+") as f:
f.write("1234")
def test_process_file_function(self):
process_file(self.line)
process_blackhole_job(get_blackhole_path())
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