100% coverage of checks schemas

This commit is contained in:
Andrew Herrington
2021-12-06 16:49:20 -06:00
parent c291ce6895
commit 38128c8151
40 changed files with 3495 additions and 128 deletions

12
.cookiecutter.json Normal file
View File

@@ -0,0 +1,12 @@
{
"_template": "gh:cjolowicz/cookiecutter-hypermodern-python",
"author": "Andrew Herrington",
"development_status": "Development Status :: 3 - Alpha",
"email": "andrew@\ud83d\udcbb.kz",
"friendly_name": "Py Healthchecks.Io",
"github_user": "andrewthetechie",
"license": "MIT",
"package_name": "healthchecks_io",
"project_name": "py-healthchecks.io",
"version": "0.0.0"
}

2
.darglint Normal file
View File

@@ -0,0 +1,2 @@
[darglint]
strictness = long

9
.flake8 Normal file
View File

@@ -0,0 +1,9 @@
[flake8]
select = B,B9,C,D,DAR,E,F,N,RST,S,W
ignore = E203,E501,RST201,RST203,RST301,W503
max-line-length = 80
max-complexity = 10
docstring-convention = google
per-file-ignores = tests/*:S101
rst-roles = class,const,func,meth,mod,ref
rst-directives = deprecated

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
* text=auto eol=lf

18
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,18 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
- package-ecosystem: pip
directory: "/.github/workflows"
schedule:
interval: daily
- package-ecosystem: pip
directory: "/docs"
schedule:
interval: daily
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily

66
.github/labels.yml vendored Normal file
View File

@@ -0,0 +1,66 @@
---
# Labels names are important as they are used by Release Drafter to decide
# regarding where to record them in changelog or if to skip them.
#
# The repository labels will be automatically configured using this file and
# the GitHub Action https://github.com/marketplace/actions/github-labeler.
- name: breaking
description: Breaking Changes
color: bfd4f2
- name: bug
description: Something isn't working
color: d73a4a
- name: build
description: Build System and Dependencies
color: bfdadc
- name: ci
description: Continuous Integration
color: 4a97d6
- name: dependencies
description: Pull requests that update a dependency file
color: 0366d6
- name: documentation
description: Improvements or additions to documentation
color: 0075ca
- name: duplicate
description: This issue or pull request already exists
color: cfd3d7
- name: enhancement
description: New feature or request
color: a2eeef
- name: github_actions
description: Pull requests that update Github_actions code
color: "000000"
- name: good first issue
description: Good for newcomers
color: 7057ff
- name: help wanted
description: Extra attention is needed
color: 008672
- name: invalid
description: This doesn't seem right
color: e4e669
- name: performance
description: Performance
color: "016175"
- name: python
description: Pull requests that update Python code
color: 2b67c6
- name: question
description: Further information is requested
color: d876e3
- name: refactoring
description: Refactoring
color: ef67c4
- name: removal
description: Removals and Deprecations
color: 9ae7ea
- name: style
description: Style
color: c120e5
- name: testing
description: Testing
color: b1fc6f
- name: wontfix
description: This will not be worked on
color: ffffff

29
.github/release-drafter.yml vendored Normal file
View File

@@ -0,0 +1,29 @@
categories:
- title: ":boom: Breaking Changes"
label: "breaking"
- title: ":rocket: Features"
label: "enhancement"
- title: ":fire: Removals and Deprecations"
label: "removal"
- title: ":beetle: Fixes"
label: "bug"
- title: ":racehorse: Performance"
label: "performance"
- title: ":rotating_light: Testing"
label: "testing"
- title: ":construction_worker: Continuous Integration"
label: "ci"
- title: ":books: Documentation"
label: "documentation"
- title: ":hammer: Refactoring"
label: "refactoring"
- title: ":lipstick: Style"
label: "style"
- title: ":package: Dependencies"
labels:
- "dependencies"
- "build"
template: |
## Changes
$CHANGES

5
.github/workflows/constraints.txt vendored Normal file
View File

@@ -0,0 +1,5 @@
pip==21.3.1
nox==2021.10.1
nox-poetry==0.9.0
poetry==1.1.12
virtualenv==20.10.0

19
.github/workflows/labeler.yml vendored Normal file
View File

@@ -0,0 +1,19 @@
name: Labeler
on:
push:
branches:
- main
- master
jobs:
labeler:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v2.4.0
- name: Run Labeler
uses: crazy-max/ghaction-github-labeler@v3.1.1
with:
skip-delete: true

79
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,79 @@
name: Release
on:
push:
branches:
- main
- master
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v2.4.0
with:
fetch-depth: 2
- name: Set up Python
uses: actions/setup-python@v2.3.1
with:
python-version: "3.10"
- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
- name: Install Poetry
run: |
pip install --constraint=.github/workflows/constraints.txt poetry
poetry --version
- name: Check if there is a parent commit
id: check-parent-commit
run: |
echo "::set-output name=sha::$(git rev-parse --verify --quiet HEAD^)"
- name: Detect and tag new version
id: check-version
if: steps.check-parent-commit.outputs.sha
uses: salsify/action-detect-and-tag-new-version@v2.0.1
with:
version-command: |
bash -o pipefail -c "poetry version | awk '{ print \$2 }'"
- name: Bump version for developmental release
if: "! steps.check-version.outputs.tag"
run: |
poetry version patch &&
version=$(poetry version | awk '{ print $2 }') &&
poetry version $version.dev.$(date +%s)
- name: Build package
run: |
poetry build --ansi
- name: Publish package on PyPI
if: steps.check-version.outputs.tag
uses: pypa/gh-action-pypi-publish@v1.4.2
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
- name: Publish package on TestPyPI
if: "! steps.check-version.outputs.tag"
uses: pypa/gh-action-pypi-publish@v1.4.2
with:
user: __token__
password: ${{ secrets.TEST_PYPI_TOKEN }}
repository_url: https://test.pypi.org/legacy/
- name: Publish the release notes
uses: release-drafter/release-drafter@v5.15.0
with:
publish: ${{ steps.check-version.outputs.tag != '' }}
tag: ${{ steps.check-version.outputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

154
.github/workflows/tests.yml vendored Normal file
View File

@@ -0,0 +1,154 @@
name: Tests
on:
- push
- pull_request
jobs:
tests:
name: ${{ matrix.session }} ${{ matrix.python }} / ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { python: "3.10", os: "ubuntu-latest", session: "pre-commit" }
- { python: "3.10", os: "ubuntu-latest", session: "safety" }
- { python: "3.10", os: "ubuntu-latest", session: "mypy" }
- { python: "3.9", os: "ubuntu-latest", session: "mypy" }
- { python: "3.8", os: "ubuntu-latest", session: "mypy" }
- { python: "3.7", os: "ubuntu-latest", session: "mypy" }
- { python: "3.10", os: "ubuntu-latest", session: "tests" }
- { python: "3.9", os: "ubuntu-latest", session: "tests" }
- { python: "3.8", os: "ubuntu-latest", session: "tests" }
- { python: "3.7", os: "ubuntu-latest", session: "tests" }
- { python: "3.10", os: "windows-latest", session: "tests" }
- { python: "3.10", os: "macos-latest", session: "tests" }
- { python: "3.10", os: "ubuntu-latest", session: "typeguard" }
- { python: "3.10", os: "ubuntu-latest", session: "xdoctest" }
- { python: "3.10", os: "ubuntu-latest", session: "docs-build" }
env:
NOXSESSION: ${{ matrix.session }}
FORCE_COLOR: "1"
PRE_COMMIT_COLOR: "always"
steps:
- name: Check out the repository
uses: actions/checkout@v2.4.0
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2.3.1
with:
python-version: ${{ matrix.python }}
- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
- name: Upgrade pip in virtual environments
shell: python
run: |
import os
import pip
with open(os.environ["GITHUB_ENV"], mode="a") as io:
print(f"VIRTUALENV_PIP={pip.__version__}", file=io)
- name: Install Poetry
run: |
pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry
poetry --version
- name: Install Nox
run: |
pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox
pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry
nox --version
- name: Compute pre-commit cache key
if: matrix.session == 'pre-commit'
id: pre-commit-cache
shell: python
run: |
import hashlib
import sys
python = "py{}.{}".format(*sys.version_info[:2])
payload = sys.version.encode() + sys.executable.encode()
digest = hashlib.sha256(payload).hexdigest()
result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest[:8])
print("::set-output name=result::{}".format(result))
- name: Restore pre-commit cache
uses: actions/cache@v2.1.7
if: matrix.session == 'pre-commit'
with:
path: ~/.cache/pre-commit
key: ${{ steps.pre-commit-cache.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
${{ steps.pre-commit-cache.outputs.result }}-
- name: Run Nox
run: |
nox --force-color --python=${{ matrix.python }}
- name: Upload coverage data
if: always() && matrix.session == 'tests'
uses: "actions/upload-artifact@v2.2.4"
with:
name: coverage-data
path: ".coverage.*"
- name: Upload documentation
if: matrix.session == 'docs-build'
uses: actions/upload-artifact@v2.2.4
with:
name: docs
path: docs/_build
coverage:
runs-on: ubuntu-latest
needs: tests
steps:
- name: Check out the repository
uses: actions/checkout@v2.4.0
- name: Set up Python
uses: actions/setup-python@v2.3.1
with:
python-version: "3.10"
- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
- name: Install Poetry
run: |
pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry
poetry --version
- name: Install Nox
run: |
pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox
pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry
nox --version
- name: Download coverage data
uses: actions/download-artifact@v2.0.10
with:
name: coverage-data
- name: Combine coverage data and display human readable report
run: |
nox --force-color --session=coverage
- name: Create coverage report
run: |
nox --force-color --session=coverage -- xml
- name: Upload coverage report
uses: codecov/codecov-action@v2.1.0

137
.gitignore vendored
View File

@@ -1,129 +1,10 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
/.coverage
/.coverage.*
/.nox/
/.python-version
/.pytype/
/dist/
/docs/_build/
/src/*.egg-info/
__pycache__/

58
.pre-commit-config.yaml Normal file
View File

@@ -0,0 +1,58 @@
repos:
- repo: local
hooks:
- id: black
name: black
entry: black
language: system
types: [python]
require_serial: true
- id: check-added-large-files
name: Check for added large files
entry: check-added-large-files
language: system
- id: check-toml
name: Check Toml
entry: check-toml
language: system
types: [toml]
- id: check-yaml
name: Check Yaml
entry: check-yaml
language: system
types: [yaml]
- id: end-of-file-fixer
name: Fix End of Files
entry: end-of-file-fixer
language: system
types: [text]
stages: [commit, push, manual]
- id: flake8
name: flake8
entry: flake8
language: system
types: [python]
require_serial: true
- id: pyupgrade
name: pyupgrade
description: Automatically upgrade syntax for newer versions.
entry: pyupgrade
language: system
types: [python]
args: [--py37-plus]
- id: reorder-python-imports
name: Reorder python imports
entry: reorder-python-imports
language: system
types: [python]
args: [--application-directories=src]
- id: trailing-whitespace
name: Trim Trailing Whitespace
entry: trailing-whitespace-fixer
language: system
types: [text]
stages: [commit, push, manual]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.5.1
hooks:
- id: prettier

12
.readthedocs.yml Normal file
View File

@@ -0,0 +1,12 @@
version: 2
build:
os: ubuntu-20.04
tools:
python: "3.10"
sphinx:
configuration: docs/conf.py
formats: all
python:
install:
- requirements: docs/requirements.txt
- path: .

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"python.pythonPath": "/home/andrew/.pyenv/versions/3.10.0/envs/healthchecks/bin/python"
}

105
CODE_OF_CONDUCT.rst Normal file
View File

@@ -0,0 +1,105 @@
Contributor Covenant Code of Conduct
====================================
Our Pledge
----------
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
Our Standards
-------------
Examples of behavior that contributes to a positive environment for our community include:
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
- Focusing on what is best not just for us as individuals, but for the overall community
Examples of unacceptable behavior include:
- The use of sexualized language or imagery, and sexual attention or
advances of any kind
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email
address, without their explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting
Enforcement Responsibilities
----------------------------
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
Scope
-----
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
Enforcement
-----------
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at andrew@💻.kz. All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
Enforcement Guidelines
----------------------
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
1. Correction
~~~~~~~~~~~~~
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
2. Warning
~~~~~~~~~~
**Community Impact**: A violation through a single incident or series of actions.
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
3. Temporary Ban
~~~~~~~~~~~~~~~~
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
4. Permanent Ban
~~~~~~~~~~~~~~~~
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within the community.
Attribution
-----------
This Code of Conduct is adapted from the `Contributor Covenant <homepage_>`__, version 2.0,
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by `Mozillas code of conduct enforcement ladder <https://github.com/mozilla/diversity>`__.
.. _homepage: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.

123
CONTRIBUTING.rst Normal file
View File

@@ -0,0 +1,123 @@
Contributor Guide
=================
Thank you for your interest in improving this project.
This project is open-source under the `MIT license`_ and
welcomes contributions in the form of bug reports, feature requests, and pull requests.
Here is a list of important resources for contributors:
- `Source Code`_
- `Documentation`_
- `Issue Tracker`_
- `Code of Conduct`_
.. _MIT license: https://opensource.org/licenses/MIT
.. _Source Code: https://github.com/andrewthetechie/py-healthchecks.io
.. _Documentation: https://py-healthchecks.io.readthedocs.io/
.. _Issue Tracker: https://github.com/andrewthetechie/py-healthchecks.io/issues
How to report a bug
-------------------
Report bugs on the `Issue Tracker`_.
When filing an issue, make sure to answer these questions:
- Which operating system and Python version are you using?
- Which version of this project are you using?
- What did you do?
- What did you expect to see?
- What did you see instead?
The best way to get your bug fixed is to provide a test case,
and/or steps to reproduce the issue.
How to request a feature
------------------------
Request features on the `Issue Tracker`_.
How to set up your development environment
------------------------------------------
You need Python 3.7+ and the following tools:
- Poetry_
- Nox_
- nox-poetry_
Install the package with development requirements:
.. code:: console
$ poetry install
You can now run an interactive Python session,
or the command-line interface:
.. code:: console
$ poetry run python
$ poetry run py-healthchecks.io
.. _Poetry: https://python-poetry.org/
.. _Nox: https://nox.thea.codes/
.. _nox-poetry: https://nox-poetry.readthedocs.io/
How to test the project
-----------------------
Run the full test suite:
.. code:: console
$ nox
List the available Nox sessions:
.. code:: console
$ nox --list-sessions
You can also run a specific Nox session.
For example, invoke the unit test suite like this:
.. code:: console
$ nox --session=tests
Unit tests are located in the ``tests`` directory,
and are written using the pytest_ testing framework.
.. _pytest: https://pytest.readthedocs.io/
How to submit changes
---------------------
Open a `pull request`_ to submit changes to this project.
Your pull request needs to meet the following guidelines for acceptance:
- The Nox test suite must pass without errors and warnings.
- Include unit tests. This project maintains 100% code coverage.
- If your changes add functionality, update the documentation accordingly.
Feel free to submit early, though—we can always iterate on this.
To run linting and code formatting checks before committing your change, you can install pre-commit as a Git hook by running the following command:
.. code:: console
$ nox --session=pre-commit -- install
It is recommended to open an issue before starting work on anything.
This will allow a chance to talk it over with the owners and validate your approach.
.. _pull request: https://github.com/andrewthetechie/py-healthchecks.io/pulls
.. github-only
.. _Code of Conduct: CODE_OF_CONDUCT.rst

22
LICENSE.rst Normal file
View File

@@ -0,0 +1,22 @@
MIT License
===========
Copyright © 2021 Andrew Herrington
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
**The software is provided "as is", without warranty of any kind, express or
implied, including but not limited to the warranties of merchantability,
fitness for a particular purpose and noninfringement. In no event shall the
authors or copyright holders be liable for any claim, damages or other
liability, whether in an action of contract, tort or otherwise, arising from,
out of or in connection with the software or the use or other dealings in the
software.**

View File

@@ -1,2 +1,3 @@
# py-healthchecks.io
A python client for healthchecks.io. Supports the management api and ping api

103
README.rst Normal file
View File

@@ -0,0 +1,103 @@
Py Healthchecks.Io
==================
|PyPI| |Status| |Python Version| |License|
|Read the Docs| |Tests| |Codecov|
|pre-commit| |Black|
.. |PyPI| image:: https://img.shields.io/pypi/v/py-healthchecks.io.svg
:target: https://pypi.org/project/py-healthchecks.io/
:alt: PyPI
.. |Status| image:: https://img.shields.io/pypi/status/py-healthchecks.io.svg
:target: https://pypi.org/project/py-healthchecks.io/
:alt: Status
.. |Python Version| image:: https://img.shields.io/pypi/pyversions/py-healthchecks.io
:target: https://pypi.org/project/py-healthchecks.io
:alt: Python Version
.. |License| image:: https://img.shields.io/pypi/l/py-healthchecks.io
:target: https://opensource.org/licenses/MIT
:alt: License
.. |Read the Docs| image:: https://img.shields.io/readthedocs/py-healthchecks.io/latest.svg?label=Read%20the%20Docs
:target: https://py-healthchecks.io.readthedocs.io/
:alt: Read the documentation at https://py-healthchecks.io.readthedocs.io/
.. |Tests| image:: https://github.com/andrewthetechie/py-healthchecks.io/workflows/Tests/badge.svg
:target: https://github.com/andrewthetechie/py-healthchecks.io/actions?workflow=Tests
:alt: Tests
.. |Codecov| image:: https://codecov.io/gh/andrewthetechie/py-healthchecks.io/branch/main/graph/badge.svg
:target: https://codecov.io/gh/andrewthetechie/py-healthchecks.io
:alt: Codecov
.. |pre-commit| image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white
:target: https://github.com/pre-commit/pre-commit
:alt: pre-commit
.. |Black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
:alt: Black
A python client for healthchecks.io. Supports the management api and ping api
Features
--------
* TODO
Requirements
------------
* TODO
Installation
------------
You can install *Py Healthchecks.Io* via pip_ from PyPI_:
.. code:: console
$ pip install py-healthchecks.io
Usage
-----
Please see the `Command-line Reference <Usage_>`_ for details.
Contributing
------------
Contributions are very welcome.
To learn more, see the `Contributor Guide`_.
License
-------
Distributed under the terms of the `MIT license`_,
*Py Healthchecks.Io* is free and open source software.
Issues
------
If you encounter any problems,
please `file an issue`_ along with a detailed description.
Credits
-------
This project was generated from `@cjolowicz`_'s `Hypermodern Python Cookiecutter`_ template.
.. _@cjolowicz: https://github.com/cjolowicz
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _MIT license: https://opensource.org/licenses/MIT
.. _PyPI: https://pypi.org/
.. _Hypermodern Python Cookiecutter: https://github.com/cjolowicz/cookiecutter-hypermodern-python
.. _file an issue: https://github.com/andrewthetechie/py-healthchecks.io/issues
.. _pip: https://pip.pypa.io/
.. github-only
.. _Contributor Guide: CONTRIBUTING.rst
.. _Usage: https://py-healthchecks.io.readthedocs.io/en/latest/usage.html

9
codecov.yml Normal file
View File

@@ -0,0 +1,9 @@
comment: false
coverage:
status:
project:
default:
target: "100"
patch:
default:
target: "100"

1
docs/codeofconduct.rst Normal file
View File

@@ -0,0 +1 @@
.. include:: ../CODE_OF_CONDUCT.rst

14
docs/conf.py Normal file
View File

@@ -0,0 +1,14 @@
"""Sphinx configuration."""
from datetime import datetime
project = "Py Healthchecks.Io"
author = "Andrew Herrington"
copyright = f"{datetime.now().year}, {author}"
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx_click",
]
autodoc_typehints = "description"
html_theme = "furo"

4
docs/contributing.rst Normal file
View File

@@ -0,0 +1,4 @@
.. include:: ../CONTRIBUTING.rst
:end-before: github-only
.. _Code of Conduct: codeofconduct.html

16
docs/index.rst Normal file
View File

@@ -0,0 +1,16 @@
.. include:: ../README.rst
:end-before: github-only
.. _Contributor Guide: contributing.html
.. _Usage: usage.html
.. toctree::
:hidden:
:maxdepth: 1
usage
reference
contributing
Code of Conduct <codeofconduct>
License <license>
Changelog <https://github.com/andrewthetechie/py-healthchecks.io/releases>

1
docs/license.rst Normal file
View File

@@ -0,0 +1 @@
.. include:: ../LICENSE.rst

9
docs/reference.rst Normal file
View File

@@ -0,0 +1,9 @@
Reference
=========
py_healthchecks.io
------------------
.. automodule:: healthchecks_io
:members:

3
docs/requirements.txt Normal file
View File

@@ -0,0 +1,3 @@
furo==2021.11.23
sphinx==4.3.1
sphinx-click==3.0.2

2
docs/usage.rst Normal file
View File

@@ -0,0 +1,2 @@
Usage
=====

227
noxfile.py Normal file
View File

@@ -0,0 +1,227 @@
"""Nox sessions."""
import os
import shlex
import shutil
import sys
from pathlib import Path
from textwrap import dedent
import nox
try:
from nox_poetry import Session
from nox_poetry import session
except ImportError:
message = f"""\
Nox failed to import the 'nox-poetry' package.
Please install it using the following command:
{sys.executable} -m pip install nox-poetry"""
raise SystemExit(dedent(message)) from None
package = "healthchecks_io"
python_versions = ["3.10", "3.9", "3.8", "3.7"]
nox.needs_version = ">= 2021.6.6"
nox.options.sessions = (
"pre-commit",
"safety",
"mypy",
"tests",
# "typeguard",
"xdoctest",
"docs-build",
)
mypy_type_packages = ('types-croniter', 'types-pytz')
def activate_virtualenv_in_precommit_hooks(session: Session) -> None:
"""Activate virtualenv in hooks installed by pre-commit.
This function patches git hooks installed by pre-commit to activate the
session's virtual environment. This allows pre-commit to locate hooks in
that environment when invoked from git.
Args:
session: The Session object.
"""
assert session.bin is not None # noqa: S101
# Only patch hooks containing a reference to this session's bindir. Support
# quoting rules for Python and bash, but strip the outermost quotes so we
# can detect paths within the bindir, like <bindir>/python.
bindirs = [
bindir[1:-1] if bindir[0] in "'\"" else bindir
for bindir in (repr(session.bin), shlex.quote(session.bin))
]
virtualenv = session.env.get("VIRTUAL_ENV")
if virtualenv is None:
return
headers = {
# pre-commit < 2.16.0
"python": f"""\
import os
os.environ["VIRTUAL_ENV"] = {virtualenv!r}
os.environ["PATH"] = os.pathsep.join((
{session.bin!r},
os.environ.get("PATH", ""),
))
""",
# pre-commit >= 2.16.0
"bash": f"""\
VIRTUAL_ENV={shlex.quote(virtualenv)}
PATH={shlex.quote(session.bin)}"{os.pathsep}$PATH"
""",
}
hookdir = Path(".git") / "hooks"
if not hookdir.is_dir():
return
for hook in hookdir.iterdir():
if hook.name.endswith(".sample") or not hook.is_file():
continue
if not hook.read_bytes().startswith(b"#!"):
continue
text = hook.read_text()
if not any(
Path("A") == Path("a") and bindir.lower() in text.lower() or bindir in text
for bindir in bindirs
):
continue
lines = text.splitlines()
for executable, header in headers.items():
if executable in lines[0].lower():
lines.insert(1, dedent(header))
hook.write_text("\n".join(lines))
break
@session(name="pre-commit", python=python_versions[0])
def precommit(session: Session) -> None:
"""Lint using pre-commit."""
args = session.posargs or ["run", "--all-files", "--show-diff-on-failure"]
session.install(
"black",
"darglint",
"flake8",
"flake8-bandit",
"flake8-bugbear",
"flake8-docstrings",
"flake8-rst-docstrings",
"pep8-naming",
"pre-commit",
"pre-commit-hooks",
"pyupgrade",
"reorder-python-imports",
)
session.run("pre-commit", *args)
if args and args[0] == "install":
activate_virtualenv_in_precommit_hooks(session)
@session(python=python_versions[0])
def safety(session: Session) -> None:
"""Scan dependencies for insecure packages."""
requirements = session.poetry.export_requirements()
session.install("safety")
session.run("safety", "check", "--full-report", f"--file={requirements}")
@session(python=python_versions)
def mypy(session: Session) -> None:
"""Type-check using mypy."""
args = session.posargs or ["src", "docs/conf.py"]
session.install(".")
session.install("mypy", "pytest")
session.install(*mypy_type_packages)
session.run("mypy", *args)
if not session.posargs:
session.run("mypy", f"--python-executable={sys.executable}", "noxfile.py")
@session(python=python_versions)
def tests(session: Session) -> None:
"""Run the test suite."""
session.install(".")
session.install("coverage[toml]", "pytest", "pygments")
try:
session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
finally:
if session.interactive:
session.notify("coverage", posargs=[])
@session(python=python_versions[0])
def coverage(session: Session) -> None:
"""Produce the coverage report."""
args = session.posargs or ["report"]
session.install("coverage[toml]")
if not session.posargs and any(Path().glob(".coverage.*")):
session.run("coverage", "combine")
session.run("coverage", *args)
@session(python=python_versions)
def typeguard(session: Session) -> None:
"""Runtime type checking using Typeguard."""
session.install(".")
session.install("pytest", "typeguard", "pygments")
session.run("pytest", f"--typeguard-packages={package}", *session.posargs)
@session(python=python_versions)
def xdoctest(session: Session) -> None:
"""Run examples with xdoctest."""
if session.posargs:
args = [package, *session.posargs]
else:
args = [f"--modname={package}", "--command=all"]
if "FORCE_COLOR" in os.environ:
args.append("--colored=1")
session.install(".")
session.install("xdoctest[colors]")
session.run("python", "-m", "xdoctest", *args)
@session(name="docs-build", python=python_versions[0])
def docs_build(session: Session) -> None:
"""Build the documentation."""
args = session.posargs or ["docs", "docs/_build"]
if not session.posargs and "FORCE_COLOR" in os.environ:
args.insert(0, "--color")
session.install(".")
session.install("sphinx", "sphinx-click", "furo")
build_dir = Path("docs", "_build")
if build_dir.exists():
shutil.rmtree(build_dir)
session.run("sphinx-build", *args)
@session(python=python_versions[0])
def docs(session: Session) -> None:
"""Build and serve the documentation with live reloading on file changes."""
args = session.posargs or ["--open-browser", "docs", "docs/_build"]
session.install(".")
session.install("sphinx", "sphinx-autobuild", "sphinx-click", "furo")
build_dir = Path("docs", "_build")
if build_dir.exists():
shutil.rmtree(build_dir)
session.run("sphinx-autobuild", *args)

1991
poetry.lock generated Normal file

File diff suppressed because it is too large Load Diff

76
pyproject.toml Normal file
View File

@@ -0,0 +1,76 @@
[tool.poetry]
name = "healthchecks_io"
version = "0.0.0"
description = "A python client package for Healthchecks.io API"
authors = ["Andrew Herrington <andrew@💻.kz>"]
license = "MIT"
readme = "README.rst"
homepage = "https://github.com/andrewthetechie/py-healthchecks.io"
repository = "https://github.com/andrewthetechie/py-healthchecks.io"
documentation = "https://py-healthchecks.io.readthedocs.io"
classifiers = [
"Development Status :: 3 - Alpha",
]
[tool.poetry.urls]
Changelog = "https://github.com/andrewthetechie/py-healthchecks.io/releases"
[tool.poetry.dependencies]
python = "^3.7"
click = "^8.0.1"
pydantic = "^1.8.2"
httpx = "^0.21.1"
croniter = "^1.1.0"
pytz = "^2021.3"
[tool.poetry.dev-dependencies]
pytest = "^6.2.5"
coverage = {extras = ["toml"], version = "^6.2"}
safety = "^1.10.3"
mypy = "^0.910"
typeguard = "^2.13.2"
xdoctest = {extras = ["colors"], version = "^0.15.10"}
sphinx = "^4.3.1"
sphinx-autobuild = ">=2021.3.14"
pre-commit = "^2.16.0"
flake8 = "^4.0.1"
black = ">=21.10b0"
flake8-bandit = "^2.1.2"
flake8-bugbear = ">=21.9.2"
flake8-docstrings = "^1.6.0"
flake8-rst-docstrings = "^0.2.3"
pep8-naming = "^0.12.1"
darglint = "^1.8.1"
reorder-python-imports = "^2.6.0"
pre-commit-hooks = "^4.0.1"
sphinx-click = "^3.0.2"
Pygments = "^2.10.0"
pyupgrade = "^2.29.1"
furo = ">=2021.11.12"
pytest-cov = "^3.0.0"
types-croniter = "^1.0.3"
types-pytz = "^2021.3.1"
[tool.coverage.paths]
source = ["src", "*/site-packages"]
tests = ["tests", "*/tests"]
[tool.coverage.run]
branch = true
source = ["healthchecks_io"]
[tool.coverage.report]
show_missing = true
fail_under = 100
[tool.mypy]
strict = true
warn_unreachable = true
pretty = true
show_column_numbers = true
show_error_codes = true
show_error_context = true
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

