Skip to content
Snippets Groups Projects
Commit fb3abf46 authored by Sascha Herzinger's avatar Sascha Herzinger
Browse files

added redislite

parent 3cd18e30
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -5,13 +5,17 @@ Exports:
"""
import os
from redislite import Redis
class BaseConfig(object):
"""Basic configuration that should be used in production."""
DEBUG = False
TESTING = False
CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
REDIS_DB_PATH = os.path.join(os.sep, 'tmp', 'fractalis.db')
rdb = Redis(REDIS_DB_PATH)
CELERY_BROKER_URL = 'redis+socket://{}'.format(rdb.socket_file)
CELERY_RESULT_BACKEND = CELERY_BROKER_URL
class DevelopmentConfig(BaseConfig):
......@@ -33,7 +37,7 @@ config = {
}
def configure_app(app):
def configure_app(app, mode=None):
"""Apply configuration to given flask app based on environment variable.
This function assumes that the environment variable FRACTALIS_MODE contains
......@@ -41,13 +45,16 @@ def configure_app(app):
it defaults to 'production'. Each of these keys maps to a class in this
module that contains appropriate settings.
Arguments:
Keyword Arguments:
app (Flask) -- An instance of the app to configure
mode (string) -- (optional) Use this instead of the environment variable
Exceptions:
KeyError (Exception) -- Is raised when FRACTALIS_MODE contains unknown key
"""
mode = os.getenv('FRACTALIS_MODE', default='production')
if mode is None:
mode = os.getenv('FRACTALIS_MODE', default='production')
try:
app.config.from_object(config[mode])
except KeyError as e:
......
......@@ -8,7 +8,8 @@ setup(
packages=find_packages(),
install_requires=[
'Flask',
'celery'
'celery',
'redislite'
],
setup_requires=[
'pytest-runner',
......
import pytest
from celery import Celery
from fractalis import celery
from fractalis.celery import init_celery
class TestCelery(object):
@pytest.fixture
def flask_app(self):
def app(self):
from flask import Flask
from fractalis.config import configure_app
app = Flask('test_app')
app.config['TESTING'] = True
app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379'
configure_app(app, mode='testing')
return app
def test_exception_if_no_connection_to_broker(self, flask_app):
flask_app.config['CELERY_BROKER_URL'] = 'foobar'
def test_exception_if_no_connection_to_broker(self, app):
app.config['CELERY_BROKER_URL'] = 'redis+socket:///foobar.socket'
with pytest.raises(ConnectionRefusedError):
celery.init_celery(flask_app)
init_celery(app)
def test_exception_if_no_connection_to_result_backend(self, flask_app):
flask_app.config['CELERY_RESULT_BACKEND'] = 'foobar'
def test_exception_if_no_connection_to_result_backend(self, app):
app.config['CELERY_RESULT_BACKEND'] = 'redis+socket:///foobar.socket'
with pytest.raises(ConnectionRefusedError):
celery.init_celery(flask_app)
init_celery(app)
def test_returns_celery_instance_if_connection_valid(self, flask_app):
celery_instance = celery.init_celery(flask_app)
def test_returns_celery_instance_if_connection_valid(self, app):
celery_instance = init_celery(app)
assert isinstance(celery_instance, Celery)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment