Creating A Mock Server For Testing
See Through The `Flask`
11 min readJul 10, 2022
In many cases, we just need a basic mock server to test for basic features, e.g.:
├── Present a page
├── Send parameters*
├── Upload a file*
├── Download a file* and have the server store or process them.
Basic Set Up
├── app.py
├── get_data_from_url.py
├── requirements.txt
├── static
│ └── image_00.jpg
└── templates
│ ├── index.html
│ └── uploader.html
│ └── download.html
└── uploads # where files will be uploaded to [aka 'files_upload']
└── files_for_download
Flask Server
├── app.py
"""
import osfrom flask import Flask, render_template, flash, request, redirect, send_file
from datetime import datetimeapp = Flask(__name__)@app.route('/main', methods=['GET'])
def main():
return render_template('index.html')@app.route('/add/<int:n1>/<int:n2>/')
def add(n1, n2): # e.g. /add/11/22/
return '<h1>{}</h1>'.format(n1 + n2)# demonstrates passing inputs
# usage:
# e.g. http://127.0.0.1:5000/index/a=20
# e.g. http://127.0.0.1:5000/index/
@app.route('/index/', defaults={'a' : 'Flask'})
@app.route('/index/<a>')
def subject_00(a):
statement = 'The value is…