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

Added testcases and bumped up the coverage

parent c69e43df
Pipeline #287 passed with stage
in 6 minutes and 12 seconds
import json
from flask import url_for
from flask.testing import FlaskClient
from flask_testing import TestCase
from eBookHub.models import User
from eBookHub.models.factory import UserFactory
from tests.base import MyTestCase
class TestApi(MyTestCase, TestCase):
current_user = None
def test_login(self):
assert isinstance(self.client, FlaskClient)
rv = self.client_login()
self.assert200(rv)
content = rv.json
self.assertTrue(content.get("login"))
rv = self.client.get(url_for("auth.refresh"))
self.assert200(rv)
rv = self.client.get(url_for("auth.logout"))
self.assert200(rv)
def client_login(self, user=None, password=None):
assert isinstance(self.client, FlaskClient)
data = {
"password": password if password is not None else 'pa$$w0rd'
}
if user is None:
self.current_user = user = UserFactory()
assert isinstance(user, User)
user.hash_password(data.get("password"))
user.save()
else:
assert isinstance(user, User)
data['email'] = str(user.email)
_data = {}
for k, v in data.items():
_data[str(k)] = str(v)
data = _data
rv = self.client.post(url_for("auth.login"), data=json.dumps(data), content_type='application/json')
self.assert200(rv)
return rv
# -*- coding: utf-8 -*-
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 tests.base import MyTestCase
class GoodreadsSourceTestCase(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_file_function(self):
process_file(self.line)
# -*- coding: utf-8 -*-
import time
from flask_testing import TestCase
from eBookHub.extensions import scheduler
from tests.base import MyTestCase
class SchedulerTestCase(MyTestCase, TestCase):
def test_scheduler(self):
def scheduler_test_job():
time.sleep(0.1)
scheduler.add_job(
func=scheduler_test_job,
trigger="interval",
minutes=1,
)
scheduler.start()
self.assertTrue(hasattr(scheduler, "_thread"))
scheduler.shutdown()
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