A simple (but not trivial) example application for a blog post about git branching and writing tests with pytest.
After cloning this repository, first initialize a virtual environment, then activate it:
$ python -m venv .
$ source bin/activate
Then install the application:
$ pip install -e .
And the development/testing requirements:
$ pip install -r requirements.txt
Tests are written with pytest.
They can be invoked like this:
$ pytest src
First you will need a CSV file containing quotes and author names. Call it quotes.csv
.
You can create your own if you'd like. Ensure the first row contains the column names:
quote,author
"When I get a little money I buy books; and if any is left, I buy food and clothes.", "Erasmus"
"Various disguises are regrettable but necessary, If you’re going to make it through the day.", "NoMeansNo"
But a script is provided that will generate many (defaults to 1000):
$ python scripts/generate_quotes.py
From a python prompt run:
>>> from random_quote import util
>>> conn = util.connection_factory("test.db")
>>> util.init(conn)
>>> util.ingest("quotes.csv", conn)
In requirements.txt
, Gunicorn is provided. There is also an example wsgi.py
file showing how to invoke the RandomQuoteApp
for use by Gunicorn.
A basic web instance can be launched like this:
$ gunicorn wsgi:app
The web server will be available at http://127.0.0.1:8000.
To facilitate easier use of the guide that this application was written for, branches are provided in this repository that correspond to various points of progress: