Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a testing option to use fakeredis #55

Open
moritz89 opened this issue Mar 25, 2018 · 7 comments
Open

Add a testing option to use fakeredis #55

moritz89 opened this issue Mar 25, 2018 · 7 comments

Comments

@moritz89
Copy link
Contributor

When writing unit tests it would be useful to have an option to use fakeredis instead of a real redis server. Are there any accepted methods that I am missing or would it make sense to integrate it directly into this library?

One approach is described by python-rq but I am not sure how to best integrate it.

For context, I am using Flask-base and would like to test the registration aspect, which creates a queue event but fails since there is no running redis server.

@jezdez
Copy link
Member

jezdez commented Mar 26, 2018

There is a class attribute called connection_class that is used in the RQ._connect method to create the Redis client. Since fakeredis supports the from_url API it should be enough to subclass the RQ class and overwrite connection_class with the dotted path to the fakeredis client class.

@moritz89
Copy link
Contributor Author

moritz89 commented Mar 26, 2018 via email

@jezdez
Copy link
Member

jezdez commented Mar 26, 2018

Would make sense to add a testing section to the docs. Mind opening a PR?

@moritz89
Copy link
Contributor Author

Check that 👍🏼

@moritz89
Copy link
Contributor Author

It was actually much simpler than that, just set RQ_CONNECTION_CLASS = 'fakeredis.FakeStrictRedis' when setting the config variables. The relevant sections are:

class Config:
    APP_NAME = os.environ.get('APP_NAME')
    RQ_CONNECTION_CLASS = 'fakeredis.FakeStrictRedis'
rq = RQ()

def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    rq.init_app(app)

Where and how would it make sense to add the documentation? I would add a section in https://github.com/rq/Flask-RQ2/blob/master/docs/index.rst

@jezdez
Copy link
Member

jezdez commented Sep 19, 2018

@moritz89 Yeah, adding something to docs/index.rst makes sense to me, as a "Testing" section?

@moritz89
Copy link
Contributor Author

moritz89 commented Sep 19, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants