diff --git a/app.py b/app.py index 209c8df..41e5316 100644 --- a/app.py +++ b/app.py @@ -439,8 +439,13 @@ def api_plusminus(): @app.route('/api/stats', methods=['GET']) def api_stats(): log_path = os.path.join('log', 'pageviews.log') - pageviews, func_counts, impressions_per_day, api_counts = parse_log_stats(log_path) - return render_template('stats_dashboard.html', pageviews=pageviews, func_counts=func_counts, impressions_per_day=impressions_per_day, api_counts=api_counts) + pageviews, func_counts, func_counts_hourly, impressions_per_day, impressions_per_hour, api_counts, api_counts_hourly = parse_log_stats(log_path) + return jsonify({ + "pageviews": pageviews, + "func_counts": func_counts, + "impressions_per_day": impressions_per_day, + "api_counts": api_counts + }) @app.route('/api/monitor', methods=['GET']) def api_monitor(): diff --git a/test_app.py b/test_app.py index c6d5a6f..1e9821a 100644 --- a/test_app.py +++ b/test_app.py @@ -221,10 +221,11 @@ def test_api_plusminus(client): def test_api_stats(client): resp = client.get('/api/stats') assert resp.status_code == 200 - # Die Route gibt HTML zurück, nicht JSON - html = resp.data.decode('utf-8') - # Prüfe auf typische HTML-Elemente des Dashboards - assert 'Statistik-Dashboard' in html or 'Dashboard' in html + data = resp.get_json() + assert "pageviews" in data + assert "func_counts" in data + assert "impressions_per_day" in data + assert "api_counts" in data def test_api_monitor(client): resp = client.get('/api/monitor')