View File

@@ -0,0 +1 @@
"""Py Healthchecks.Io."""

View File

View File

@@ -0,0 +1,24 @@
"""
Schemas for badges
https://healthchecks.io/docs/api/
"""
from pydantic import BaseModel, AnyUrl
from typing import Dict
class Badges(BaseModel):
svg: str
svg3: str
json_url: str
json3_url: str
shields: str
shields3: str
@classmethod
def from_api_result(cls, badges_dict: Dict[str, str]) -> 'Badges':
"""
Converts an API response into a Badges object
"""
badges_dict['json_url'] = badges_dict['json']
badges_dict['json3_url'] = badges_dict['json3']
return cls(**badges_dict)

View File

@@ -0,0 +1,117 @@
"""
Schemas for checks
https://healthchecks.io/docs/api/
"""
from pydantic import BaseModel, validator, Field
from datetime import datetime
from typing import Optional, List, Dict, Any, Union
from pydantic import AnyUrl
from croniter import croniter
import pytz
from urllib.parse import urlparse
from pathlib import PurePath
class Check(BaseModel):
unique_key: Optional[str]
name: str
slug: str
tags: Optional[str]
desc: Optional[str]
grace: int
n_pings: int
status: str
last_ping: Optional[datetime]
next_ping: Optional[datetime]
manual_resume: bool
methods: Optional[str]
# healthchecks.io's api doesn't return a scheme so we cant use Pydantic AnyUrl here
ping_url: Optional[str]
update_url: Optional[str]
pause_url: Optional[str]
channels: Optional[str]
timeout: int
uuid: Optional[str]
@validator('uuid', always=True)
def validate_uuid(cls, value: Optional[str], values: Dict[str, Any]) -> Optional[str]:
"""
Tries to set the uuid from the ping_url.
Will return none if a read only token is used because it cannot retrieve the UUID of a check
"""
if value is None and values.get('ping_url', None) is not None:
# url is like healthchecks.io/ping/8f57b84b-86c2-4546-8923-03f83d27604a, so we want just the UUID off the end
# Parse the url, grab the path and then just get the name using pathlib
path = PurePath(str(urlparse(values.get('ping_url')).path))
return path.name
return value
@classmethod
def from_api_result(cls, check_dict: Dict[str, Any]) -> 'Check':
"""
Converts a dict result from the healthchecks API into a Check object
"""
return cls(**check_dict)
class CheckCreate(BaseModel):
name: Optional[str] = Field(..., description="Name of the check")
tags: Optional[str] = Field(..., description="String separated list of tags to apply")
desc: Optional[str] = Field(..., description="Description of the check")
timeout: Optional[int] = Field(86400, description="The expected period of this check in seconds." , gte=60, lte=31536000)
grace: Optional[int] = Field(3600, description="The grace period for this check in seconds.", gte=60, lte=31536000)
schedule: Optional[str] = Field("* * * * *", description="A cron expression defining this check's schedule. If you specify both timeout and schedule parameters, Healthchecks.io will create a Cron check and ignore the timeout value.")
tz: Optional[str] = Field("UTC", description="Server's timezone. This setting only has an effect in combination with the schedule parameter.")
manual_resume: Optional[bool] = Field(False, description="Controls whether a paused check automatically resumes when pinged (the default) or not. If set to false, a paused check will leave the paused state when it receives a ping. If set to true, a paused check will ignore pings and stay paused until you manually resume it from the web dashboard.")
methods: Optional[str] = Field("", description="Specifies the allowed HTTP methods for making ping requests. Must be one of the two values: an empty string or POST. Set this field to an empty string to allow HEAD, GET, and POST requests. Set this field to POST to allow only POST requests.")
channels: Optional[str] = Field(None, description="By default, this API call assigns no integrations to the newly created check. By default, this API call assigns no integrations to the newly created check. To assign specific integrations, use a comma-separated list of integration UUIDs.")
unique: Optional[List[Optional[str]]] = Field([], description="Enables upsert functionality. Before creating a check, Healthchecks.io looks for existing checks, filtered by fields listed in unique. If Healthchecks.io does not find a matching check, it creates a new check and returns it with the HTTP status code 201 If Healthchecks.io finds a matching check, it updates the existing check and returns it with HTTP status code 200. The accepted values for the unique field are name, tags, timeout, and grace.")
@validator('schedule')
def validate_schedule(cls, value: str) -> str:
if not croniter.is_valid(value):
raise ValueError("Schedule is not a valid cron expression")
return value
@validator('tz')
def validate_tz(cls, value: str) -> str:
if not value in pytz.all_timezones:
raise ValueError("Tz is not a valid timezone")
return value
@validator('methods')
def validate_methods(cls, value: str) -> str:
if value not in ("", "POST"):
raise ValueError("Methods is invalid, it should be either an empty string or POST")
return value
@validator('unique')
def validate_unique(cls, value: List[Optional[str]]) -> List[Optional[str]]:
for unique in value:
if unique not in ('name', 'tags', 'timeout', 'grace'):
raise ValueError("Unique is not valid. Unique can only be name, tags, timeout, and grace or an empty list")
return value
class CheckPings(BaseModel):
type: str
date: datetime
number_of_pings: int
scheme: str
remote_addr: str
method: str
user_agent: str
duration: float
@classmethod
def from_api_result(cls, ping_dict: Dict[str, Union[str, int, datetime]]) -> 'CheckPings':
ping_dict['number_of_pings'] = ping_dict['n']
ping_dict['user_agent'] = ping_dict['ua']
return cls(**ping_dict)
class CheckStatuses(BaseModel):
timestamp: datetime
up: int

