Fact pages and node page tests
This commit is contained in:
@@ -391,9 +391,9 @@ def inventory(env):
|
||||
)))
|
||||
|
||||
|
||||
@app.route('/node/<node_name>/',
|
||||
@app.route('/node/<node_name>',
|
||||
defaults={'env': app.config['DEFAULT_ENVIRONMENT']})
|
||||
@app.route('/<env>/node/<node_name>/')
|
||||
@app.route('/<env>/node/<node_name>')
|
||||
def node(env, node_name):
|
||||
"""Display a dashboard for a node showing as much data as we have on that
|
||||
node. This includes facts and reports but not Resources as that is too
|
||||
@@ -421,11 +421,11 @@ def node(env, node_name):
|
||||
columns=REPORTS_COLUMNS[:2])
|
||||
|
||||
|
||||
@app.route('/reports/',
|
||||
@app.route('/reports',
|
||||
defaults={'env': app.config['DEFAULT_ENVIRONMENT'],
|
||||
'node_name': None})
|
||||
@app.route('/<env>/reports/', defaults={'node_name': None})
|
||||
@app.route('/reports/<node_name>/',
|
||||
@app.route('/<env>/reports', defaults={'node_name': None})
|
||||
@app.route('/reports/<node_name>',
|
||||
defaults={'env': app.config['DEFAULT_ENVIRONMENT']})
|
||||
@app.route('/<env>/reports/<node_name>')
|
||||
def reports(env, node_name):
|
||||
|
||||
@@ -1,51 +1,3 @@
|
||||
{% macro facts_table(facts, current_env, autofocus=False, condensed=False, show_node=False, show_value=True, link_facts=False, margin_top=20, margin_bottom=20) -%}
|
||||
<div class="ui fluid icon input hide" style="margin-bottom:20px">
|
||||
<input {% if autofocus %} autofocus="autofocus" {% endif %} class="filter-table" placeholder="Type here to filter...">
|
||||
</div>
|
||||
<table class="ui very basic {% if condensed %}very{% endif%} compact sortable table" style="table-layout: fixed;">
|
||||
<thead>
|
||||
<tr>
|
||||
{% if show_node %}
|
||||
<th>Node</th>
|
||||
{% else %}
|
||||
<th class="default-sort">Fact</th>
|
||||
{% endif %}
|
||||
{% if show_value %}
|
||||
<th>Value</th>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="searchable">
|
||||
{% for fact in facts %}
|
||||
<tr>
|
||||
{% if show_node %}
|
||||
<td><a href="{{url_for('node', env=current_env, node_name=fact.node)}}">{{fact.node}}</a></td>
|
||||
{% else %}
|
||||
<td><a href="{{url_for('fact', env=current_env, fact=fact.name)}}">{{fact.name}}</a></td>
|
||||
{% endif %}
|
||||
{% if show_value %}
|
||||
<td style="word-wrap:break-word">
|
||||
{% if link_facts %}
|
||||
{% if fact.value is mapping %}
|
||||
<a href="{{url_for('fact_value', env=current_env, fact=fact.name, value=fact.value)}}"><pre>{{fact.value|jsonprint}}</pre></a>
|
||||
{% else %}
|
||||
<a href="{{url_for('fact_value', env=current_env, fact=fact.name, value=fact.value)}}">{{fact.value}}</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if fact.value is mapping %}
|
||||
<pre>{{fact.value|jsonprint}}</pre>
|
||||
{% else %}
|
||||
{{fact.value}}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro status_counts(caller, status, node_name, events, current_env, unreported_time=False, report_hash=False) -%}
|
||||
<a class="ui {{status}} label status" href="{{url_for('report', env=current_env, node_name=node_name, report_id=report_hash)}}">{{ status|upper }}</a>
|
||||
{% if status == 'unreported' %}
|
||||
|
||||
186
test/test_app.py
186
test/test_app.py
@@ -582,7 +582,7 @@ def test_catalogs_json(client, mocker,
|
||||
found_status = None
|
||||
for status in ['failed', 'changed', 'unchanged', 'noop', 'unreported']:
|
||||
val = BeautifulSoup(line[0], 'html.parser').find_all(
|
||||
'a', {"href": "/node/node-%s/" % status})
|
||||
'a', {"href": "/node/node-%s" % status})
|
||||
if len(val) == 1:
|
||||
found_status = status
|
||||
break
|
||||
@@ -609,7 +609,7 @@ def test_catalogs_json_compare(client, mocker,
|
||||
found_status = None
|
||||
for status in ['failed', 'changed', 'unchanged', 'noop', 'unreported']:
|
||||
val = BeautifulSoup(line[0], 'html.parser').find_all(
|
||||
'a', {"href": "/node/node-%s/" % status})
|
||||
'a', {"href": "/node/node-%s" % status})
|
||||
if len(val) == 1:
|
||||
found_status = status
|
||||
break
|
||||
@@ -639,3 +639,185 @@ def test_facts_view(client, mocker, mock_puppetdb_environments):
|
||||
searchable = soup.find('div', {'class': 'searchable'})
|
||||
vals = searchable.find_all('div', {'class': 'column'})
|
||||
assert len(vals) == 4
|
||||
|
||||
|
||||
def test_fact_view_with_graph(client, mocker,
|
||||
mock_puppetdb_environments,
|
||||
mock_puppetdb_default_nodes):
|
||||
rv = client.get('/fact/architecture')
|
||||
assert rv.status_code == 200
|
||||
|
||||
soup = BeautifulSoup(rv.data, 'html.parser')
|
||||
assert soup.title.contents[0] == 'Puppetboard'
|
||||
|
||||
vals = soup.find_all('div', {"id": "factChart"})
|
||||
assert len(vals) == 1
|
||||
|
||||
|
||||
def test_fact_view_without_graph(client, mocker,
|
||||
mock_puppetdb_environments,
|
||||
mock_puppetdb_default_nodes):
|
||||
rv = client.get('/%2A/fact/augeas')
|
||||
assert rv.status_code == 200
|
||||
|
||||
soup = BeautifulSoup(rv.data, 'html.parser')
|
||||
assert soup.title.contents[0] == 'Puppetboard'
|
||||
|
||||
vals = soup.find_all('div', {"id": "factChart"})
|
||||
assert len(vals) == 0
|
||||
|
||||
|
||||
def test_fact_value_view(client, mocker,
|
||||
mock_puppetdb_environments,
|
||||
mock_puppetdb_default_nodes):
|
||||
rv = client.get('/fact/architecture/amd64')
|
||||
assert rv.status_code == 200
|
||||
|
||||
soup = BeautifulSoup(rv.data, 'html.parser')
|
||||
assert soup.title.contents[0] == 'Puppetboard'
|
||||
|
||||
vals = soup.find_all('div', {"id": "factChart"})
|
||||
assert len(vals) == 0
|
||||
|
||||
|
||||
def test_node_view(client, mocker,
|
||||
mock_puppetdb_environments,
|
||||
mock_puppetdb_default_nodes):
|
||||
rv = client.get('/node/node-failed')
|
||||
assert rv.status_code == 200
|
||||
|
||||
soup = BeautifulSoup(rv.data, 'html.parser')
|
||||
assert soup.title.contents[0] == 'Puppetboard'
|
||||
|
||||
vals = soup.find_all('table', {"id": "facts_table"})
|
||||
assert len(vals) == 1
|
||||
|
||||
vals = soup.find_all('table', {"id": "reports_table"})
|
||||
assert len(vals) == 1
|
||||
|
||||
|
||||
def test_fact_json_with_graph(client, mocker,
|
||||
mock_puppetdb_environments,
|
||||
mock_puppetdb_default_nodes):
|
||||
values = ['a', 'b', 'b', 'd']
|
||||
query_data = {'facts': []}
|
||||
query_data['facts'].append([])
|
||||
for i, value in enumerate(values):
|
||||
query_data['facts'][0].append({
|
||||
'certname': 'node-%s' % i,
|
||||
'name': 'architecture',
|
||||
'value': value,
|
||||
'environment': 'production'
|
||||
})
|
||||
|
||||
dbquery = MockDbQuery(query_data)
|
||||
|
||||
mocker.patch.object(app.puppetdb, '_query', side_effect=dbquery.get)
|
||||
|
||||
rv = client.get('/fact/architecture/json')
|
||||
assert rv.status_code == 200
|
||||
|
||||
result_json = json.loads(rv.data.decode('utf-8'))
|
||||
|
||||
assert 'data' in result_json
|
||||
assert len(result_json['data']) == 4
|
||||
for line in result_json['data']:
|
||||
assert len(line) == 2
|
||||
|
||||
assert 'chart' in result_json
|
||||
assert len(result_json['chart']) == 3
|
||||
# Test group_by
|
||||
assert result_json['chart'][1]['value'] == 2
|
||||
|
||||
|
||||
def test_fact_json_without_graph(client, mocker,
|
||||
mock_puppetdb_environments,
|
||||
mock_puppetdb_default_nodes):
|
||||
values = ['a', 'b', 'b', 'd']
|
||||
query_data = {'facts': []}
|
||||
query_data['facts'].append([])
|
||||
for i, value in enumerate(values):
|
||||
query_data['facts'][0].append({
|
||||
'certname': 'node-%s' % i,
|
||||
'name': 'architecture',
|
||||
'value': value,
|
||||
'environment': 'production'
|
||||
})
|
||||
|
||||
dbquery = MockDbQuery(query_data)
|
||||
|
||||
mocker.patch.object(app.puppetdb, '_query', side_effect=dbquery.get)
|
||||
|
||||
rv = client.get('/%2A/fact/augeas/json')
|
||||
assert rv.status_code == 200
|
||||
|
||||
result_json = json.loads(rv.data.decode('utf-8'))
|
||||
|
||||
assert 'data' in result_json
|
||||
assert len(result_json['data']) == 4
|
||||
for line in result_json['data']:
|
||||
assert len(line) == 2
|
||||
|
||||
assert 'chart' not in result_json
|
||||
|
||||
|
||||
def test_fact_value_json(client, mocker,
|
||||
mock_puppetdb_environments,
|
||||
mock_puppetdb_default_nodes):
|
||||
values = ['a', 'b', 'b', 'd']
|
||||
query_data = {'facts': []}
|
||||
query_data['facts'].append([])
|
||||
for i, value in enumerate(values):
|
||||
query_data['facts'][0].append({
|
||||
'certname': 'node-%s' % i,
|
||||
'name': 'architecture',
|
||||
'value': value,
|
||||
'environment': 'production'
|
||||
})
|
||||
|
||||
dbquery = MockDbQuery(query_data)
|
||||
|
||||
mocker.patch.object(app.puppetdb, '_query', side_effect=dbquery.get)
|
||||
|
||||
rv = client.get('/fact/architecture/amd64/json')
|
||||
assert rv.status_code == 200
|
||||
|
||||
result_json = json.loads(rv.data.decode('utf-8'))
|
||||
|
||||
assert 'data' in result_json
|
||||
assert len(result_json['data']) == 4
|
||||
for line in result_json['data']:
|
||||
assert len(line) == 1
|
||||
|
||||
assert 'chart' not in result_json
|
||||
|
||||
|
||||
def test_node_facts_json(client, mocker,
|
||||
mock_puppetdb_environments,
|
||||
mock_puppetdb_default_nodes):
|
||||
values = ['a', 'b', 'b', 'd']
|
||||
query_data = {'facts': []}
|
||||
query_data['facts'].append([])
|
||||
for i, value in enumerate(values):
|
||||
query_data['facts'][0].append({
|
||||
'certname': 'node-failed',
|
||||
'name': 'fact-%s' % i,
|
||||
'value': value,
|
||||
'environment': 'production'
|
||||
})
|
||||
|
||||
dbquery = MockDbQuery(query_data)
|
||||
|
||||
mocker.patch.object(app.puppetdb, '_query', side_effect=dbquery.get)
|
||||
|
||||
rv = client.get('/node/node-failed/facts/json')
|
||||
assert rv.status_code == 200
|
||||
|
||||
result_json = json.loads(rv.data.decode('utf-8'))
|
||||
|
||||
assert 'data' in result_json
|
||||
assert len(result_json['data']) == 4
|
||||
for line in result_json['data']:
|
||||
assert len(line) == 2
|
||||
|
||||
assert 'chart' not in result_json
|
||||
|
||||
Reference in New Issue
Block a user