Initial commit
This commit is contained in:
17
app/__init__.py
Normal file
17
app/__init__.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from flask import Flask, jsonify
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
db = SQLAlchemy()
|
||||
|
||||
|
||||
def create_app(env=None):
|
||||
from fte.config import config_by_name
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(config_by_name[env or 'test'])
|
||||
|
||||
db.init_app(app)
|
||||
|
||||
@app.route('/health')
|
||||
def health():
|
||||
return jsonify('healthy')
|
||||
return app
|
14
app/__init__test.py
Normal file
14
app/__init__test.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from fte.test.fixtures import app, client # noqa
|
||||
|
||||
|
||||
def test_app_creates(app): # noqa
|
||||
assert app
|
||||
|
||||
|
||||
def test_app_healthy(app, client): # noqa
|
||||
#with app.app_context():
|
||||
with client:
|
||||
resp = client.get('/health')
|
||||
assert resp.status_code == 200
|
||||
assert resp.is_json
|
||||
assert resp.json == 'healthy'
|
0
app/client/__init__.py
Normal file
0
app/client/__init__.py
Normal file
16
app/client/requests_test.py
Normal file
16
app/client/requests_test.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from fte import create_app
|
||||
from fte.decorators import accepts
|
||||
|
||||
from fte.test.fixtures import app, client # noqa
|
||||
|
||||
|
||||
def test_reqparse(app):
|
||||
@app.route('/hello_world')
|
||||
def respond():
|
||||
from flask import jsonify
|
||||
return jsonify('Hello, World')
|
||||
with app.test_client() as cl:
|
||||
response = cl.get('/hello_world')
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json == 'Hello, World'
|
37
app/config.py
Normal file
37
app/config.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import os
|
||||
|
||||
basedir = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
|
||||
class BaseConfig:
|
||||
USE_MOCK_EQUIVALENCY = False
|
||||
DEBUG = False
|
||||
|
||||
|
||||
class DevelopmentConfig(BaseConfig):
|
||||
CONFIG_NAME = 'dev'
|
||||
SECRET_KEY = os.getenv(
|
||||
"DEV_SECRET_KEY", "You can't see California without Marlon Brando's eyes")
|
||||
DEBUG = True
|
||||
TESTING = False
|
||||
SQLALCHEMY_DATABASE_URI = "sqlite:///{0}/app-dev.db".format(basedir)
|
||||
|
||||
|
||||
class TestingConfig(BaseConfig):
|
||||
CONFIG_NAME = 'test'
|
||||
SECRET_KEY = os.getenv("TEST_SECRET_KEY", "Thanos did nothing wrong")
|
||||
DEBUG = True
|
||||
TESTING = True
|
||||
SQLALCHEMY_DATABASE_URI = "sqlite:///{0}/app-test.db".format(basedir)
|
||||
|
||||
|
||||
class ProductionConfig(BaseConfig):
|
||||
CONFIG_NAME = 'prod'
|
||||
SECRET_KEY = os.getenv("PROD_SECRET_KEY", "I'm Ron Burgundy?")
|
||||
DEBUG = False
|
||||
TESTING = False
|
||||
SQLALCHEMY_DATABASE_URI = "sqlite:///{0}/app-prod.db".format(basedir)
|
||||
|
||||
|
||||
EXPORT_CONFIGS = [DevelopmentConfig, TestingConfig, ProductionConfig]
|
||||
config_by_name = {cfg.CONFIG_NAME: cfg for cfg in EXPORT_CONFIGS}
|
0
app/test/__init__.py
Normal file
0
app/test/__init__.py
Normal file
23
app/test/fixtures.py
Normal file
23
app/test/fixtures.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import pytest
|
||||
|
||||
from fte import create_app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app():
|
||||
return create_app('test')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(app):
|
||||
return app.test_client()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def db(app):
|
||||
from fte import db
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
yield db
|
||||
db.drop_all()
|
||||
db.session.commit()
|
Reference in New Issue
Block a user