Skip to content

Commit

Permalink
Merge pull request #1 from ahmedsadman/development
Browse files Browse the repository at this point in the history
Structure change and basic CI/CD test
  • Loading branch information
ahmedsadman authored Nov 28, 2019
2 parents 68df0e6 + c0d74bb commit ce747d2
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: python
python:
- '3.7'
install:
- pip install -r requirements.txt
script:
- if [ "$TRAVIS_BRANCH" = "master" ]; then pytest tests/test_prod; fi
- if [ "$TRAVIS_BRANCH" = "development" ]; then pytest tests/test_dev; fi
5 changes: 2 additions & 3 deletions application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_jwt_extended import JWTManager
from config import Config
from application.error_handlers import *

# globally accessible variables
Expand All @@ -11,10 +10,10 @@
jwt = JWTManager()


def create_app():
def create_app(config):
"""Create the core application, uses application factory pattern"""
app = Flask(__name__)
app.config.from_object(Config)
app.config.from_object(config)

db.init_app(app)
migrate.init_app(app, db)
Expand Down
7 changes: 3 additions & 4 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@


class Config:
'''holds all the configuration for the flask application'''
"""holds all the configuration for the flask application"""

# general config
SECRET_KEY = os.environ.get('FLASK_SECRET_KEY', 'mysecretkeytest')
SECRET_KEY = os.environ.get("FLASK_SECRET_KEY")
PROPAGATE_EXCEPTIONS = True

# database
SQLALCHEMY_DATABASE_URI = os.environ.get(
'DATABASE_URL', 'sqlite:///data.db')
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL")
SQLALCHEMY_TRACK_MODIFICATIONS = False
16 changes: 16 additions & 0 deletions config_dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
from dotenv import load_dotenv

load_dotenv()


class Config:
"""holds all the configuration for the flask application"""

# general config
SECRET_KEY = os.environ.get("FLASK_SECRET_KEY")
PROPAGATE_EXCEPTIONS = True

# database for dev test
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL_DEV")
SQLALCHEMY_TRACK_MODIFICATIONS = False
11 changes: 11 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ alembic==1.1.0
aniso8601==7.0.0
appdirs==1.4.3
astroid==2.2.5
atomicwrites==1.3.0
attrs==19.1.0
autopep8==1.4.4
black==19.3b0
certifi==2019.9.11
cffi==1.13.1
Expand All @@ -18,6 +20,7 @@ gevent==1.4.0
geventhttpclient-wheels==1.3.1.dev2
greenlet==0.4.15
idna==2.8
importlib-metadata==0.23
isort==4.3.21
itsdangerous==1.1.0
Jinja2==2.10.1
Expand All @@ -27,12 +30,18 @@ Mako==1.1.0
MarkupSafe==1.1.1
marshmallow==3.0.0
mccabe==0.6.1
more-itertools==7.2.0
msgpack-python==0.5.6
packaging==19.2
pep8==1.7.1
pluggy==0.13.1
psycopg2==2.8.3
py==1.8.0
pycodestyle==2.5.0
pycparser==2.19
PyJWT==1.7.1
pyparsing==2.4.5
pytest==5.3.1
python-dateutil==2.8.0
python-dotenv==0.10.3
python-editor==1.0.4
Expand All @@ -46,6 +55,8 @@ SQLAlchemy==1.3.6
toml==0.10.0
typed-ast==1.4.0
urllib3==1.25.6
wcwidth==0.1.7
Werkzeug==0.15.5
wrapt==1.11.2
zipp==0.6.0
uwsgi
4 changes: 2 additions & 2 deletions start_dev.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from application import create_app
from dotenv import load_dotenv
from config_dev import Config

load_dotenv()
app = create_app()
app = create_app(Config)

if __name__ == "__main__":
app.run(debug=True)
Empty file added tests/__init__.py
Empty file.
Empty file added tests/test_dev/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions tests/test_dev/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
from dotenv import load_dotenv
from application import create_app
from config_dev import Config

# holds all the fixtures
# fixtures are ran once during request, this client will be passed in
# other test_*.py files


@pytest.fixture(scope="module")
def client(request):
flask_app = create_app(Config)
testing_client = flask_app.test_client()
return testing_client
16 changes: 16 additions & 0 deletions tests/test_dev/test_read.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest
import json
from application import create_app
from dotenv import load_dotenv
from config import Config


def test_homepage(client):
r = client.get("/")
assert r.status_code == 200


def test_events(client):
r = client.get("/events")
# res = json.loads(r.data)
assert r.status_code == 200
Empty file added tests/test_prod/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions tests/test_prod/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
from dotenv import load_dotenv
from application import create_app
from config import Config

# holds all the fixtures
# fixtures are ran once during request, this client will be passed in
# other test_*.py files


@pytest.fixture(scope="module")
def client(request):
flask_app = create_app(Config)
testing_client = flask_app.test_client()
return testing_client
1 change: 1 addition & 0 deletions tests/test_prod/test_read.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from tests.test_dev.test_read import *
3 changes: 2 additions & 1 deletion wsgi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from application import create_app
from config import Config

app = create_app()
app = create_app(Config)

0 comments on commit ce747d2

Please sign in to comment.