Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

Commit

Permalink
setup.py
Browse files Browse the repository at this point in the history
  * setting up for 0.5

.travis.yml
  * Added tests for 3.4
  * Removed testing for 0.8 (we test 0.8.1, it seemed redundant)
  * Install separate requirements-contrib.txt file

requirements-dev.txt
requirements-contrib.txt
  * Moved contrib modules out into their own file - Travis was erroring out when we put the contrib stuff in with the dev requirements, and it's cleaner to do it this way, too.

CONTRIBUTING.rst
CHANGES.rst
docs/contrib.rst
docs/index.rst
  * documenting the new contrib changes
  * adding doc on how to contribute

tests/test_core_function.py
  * noticed I'd accidentally duplicated a test and not tested something I meant to
  * notice that a test wasn't testing exception throwing correctly (if no exception was thrown when one was
  expected, then it would pass)
  • Loading branch information
Rachel Sanders committed Aug 7, 2014
1 parent 170e612 commit eb9db73
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 14 deletions.
7 changes: 1 addition & 6 deletions .travis.yml
Expand Up @@ -7,21 +7,16 @@ python:
- "pypy"

env:
- FLASK=0.8
- FLASK=0.8.1
- FLASK=0.9
- FLASK=0.10.1

matrix:
exclude:
- python: "3.3"
env: FLASK=0.8
- python: "3.3"
env: FLASK=0.8.1
- python: "3.3"
env: FLASK=0.9
- python: "3.4"
env: FLASK=0.8
- python: "3.4"
env: FLASK=0.8.1
- python: "3.4"
Expand All @@ -30,7 +25,7 @@ matrix:
# command to install dependencies
install:
- pip install -q Flask==$FLASK
- pip install -r requirements-dev.txt
- pip install -r requirements-contrib.txt

# command to run tests
script: nosetests tests
10 changes: 9 additions & 1 deletion CHANGES.rst
Expand Up @@ -23,4 +23,12 @@ Revved the version number so I could re-upload to PyPI. No real changes other th

* General code cleanup and optimization
* Adding optional redirect to is_active_feature, thank you to michaelcontento
* Fixed syntax error in docs, thank you to iurisilvio
* Fixed syntax error in docs, thank you to iurisilvio

0.5 (August 7, 2014)
-------------------

Official support for contributed modules, thank you to iurisilvio! He contributed the first for
SQLAlchemy, so you can store your flags in the database instead.

Other contributions welcome.
88 changes: 88 additions & 0 deletions CONTRIBUTING.rst
@@ -0,0 +1,88 @@
Contributing
============

Hi! Thanks so much for wanting to contribute.

Setting up for development
--------------------------

There's a few extra steps to set up for development.

Installing from source
``````````````````````

To install in development mode from source, download the source code, then run this::

python setup.py develop

Installing libraries
````````````````````

To do development work, you'll need a few more libraries::

pip install -r requirements-dev.txt
pip install -r requirements-contrib.txt


Running the tests
`````````````````

Make sure you have the development libraries installed, then run::

nosetests

Building documentation
``````````````````````

Make sure you have the development libraries installed, then do::

cd docs
make html

The generated documentation will be in ``docs/_build/html/``.

Guidelines
----------

Style guide
```````````

The code follows `PEP8
<http://www.python.org/dev/peps/pep-0008/>`_ with the following exceptions:

* Indentation is 2 spaces (no tabs)
* Line length: use your best judgment. (We all have big monitors now, no need to limit to 80 columns.)

Your code should pass `flake8
<http://flake8.readthedocs.org/>`_ unless readability is hurt. Configuration is in ``setup.cfg``.

Supported versions
```````````````````

Your code should be compatible with Python 2.6, 2.7, and 3.3+, and Flask 0.8+. Travis CI will test all that for you
automatically.

Tests
`````

Submitted code should have tests covering the code submitted, and your code should pass the travis build.

If possible, use the fixtures in test/fixtures.py - there's a sample app with all the functionality that you can
use to test on.

Creating a contrib module
-------------------------

If you store your flags somewhere other than the config file, and want to share your code with others, fantastic!

Here's a couple guidelines:

1. Contrib code goes in ``flask_featureflags/contrib``

2. Tests for contrib modules go in ``tests/contrib``

3. Add a description and a quick example of how to use your module in ``docs/contrib.rst``

4. If your code has any package requirements, please put them in ``requirements-contrib.txt``

Thanks for contributing!
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -106,7 +106,14 @@ You can also check for features in Jinja template code:
old behavior...
{% endif %}

Using other backends
====================

Want to store your flags somewhere other than the config file? There are third-party contrib modules for other backends.

