903b83e211
We introduce a patroni_api fixture, defined in tests/conftest.py, which sets up an HTTP server serving files in a temporary directory. The server is itself defined by the PatroniAPI class; it has a 'routes()' context manager method to be used in actual tests to setup expected responses based on specified JSON files. We set up some logging in order to improve debugging. The direct advantage of this is that PatroniResource.rest_api() method is now covered by the test suite. Coverage before this commit: Name Stmts Miss Cover ----------------------------------------------- check_patroni/__init__.py 3 0 100% check_patroni/cli.py 193 18 91% check_patroni/cluster.py 113 0 100% check_patroni/convert.py 23 5 78% check_patroni/node.py 146 1 99% check_patroni/types.py 50 23 54% ----------------------------------------------- TOTAL 528 47 91% and after this commit: Name Stmts Miss Cover ----------------------------------------------- check_patroni/__init__.py 3 0 100% check_patroni/cli.py 193 18 91% check_patroni/cluster.py 113 0 100% check_patroni/convert.py 23 5 78% check_patroni/node.py 146 1 99% check_patroni/types.py 50 9 82% ----------------------------------------------- TOTAL 528 33 94% In actual test functions, we either invoke patroni_api.routes() to configure which JSON file(s) should be served for each endpoint, or we define dedicated fixtures (e.g. cluster_config_has_changed()) to configure this for several test functions or the whole module. The 'old_replica_state' parametrized fixture is used when needed to adjust such fixtures, e.g. in cluster_has_replica_ok(), to modify the JSON content using cluster_api_set_replica_running() (previously in tests/tools.py, now in tests/__init__.py). The dependency on pytest-mock is no longer needed.
58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
import pathlib
|
|
|
|
from setuptools import find_packages, setup
|
|
|
|
HERE = pathlib.Path(__file__).parent
|
|
|
|
long_description = (HERE / "README.md").read_text()
|
|
|
|
|
|
def get_version() -> str:
|
|
fpath = HERE / "check_patroni" / "__init__.py"
|
|
with fpath.open() as f:
|
|
for line in f:
|
|
if line.startswith("__version__"):
|
|
return line.split('"')[1]
|
|
raise Exception(f"version information not found in {fpath}")
|
|
|
|
|
|
setup(
|
|
name="check_patroni",
|
|
version=get_version(),
|
|
author="Dalibo",
|
|
author_email="contact@dalibo.com",
|
|
packages=find_packages(include=["check_patroni*"]),
|
|
include_package_data=True,
|
|
url="https://github.com/dalibo/check_patroni",
|
|
license="PostgreSQL",
|
|
description="Nagios plugin to check on patroni",
|
|
long_description=long_description,
|
|
long_description_content_type="text/markdown",
|
|
classifiers=[
|
|
"Development Status :: 5 - Production/Stable",
|
|
"Environment :: Console",
|
|
"License :: OSI Approved :: PostgreSQL License",
|
|
"Programming Language :: Python :: 3",
|
|
"Topic :: System :: Monitoring",
|
|
],
|
|
keywords="patroni nagios check",
|
|
python_requires=">=3.6",
|
|
install_requires=[
|
|
"attrs >= 17, !=21.1",
|
|
"requests",
|
|
"nagiosplugin >= 1.3.2",
|
|
"click >= 8.0.1",
|
|
],
|
|
extras_require={
|
|
"test": [
|
|
"pytest",
|
|
],
|
|
},
|
|
entry_points={
|
|
"console_scripts": [
|
|
"check_patroni=check_patroni.cli:main",
|
|
],
|
|
},
|
|
zip_safe=False,
|
|
)
|