Test driven development ["TDD"] of a Python module for Biblia API.
Create a Python module that we can use to perform requests to Biblia API.
The CLI contains a subset of the module. The parameters are:
- Bible content
- Bible search
- Table of contents
- Verse of the day
We'll start by cloning this repository to our workstation. Then, we'll install pipenv
and create a Python 3 virtualenv for this project.
$ git clone https://github.com/dennislwm/pybiblia
$ cd pybiblia
$ pip3 install --user pipenv
$ pipenv --python $(which python3)
Before you can use pybiblia
module, you need to obtain an API key. You can then pass the API key as a str
parameter to class Pybiblia
.
There are two options available to configure the API key if you're using the Biblia CLI. Choose either
- set environment variable
BIBLIA_API_KEY=<API_KEY>
; or - create a
config.json
file and insert the line{ "BIBLIA_API_KEY": "<API_KEY>" }
.
Sign in at https://api.biblia.com/v1/Users/SignIn
to register your application.
pybiblia/ <-- Root of your project
|- .dockerignore <-- Docker ignore
|- .gitignore <-- GitHub ignore
|- Dockerfile
|- LICENSE
|- Makefile <-- Make
|- Pipfile <-- Generated by pipenv
|- Pipfile.lock
|- README.md <-- GitHub README markdown
|- requirements.txt <-- Python requirements used by Dockerfile
+- src/
+- pybiblia/ <-- Holds any business logic
|- __init__.py
|- cli.py <-- Python module to parse command line
|- pybiblia.py <-- Python module to requests
+- tests/ <-- Holds any automated tests
|- test_cli.py <-- Python script to test cli.py
|- test_pybiblia.py
For this project, we're using pytest
as our testing framework. We wrote a line in our Makefile
that utilizes the pytest
.
The file test_cli.py
ensures that our CLI works as expected.
The file test_pybiblia.py
ensures that our requests to Biblia API works as expected.
Before we can use pybiblia
in our Python development, we need to activate virtualenv and install our package locally.
$ pipenv shell
(pybiblia) $ pip install -e .
To uninstall our package.
(pybiblia) $ pip uninstall pybiblia
We need to install using pip install pybiblia
and then we can add the line import pybiblia
in our Python script.