add test_app.py (manually)

This commit is contained in:
2025-07-23 12:44:44 +02:00
parent b351a8b564
commit b83736917c
2 changed files with 44 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
Flask==3.0.3 Flask==3.0.3
numpy==1.26.4 numpy==1.26.4
python-dateutil==2.9.0.post0 python-dateutil==2.9.0.post0
pytest==8.2.2

42
test_app.py Normal file
View File

@@ -0,0 +1,42 @@
import os
import pytest
from app import app as flask_app
@pytest.fixture
def client():
flask_app.config['TESTING'] = True
with flask_app.test_client() as client:
yield client
def test_homepage(client):
resp = client.get('/')
assert resp.status_code == 200
assert b'Elpatrons Datumsrechner' in resp.data
def test_tage_berechnung(client):
resp = client.post('/', data={
'action': 'tage',
'start1': '2024-01-01',
'end1': '2024-01-10'
})
assert resp.status_code == 200
assert b'Anzahl der Tage' in resp.data
assert b'9' in resp.data
def test_xss_protection(client):
# Versuche ein Skript einzuschleusen
xss = '<script>alert(1)</script>'
resp = client.post('/', data={
'action': 'tage',
'start1': xss,
'end1': '2024-01-10'
})
assert resp.status_code == 200
# Das Skript darf nicht im HTML erscheinen (sollte escaped sein)
assert b'<script>alert(1)</script>' not in resp.data
assert b'&lt;script&gt;alert(1)&lt;/script&gt;' in resp.data
def test_stats_login_required(client):
resp = client.get('/stats')
assert resp.status_code == 200
assert b'Dashboard Login' in resp.data