Member-only story
Creating A Mock Server For Testing
See Through The `Flask`
13 min readJul 10, 2022
1. Basic Set Up
2. Flask Server
3. Farming And Harvesting Online Data Sources
4. Creating Mock Data
5. Creating A Flask Server For Simple curl
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…