Skip to content

Example Application For A Blog Post About Branching And Tests

Notifications You must be signed in to change notification settings

jjmojojjmojo/random_quote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

random_quote

A simple (but not trivial) example application for a blog post about git branching and writing tests with pytest.

Basic Setup

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

Running The Tests

Tests are written with pytest.

They can be invoked like this:

$ pytest src

Initializing The Database And Populating It With Some Quotes

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)

Running The Application

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.

Branches

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:

part1
All the changes from part 1.
part2
All the changes from part 1 and part 2
qotd
Developer A's feature from part 3.
index-info
Developer B's bug fix from part 3.
part3
All the changes from part 1, part 2 and part 3!

About

Example Application For A Blog Post About Branching And Tests

Resources

Stars

Watchers

Forks

Packages

No packages published