Please see the documentation here: [https://flask-featureflags.readthedocs.org/en/latest/contrib.html](https://flask-featureflags.readthedocs.org/en/latest/contrib.html)

Feel free to add your own - see CONTRIBUTING.rst for help.

Customization
=============
Expand Down Expand Up @@ -182,6 +189,7 @@ You can override this behavior by raising the StopCheckingFeatureFlags exception

If it isn't Tuesday, this will cause the chain to return False and any other handlers won't run.


Acknowledgements
================

Expand Down
32 changes: 32 additions & 0 deletions docs/contrib.rst
@@ -0,0 +1,32 @@
Third-party modules
===================

Sometimes you don't want to use the config file to store your feature flags. You can use these premade modules
to use other backends.

SQLAlchemy
----------

You'll need Flask-SQLAlchemy::

pip install Flask-SQLAlchemy


Then, in your app, add the ``SQLAlchemyFeatureFlags`` handler::

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
import flask_featureflags as feature_flags
from flask_featureflags.contrib.sqlalchemy import SQLAlchemyFeatureFlags

app = Flask(__name__)

db = SQLAlchemy(app)

ff = feature_flags.FeatureFlag(app)
ff.add_handler(SQLAlchemyFeatureFlags(db))

It will automatically create a table to store your flags in, or you can override by passing in your own model::

ff.add_handler(SQLAlchemyFeatureFlags(db, model=MyModel))

5 changes: 5 additions & 0 deletions docs/index.rst
Expand Up @@ -14,6 +14,7 @@ Links

* `source <https://github.com/trustrachel/Flask-FeatureFlags/>`_
* :doc:`changelog </changelog>`
* :doc:`Contributed modules </contrib>`


Installation
Expand Down Expand Up @@ -185,6 +186,10 @@ You can override this behavior by raising the StopCheckingFeatureFlags exception

If it isn't Tuesday, this will cause the chain to return False and any other handlers won't run.

Third-party modules
-------------------

Don't want to store your flags in the config file? There are :doc:`third-party contributed modules </contrib>` for other backends. Feel free to add your own, too.

Questions?
==========
Expand Down
1 change: 1 addition & 0 deletions requirements-contrib.txt
@@ -0,0 +1 @@
Flask-SQLAlchemy>=0.16
1 change: 0 additions & 1 deletion requirements-dev.txt
Expand Up @@ -2,4 +2,3 @@ nose>=1.0.0
sphinx>=1.0
coverage>=3.5
flake8>=2.1.0
Flask-SQLAlchemy>=0.16
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -19,7 +19,7 @@

setup(
name='Flask-FeatureFlags',
version='0.4',
version='0.5-dev',
url='https://github.com/trustrachel/Flask-FeatureFlags',
license='Apache',
author='Rachel Sanders',
Expand Down
11 changes: 6 additions & 5 deletions tests/test_core_function.py
Expand Up @@ -57,16 +57,15 @@ def test_decorator_redirects_to_url_if_redirect_to_is_set_and_feature_is_off(sel
assert response.location == url_for('redirect_destination', _external=True), \
u'Expected redirect to %s, got %s => ' % (url_for('redirect_destination'), response.location)

def test_decorator_redirects_to_url_if_redirect_is_set_and_feature_is_off(self):
def test_decorator_does_not_redirect_if_redirect_is_set_and_feature_is_on(self):
with self.app.test_request_context('/'):
url = url_for('redirect_with_decorator')

app.config[FLAG_CONFIG][FEATURE_NAME] = False
app.config[FLAG_CONFIG][FEATURE_NAME] = True

response = self.test_client.get(url)
assert response.status_code == 302, u'Unexpected status code %s' % response.status_code
assert response.location == url_for('redirect_destination', _external=True), \
u'Expected redirect to %s, got %s => ' % (url_for('redirect_destination'), response.location)
assert response.status_code == 200, u'Unexpected status code %s' % response.status_code
assert response.location is None, u'We redirected to %s, but this was unexpected' % request.location

def test_view_based_feature_flag_returns_new_code_if_flag_is_on(self):
with self.app.test_request_context('/'):
Expand Down Expand Up @@ -131,6 +130,8 @@ def test_raise_exception_if_flag_doesnt_exist_but_config_flag_is_set(self):
self.test_client.get(url)
except KeyError: # assertRaises no worky for some reason :/
pass
else:
raise AssertionError("We expected to throw a KeyError, but didn't.")

def test_do_not_raise_exception_if_we_are_not_in_dev_but_feature_is_missing_and_config_flag_is_set(self):
"""If a feature doesn't exist, only raise an error if we're in dev, no matter what the config says """
Expand Down

0 comments on commit eb9db73

Please sign in to comment.