@@ -17,7 +17,6 @@ from flask import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from pypuppetdb import connect
|
from pypuppetdb import connect
|
||||||
from pypuppetdb.errors import EmptyResponseError
|
|
||||||
from pypuppetdb.QueryBuilder import *
|
from pypuppetdb.QueryBuilder import *
|
||||||
|
|
||||||
from puppetboard.forms import (CatalogForm, QueryForm)
|
from puppetboard.forms import (CatalogForm, QueryForm)
|
||||||
@@ -119,26 +118,6 @@ def utility_processor():
|
|||||||
return dict(now=now)
|
return dict(now=now)
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# 204 doesn't have a mapping in werkzeug, we need to define a custom
|
|
||||||
# class and then set it to the mappings.
|
|
||||||
#
|
|
||||||
class NoContent(ex.HTTPException):
|
|
||||||
code = 204
|
|
||||||
description = '<p>No content</p'
|
|
||||||
|
|
||||||
abort.mapping[204] = NoContent
|
|
||||||
|
|
||||||
try:
|
|
||||||
@app.errorhandler(204)
|
|
||||||
def no_content(e):
|
|
||||||
return '', 204
|
|
||||||
except KeyError:
|
|
||||||
@app.errorhandler(EmptyResponseError)
|
|
||||||
def no_content(e):
|
|
||||||
return '', 204
|
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(400)
|
@app.errorhandler(400)
|
||||||
def bad_request(e):
|
def bad_request(e):
|
||||||
envs = environments()
|
envs = environments()
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from flask.ext.wtf import Form
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import (
|
from wtforms import (
|
||||||
HiddenField, RadioField, SelectField,
|
HiddenField, RadioField, SelectField,
|
||||||
TextAreaField, BooleanField, validators
|
TextAreaField, BooleanField, validators
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class QueryForm(Form):
|
class QueryForm(FlaskForm):
|
||||||
"""The form used to allow freeform queries to be executed against
|
"""The form used to allow freeform queries to be executed against
|
||||||
PuppetDB."""
|
PuppetDB."""
|
||||||
query = TextAreaField('Query', [validators.Required(
|
query = TextAreaField('Query', [validators.Required(
|
||||||
@@ -30,7 +30,7 @@ class QueryForm(Form):
|
|||||||
rawjson = BooleanField('Raw JSON')
|
rawjson = BooleanField('Raw JSON')
|
||||||
|
|
||||||
|
|
||||||
class CatalogForm(Form):
|
class CatalogForm(FlaskForm):
|
||||||
"""The form used to compare the catalogs of different nodes."""
|
"""The form used to compare the catalogs of different nodes."""
|
||||||
compare = HiddenField('compare')
|
compare = HiddenField('compare')
|
||||||
against = SelectField('against')
|
against = SelectField('against')
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
Flask >=0.10.1
|
Flask >=0.12
|
||||||
Flask-WTF >=0.12,<=0.13
|
Flask-WTF >=0.14.2
|
||||||
Jinja2 >=2.7.2
|
Jinja2 >=2.9.5
|
||||||
MarkupSafe >=0.19
|
MarkupSafe >=0.19
|
||||||
WTForms >=2.0,<3.0
|
WTForms >=2.1
|
||||||
Werkzeug >=0.7,<= 0.11.5
|
Werkzeug >=0.12.1
|
||||||
itsdangerous >=0.23
|
itsdangerous >=0.23
|
||||||
pypuppetdb >=0.3.2
|
pypuppetdb >=0.3.2
|
||||||
requests >=2.6.0
|
requests >=2.13.0
|
||||||
|
|||||||
@@ -16,12 +16,6 @@ def mock_puppetdb_environments(mocker):
|
|||||||
return_value=environemnts)
|
return_value=environemnts)
|
||||||
|
|
||||||
|
|
||||||
def test_error_no_content():
|
|
||||||
result = app.no_content(None)
|
|
||||||
assert result[0] == ''
|
|
||||||
assert result[1] == 204
|
|
||||||
|
|
||||||
|
|
||||||
def test_error_bad_request(mock_puppetdb_environments):
|
def test_error_bad_request(mock_puppetdb_environments):
|
||||||
with app.app.test_request_context():
|
with app.app.test_request_context():
|
||||||
(output, error_code) = app.bad_request(None)
|
(output, error_code) = app.bad_request(None)
|
||||||
|
|||||||
12
test/test_form.py
Normal file
12
test/test_form.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import pytest
|
||||||
|
from puppetboard import app, forms
|
||||||
|
|
||||||
|
|
||||||
|
def test_form_valid(capsys):
|
||||||
|
for form in [forms.QueryForm, forms.CatalogForm]:
|
||||||
|
with app.app.test_request_context():
|
||||||
|
qf = form()
|
||||||
|
out, err = capsys.readouterr()
|
||||||
|
assert qf is not None
|
||||||
|
assert err == ""
|
||||||
|
assert out == ""
|
||||||
@@ -12,7 +12,6 @@ from werkzeug.exceptions import NotFound, InternalServerError
|
|||||||
|
|
||||||
from puppetboard import utils
|
from puppetboard import utils
|
||||||
from puppetboard import app
|
from puppetboard import app
|
||||||
from puppetboard.app import NoContent
|
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import logging
|
import logging
|
||||||
@@ -108,19 +107,6 @@ def test_http_connection_error(mock_log):
|
|||||||
mock_log.error.assert_called_with(err)
|
mock_log.error.assert_called_with(err)
|
||||||
|
|
||||||
|
|
||||||
def test_http_empty(mock_log, mocker):
|
|
||||||
err = "Empty Response"
|
|
||||||
|
|
||||||
def connection_error():
|
|
||||||
raise EmptyResponseError(err)
|
|
||||||
|
|
||||||
flask_abort = mocker.patch('flask.abort')
|
|
||||||
with pytest.raises(NoContent):
|
|
||||||
utils.get_or_abort(connection_error)
|
|
||||||
mock_log.error.assert_called_with(err)
|
|
||||||
flask_abort.assert_called_with('204')
|
|
||||||
|
|
||||||
|
|
||||||
def test_db_version_good(mocker, mock_info_log):
|
def test_db_version_good(mocker, mock_info_log):
|
||||||
mocker.patch.object(app.puppetdb, 'current_version', return_value='4.2.0')
|
mocker.patch.object(app.puppetdb, 'current_version', return_value='4.2.0')
|
||||||
err = 'PuppetDB Version %d.%d.%d' % (4, 2, 0)
|
err = 'PuppetDB Version %d.%d.%d' % (4, 2, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user