config tests
This commit is contained in:
parent
6fb4b2a278
commit
836b0bb7dd
9 changed files with 116 additions and 10 deletions
17
app.py
17
app.py
|
@ -14,15 +14,13 @@ from flask_cors import CORS
|
|||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
|
||||
# base directory
|
||||
basedir = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
# dev database
|
||||
DATABASE = 'postgresql://localhost/browser-go'
|
||||
|
||||
# config database
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
app_settings = os.getenv(
|
||||
'APP_SETTINGS',
|
||||
'project.server.config.DevelopmentConfig'
|
||||
)
|
||||
|
||||
app.config.from_object(app_settings)
|
||||
|
||||
#init bcrypt
|
||||
bcrypt = Bcrypt(app)
|
||||
|
@ -54,5 +52,8 @@ PORT = 8000
|
|||
def hello_world():
|
||||
return 'Hello World'
|
||||
|
||||
@app.route('/api')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=DEBUG, port=PORT)
|
32
config.py
Normal file
32
config.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
|
||||
# local db
|
||||
DATABASE = 'postgresql://localhost/browser-go'
|
||||
|
||||
class BaseConfig:
|
||||
"""Base configuration."""
|
||||
SECRET_KEY = os.getenv('SECRET_KEY')
|
||||
DEBUG = False
|
||||
BCRYPT_LOG_ROUNDS = 13
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
|
||||
class DevelopmentConfig(BaseConfig):
|
||||
"""Development configuration."""
|
||||
DEBUG = True
|
||||
BCRYPT_LOG_ROUNDS = 4
|
||||
SQLALCHEMY_DATABASE_URI = DATABASE
|
||||
|
||||
|
||||
class TestingConfig(BaseConfig):
|
||||
"""Testing configuration."""
|
||||
DEBUG = True
|
||||
TESTING = True
|
||||
BCRYPT_LOG_ROUNDS = 4
|
||||
SQLALCHEMY_DATABASE_URI = DATABASE
|
||||
PRESERVE_CONTEXT_ON_EXCEPTION = False
|
||||
|
||||
|
||||
class ProductionConfig(BaseConfig):
|
||||
"""Production configuration."""
|
||||
SECRET_KEY = ''
|
||||
DEBUG = False
|
||||
SQLALCHEMY_DATABASE_URI = 'postgresql:///'
|
39
manage.py
Normal file
39
manage.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import os
|
||||
import unittest
|
||||
|
||||
from flask_script import Manager
|
||||
from flask_migrate import Migrate, MigrateCommand
|
||||
|
||||
from app import app, db
|
||||
|
||||
migrate = Migrate(app, db)
|
||||
manager = Manager(app)
|
||||
|
||||
# migrations
|
||||
manager.add_command('db', MigrateCommand)
|
||||
|
||||
|
||||
@manager.command
|
||||
def test():
|
||||
"""Runs the unit tests without test coverage."""
|
||||
tests = unittest.TestLoader().discover('browser-go-api/tests', pattern='test*.py')
|
||||
result = unittest.TextTestRunner(verbosity=2).run(tests)
|
||||
if result.wasSuccessful():
|
||||
return 0
|
||||
return 1
|
||||
|
||||
|
||||
@manager.command
|
||||
def create_db():
|
||||
"""Creates the db tables."""
|
||||
db.create_all()
|
||||
|
||||
|
||||
@manager.command
|
||||
def drop_db():
|
||||
"""Drops the db tables."""
|
||||
db.drop_all()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
manager.run()
|
|
@ -1 +0,0 @@
|
|||
from app import db, ma
|
|
@ -1,4 +1,5 @@
|
|||
from ..app import db, ma, bcrypt
|
||||
import datetime
|
||||
import enum
|
||||
|
||||
class Ranks(enum.Enum): # with minimal Elo rating
|
||||
|
@ -39,6 +40,7 @@ class Ranks(enum.Enum): # with minimal Elo rating
|
|||
K28 = "Twenty-Eight Kyu"
|
||||
K29 = "Twenty-Nine Kyu"
|
||||
K30 = "Thirty Kyu" # Elo -900
|
||||
RU = "Unknown Rank"
|
||||
|
||||
class User(db.Model):
|
||||
__tablename__ = "users"
|
||||
|
@ -52,7 +54,10 @@ class User(db.Model):
|
|||
elo = db.Column(db.Integer)
|
||||
rank_certainty = db.Column(db.Boolean, nullable=False, default=False)
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, email, password, admin=False,):
|
||||
self.email = email
|
||||
self.password = bcrypt.generate_password_hash(
|
||||
password, app.config.get('BCRYPT_LOG_ROUNDS')
|
||||
).decode()
|
||||
self.registered_on = datetime.datetime.now()
|
||||
self.admin = admin
|
||||
|
|
|
@ -8,7 +8,9 @@ Flask-Bcrypt==0.7.1
|
|||
Flask-Cors==3.0.8
|
||||
flask-marshmallow==0.10.1
|
||||
Flask-Migrate==2.5.2
|
||||
Flask-Script==2.0.6
|
||||
Flask-SQLAlchemy==2.4.1
|
||||
Flask-Testing==0.7.1
|
||||
isort==4.3.21
|
||||
itsdangerous==1.1.0
|
||||
Jinja2==2.10.1
|
||||
|
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
14
tests/base.py
Normal file
14
tests/base.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from flask_testing import TestCase
|
||||
from ..app import app, db
|
||||
|
||||
class BaseTestCase(TestCase):
|
||||
""" Base Tests """
|
||||
|
||||
def create_app(self):
|
||||
pass
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
14
tests/test_config.py
Normal file
14
tests/test_config.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
import unittest
|
||||
|
||||
from flask import current_app
|
||||
from flask_testing import TestCase
|
||||
|
||||
from ..app import app
|
||||
|
||||
class TestDevelopmentConfig(TestCase):
|
||||
def create_app(self):
|
||||
app.config.from_object('browser-go-api.config.DevelopmentConfig')
|
||||
return app
|
||||
|
||||
def test_app_is_development(self):
|
||||
self.assertFalse(app.config['SECRET_KEY'] is 'my_precious')
|
Loading…
Reference in a new issue