You've already forked devops-exercises
Rename repository
Unforunately, It came to my knowledge that this repository promoted a phenomenon where DevOps interviews became a trivia game where people think it's normal to throw 20 random short questions like "what is fork()" or "which tools would you use for each of the following areas?" and this was not my intention. To explcitly state this repository doesn't represents real DevOps interview questions I've decided to rename it.
This commit is contained in:
2
exercises/flask_container_ci/app/__init__.py
Normal file
2
exercises/flask_container_ci/app/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
53
exercises/flask_container_ci/app/app.py
Normal file
53
exercises/flask_container_ci/app/app.py
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/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)
|
||||
11
exercises/flask_container_ci/app/config.py
Normal file
11
exercises/flask_container_ci/app/config.py
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
|
||||
import os
|
||||
|
||||
basedir = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
SECRET_KEY = 'shhh'
|
||||
CSRF_ENABLED = True
|
||||
|
||||
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db')
|
||||
58
exercises/flask_container_ci/app/main.py
Normal file
58
exercises/flask_container_ci/app/main.py
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/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.route("/", 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
|
||||
|
||||
|
||||
def create_test_app():
|
||||
app = Flask(__name__)
|
||||
return app
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(port=5000)
|
||||
28
exercises/flask_container_ci/app/tests.py
Normal file
28
exercises/flask_container_ci/app/tests.py
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from config import basedir
|
||||
from app import app
|
||||
from app import db
|
||||
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
app.config['TESTING'] = True
|
||||
app.config['WTF_CSRF_ENABLED'] = False
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(
|
||||
basedir, 'test.db')
|
||||
self.app = app.test_client()
|
||||
db.create_all()
|
||||
|
||||
def tearDown(self):
|
||||
db.session.remove()
|
||||
db.drop_all()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user