Skip to content

Commit

Permalink
Refactoring the structure of project, and add test using pytest
Browse files Browse the repository at this point in the history
* README.md; modify the explanation
* Refactoring the structure of project
  * Dockerfile3
  * app/__init__.py
  * app/api_only_flask.py
  * run.py
  * common/__init__.py
  * common/src/__init__.py
  * app/requirements.txt
* Add test using pytest
  * test/__init__.py
  * test/test_api_only_flask.py
  * test/test_app.py
  * test/pytest.ini
  • Loading branch information
morpheus.0 committed Jul 18, 2017
1 parent 44863bd commit fa446d2
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 18 deletions.
9 changes: 4 additions & 5 deletions python/test-flask/API/Dockerfile3
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ RUN apt-get install -y python3-pip python3-dev build-essential

RUN mkdir /app
RUN mkdir /app/logs
COPY ./api_only_flask.py /app
COPY ./settings.py /app
COPY ./requirements.txt /app
COPY ./run.py /app/run.py
COPY ./app/* /app/app/
COPY ./common /app/common
COPY ./test /app/test
WORKDIR /app

RUN pip3 install --upgrade pip
RUN pip3 install -r requirements.txt
RUN pip3 install -r app/requirements.txt

ENTRYPOINT ["python3"]
CMD ["api_only_flask.py"]
CMD ["run.py"]
9 changes: 8 additions & 1 deletion python/test-flask/API/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Flask API
* Execution

```
$ docker run --env-file=common/config/settings.env --rm -v `pwd`/logs:/app/logs -p 59459:5000 test-flask-api
$ docker run --env-file=common/config/settings.env --rm -v `pwd`/logs:/app/logs -v /etc/localtime:/etc/localtime:ro -p 59459:5000 test-flask-api
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
Expand Down Expand Up @@ -33,3 +33,10 @@ Flask API
```
$ docker build -f Dockerfile3 -t test-flask-api:latest .
```
* Test

```
$ pip3 install -U pytest
$ pip3 install pytest-env
$ pytest -v -c test/pytest.ini
```
7 changes: 7 additions & 0 deletions python/test-flask/API/app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from flask import Flask


app = Flask(__name__)


from app import api_only_flask
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf8 -*-
from app import app
from flask import Flask
from flask import request
from flask_pytest import FlaskPytest
import logging
import os
import sys
Expand All @@ -17,11 +16,6 @@
common.setup_logging(os.environ.get('LOGGING_CONFIG_FILEPATH'))


app = Flask(__name__)
app.config.from_pyfile('settings.py')
app = FlaskPytest(app)


@app.route('/')
def api_root():
return 'Welcome'
Expand Down Expand Up @@ -81,8 +75,8 @@ def stop():
return 'stop'


if __name__ == '__main__':
# IP_ADDRESS = socket.gethostbyname(socket.gethostname())
app.logger.setLevel(logging.DEBUG)
# app.run(host=IP_ADDRESS, port=59459, debug=True)
app.run(host='0.0.0.0', debug=True)
# if __name__ == '__main__':
# # IP_ADDRESS = socket.gethostbyname(socket.gethostname())
# app.logger.setLevel(logging.DEBUG)
# # app.run(host=IP_ADDRESS, port=59459, debug=True)
# app.run(host='0.0.0.0', debug=True)
File renamed without changes.
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions python/test-flask/API/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from app import app

if __name__ == '__main__':
# app.run(host='0.0.0.0', port=59459, debug=True)
app.run(host='0.0.0.0', debug=True)
Empty file.
4 changes: 4 additions & 0 deletions python/test-flask/API/test/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
env =
DEBUG=True
LOGGING_CONFIG_FILEPATH=common/config/logging.yaml
13 changes: 13 additions & 0 deletions python/test-flask/API/test/test_api_only_flask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os
import sys
import py.test


sys.path.append(os.path.join('.', '..',))


from app import api_only_flask


def test_api_root():
assert api_only_flask.api_root() == 'Welcome'
3 changes: 3 additions & 0 deletions python/test-flask/API/test/test_app.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
import pytest


def test_app():
assert True

0 comments on commit fa446d2

Please sign in to comment.