Solution: Random redirect



examples/flask/random-redirect/app.py
from flask import Flask, redirect
import random

app = Flask(__name__)

urls = [
    'https://code-maven.com/',
    'https://perlmaven.com/',
    'https://hostlocal.com/',
    'https://pydigger.com/',
    'https://szabgab.com/',
]

@app.route('/')
def index():
    return '<a href="/random">Random</a>'

@app.route('/random')
def random_redirect():
    return redirect(random.choice(urls))

examples/flask/random-redirect/test_app.py
import app

def test_app():
    web = app.app.test_client()

    rv = web.get('/')
    assert rv.status == '200 OK'
    assert rv.data == b'<a href="/random">Random</a>'


    rv = web.get('/random')
    assert rv.status == '302 FOUND'
    assert 'https://' in rv.headers['Location']
    print(rv.headers['Location'])
    assert rv.headers['Location'] in app.urls