Update flask_container_ci challenge
This commit is contained in:
parent
dc802d41b5
commit
e08c1cbf47
12
README.md
12
README.md
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
:information_source: This repository contains questions on various DevOps and SRE related topics
|
:information_source: This repository contains questions on various DevOps and SRE related topics
|
||||||
|
|
||||||
:bar_chart: There are currently **700** questions
|
:bar_chart: There are currently **701** questions
|
||||||
|
|
||||||
:books: To learn more about DevOps check the resources in [DevOpsBit.com](https://devopsbit.com)
|
:books: To learn more about DevOps check the resources in [DevOpsBit.com](https://devopsbit.com)
|
||||||
|
|
||||||
@ -23,7 +23,7 @@
|
|||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center"><a href="#devops"><img src="images/devops.png" width="70px;" height="75px;" alt="DevOps" /><br /><b>DevOps</b></a><br /><sub><a href="#devops-beginner">Beginner :baby:</a></sub><br><sub><a href="#devops-advanced">Advanced :star:</a></sub></td>
|
<td align="center"><a href="#devops"><img src="images/devops.png" width="70px;" height="75px;" alt="DevOps" /><br /><b>DevOps</b></a><br /><sub><a href="#devops-beginner">Beginner :baby:</a></sub><br><sub><a href="#devops-advanced">Advanced :star:</a></sub></td>
|
||||||
<td align="center"><a href="#jenkins"><img src="images/jenkins.png" width="80px;" height="85px;" alt="Jenkins"/><br /><b>Jenkins</b></a><br /><sub><a href="#jenkins-beginner">Beginner :baby:</a></sub><br><sub><a href="#jenkins-advanced">Advanced :star:</a></sub></td>
|
<td align="center"><a href="#jenkins"><img src="images/jenkins.png" width="85px;" height="85px;" alt="Jenkins"/><br /><b>Jenkins</b></a><br /><sub><a href="#jenkins-beginner">Beginner :baby:</a></sub><br><sub><a href="#jenkins-advanced">Advanced :star:</a></sub></td>
|
||||||
<td align="center"><a href="#git"><img src="images/git.png" width="80px;" height="75px;" alt="Git"/><br /><b>Git</b></a><br /><sub><a href="#git-beginner">Beginner :baby:</a></sub><br><sub><a href="#git-advanced">Advanced :star:</a></sub></td>
|
<td align="center"><a href="#git"><img src="images/git.png" width="80px;" height="75px;" alt="Git"/><br /><b>Git</b></a><br /><sub><a href="#git-beginner">Beginner :baby:</a></sub><br><sub><a href="#git-advanced">Advanced :star:</a></sub></td>
|
||||||
<td align="center"><a href="#ansible"><img src="images/ansible.png" width="65px;" height="75px;" alt="Ansible"/><br /><b>Ansible</b></a><br /><sub><a href="#ansible-beginner">Beginner :baby:</a></sub><br><sub><a href="#ansible-advanced">Advanced :star:</a></sub></td>
|
<td align="center"><a href="#ansible"><img src="images/ansible.png" width="65px;" height="75px;" alt="Ansible"/><br /><b>Ansible</b></a><br /><sub><a href="#ansible-beginner">Beginner :baby:</a></sub><br><sub><a href="#ansible-advanced">Advanced :star:</a></sub></td>
|
||||||
<td align="center"><a href="#Network"><img src="images/network.png" width="80x;" height="75px;" alt="Network"/><br /><b>Network</b></a><br /><sub><a href="#network-beginner">Beginner :baby:</a></sub><br><sub><a href="#network-advanced">Advanced :star:</a></sub></td>
|
<td align="center"><a href="#Network"><img src="images/network.png" width="80x;" height="75px;" alt="Network"/><br /><b>Network</b></a><br /><sub><a href="#network-beginner">Beginner :baby:</a></sub><br><sub><a href="#network-advanced">Advanced :star:</a></sub></td>
|
||||||
@ -1664,7 +1664,7 @@ Re-install the OS IS NOT the right answer :)
|
|||||||
<summary>What is sudo? How do you set it up?</summary><br><b>
|
<summary>What is sudo? How do you set it up?</summary><br><b>
|
||||||
</b></details>
|
</b></details>
|
||||||
|
|
||||||
##### Random and Strange :)
|
#### Random and Strange :)
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Give 5 commands which are two letters long</summary><br><b>
|
<summary>Give 5 commands which are two letters long</summary><br><b>
|
||||||
@ -1672,6 +1672,12 @@ Re-install the OS IS NOT the right answer :)
|
|||||||
ls, wc, dd, df, du, ps, ip, cp, cd ...
|
ls, wc, dd, df, du, ps, ip, cp, cd ...
|
||||||
</b></details>
|
</b></details>
|
||||||
|
|
||||||
|
#### Commands
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>What the lsof command does?</summary><br><b>
|
||||||
|
</b></details>
|
||||||
|
|
||||||
<a name="linux-advanced"></a>
|
<a name="linux-advanced"></a>
|
||||||
#### :star: Advanced
|
#### :star: Advanced
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ Please read carefully all the instructions.
|
|||||||
If any of the following steps is not working, it is expected from you to fix them
|
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. Move to `challenges/flask_container_ci` directory, if you are not already there
|
||||||
1. Run `export FLASK_APP=app/app.py`
|
1. Run `export FLASK_APP=app/main.py`
|
||||||
1. To run the app execute `flask run`. If it doesn't works, fix it
|
1. To run the app execute `flask run`. If it doesn't works, fix it
|
||||||
3. Access `http://127.0.0.1:5000`. You should see the following
|
3. Access `http://127.0.0.1:5000`. You should see the following
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ docker run -d -p 5000:5000 app
|
|||||||
Great, now that we have a working app and also can run it in a container, let's set up a CI for it so it won't break again in the future
|
Great, now that we have a working app and also can run it in a container, let's set up a CI for it so it won't break again in the future
|
||||||
In current directory you have a file called tests.py which includes the tests for the app. What is expected from you is:
|
In current directory you have a file called tests.py which includes the tests for the app. What is expected from you is:
|
||||||
|
|
||||||
1. The CI should run the app tests. You are free to choose whatever CI system or service you prefer.
|
1. The CI should run the app tests. You are free to choose whatever CI system or service you prefer. Use `python tests.py` for running the tests.
|
||||||
2. There should be some kind of test for the Dockerfile you wrote
|
2. There should be some kind of test for the Dockerfile you wrote
|
||||||
3. Add additional unit test (or another level of tests) for testing the app
|
3. Add additional unit test (or another level of tests) for testing the app
|
||||||
|
|
||||||
|
58
challenges/flask_container_ci/app/main.py
Normal file
58
challenges/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)
|
@ -1,27 +1,23 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
|
|
||||||
import os
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from config import basedir
|
from app import main
|
||||||
from app import app
|
|
||||||
from app import db
|
|
||||||
|
|
||||||
|
|
||||||
class TestCase(unittest.TestCase):
|
class TestCase(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
app.config['TESTING'] = True
|
self.app = main.app.test_client()
|
||||||
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):
|
def test_main_page(self):
|
||||||
db.session.remove()
|
response = self.app.get('/', follow_redirects=True)
|
||||||
db.drop_all()
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_users_page(self):
|
||||||
|
response = self.app.get('/users', follow_redirects=True)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user