Charles Reid
2d8f830a7a
|
2 years ago | |
---|---|---|
docs/img | 2 years ago | |
src | 2 years ago | |
tests | 2 years ago | |
.flake8 | 2 years ago | |
.gitignore | 2 years ago | |
.pre-commit-config.yaml | 2 years ago | |
LICENSE | 2 years ago | |
Makefile | 2 years ago | |
Readme.md | 2 years ago | |
common.mk | 2 years ago | |
environment.example | 2 years ago | |
requirements-test.txt | 2 years ago | |
requirements.txt | 2 years ago | |
setup.py | 2 years ago |
Readme.md
alan-rickman
A Python project that wraps an authenticated API, and implements tests with pytest and mock. Also demonstrates how to separate offline and online tests, and safely manage secrets.
What's in this repo?
-
environment
- you must copyenvironment.example
toenvironment
and update the environment variable values before using this package. This environment file is ignored by git so that secrets are not accidentally added to the git repo.- Run
source environment
to load the variables.
- Run
-
src/
- contains a simple library wrapping a few calls to the GitHub API. This API requires a GitHub API token to call. This package uses the PyGithub package under the hood.- Run
make requirements
to install dependencies. - Run
make build
to build and install the package.
- Run
-
tests/
- contains tests implemented with pytest and unittest. Tests are categorized as offline (standalone) or online (integration). Which tests are run is controlled by environment variables.- Run
make requirements-test
to install packages required for tests. - Update
environment
to control whether standalone or integration tests are run. - Run
make test
to run the test suite.
- Run
Quick Start
git clone git@github.com:charlesreid1-toy-factory/alan-rickman.git
cd alan-rickman
Set up a virtual environment:
python3 -m virtualenv vp && source vp/bin/activate
Next, run make requirements
to install dependencies.
Next, run make build
to build and install the package.
Now you should be able to successfully import the package from Python:
$ python3
>>> import alan_rickman
>>>
Finally, to install the pre-commit hooks, run this command from the command line from the repository root:
pre-commit install
This will install pre-commit checks as specified in .pre-commit-config.yaml
.
Running Tests
Before running tests, run make requirements-test
to install packages required for tests.
Tests can run in standalone mode (offline) or integration mode (online). Integration mode
requires a working GitHub API access token, which you can specify via the environment
file
or the ALAN_RICKMAN_GITHUB_ACCESS_TOKEN
environment var.
The test mode is specified via an environment variable ALAN_RICKMAN_TEST_MODE
.
Run make test
to run the test suite.
Note: Running standalone tests does not require a real GitHub API access token. Integration tests do require a real access token. Any Github user's access token will work.
Environment Variables
ALAN_RICKMAN_HOME
- location of the repository root, used by scriptsALAN_RICKMAN_GITHUB_ACCESS_TOKEN
- GitHub API access tokenALAN_RICKMAN_TEST_MODE
- which mode to run tests in (standalone, integration, or both)
Technologies Used
Core library:
Tests:
Lint and style:
Patterns Demonstrated
- Environment variables and
environment
file to safely manage secrets and access them from the program when needed - Makefile, and associated useful Makefile patterns
- Pre-commit hooks to enforce linting and code style
- Pytest to run the test suite
- Separation of standalone and integation tests
(The use of the PyGithub library is not the feature of this repo, but PyGuthub is a really great library!)