Skip to content

Commit

Permalink
Merge pull request #28 from vuLgAr/dry-config
Browse files Browse the repository at this point in the history
dry config
  • Loading branch information
mjhea0 committed Mar 4, 2018
2 parents 18dcda7 + a80739c commit 6f9531c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
24 changes: 10 additions & 14 deletions project/server/config.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
# project/server/config.py

import os

basedir = os.path.abspath(os.path.dirname(__file__))


class BaseConfig(object):
"""Base configuration."""
SECRET_KEY = 'my_precious'
BCRYPT_LOG_ROUNDS = 13
WTF_CSRF_ENABLED = True
BCRYPT_LOG_ROUNDS = 4
DEBUG_TB_ENABLED = False
DEBUG_TB_INTERCEPT_REDIRECTS = False
SECRET_KEY = os.getenv('SECRET_KEY', default='my_precious')
SQLALCHEMY_TRACK_MODIFICATIONS = False
WTF_CSRF_ENABLED = False


class DevelopmentConfig(BaseConfig):
"""Development configuration."""
BCRYPT_LOG_ROUNDS = 4
WTF_CSRF_ENABLED = False
DEBUG_TB_ENABLED = True
DEBUG_TB_INTERCEPT_REDIRECTS = False
SQLALCHEMY_DATABASE_URI = 'sqlite:///{0}'.format(
os.path.join(basedir, 'dev.db'))
DEBUG_TB_ENABLED = True


class TestingConfig(BaseConfig):
"""Testing configuration."""
TESTING = True
BCRYPT_LOG_ROUNDS = 4
WTF_CSRF_ENABLED = False
SQLALCHEMY_DATABASE_URI = 'sqlite:///'
DEBUG_TB_ENABLED = False
PRESERVE_CONTEXT_ON_EXCEPTION = False
SQLALCHEMY_DATABASE_URI = 'sqlite:///'
TESTING = True


class ProductionConfig(BaseConfig):
"""Production configuration."""
SECRET_KEY = 'my_precious'
BCRYPT_LOG_ROUNDS = 13
SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/example'
DEBUG_TB_ENABLED = False
WTF_CSRF_ENABLED = True
5 changes: 5 additions & 0 deletions project/tests/test__config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import unittest
import os

from flask import current_app
from flask_testing import TestCase
Expand Down Expand Up @@ -48,6 +49,10 @@ def test_app_is_production(self):
self.assertTrue(app.config['WTF_CSRF_ENABLED'] is True)
self.assertTrue(app.config['BCRYPT_LOG_ROUNDS'] == 13)

def test_secret_key_has_been_set(self):
self.assertTrue(app.secret_key == os.getenv(
'SECRET_KEY', default='my_precious'))


if __name__ == '__main__':
unittest.main()

0 comments on commit 6f9531c

Please sign in to comment.