forked from qxf2/qa-interview-web-application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
52 lines (41 loc) · 1.5 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
This is a Flask application that can be used to interview QA engineers.
All the application does is to calculate the factorial of a number.
But there have been bugs seeded. For example, this application will go into an infinite loop if you pass it a negative number.
To learn more, see the README.md of this application.
"""
from flask import Flask
from flask import jsonify
from flask import render_template
from flask import request
app = Flask(__name__)
def calculate_factorial(n):
"Calculate the factorial of a number"
if n == 0:
return 1
else:
return n * calculate_factorial(n - 1)
@app.route("/", methods=["GET", "POST"])
@app.route("/factorial", methods=["GET", "POST"])
def factorial():
"Endpoint for calculating the factorial of a number"
if request.method == "GET":
# return the form
return render_template("factorial.html")
if request.method == "POST":
# return the answer
number = int(request.form.get("number"))
result = calculate_factorial(number)
api_response = {"answer": result}
return jsonify(api_response)
@app.route("/terms")
def terms_and_conditions():
"Return terms and conditions"
return "This is the terms and conditions document. We are not yet ready with it. Stay tuned!"
@app.route("/privacy")
def privacy():
"Return privacy statement"
return "This is the privacy document. We are not yet ready with it. Stay tuned!"
# ---START OF SCRIPT
if __name__ == "__main__":
app.run()