Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install flake8 pytest-flask
python -m pip install --requirement requirements.txt
- name: Lint with flake8
run: |
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pytest = "*"
pytest-flask = "*"

[packages]
requests = "==2.23.0"
Expand Down
27 changes: 15 additions & 12 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@

from adapter import Adapter

app = Flask(__name__)

def create_app(test_config=None):
app = Flask(__name__)

@app.before_request
def log_request_info():
app.logger.debug('Headers: %s', request.headers)
app.logger.debug('Body: %s', request.get_data())
@app.before_request
def log_request_info():
app.logger.debug('Headers: %s', request.headers)
app.logger.debug('Body: %s', request.get_data())

@app.route('/', methods=['POST'])
def call_adapter():
data = request.get_json()
if data == '':
data = {}
adapter = Adapter(data)
return jsonify(adapter.result)

@app.route('/', methods=['POST'])
def call_adapter():
data = request.get_json()
if data == '':
data = {}
adapter = Adapter(data)
return jsonify(adapter.result)
return app


if __name__ == '__main__':
app = create_app()
app.run(debug=True, host='0.0.0.0', port='8080', threaded=True)
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest

from app import create_app


@pytest.fixture
def app():
app = create_app()
return app
8 changes: 8 additions & 0 deletions tests/functional/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def test_call_adapter(client):
assert client.post('/').status_code == 500
assert client.get('/').status_code == 405

rv = client.post('/', json={'id': '1', 'data': {}})
json_data = rv.get_json()
assert json_data.get('statusCode') == 500
assert json_data.get('status') == 'errored'