Skip to content

Commit

Permalink
Test slightly more for Query
Browse files Browse the repository at this point in the history
- separately table and raw JSON view,
although we can't test the actual response
as in both cases it's generated with JavaScript
  • Loading branch information
gdubicki committed Jun 12, 2022
1 parent 0d796dc commit 36880df
Showing 1 changed file with 49 additions and 7 deletions.
56 changes: 49 additions & 7 deletions test/views/test_query.py
Expand Up @@ -18,23 +18,23 @@ def test_query_view(client, mocker,
assert len(vals) == 0


def test_query__some_response(client, mocker,
def test_query__some_response__table(client, mocker,
mock_puppetdb_environments,
mock_puppetdb_default_nodes):
app.app.config['WTF_CSRF_ENABLED'] = False

query_data = [
{'certname': 'foobar'},
result = [
{'certname': 'foobar', 'catalog_environment': 'qa'},
]
mocker.patch.object(app.puppetdb, '_query', return_value=query_data)
mocker.patch.object(app.puppetdb, '_query', return_value=result)

data = {
query_data = {
'query': 'nodes[certname] { certname = "foobar" }',
'endpoints': 'pql',
}
rv = client.post(
'/query',
data=data,
data=query_data,
content_type='application/x-www-form-urlencoded',
)

Expand All @@ -48,7 +48,49 @@ def test_query__some_response(client, mocker,

vals = soup.find_all('p', {"id": "number_of_results"})
assert len(vals) == 1
assert str(len(query_data)) in vals[0].string
assert 'Number of results: 1' in vals[0].string

vals = soup.find_all('table', {"id": "query_table"})
assert len(vals) == 1
# we can't test more here as the content of this table is generated with JavaScript...


def test_query__some_response__json(client, mocker,
mock_puppetdb_environments,
mock_puppetdb_default_nodes):
app.app.config['WTF_CSRF_ENABLED'] = False

result = [
{'certname': 'foobar', 'catalog_environment': 'qa'},
]
mocker.patch.object(app.puppetdb, '_query', return_value=result)

query_data = {
'query': 'nodes[certname] { certname = "foobar" }',
'endpoints': 'pql',
'rawjson': 'y',
}
rv = client.post(
'/query',
data=query_data,
content_type='application/x-www-form-urlencoded',
)

assert rv.status_code == 200

soup = BeautifulSoup(rv.data, 'html.parser')
assert soup.title.contents[0] == 'Puppetboard'

vals = soup.find_all('h2', {"id": "results_header"})
assert len(vals) == 1

vals = soup.find_all('p', {"id": "number_of_results"})
assert len(vals) == 1
assert 'Number of results: 1' in vals[0].string

vals = soup.find_all('pre', {"id": "result"})
assert len(vals) == 1
# we can't test more here as the content of this tag is generated with JavaScript...


def test_query__empty_response(client, mocker,
Expand Down

0 comments on commit 36880df

Please sign in to comment.