Skip to content

Commit 6f9531c

Browse files
authored
Merge pull request #28 from vuLgAr/dry-config
dry config
2 parents 18dcda7 + a80739c commit 6f9531c

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

project/server/config.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,36 @@
11
# project/server/config.py
22

33
import os
4+
45
basedir = os.path.abspath(os.path.dirname(__file__))
56

67

78
class BaseConfig(object):
89
"""Base configuration."""
9-
SECRET_KEY = 'my_precious'
10-
BCRYPT_LOG_ROUNDS = 13
11-
WTF_CSRF_ENABLED = True
10+
BCRYPT_LOG_ROUNDS = 4
1211
DEBUG_TB_ENABLED = False
13-
DEBUG_TB_INTERCEPT_REDIRECTS = False
12+
SECRET_KEY = os.getenv('SECRET_KEY', default='my_precious')
1413
SQLALCHEMY_TRACK_MODIFICATIONS = False
14+
WTF_CSRF_ENABLED = False
1515

1616

1717
class DevelopmentConfig(BaseConfig):
1818
"""Development configuration."""
19-
BCRYPT_LOG_ROUNDS = 4
20-
WTF_CSRF_ENABLED = False
19+
DEBUG_TB_ENABLED = True
20+
DEBUG_TB_INTERCEPT_REDIRECTS = False
2121
SQLALCHEMY_DATABASE_URI = 'sqlite:///{0}'.format(
2222
os.path.join(basedir, 'dev.db'))
23-
DEBUG_TB_ENABLED = True
2423

2524

2625
class TestingConfig(BaseConfig):
2726
"""Testing configuration."""
28-
TESTING = True
29-
BCRYPT_LOG_ROUNDS = 4
30-
WTF_CSRF_ENABLED = False
31-
SQLALCHEMY_DATABASE_URI = 'sqlite:///'
32-
DEBUG_TB_ENABLED = False
3327
PRESERVE_CONTEXT_ON_EXCEPTION = False
28+
SQLALCHEMY_DATABASE_URI = 'sqlite:///'
29+
TESTING = True
3430

3531

3632
class ProductionConfig(BaseConfig):
3733
"""Production configuration."""
38-
SECRET_KEY = 'my_precious'
34+
BCRYPT_LOG_ROUNDS = 13
3935
SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/example'
40-
DEBUG_TB_ENABLED = False
36+
WTF_CSRF_ENABLED = True

project/tests/test__config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import unittest
5+
import os
56

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

52+
def test_secret_key_has_been_set(self):
53+
self.assertTrue(app.secret_key == os.getenv(
54+
'SECRET_KEY', default='my_precious'))
55+
5156

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

0 commit comments

Comments
 (0)