diff --git a/test_app.py b/test_app.py index e0aeb4f..998c3d8 100644 --- a/test_app.py +++ b/test_app.py @@ -147,4 +147,85 @@ def test_werktage_berechnung(client): }) assert resp.status_code == 200 assert b'Anzahl der Werktage' in resp.data - assert f': {expected}'.encode() in resp.data \ No newline at end of file + assert f': {expected}'.encode() in resp.data + +def test_api_tage_werktage(client): + # Erfolgsfall: Werktage + resp = client.post('/api/tage_werktage', json={ + 'start': '2024-06-01', 'end': '2024-06-10', 'werktage': True + }) + assert resp.status_code == 200 + data = resp.get_json() + assert 'result' in data + # Fehlerfall: Ungültiges Datum + resp = client.post('/api/tage_werktage', json={ + 'start': 'foo', 'end': 'bar', 'werktage': True + }) + assert resp.status_code == 400 + data = resp.get_json() + assert 'error' in data + +def test_api_wochentag(client): + resp = client.post('/api/wochentag', json={'datum': '2024-06-10'}) + assert resp.status_code == 200 + data = resp.get_json() + assert data['result'] == 'Montag' + # Fehlerfall + resp = client.post('/api/wochentag', json={'datum': 'foo'}) + assert resp.status_code == 400 + assert 'error' in resp.get_json() + +def test_api_kw_berechnen(client): + resp = client.post('/api/kw_berechnen', json={'datum': '2024-06-10'}) + assert resp.status_code == 200 + data = resp.get_json() + assert 'KW' in data['result'] + # Fehlerfall + resp = client.post('/api/kw_berechnen', json={'datum': 'foo'}) + assert resp.status_code == 400 + assert 'error' in resp.get_json() + +def test_api_kw_datum(client): + resp = client.post('/api/kw_datum', json={'jahr': 2024, 'kw': 24}) + assert resp.status_code == 200 + data = resp.get_json() + assert 'result' in data and 'start' in data and 'end' in data + # Fehlerfall + resp = client.post('/api/kw_datum', json={'jahr': 'foo', 'kw': 'bar'}) + assert resp.status_code == 400 + assert 'error' in resp.get_json() + +def test_api_plusminus(client): + # Tage addieren + resp = client.post('/api/plusminus', json={ + 'datum': '2024-06-10', 'anzahl': 5, 'einheit': 'tage', 'richtung': 'add', 'werktage': False + }) + assert resp.status_code == 200 + data = resp.get_json() + assert data['result'] == '2024-06-15' + # Werktage subtrahieren + resp = client.post('/api/plusminus', json={ + 'datum': '2024-06-10', 'anzahl': 5, 'einheit': 'tage', 'richtung': 'sub', 'werktage': True + }) + assert resp.status_code == 200 + data = resp.get_json() + assert 'result' in data + # Fehlerfall: ungültige Einheit + resp = client.post('/api/plusminus', json={ + 'datum': '2024-06-10', 'anzahl': 5, 'einheit': 'foo' + }) + assert resp.status_code == 400 + assert 'error' in resp.get_json() + +def test_api_stats(client): + resp = client.get('/api/stats') + assert resp.status_code == 200 + data = resp.get_json() + assert 'pageviews' in data and 'func_counts' in data and 'impressions_per_day' in data + +def test_api_monitor(client): + resp = client.get('/api/monitor') + assert resp.status_code == 200 + data = resp.get_json() + assert data['status'] == 'ok' + assert 'uptime_seconds' in data \ No newline at end of file