45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
import pytest
|
|
from app import app
|
|
from unittest.mock import patch
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
app.config['TESTING'] = True
|
|
with app.test_client() as client:
|
|
with client.session_transaction() as sess:
|
|
sess['_csrf_token'] = 'test-token'
|
|
yield client
|
|
|
|
def test_home_page(client):
|
|
response = client.get('/')
|
|
assert response.status_code == 200
|
|
assert b"Zomeravond" in response.data or b"Papklokken" in response.data
|
|
|
|
@patch('app.get_google_sheet')
|
|
def test_post_missing_fields(mock_get_sheet, client):
|
|
response = client.post('/zomeravond', data={'_csrf_token': 'test-token'})
|
|
assert b"Oeps! Bepaalde verplichte velden ontbreken" in response.data
|
|
mock_get_sheet.return_value.append_row.assert_not_called()
|
|
|
|
@patch('app.get_google_sheet')
|
|
@patch('app.get_public_participants')
|
|
def test_post_success(mock_participants, mock_get_sheet, client):
|
|
mock_participants.return_value = []
|
|
|
|
data = {
|
|
'_csrf_token': 'test-token',
|
|
'klasse': 'Kajuitklasse',
|
|
'zeilnummer': '123',
|
|
'bootnaam': 'TestBoat',
|
|
'naam': 'Test Name',
|
|
'telefoonmobiel': '0612345678',
|
|
'email': 'test@example.com'
|
|
}
|
|
|
|
response = client.post('/zomeravond', data=data)
|
|
assert response.status_code == 302
|
|
assert '/zomeravond/success' in response.headers.get('Location', '')
|
|
|
|
# In full testing, append_row is called unless TESTING_NO_APPEND is set.
|
|
# But since it's mocked, we can check it.
|
|
assert mock_get_sheet.return_value.append_row.called
|