Skip to content

Commit ac124dd

Browse files
author
Scott Walton
committed
Added the test project outline
1 parent 1272418 commit ac124dd

File tree

10 files changed

+238
-13
lines changed

10 files changed

+238
-13
lines changed

README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ depending on your user, or customise your own.
2727
Set the flag choices in your `settings.py` file as:
2828

2929
```python
30-
FEATURE_FLIPPER = {
31-
'FEATURE_FLAGS': (
32-
('simple_feature', u'Simple Feature'),
33-
('beta_testing', u'Beta Testing'),
34-
),
35-
}
30+
FEATURE_FLIPPER_FLAGS = (
31+
('simple_feature', u'Simple Feature'),
32+
('beta_testing', u'Beta Testing'),
33+
)
3634
```
3735

3836
When you add features, simply add flags here and your application will be able
@@ -64,7 +62,5 @@ determining whether to show the feature to a user. The final part is to
6462
reference this in your `settings.py`:
6563

6664
```python
67-
FEATURE_FLIPPER = {
68-
'FEATURE_MODEL': 'myapp.MyFeatureFlipper',
69-
}
65+
FEATURE_FLIPPER_MODEL = 'myapp.MyFeatureFlipper',
7066
```

feature_flipper/flipper_settings.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
from django.conf import settings
22

3-
FEATURE_SETTING = getattr(settings, 'FEATURE_FLIPPER', {})
4-
53
_DEFAULT_FEATURE_FLAGS = ()
64

7-
FEATURE_FLAGS = FEATURE_SETTING.get('FEATURE_FLAGS', _DEFAULT_FEATURE_FLAGS)
5+
FEATURE_FLIPPER_FLAGS = getattr(
6+
settings, 'FEATURE_FLIPPER_FLAGS',
7+
_DEFAULT_FEATURE_FLAGS)
8+
89
AUTH_USER_MODEL = settings.AUTH_USER_MODEL
10+
11+
FEATURE_FLIPPER_MODEL = getattr(
12+
settings, 'FEATURE_FLIPPER_MODEL',
13+
'feature_flipper.FeatureFlipper')
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9.8 on 2016-07-21 15:34
3+
from __future__ import unicode_literals
4+
5+
from django.conf import settings
6+
from django.db import migrations, models
7+
import django.db.models.deletion
8+
9+
10+
class Migration(migrations.Migration):
11+
12+
initial = True
13+
14+
dependencies = [
15+
('auth', '0001_initial'),
16+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
17+
]
18+
19+
operations = [
20+
migrations.CreateModel(
21+
name='FeatureFlipper',
22+
fields=[
23+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
24+
('feature', models.CharField(choices=[(b'feature_for_all', 'Feature for everyone'), (b'restricted_feature', 'Restricted Feature')], max_length=15)),
25+
('everyone', models.BooleanField(default=False)),
26+
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
27+
],
28+
options={
29+
'swappable': 'FEATURE_FLIPPER_MODEL',
30+
},
31+
),
32+
]

feature_flipper/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AbstractFeatureFlipper(models.Model):
3030
objects = FeatureFlipperQuerySet.as_manager()
3131

3232
feature = models.CharField(
33-
max_length=15, choices=flipper_settings.FEATURE_FLAGS)
33+
max_length=15, choices=flipper_settings.FEATURE_FLIPPER_FLAGS)
3434
everyone = models.BooleanField(default=False)
3535

3636
class Meta:
@@ -45,3 +45,6 @@ class FeatureFlipper(AbstractFeatureFlipper):
4545
USER_FEATURE_FIELD = 'user'
4646

4747
user = models.ForeignKey(flipper_settings.AUTH_USER_MODEL)
48+
49+
class Meta:
50+
swappable = 'FEATURE_FLIPPER_MODEL'

setup.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from distutils.core import setup
2+
3+
with open('README.md') as f:
4+
LONG_DESCRIPTION = f.read()
5+
6+
setup(
7+
name='django-feature-flipper',
8+
version='0.0.1',
9+
packages=[
10+
'feature_flipper',
11+
],
12+
license='MIT',
13+
long_description=LONG_DESCRIPTION,
14+
)

test_project/manage.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings")
7+
8+
from django.core.management import execute_from_command_line
9+
10+
execute_from_command_line(sys.argv)

test_project/test_project/__init__.py

Whitespace-only changes.

test_project/test_project/settings.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
"""
2+
Django settings for test_project project.
3+
4+
Generated by 'django-admin startproject' using Django 1.9.8.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.9/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/1.9/ref/settings/
11+
"""
12+
13+
import os
14+
15+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = '+1*a^vzlm&_^xlf_-r9#as5m8j)w9q$o+8b@5uumcna@oy3#q='
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'django.contrib.admin',
35+
'django.contrib.auth',
36+
'django.contrib.contenttypes',
37+
'django.contrib.sessions',
38+
'django.contrib.messages',
39+
'django.contrib.staticfiles',
40+
41+
'feature_flipper',
42+
]
43+
44+
MIDDLEWARE_CLASSES = [
45+
'django.middleware.security.SecurityMiddleware',
46+
'django.contrib.sessions.middleware.SessionMiddleware',
47+
'django.middleware.common.CommonMiddleware',
48+
'django.middleware.csrf.CsrfViewMiddleware',
49+
'django.contrib.auth.middleware.AuthenticationMiddleware',
50+
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
51+
'django.contrib.messages.middleware.MessageMiddleware',
52+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
53+
]
54+
55+
ROOT_URLCONF = 'test_project.urls'
56+
57+
TEMPLATES = [
58+
{
59+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
60+
'DIRS': [],
61+
'APP_DIRS': True,
62+
'OPTIONS': {
63+
'context_processors': [
64+
'django.template.context_processors.debug',
65+
'django.template.context_processors.request',
66+
'django.contrib.auth.context_processors.auth',
67+
'django.contrib.messages.context_processors.messages',
68+
],
69+
},
70+
},
71+
]
72+
73+
WSGI_APPLICATION = 'test_project.wsgi.application'
74+
75+
76+
# Database
77+
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
78+
79+
DATABASES = {
80+
'default': {
81+
'ENGINE': 'django.db.backends.sqlite3',
82+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
83+
}
84+
}
85+
86+
87+
# Password validation
88+
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
89+
90+
AUTH_PASSWORD_VALIDATORS = [
91+
{
92+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
93+
},
94+
{
95+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
96+
},
97+
{
98+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
99+
},
100+
{
101+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
102+
},
103+
]
104+
105+
106+
# Internationalization
107+
# https://docs.djangoproject.com/en/1.9/topics/i18n/
108+
109+
LANGUAGE_CODE = 'en-us'
110+
111+
TIME_ZONE = 'UTC'
112+
113+
USE_I18N = True
114+
115+
USE_L10N = True
116+
117+
USE_TZ = True
118+
119+
120+
# Static files (CSS, JavaScript, Images)
121+
# https://docs.djangoproject.com/en/1.9/howto/static-files/
122+
123+
STATIC_URL = '/static/'
124+
125+
FEATURE_FLIPPER_FLAGS = (
126+
('feature_for_all', u'Feature for everyone'),
127+
('restricted_feature', u'Restricted Feature'),
128+
)

test_project/test_project/urls.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""test_project URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/1.9/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.conf.urls import url, include
14+
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
15+
"""
16+
from django.conf.urls import url
17+
from django.contrib import admin
18+
19+
urlpatterns = [
20+
url(r'^admin/', admin.site.urls),
21+
]

test_project/test_project/wsgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for test_project project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings")
15+
16+
application = get_wsgi_application()

0 commit comments

Comments
 (0)