View File

@@ -0,0 +1,11 @@
"""
Schemas for integrations
https://healthchecks.io/docs/api/
"""
from pydantic import BaseModel
class Integration(BaseModel):
id: str
name: str
kind: str

1
tests/__init__.py Normal file
View File

@@ -0,0 +1 @@
"""Test suite for the healthchecks_io package."""

74
tests/conftest.py Normal file
View File

@@ -0,0 +1,74 @@
import pytest
from datetime import datetime
from typing import Dict, Union
from healthchecks_io.schemas import checks
@pytest.fixture
def fake_check_api_result() -> Dict[str, Union[str, int]]:
yield {
"name": "Test Check",
"slug": "Test Check",
"tags": "test check",
"desc": "Test Check",
"grace": 43200,
"n_pings": 76,
"status": "up",
"last_ping": "2021-12-03T12:30:16+00:00",
"next_ping": "2021-12-06T12:30:16+00:00",
"manual_resume": False,
"methods": "",
"ping_url": "testhc.io/ping/8f57a84b-86c2-4246-8923-02f83d17604a",
"update_url": "testhc.io/api/v1/checks/8f57a84b-86c2-4246-8923-02f83d17604a",
"pause_url": "testhc.io/api/v1/checks/8f57a84b-86c2-4246-8923-02f83d17604a/pause",
"channels": "*",
"timeout": 259200
}
@pytest.fixture
def fake_check_ro_api_result() -> Dict[str, Union[str, int]]:
yield {
"name": "Test Check",
"slug": "Test Check",
"tags": "Test Check",
"desc": "Test Check",
"grace": 600,
"n_pings": 1,
"status": "up",
"last_ping": "2020-03-24T14:02:03+00:00",
"next_ping": "2020-03-24T15:02:03+00:00",
"manual_resume": False,
"methods": "",
"unique_key": "a6c7b0a8a66bed0df66abfdab3c77736861703ee",
"timeout": 3600
}
@pytest.fixture
def fake_check() -> checks.Check:
yield checks.Check(
name="Test Check",
slug="Test Check",
tags="test check",
desc="Test Check",
grace=3600,
n_pings=1,
status="Test",
last_ping=datetime.utcnow(),
next_ping=datetime.utcnow(),
manual_resume=False,
ping_url="testurl.com/ping/test-uuid",
update_url="testurl.com/api/v1/checks/test-uuid",
pause_url="testurl.com/api/v1/checks/test-uuid/pause",
channel="*",
timeout=86400,
uuid="test-uuid"
)
@pytest.fixture
def fake_ro_check(fake_check: checks.Check):
fake_check.unique_key = "test-unique-key"
fake_check.uuid = None
fake_check.ping_url = None
fake_check.update_url = None
fake_check.pause_url = None
yield fake_check

