diff --git a/.bumpversion.cfg b/.bumpversion.cfg new file mode 100644 index 0000000..98a86cb --- /dev/null +++ b/.bumpversion.cfg @@ -0,0 +1,9 @@ +[bumpversion] +current_version = 0.1.0 + +[bumpversion:file:setup.py] + +[bumpversion:file:CHANGELOG.md] +search = Next Release +replace = {new_version} + diff --git a/.coveragerc b/.coveragerc index 2781c02..8f7ee85 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,6 +1,6 @@ [run] branch = True -source = boilerplate +source = eve_healthcheck [report] show_missing = True diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..c22ec13 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1 @@ +repo_token: 3FLlXcyRliVhxZYTLiuNv979OJaxljgni diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..53f593f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +root = true + +[{*.{cfg,ini,json,py,yml},Makefile}] +charset = utf-8 +trim_trailing_whitespace = true +indent_style = space +indent_size = 4 +end_of_line = lf +insert_final_newline = true + +# Para arquivos JSON e YAML +[*.{json,yml}] +# Indentação em 2 espaços +indent_size = 2 +# Para arquivos Makefile + +[Makefile] +# Indentação deve ser por tabs +indent_style = tab diff --git a/.gitignore b/.gitignore index 4641f88..665202a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,122 @@ -htmlcov/ +###Linux### + +*~ + +# KDE directory preferences +.directory + + +###OSX### + +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +###Python### + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ build/ +develop-eggs/ dist/ -docs/_build/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# 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/ .coverage -*.egg-info -*.pyc +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +db + +###PyCharm### + +# PyCharm +# http://www.jetbrains.com/pycharm/webhelp/project.html +.idea +.iml + + +###Windows### + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk diff --git a/.travis.yml b/.travis.yml index e7c89a7..32cc80e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: python +services: mongodb +python: 3.5 install: - pip install tox script: @@ -6,4 +8,4 @@ script: env: - TOXENV=py27 - TOXENV=py3 - - TOXENV=docs + - TOXENV=coveralls diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b7aea2a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +eve-healthckeck +=========== + +0.1.0 +----- + +* Initial release diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..8da04a0 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include README.rst +include LICENSE +include requirements.txt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9e7efef --- /dev/null +++ b/Makefile @@ -0,0 +1,44 @@ +include defines.mk + +ifdef PY_VENV_PATH +PYTHON_ACTIVATE = . $(PY_VENV_PATH)/bin/activate +PIP = $(PYTHON_ACTIVATE) && pip +PYTHON_BIN := $(PYTHON) +PYTHON := $(PYTHON_ACTIVATE) && $(PYTHON) +ifneq ("$(wildcard $(PY_VENV_PATH)/bin/activate)","") +$(PYTHON_ACTIVATE): +else +$(PYTHON_ACTIVATE): + virtualenv -p$(PYTHON_BIN) $(PY_VENV_PATH) +endif +endif + +.PHONY: install +install: $(PYTHON_ACTIVATE) + # $(PIP) install -r requirements-dev.txt + $(PYTHON) setup.py install + +# make test PY_VENV_PATH=env +.PHONY: test +test: install-dev lint + echo "Start testing" + $(PYTHON_ACTIVATE) && nosetests -v --with-doctest + +# make register PIPY_REPOSITORY=pypitest +.PHONY: register +register: + $(PYTHON) setup.py register -r ${PIPY_REPOSITORY} + +# make dist PIPY_REPOSITORY=pypitest +.PHONY: dist +dist: install + $(PYTHON) setup.py sdist + +# make upload PIPY_REPOSITORY=pypitest +.PHONY: upload +upload: + $(PYTHON) setup.py sdist upload -r ${PIPY_REPOSITORY} + +ifndef VERBOSE +.SILENT: +endif diff --git a/README.md b/README.md deleted file mode 100644 index 467e637..0000000 --- a/README.md +++ /dev/null @@ -1,8 +0,0 @@ -Boilerplate -=========== - -[![Build Status](https://travis-ci.org/ateliedocodigo/python-module-boilerplate.svg?branch=master)](https://travis-ci.org/ateliedocodigo/python-module-boilerplate) -[![Requirements Status](https://requires.io/github/ateliedocodigo/python-module-boilerplate/requirements.svg?branch=master)](https://requires.io/github/ateliedocodigo/python-module-boilerplate/requirements/?branch=master) - -This project servers as an example of a Python package with some boilerplate -code already in place. diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..0fa42f5 --- /dev/null +++ b/README.rst @@ -0,0 +1,58 @@ +eve-healthcheck +=============== + +|Build Status| |Requirements Status| |Coverage Status| + +`eve-healthcheck`_ is project that servers healthcheck urls used to +monitor your application `Eve`_ powered RESTful API. + +Usage +----- + +.. code:: python + + from eve_healthcheck import EveHealthCheck + ... + + app = Eve() + hc = EveHealthCheck(app, '/healthcheck') + ... + +This will add an url ``/healthckeck`` that will check database +connection like: + +.. code:: json + + {'hostname': 'localhost', + 'results': [{'checker': 'database_check', + 'expires': 1487655119.5796409, + 'output': 'Database OK', + 'passed': True, + 'timestamp': 1487655092.5796409}], + 'status': 'success', + 'timestamp': 1487655092.5820687} + +Running tests with ``tox`` +-------------------------- + +Install ``tox`` + +:: + + $ pip install tox + +Run tests + +:: + + tox + +.. _eve-healthcheck: https://pypi.python.org/pypi/eve-healthcheck +.. _Eve: http://python-eve.org/ + +.. |Build Status| image:: https://travis-ci.org/ateliedocodigo/eve-healthcheck.svg?branch=master + :target: https://travis-ci.org/ateliedocodigo/eve-healthcheck +.. |Requirements Status| image:: https://requires.io/github/ateliedocodigo/eve-healthcheck/requirements.svg?branch=master + :target: https://requires.io/github/ateliedocodigo/eve-healthcheck/requirements/?branch=master +.. |Coverage Status| image:: https://coveralls.io/repos/github/ateliedocodigo/eve-healthcheck/badge.svg?branch=master + :target: https://coveralls.io/github/ateliedocodigo/eve-healthcheck?branch=master \ No newline at end of file diff --git a/boilerplate/__init__.py b/boilerplate/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/boilerplate/script.py b/boilerplate/script.py deleted file mode 100644 index 163cdf5..0000000 --- a/boilerplate/script.py +++ /dev/null @@ -1,14 +0,0 @@ -import argparse -import logging - - -def main(): - """Boilerplate example command line interface""" - parser = argparse.ArgumentParser(description="Boilerplate example script") - parser.add_argument('--level', '-l', default='info', - choices=['debug', 'info', 'warning', 'error', 'critical', ], - help="Set the log level") - - args = parser.parse_args() - - logging.basicConfig(level=args.level.upper()) diff --git a/defines.mk b/defines.mk new file mode 100644 index 0000000..2fdfc9e --- /dev/null +++ b/defines.mk @@ -0,0 +1,30 @@ +PIP = pip3 +PYTHON = python3 +PIPY_REPOSITORY=pypi + +BASE_PKG_NAME=boilerplate +PKG_NAME=boilerplate + +script_env = \ + PIP="$(PIP)" \ + PYTHON="$(PYTHON)" \ + PIPY_REPOSITORY="$(PIPY_REPOSITORY)" \ + BASE_PKG_NAME="$(BASE_PKG_NAME)" \ + PKG_NAME="$(PKG_NAME)" \ + VERSION="$(VERSION)" + + +.PHONY: clean +clean: + rm -rf .cache .tox/ .coverage build/ dist/ docs/_build htmlcov *.egg-info + +.PHONY: rename +rename: $(script_env) +ifeq ($(BASE_PKG_NAME),$(PKG_NAME)) + echo "Set a different name to rename BASE_PKG_NAME or PKG_NAME ie.:"; + echo "\t$$ make rename PKG_NAME=my_pkg" + exit 1 +endif + echo "Rename package from $(BASE_PKG_NAME) to $(PKG_NAME)" + grep -rl $(BASE_PKG_NAME) . | grep -v .git/ | grep -v defines.mk | xargs sed -i 's/$(BASE_PKG_NAME)/$(PKG_NAME)/g' + mv $(BASE_PKG_NAME) $(PKG_NAME) diff --git a/docs/Makefile b/docs/Makefile deleted file mode 100644 index dc160b2..0000000 --- a/docs/Makefile +++ /dev/null @@ -1,192 +0,0 @@ -# Makefile for Sphinx documentation -# - -# You can set these variables from the command line. -SPHINXOPTS = -SPHINXBUILD = sphinx-build -PAPER = -BUILDDIR = _build - -# User-friendly check for sphinx-build -ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) -$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) -endif - -# Internal variables. -PAPEROPT_a4 = -D latex_paper_size=a4 -PAPEROPT_letter = -D latex_paper_size=letter -ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . -# the i18n builder cannot share the environment and doctrees with the others -I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . - -.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext - -help: - @echo "Please use \`make ' where is one of" - @echo " html to make standalone HTML files" - @echo " dirhtml to make HTML files named index.html in directories" - @echo " singlehtml to make a single large HTML file" - @echo " pickle to make pickle files" - @echo " json to make JSON files" - @echo " htmlhelp to make HTML files and a HTML help project" - @echo " qthelp to make HTML files and a qthelp project" - @echo " applehelp to make an Apple Help Book" - @echo " devhelp to make HTML files and a Devhelp project" - @echo " epub to make an epub" - @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" - @echo " latexpdf to make LaTeX files and run them through pdflatex" - @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" - @echo " text to make text files" - @echo " man to make manual pages" - @echo " texinfo to make Texinfo files" - @echo " info to make Texinfo files and run them through makeinfo" - @echo " gettext to make PO message catalogs" - @echo " changes to make an overview of all changed/added/deprecated items" - @echo " xml to make Docutils-native XML files" - @echo " pseudoxml to make pseudoxml-XML files for display purposes" - @echo " linkcheck to check all external links for integrity" - @echo " doctest to run all doctests embedded in the documentation (if enabled)" - @echo " coverage to run coverage check of the documentation (if enabled)" - -clean: - rm -rf $(BUILDDIR)/* - -html: - $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." - -dirhtml: - $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." - -singlehtml: - $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml - @echo - @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." - -pickle: - $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle - @echo - @echo "Build finished; now you can process the pickle files." - -json: - $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json - @echo - @echo "Build finished; now you can process the JSON files." - -htmlhelp: - $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp - @echo - @echo "Build finished; now you can run HTML Help Workshop with the" \ - ".hhp project file in $(BUILDDIR)/htmlhelp." - -qthelp: - $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp - @echo - @echo "Build finished; now you can run "qcollectiongenerator" with the" \ - ".qhcp project file in $(BUILDDIR)/qthelp, like this:" - @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Boilerplate.qhcp" - @echo "To view the help file:" - @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Boilerplate.qhc" - -applehelp: - $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp - @echo - @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." - @echo "N.B. You won't be able to view it unless you put it in" \ - "~/Library/Documentation/Help or install it in your application" \ - "bundle." - -devhelp: - $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp - @echo - @echo "Build finished." - @echo "To view the help file:" - @echo "# mkdir -p $$HOME/.local/share/devhelp/Boilerplate" - @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Boilerplate" - @echo "# devhelp" - -epub: - $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub - @echo - @echo "Build finished. The epub file is in $(BUILDDIR)/epub." - -latex: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo - @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." - @echo "Run \`make' in that directory to run these through (pdf)latex" \ - "(use \`make latexpdf' here to do that automatically)." - -latexpdf: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo "Running LaTeX files through pdflatex..." - $(MAKE) -C $(BUILDDIR)/latex all-pdf - @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." - -latexpdfja: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo "Running LaTeX files through platex and dvipdfmx..." - $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja - @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." - -text: - $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text - @echo - @echo "Build finished. The text files are in $(BUILDDIR)/text." - -man: - $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man - @echo - @echo "Build finished. The manual pages are in $(BUILDDIR)/man." - -texinfo: - $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo - @echo - @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." - @echo "Run \`make' in that directory to run these through makeinfo" \ - "(use \`make info' here to do that automatically)." - -info: - $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo - @echo "Running Texinfo files through makeinfo..." - make -C $(BUILDDIR)/texinfo info - @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." - -gettext: - $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale - @echo - @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." - -changes: - $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes - @echo - @echo "The overview file is in $(BUILDDIR)/changes." - -linkcheck: - $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck - @echo - @echo "Link check complete; look for any errors in the above output " \ - "or in $(BUILDDIR)/linkcheck/output.txt." - -doctest: - $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest - @echo "Testing of doctests in the sources finished, look at the " \ - "results in $(BUILDDIR)/doctest/output.txt." - -coverage: - $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage - @echo "Testing of coverage in the sources finished, look at the " \ - "results in $(BUILDDIR)/coverage/python.txt." - -xml: - $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml - @echo - @echo "Build finished. The XML files are in $(BUILDDIR)/xml." - -pseudoxml: - $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml - @echo - @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/conf.py b/docs/conf.py deleted file mode 100644 index 2bcd31b..0000000 --- a/docs/conf.py +++ /dev/null @@ -1,288 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# Boilerplate documentation build configuration file, created by -# sphinx-quickstart on Tue Aug 18 19:16:31 2015. -# -# This file is execfile()d with the current directory set to its -# containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -import sys -import os -import shlex - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath('..')) - -# -- General configuration ------------------------------------------------ - -# If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.viewcode', -] - -# Add any paths that contain templates here, relative to this directory. -#templates_path = ['_templates'] - -# The suffix(es) of source filenames. -# You can specify multiple suffix as a list of string: -# source_suffix = ['.rst', '.md'] -source_suffix = '.rst' - -# The encoding of source files. -#source_encoding = 'utf-8-sig' - -# The master toctree document. -master_doc = 'index' - -# General information about the project. -project = 'Boilerplate' -copyright = '2015, Simon Westphahl' -author = 'Simon Westphahl' - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The short X.Y version. -version = '0.1' -# The full version, including alpha/beta/rc tags. -release = '0.1' - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. -language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -#today = '' -# Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = ['_build'] - -# The reST default role (used for this markup: `text`) to use for all -# documents. -#default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -#add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -#show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' - -# A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False - -# If true, `todo` and `todoList` produce output, else they produce nothing. -todo_include_todos = False - - -# -- Options for HTML output ---------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = 'alabaster' - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -#html_theme_options = {} - -# Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -#html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -#html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -#html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -#html_static_path = ['_static'] - -# Add any extra paths that contain custom files (such as robots.txt or -# .htaccess) here, relative to this directory. These files are copied -# directly to the root of the documentation. -#html_extra_path = [] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -#html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -#html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -#html_additional_pages = {} - -# If false, no module index is generated. -#html_domain_indices = True - -# If false, no index is generated. -#html_use_index = True - -# If true, the index is split into individual pages for each letter. -#html_split_index = False - -# If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -#html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None - -# Language to be used for generating the HTML full-text search index. -# Sphinx supports the following languages: -# 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja' -# 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr' -#html_search_language = 'en' - -# A dictionary with options for the search language support, empty by default. -# Now only 'ja' uses this config value -#html_search_options = {'type': 'default'} - -# The name of a javascript file (relative to the configuration directory) that -# implements a search results scorer. If empty, the default will be used. -#html_search_scorer = 'scorer.js' - -# Output file base name for HTML help builder. -htmlhelp_basename = 'Boilerplatedoc' - -# -- Options for LaTeX output --------------------------------------------- - -latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', - -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', - -# Additional stuff for the LaTeX preamble. -#'preamble': '', - -# Latex figure (float) alignment -#'figure_align': 'htbp', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - (master_doc, 'Boilerplate.tex', 'Boilerplate Documentation', - 'Simon Westphahl', 'manual'), -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -#latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -#latex_use_parts = False - -# If true, show page references after internal links. -#latex_show_pagerefs = False - -# If true, show URL addresses after external links. -#latex_show_urls = False - -# Documents to append as an appendix to all manuals. -#latex_appendices = [] - -# If false, no module index is generated. -#latex_domain_indices = True - - -# -- Options for manual page output --------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - (master_doc, 'boilerplate', 'Boilerplate Documentation', - [author], 1) -] - -# If true, show URL addresses after external links. -#man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - (master_doc, 'Boilerplate', 'Boilerplate Documentation', - author, 'Boilerplate', 'One line description of project.', - 'Miscellaneous'), -] - -# Documents to append as an appendix to all manuals. -#texinfo_appendices = [] - -# If false, no module index is generated. -#texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' - -# If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False diff --git a/docs/index.rst b/docs/index.rst deleted file mode 100644 index c7d5cd4..0000000 --- a/docs/index.rst +++ /dev/null @@ -1,21 +0,0 @@ -.. Boilerplate documentation master file, created by - sphinx-quickstart on Tue Aug 18 19:16:31 2015. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - -Welcome to Boilerplate's documentation! -======================================= - -Contents: - -.. toctree:: - :maxdepth: 2 - - -Indices and tables -================== - -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search` - diff --git a/eve_healthcheck/__init__.py b/eve_healthcheck/__init__.py new file mode 100644 index 0000000..1178cc8 --- /dev/null +++ b/eve_healthcheck/__init__.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from healthcheck import HealthCheck + +import logging + + +class EveHealthCheck(object): + + def __init__(self, app=None, healthcheck_uri='/healthcheck', *argv, **kw): + self.logger = logging.getLogger(self.__module__) + self.hc = HealthCheck(*argv, **kw) + + if app: + self.init_app(app, healthcheck_uri) + + def init_app(self, app, healthcheck_uri='/healthcheck'): + + def database_check(): + # perform a count + for k, v in app.config.get('DOMAIN', {}).items(): + result = app.data.is_empty(k) + assert type(result) == bool, "Database NOK" + return True, "Database OK" + + self.hc.add_check(database_check) + app.add_url_rule(healthcheck_uri, healthcheck_uri, view_func=lambda: self.hc.run()) + for k, v in app.config.get('DOMAIN', {}).items(): + self.logger.debug("Adding uri /{}{}".format(k, healthcheck_uri)) + app.add_url_rule("/{}{}".format(k, healthcheck_uri), + "/{}{}".format(k, healthcheck_uri), + view_func=lambda: self.hc.run()) diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 1d655e3..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,3 +0,0 @@ -coverage -pep8 -nose \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 9a3bd76..b43824c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,2 @@ -pep8 -twine -tox -coverage -sphinx +eve +py-healthcheck diff --git a/setup.cfg b/setup.cfg index c1b094e..bda0c9c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,6 @@ +[metadata] +description-file = README.rst + [pep8] -max-line-length = 99 +max-line-length = 120 +exclude = .local,.tox,env,docs diff --git a/setup.py b/setup.py index f75faea..385d2a6 100644 --- a/setup.py +++ b/setup.py @@ -1,28 +1,37 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from os.path import abspath, dirname, join import setuptools +__version__ = "0.1.0" +__project_name__ = "eve-healthcheck" +__repo__ = "https://github.com/ateliedocodigo/eve-healthcheck" + + +def read(fname): + with open(join(abspath(dirname(__file__)), fname)) as thefile: + return thefile.read() + # return open(os.path.join(os.path.dirname(__file__), fname)).read() setuptools.setup( - name="boilerplate", - version="0.1", - description="Python boilerplate project", - url="https://github.com/westphahl/boilerplate", + name=__project_name__, + version=__version__, + description="Python {} project".format(__project_name__), + long_description=read("README.rst"), author="Luis Fernando Gomes", author_email="luiscoms@ateliedocodigo.com.br", + url=__repo__, + download_url="{}/tarball/{}".format(__repo__, __version__), license="MIT", - classifiers=[ # See: https://pypi.python.org/pypi?%3Aaction=list_classifier - "Development Status :: 1 - Planning", + classifiers=[ + "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Topic :: Software Development", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", ], - keywords="example boilerplate", + keywords="healthckeck eve_healthcheck", packages=setuptools.find_packages(exclude=["tests", "tests.*"]), - install_requires=[], - entry_points={ - "console_scripts": [ - "boilerplate_script = boilerplate.script:main" - ] - } + install_requires=read("requirements.txt"), ) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..a6b579c --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,8 @@ +-rrequirements.txt +bumpversion==0.5.3 +coverage==4.2 +coveralls==1.1 +nose==1.3.7 +pep8==1.7.0 +pytest==3.0.5 +PyYAML==3.12 \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..4dcc257 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import json +import os +import unittest + +import eve +from bson import ObjectId +from flask_pymongo import MongoClient + +from tests.test_settings import \ + MONGO_HOST, MONGO_PORT, \ + MONGO_USERNAME, MONGO_PASSWORD, MONGO_DBNAME + +from eve_healthcheck import EveHealthCheck + + +class TestBase(unittest.TestCase): + + healthcheck_uri = '/h' + + def setUp(self, settings=None): + self.this_directory = os.path.dirname(os.path.realpath(__file__)) + if settings is None: + settings = os.path.join(self.this_directory, 'test_settings.py') + + self.setupDB() + + self.settings = settings + self.app = eve.Eve(settings=self.settings) + + self.test_client = self.app.test_client() + self.domain = self.app.config['DOMAIN'] + + self.hc = EveHealthCheck(self.app, self.healthcheck_uri) + + def tearDown(self): + del self.app + del self.test_client + del self.hc + self.dropDB() + + def setupDB(self): + self.connection = MongoClient(MONGO_HOST, MONGO_PORT) + self.connection.drop_database(MONGO_DBNAME) + if MONGO_USERNAME: + self.connection[MONGO_DBNAME].add_user(MONGO_USERNAME, + MONGO_PASSWORD, + False) + + def dropDB(self): + self.connection = MongoClient(MONGO_HOST, MONGO_PORT) + self.connection.drop_database(MONGO_DBNAME) + self.connection.close() + + def parse_response(self, r): + try: + v = json.loads(r.get_data().decode('utf-8')) + except ValueError: + v = None + return v diff --git a/tests/test_example.py b/tests/test_example.py deleted file mode 100644 index 32e72da..0000000 --- a/tests/test_example.py +++ /dev/null @@ -1,11 +0,0 @@ -import pytest - - -class TestExample(object): - - def test_example(self): - assert True, "This should not fail" - - @pytest.mark.xfail - def test_failing(self): - assert False, "This will always fail" diff --git a/tests/test_healthckeck.py b/tests/test_healthckeck.py new file mode 100644 index 0000000..3a91683 --- /dev/null +++ b/tests/test_healthckeck.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import unittest + +from tests import TestBase + + +class TestEveHealthchek(TestBase): + + def test_api(self): + self.app.debug = True + r = self.test_client.get('/') + self.assertEqual(r.status_code, 200) + + def test_basic_check(self): + + self.app.debug = True + + r = self.test_client.get(self.healthcheck_uri) + self.assertEqual(200, r.status_code) + + def test_failing_check(self): + def fail_check(): + return False, "FAIL" + + self.hc.hc.add_check(fail_check) + r = self.test_client.get(self.healthcheck_uri) + self.assertEqual(500, r.status_code) + + jr = self.parse_response(r) + self.assertEqual("failure", jr["status"]) + + def test_database_success_check(self): + # ckeck eatch domain + for k, v in self.app.config.get('DOMAIN', {}).items(): + r = self.test_client.get("/{}{}".format(k, self.healthcheck_uri)) + self.assertEqual(200, r.status_code) + + jr = self.parse_response(r) + self.assertEqual("success", jr["status"]) + + def test_database_failure_check(self): + # set an invalid database + self.app.config['MONGO_URI'] = 'mongodb://invalid.db.net/db' + # ckeck eatch domain + for k, v in self.app.config.get('DOMAIN', {}).items(): + r = self.test_client.get("/{}{}".format(k, self.healthcheck_uri)) + + self.assertEqual(500, r.status_code) + jr = self.parse_response(r) + self.assertEqual("failure", jr["status"]) diff --git a/tests/test_settings.py b/tests/test_settings.py new file mode 100644 index 0000000..55798d3 --- /dev/null +++ b/tests/test_settings.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +MONGO_HOST = 'localhost' +MONGO_PORT = 27017 +MONGO_USERNAME = 'test_user' +MONGO_PASSWORD = 'test_pw' +MONGO_DBNAME = 'eve_healthcheck_test' + +TRANSPARENT_SCHEMA_RULES = True +RESOURCE_METHODS = ['GET', 'POST', 'DELETE'] +ITEM_METHODS = ['GET', 'PATCH', 'PUT', 'DELETE'] + +DOMAIN = { + 'people': { + 'description': 'the people resource', + 'type': 'dict', + 'schema': { + 'name': { + 'type': 'string', + 'required': True, + 'unique': True, + 'description': 'the last name of the person' + }, + 'skills': { + 'type': 'list', + 'schema': { + "type": "objectid", + "data_relation": { + "resource": "skills", + "embeddable": True + } + } + }, + } + }, + 'skills': { + 'type': 'dict', + 'schema': { + 'name': { + 'type': 'string', + 'required': True, + 'unique': True, + }, + }, + }, +} diff --git a/tox.ini b/tox.ini index 7c85884..c065308 100644 --- a/tox.ini +++ b/tox.ini @@ -1,16 +1,22 @@ [tox] -envlist = py27,py3,docs +envlist = py27,py3,coveralls [testenv] -deps = -rrequirements-dev.txt -commands = coverage erase - coverage run -m nose -v --with-doctest boilerplate +setenv = PYTHONDONTWRITEBYTECODE=1 +deps = -rtest-requirements.txt +commands = python setup.py test + coverage erase + coverage run -m nose -v --with-doctest eve_healthcheck coverage report coverage html - pep8 boilerplate + pep8 -[testenv:docs] -basepython = python3 -changedir = docs -deps = sphinx -commands = sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html +[testenv:coveralls] +setenv = PYTHONDONTWRITEBYTECODE=1 +passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH +commands = coverage erase + coverage run -m nose -v --with-doctest eve_healthcheck + coverage report + coverage html + pep8 + coveralls