""" Unit tests for the main FastAPI application. """ import pytest from fastapi.testclient import TestClient from _server.main import app class TestRootEndpoint: """Test cases for the root endpoint.""" @pytest.fixture def client(self): """Create a test client for the FastAPI app.""" return TestClient(app) def test_root_redirects_to_cicero_jobs_app(self, client): """Test that the root endpoint "/" redirects to "/cicero_jobs/app".""" response = client.get('/', follow_redirects=False) # Assert it's a redirect response assert response.status_code == 307 # Assert the location header points to the correct URL assert response.headers['location'] == '/cicero_jobs/app' def test_root_redirect_response_type(self, client): """Test that the root endpoint returns a RedirectResponse.""" response = client.get("/", follow_redirects=False) # Check status code for temporary redirect assert response.status_code == 307 # Verify it's a proper redirect response assert "location" in response.headers def test_root_redirect_follows_correctly(self, client): """Test that following the redirect leads to the expected path.""" # First, get the redirect response redirect_response = client.get('/', follow_redirects=False) redirect_url = redirect_response.headers['location'] # Then try to access the redirected URL # Note: This might fail if the marimo app isn't fully set up, # but we're testing the redirect behavior final_response = client.get(redirect_url, follow_redirects=False) # The redirect URL should be accessible (even if it returns an error due to marimo setup) # We're mainly testing that the redirect target exists in our app assert redirect_url == '/cicero_jobs/app' def test_root_redirect_preserves_method(self, client): """Test that GET method is preserved in redirect.""" response = client.get("/", follow_redirects=False) assert response.status_code == 307 # Temporary redirect preserves method assert response.headers['location'] == '/cicero_jobs/app' # Additional test class for edge cases class TestRootEndpointEdgeCases: """Test edge cases for the root endpoint.""" @pytest.fixture def client(self): """Create a test client for the FastAPI app.""" return TestClient(app) def test_root_with_query_parameters(self, client): """Test root endpoint behavior with query parameters.""" response = client.get('/?param=value', follow_redirects=False) # Should still redirect regardless of query parameters assert response.status_code == 307 assert response.headers["location"] == "/cicero_jobs/app" def test_root_post_method(self, client): """Test that POST to root also redirects (if supported).""" response = client.post('/', follow_redirects=False) # FastAPI should either redirect or return method not allowed # Since we only defined GET, this should return 405 Method Not Allowed assert response.status_code == 405 def test_root_with_trailing_slash_consistency(self, client): """Test that root endpoint handles trailing slashes consistently.""" response1 = client.get('/', follow_redirects=False) # Both should behave the same way assert response1.status_code == 307 assert response1.headers["location"] == "/cicero_jobs/app"