Validate dailychart json data

This commit is contained in:
Mike Terzo
2017-02-02 20:51:34 -05:00
committed by redref
parent 2cdf5fea61
commit 55756900c1

View File

@@ -1,6 +1,7 @@
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
@@ -544,5 +545,16 @@ def test_json_daily_reports_chart_ok(client, mocker):
mocker.patch.object(app.puppetdb, '_query', side_effect=dbquery.get)
rv = client.get('/daily_reports_chart.json')
result_json = json.loads(rv.data.decode('utf-8'))
assert 'result' in result_json
assert (len(result_json['result']) ==
app.app.config['DAILY_REPORTS_CHART_DAYS'])
day_format = '%Y-%m-%d'
cur_day = datetime.strptime(result_json['result'][0]['day'], day_format)
for day in result_json['result'][1:]:
next_day = datetime.strptime(day['day'], day_format)
assert cur_day < next_day
cur_day = next_day
assert rv.status_code == 200