View File

@@ -0,0 +1,84 @@
import pytest
from healthchecks_io.schemas import checks
from pydantic import ValidationError
def test_check_from_api_result(fake_check_api_result, fake_check_ro_api_result):
check = checks.Check.from_api_result(fake_check_api_result)
assert check.name == fake_check_api_result['name']
assert check.unique_key is None
ro_check = checks.Check.from_api_result(fake_check_ro_api_result)
assert ro_check.name == fake_check_ro_api_result['name']
assert ro_check.unique_key == fake_check_ro_api_result['unique_key']
def test_check_validate_uuid(fake_check_api_result, fake_check_ro_api_result):
check = checks.Check.from_api_result(fake_check_api_result)
assert check.uuid == '8f57a84b-86c2-4246-8923-02f83d17604a'
assert check.unique_key is None
ro_check = checks.Check.from_api_result(fake_check_ro_api_result)
assert ro_check.uuid is None
def test_check_create_validators():
check_create = checks.CheckCreate(
name="Test",
tags="",
desc="Test",
schedule="* * * * *",
tz="UTC",
methods="POST",
unique=['name']
)
assert check_create.schedule == "* * * * *"
# test validate_schedule
with pytest.raises(ValidationError):
check_create = checks.CheckCreate(
name="Test",
tags="",
desc="Test",
schedule="no good"
)
# test validate_tz
with pytest.raises(ValidationError):
check_create = checks.CheckCreate(
name="Test",
tags="",
desc="Test",
tz="no good"
)
# test validate_methods
with pytest.raises(ValidationError):
check_create = checks.CheckCreate(
name="Test",
tags="",
desc="Test",
methods="no good"
)
# test validate_unique
with pytest.raises(ValidationError):
check_create = checks.CheckCreate(
name="Test",
tags="",
desc="Test",
unique=["no good"]
)
def test_check_pings_from_api():
ping = {"type": "success",
"date": "2020-06-09T14:51:06.113073+00:00",
"n": 4,
"scheme": "http",
"remote_addr": "192.0.2.0",
"method": "GET",
"ua": "curl/7.68.0",
"duration": 2.896736
}
this_ping = checks.CheckPings.from_api_result(ping)
assert this_ping.type == ping['type']
assert this_ping.duration == ping['duration']