jail2ban/tests/conftest.py

49 lines
762 B
Python
Raw Permalink Normal View History

2024-07-31 16:30:43 +02:00
'''
Test fixtures
'''
2022-03-14 15:41:45 +00:00
import base64
2024-07-31 16:30:43 +02:00
import pytest
2022-03-10 11:22:04 +01:00
from jail2ban import create_app
@pytest.fixture()
def app():
app = create_app()
app.config.update({
"TESTING": True,
"SECRET_KEY": 'Testing',
2022-03-14 15:41:45 +00:00
"AUTHFILE": '../tests/users-test.txt'
2022-03-10 11:22:04 +01:00
})
# other setup can go here
yield app
# clean up / reset resources here
@pytest.fixture()
def client(app):
2024-07-31 16:30:43 +02:00
'''
Create a synthetic client
'''
2022-03-10 11:22:04 +01:00
return app.test_client()
@pytest.fixture()
def runner(app):
2024-07-31 16:30:43 +02:00
'''
Create a synthetic runner
'''
2022-03-10 11:22:04 +01:00
return app.test_cli_runner()
2022-03-14 15:41:45 +00:00
@pytest.fixture()
def valid_credentials():
2024-07-31 16:30:43 +02:00
'''
Mock authentication for the test
'''
2022-03-14 15:41:45 +00:00
return base64.b64encode(b"test.example.com:testpassword").decode("utf-8")