Skip to content

Commit

Permalink
Merge pull request #530 from dom-nie/tests_requirements_bump
Browse files Browse the repository at this point in the history
Upgrade of tests requirements + resolving current deprecation warnings
  • Loading branch information
bastelfreak committed Oct 31, 2019
2 parents 34ec9da + 3096560 commit 57fdb5a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 46 deletions.
2 changes: 1 addition & 1 deletion puppetboard/app.py
Expand Up @@ -858,7 +858,7 @@ def catalogs(env, compare):
check_env(env, envs)

if not app.config['ENABLE_CATALOG']:
log.warn('Access to catalog interface disabled by administrator')
log.warning('Access to catalog interface disabled by administrator')
abort(403)

return render_template(
Expand Down
2 changes: 1 addition & 1 deletion puppetboard/forms.py
Expand Up @@ -35,7 +35,7 @@
class QueryForm(FlaskForm):
"""The form used to allow freeform queries to be executed against
PuppetDB."""
query = TextAreaField('Query', [validators.Required(
query = TextAreaField('Query', [validators.DataRequired(
message='A query is required.')])
endpoints = RadioField('API endpoint', choices=[
(key, value) for key, value in QUERY_ENDPOINTS.items()
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
@@ -0,0 +1,3 @@
[pytest]
filterwarnings =
ignore::DeprecationWarning
15 changes: 7 additions & 8 deletions requirements-test.txt
@@ -1,13 +1,12 @@
-r requirements.txt
pep8==1.7.0
coverage==4.3.4
mock==1.3.0
pytest==3.0.7
pep8==1.7.1
coverage==4.5.4
mock==3.0.5
pytest==5.2.2
pytest-pep8==1.0.6
pytest-cov==2.4.0
pytest-mock==1.5.0
pytest-cov==2.8.1
pytest-mock==1.11.2
cov-core==1.15.0
unittest2==1.1.0; python_version < '2.7'
beautifulsoup4==4.5.3
beautifulsoup4==4.8.1
bandit
coveralls
62 changes: 26 additions & 36 deletions test/test_app.py
@@ -1,12 +1,12 @@
import pytest
import json
import os
from datetime import datetime
from puppetboard import app
from pypuppetdb.types import Node, Report
from puppetboard import default_settings

import pytest
from bs4 import BeautifulSoup
from pypuppetdb.types import Node

from puppetboard import app


class MockDbQuery(object):
Expand Down Expand Up @@ -122,7 +122,6 @@ def test_get_index(client, mocker,
def test_index_all(client, mocker,
mock_puppetdb_environments,
mock_puppetdb_default_nodes):

base_str = 'puppetlabs.puppetdb.population:'
query_data = {
'version': [{'version': '4.2.0'}],
Expand Down Expand Up @@ -173,7 +172,6 @@ def test_index_all(client, mocker,
def test_index_all_older_puppetdb(client, mocker,
mock_puppetdb_environments,
mock_puppetdb_default_nodes):

base_str = 'puppetlabs.puppetdb.population:type=default,'
query_data = {
'version': [{'version': '3.2.0'}],
Expand Down Expand Up @@ -221,10 +219,9 @@ def test_index_all_older_puppetdb(client, mocker,
assert rv.status_code == 200


def test_index_division_by_zero(client, mocker):
mock_puppetdb_environments(mocker)
mock_puppetdb_default_nodes(mocker)

def test_index_division_by_zero(client, mocker,
mock_puppetdb_environments,
mock_puppetdb_default_nodes):
query_data = {
'nodes': [[{'count': 0}]],
'resources': [[{'count': 40}]],
Expand All @@ -247,12 +244,11 @@ def test_index_division_by_zero(client, mocker):
assert vals[2].string == '0'


def test_offline_mode(client, mocker):
def test_offline_mode(client, mocker,
mock_puppetdb_environments,
mock_puppetdb_default_nodes):
app.app.config['OFFLINE_MODE'] = True

mock_puppetdb_environments(mocker)
mock_puppetdb_default_nodes(mocker)

query_data = {
'nodes': [[{'count': 10}]],
'resources': [[{'count': 40}]],
Expand Down Expand Up @@ -280,7 +276,6 @@ def test_offline_mode(client, mocker):
def test_default_node_view(client, mocker,
mock_puppetdb_environments,
mock_puppetdb_default_nodes):

rv = client.get('/nodes')
soup = BeautifulSoup(rv.data, 'html.parser')
assert soup.title.contents[0] == 'Puppetboard'
Expand Down Expand Up @@ -442,10 +437,9 @@ def test_radiator_view_json(client, mocker,
assert json_data['unchanged'] == 1


def test_radiator_view_bad_env(client, mocker):
mock_puppetdb_environments(mocker)
mock_puppetdb_default_nodes(mocker)

def test_radiator_view_bad_env(client, mocker,
mock_puppetdb_environments,
mock_puppetdb_default_nodes):
query_data = {
'nodes': [[{'count': 10}]],
'resources': [[{'count': 40}]],
Expand All @@ -463,10 +457,9 @@ def test_radiator_view_bad_env(client, mocker):
assert soup.h1.text == 'Not Found'


def test_radiator_view_division_by_zero(client, mocker):
mock_puppetdb_environments(mocker)
mock_puppetdb_default_nodes(mocker)

def test_radiator_view_division_by_zero(client, mocker,
mock_puppetdb_environments,
mock_puppetdb_default_nodes):
query_data = {
'nodes': [[{'count': 0}]],
'resources': [[{'count': 40}]],
Expand All @@ -487,10 +480,9 @@ def test_radiator_view_division_by_zero(client, mocker):
assert '0' in total.text


def test_json_report_ok(client, mocker, input_data):
mock_puppetdb_environments(mocker)
mock_puppetdb_default_nodes(mocker)

def test_json_report_ok(client, mocker, input_data,
mock_puppetdb_environments,
mock_puppetdb_default_nodes):
query_response = json.loads(input_data)

query_data = {
Expand Down Expand Up @@ -521,10 +513,9 @@ def test_json_report_ok(client, mocker, input_data):
assert len(result_json['data']) == 100


def test_json_daily_reports_chart_ok(client, mocker):
mock_puppetdb_environments(mocker)
mock_puppetdb_default_nodes(mocker)

def test_json_daily_reports_chart_ok(client, mocker,
mock_puppetdb_environments,
mock_puppetdb_default_nodes):
query_data = {
'reports': [
[{'status': 'changed', 'count': 1}]
Expand Down Expand Up @@ -621,7 +612,7 @@ def test_catalogs_json_compare(client, mocker,
val = BeautifulSoup(line[2], 'html.parser').find_all(
'form', {"method": "GET",
"action": "/catalogs/compare/node-unreported...node-%s" %
found_status})
found_status})
assert len(val) == 1


Expand Down Expand Up @@ -839,13 +830,12 @@ def test_offline_static(client):
assert rv.status_code == 200


def test_custom_title(client, mocker):
def test_custom_title(client, mocker,
mock_puppetdb_environments,
mock_puppetdb_default_nodes):
custom_title = 'Dev - Puppetboard'
app.app.config['PAGE_TITLE'] = custom_title

mock_puppetdb_environments(mocker)
mock_puppetdb_default_nodes(mocker)

query_data = {
'nodes': [[{'count': 10}]],
'resources': [[{'count': 40}]],
Expand Down

0 comments on commit 57fdb5a

Please sign in to comment.