||1 year ago|
|docs/img||1 year ago|
|src||1 year ago|
|tests||1 year ago|
|.flake8||1 year ago|
|.gitignore||1 year ago|
|.pre-commit-config.yaml||1 year ago|
|LICENSE||1 year ago|
|Makefile||1 year ago|
|Readme.md||1 year ago|
|common.mk||1 year ago|
|environment.example||1 year ago|
|requirements-test.txt||1 year ago|
|requirements.txt||1 year ago|
|setup.py||1 year ago|
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 copy
environmentand 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.
source environmentto load the variables.
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.
make requirementsto install dependencies.
make buildto build and install the package.
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.
make requirements-testto install packages required for tests.
environmentto control whether standalone or integration tests are run.
make testto run the test suite.
git clone email@example.com:charlesreid1-toy-factory/alan-rickman.git cd alan-rickman
Set up a virtual environment:
python3 -m virtualenv vp && source vp/bin/activate
make requirements to install dependencies.
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:
This will install pre-commit checks as specified in
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
ALAN_RICKMAN_GITHUB_ACCESS_TOKEN environment var.
The test mode is specified via an environment variable
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.
ALAN_RICKMAN_HOME- location of the repository root, used by scripts
ALAN_RICKMAN_GITHUB_ACCESS_TOKEN- GitHub API access token
ALAN_RICKMAN_TEST_MODE- which mode to run tests in (standalone, integration, or both)
Lint and style:
- Environment variables and
environmentfile 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!)