From 7cebe56fc45451699b0dcde2a315043f64c02a59 Mon Sep 17 00:00:00 2001 From: Mike Terzo Date: Mon, 23 Jan 2017 05:37:07 -0500 Subject: [PATCH] Adding testing for all environments Signed-off-by: Mike Terzo --- test/test_app.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/test/test_app.py b/test/test_app.py index 0bf28fe..db5ab10 100644 --- a/test/test_app.py +++ b/test/test_app.py @@ -14,6 +14,14 @@ class MockDbQuery(object): resp = None if method in self.responses: resp = self.responses[method].pop(0) + + if 'validate' in resp: + checks = resp['validate']['checks'] + resp = resp['validate']['data'] + for check in checks: + assert check in kws + expected_value = checks[check] + assert expected_value == kws[check] return resp @@ -73,6 +81,56 @@ def test_get_index(client, mocker, assert rv.status_code == 200 +def test_index_all(client, mocker, + mock_puppetdb_environments, + mock_puppetdb_default_nodes): + + base_str = 'puppetlabs.puppetdb.population:' + query_data = { + 'mbean': [ + { + 'validate': { + 'data': {'Value': '50'}, + 'checks': { + 'path': '%sname=num-nodes' % base_str + } + } + }, + { + 'validate': { + 'data': {'Value': '60'}, + 'checks': { + 'path': '%sname=num-resources' % base_str + } + } + }, + { + 'validate': { + 'data': {'Value': 60.3}, + 'checks': { + 'path': '%sname=avg-resources-per-node' % base_str + } + } + } + ] + } + dbquery = MockDbQuery(query_data) + mocker.patch.object(app.puppetdb, '_query', side_effect=dbquery.get) + rv = client.get('/%2A/') + + soup = BeautifulSoup(rv.data, 'html.parser') + assert soup.title.contents[0] == 'Puppetboard' + vals = soup.find_all('h1', + {"class": "ui header darkblue no-margin-bottom"}) + + assert len(vals) == 3 + assert vals[0].string == '50' + assert vals[1].string == '60' + assert vals[2].string == ' 60' + + assert rv.status_code == 200 + + def test_offline_mode(client, mocker): app.app.config['OFFLINE_MODE'] = True