"""Pytest fixtures for FlaskPaste tests.""" import pytest import app.database as db_module from app import create_app from app.api.routes import reset_lookup_rate_limits, reset_rate_limits def _clear_database(): """Clear all data from database tables for test isolation.""" if db_module._memory_db_holder is not None: db_module._memory_db_holder.execute("DELETE FROM pastes") db_module._memory_db_holder.execute("DELETE FROM content_hashes") db_module._memory_db_holder.execute("DELETE FROM issued_certificates") db_module._memory_db_holder.execute("DELETE FROM certificate_authority") db_module._memory_db_holder.execute("DELETE FROM short_urls") db_module._memory_db_holder.commit() @pytest.fixture def app(): """Create application for testing.""" # Reset global state for test isolation reset_rate_limits() reset_lookup_rate_limits() _clear_database() test_app = create_app("testing") # Clear database again after app init (in case init added anything) _clear_database() yield test_app # Cleanup after test reset_rate_limits() reset_lookup_rate_limits() @pytest.fixture def client(app): """Create test client.""" return app.test_client() @pytest.fixture def runner(app): """Create CLI runner.""" return app.test_cli_runner() @pytest.fixture def sample_text(): """Sample text content for testing.""" return "Hello, FlaskPaste!" @pytest.fixture def sample_json(): """Sample JSON payload for testing.""" return {"content": "Hello from JSON!"} @pytest.fixture def auth_header(): """Valid authentication header.""" return {"X-SSL-Client-SHA1": "a" * 40} @pytest.fixture def other_auth_header(): """Different valid authentication header.""" return {"X-SSL-Client-SHA1": "b" * 40} @pytest.fixture def png_bytes(): """Minimal valid PNG bytes for testing.""" return ( b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01" b"\x00\x00\x00\x01\x08\x02\x00\x00\x00\x90wS\xde\x00" b"\x00\x00\x0cIDATx\x9cc\xf8\x0f\x00\x00\x01\x01\x00" b"\x05\x18\xd8N\x00\x00\x00\x00IEND\xaeB`\x82" ) @pytest.fixture def jpeg_bytes(): """Minimal JPEG magic bytes for testing.""" return b"\xff\xd8\xff\xe0\x00\x10JFIF\x00" @pytest.fixture def zip_bytes(): """ZIP magic bytes for testing.""" return b"PK\x03\x04" + b"\x00" * 26 @pytest.fixture def pdf_bytes(): """PDF magic bytes for testing.""" return b"%PDF-1.4 test content"