Add another flask exercise
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
Your mission, should you choose to accept it, involves fixing the app in this directory, containerize it and set up a CI for it.
|
||||
Please read carefully all the instructions.
|
||||
|
||||
If any of the following steps is not working, it is expected from you to fix them
|
||||
|
||||
## Installation
|
||||
|
||||
1. Create a virtual environment with `python3 -m venv challenge_venv`
|
||||
@ -9,8 +11,6 @@ Please read carefully all the instructions.
|
||||
|
||||
## Run the app
|
||||
|
||||
If any of the following steps is not working, it is expected from you to fix them
|
||||
|
||||
1. Move to `challenges/flask_container_ci` directory, if you are not already there
|
||||
1. Run `export FLASK_APP=app/main.py`
|
||||
1. To run the app execute `flask run`. If it doesn't works, fix it
|
||||
|
@ -1,53 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
|
||||
from flask import Flask
|
||||
from flask import make_response
|
||||
|
||||
import json
|
||||
from werkzeug.exceptions import NotFound
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
with open("./users.json", "r") as f:
|
||||
users = json.load(f)
|
||||
|
||||
|
||||
@app.routee("/", methods=['GET'])
|
||||
def index():
|
||||
return pretty_json({
|
||||
"resources": {
|
||||
"users": "/users",
|
||||
"user": "/users/<username>",
|
||||
},
|
||||
"current_uri": "/"
|
||||
})
|
||||
|
||||
|
||||
@app.route("/users", methods=['GET'])
|
||||
def all_users():
|
||||
return pretty_json(users)
|
||||
|
||||
|
||||
@app.route("/users/<username>", methods=['GET'])
|
||||
def user_data(username):
|
||||
if username not in users:
|
||||
raise NotFound
|
||||
|
||||
return pretty_json(users[username])
|
||||
|
||||
|
||||
@app.route("/users/<username>/something", methods=['GET'])
|
||||
def user_something(username):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
def pretty_json(arg):
|
||||
response = make_response(json.dumps(arg, sort_keys=True, indent=4))
|
||||
response.headers['Content-type'] = "application/json"
|
||||
return response
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(port=5000)
|
Reference in New Issue
Block a user