Skip to content

Commit

Permalink
Merge pull request #117 from tiangolo/testing
Browse files Browse the repository at this point in the history
Add testing for all the functionality, defaults, configurations, environment variables, app set up, etc.
  • Loading branch information
tiangolo committed Jan 11, 2019
2 parents b56bf30 + fca8639 commit 605be19
Show file tree
Hide file tree
Showing 74 changed files with 1,034 additions and 307 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,6 +3,8 @@
__pycache__/
*.py[cod]
*$py.class
.mypy_cache
.vscode

# C extensions
*.so
Expand Down
14 changes: 13 additions & 1 deletion .travis.yml
Expand Up @@ -2,8 +2,20 @@ sudo: required

language: python

python:
- "3.6"

install:
- pip install docker pytest

services:
- docker

script:
- bash scripts/build-push.sh
- bash scripts/test.sh

deploy:
provider: script
script: bash scripts/build-push.sh
on:
branch: master
23 changes: 23 additions & 0 deletions Pipfile
@@ -0,0 +1,23 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
docker = "*"
pytest = "*"
black = "*"
mypy = "*"
pylint = "*"
jupyter = "*"
flake8 = "*"
autoflake = "*"

[requires]
python_version = "3.6"

[pipenv]
allow_prereleases = true

[packages]
flask = "*"
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -1085,6 +1085,10 @@ COPY ./app /app
and then customize with environment variables.


## Tests

All the image tags, configurations, environment variables and application options are tested.


## License

Expand Down
19 changes: 0 additions & 19 deletions deprecated-index/Dockerfile

This file was deleted.

87 changes: 0 additions & 87 deletions deprecated-index/entrypoint.sh

This file was deleted.

15 changes: 0 additions & 15 deletions deprecated/Dockerfile

This file was deleted.

87 changes: 0 additions & 87 deletions deprecated/entrypoint.sh

This file was deleted.

2 changes: 1 addition & 1 deletion example-flask-package-python3.7/app/app/api/api.py
@@ -1 +1 @@
from .endpoints import user
from .endpoints import user # noqa
12 changes: 4 additions & 8 deletions example-flask-package-python3.7/app/app/api/endpoints/user.py
@@ -1,19 +1,15 @@
from flask import jsonify

from ..utils import senseless_print

from ...main import app
from ...core.database import users
from ...main import app
from ..utils import senseless_print


@app.route('/users/')
@app.route("/users/")
def route_users():
users_data = []
for user in users:
user_data = {
'name': user.name,
'email': user.email,
}
user_data = {"name": user.name, "email": user.email}
users_data.append(user_data)
senseless_print()
return jsonify(users_data)
2 changes: 1 addition & 1 deletion example-flask-package-python3.7/app/app/api/utils.py
@@ -1,3 +1,3 @@
def senseless_print():
# Print something, just to demonstrate how to import modules
print('Senseless print')
print("Senseless print")
6 changes: 3 additions & 3 deletions example-flask-package-python3.7/app/app/core/app_setup.py
@@ -1,10 +1,10 @@
from ..api import api # noqa
from ..main import app
from ..api import api


@app.route("/")
def hello():
# This could also be returning an index.html
return '''Hello World from Flask in a uWSGI Nginx Docker container with \
return """Hello World from Flask in a uWSGI Nginx Docker container with \
Python 3.7 (from the example template),
try also: <a href="/users/">/users/</a>'''
try also: <a href="/users/">/users/</a>"""
4 changes: 2 additions & 2 deletions example-flask-package-python3.7/app/app/core/database.py
@@ -1,6 +1,6 @@
from ..models.user import User

users = [
User('Alice Example', 'alice@example.com'),
User('Bob Example', 'bob@example.com'),
User("Alice Example", "alice@example.com"),
User("Bob Example", "bob@example.com"),
]
4 changes: 1 addition & 3 deletions example-flask-package-python3.7/app/app/main.py
Expand Up @@ -2,9 +2,7 @@

app = Flask(__name__)

from .core import app_setup


if __name__ == "__main__":
# Only for debugging while developing
app.run(host='0.0.0.0', debug=True, port=80)
app.run(host="0.0.0.0", debug=True, port=80)
4 changes: 1 addition & 3 deletions example-flask-package-python3.7/app/app/models/user.py
@@ -1,6 +1,4 @@


# This could be a SQLAlchemy model,
# This could be a SQLAlchemy model,
# an ElasticSearch document, a MongoDB document, etc
class User:
def __init__(self, name, email):
Expand Down
9 changes: 5 additions & 4 deletions example-flask-python3.7-index/app/main.py
@@ -1,6 +1,7 @@
import os

from flask import Flask, send_file

app = Flask(__name__)


Expand All @@ -12,12 +13,12 @@ def hello():

@app.route("/")
def main():
index_path = os.path.join(app.static_folder, 'index.html')
index_path = os.path.join(app.static_folder, "index.html")
return send_file(index_path)


# Everything not declared before (not a Flask route / API endpoint)...
@app.route('/<path:path>')
@app.route("/<path:path>")
def route_frontend(path):
# ...could be a static file needed by the front end that
# doesn't use the `static` path (like in `<script src="bundle.js">`)
Expand All @@ -26,10 +27,10 @@ def route_frontend(path):
return send_file(file_path)
# ...or should be handled by the SPA's "router" in front end
else:
index_path = os.path.join(app.static_folder, 'index.html')
index_path = os.path.join(app.static_folder, "index.html")
return send_file(index_path)


if __name__ == "__main__":
# Only for debugging while developing
app.run(host='0.0.0.0', debug=True, port=80)
app.run(host="0.0.0.0", debug=True, port=80)

0 comments on commit 605be19

Please sign in to comment.