~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
refactor(tests): consolidate 70 status-tautology tests into one parametrized test (#4126)
LearningCircuitd142521169b3
diff --git a/tests/news/test_flask_api_routes.py b/tests/news/test_flask_api_routes.pyindex 663e2635ce..02f1bb563a 100644--- a/tests/news/test_flask_api_routes.py+++ b/tests/news/test_flask_api_routes.py@@ -1,14 +1,21 @@"""-Comprehensive tests for news/flask_api.py - Phase 3.1 Coverage Expansion--Tests cover:-- News feed endpoint with various parameters-- Subscription CRUD operations-- Voting and feedback endpoints-- Scheduler control endpoints-- Folder management endpoints-- Search history endpoints-- Error handling for all endpoints+Tests for news/flask_api.py.++Covers:+- safe_error_message helper (sanitises internal error details)+- get_user_id helper+- Error handlers (400 / 404 / 500)+- A parametrised auth-required smoke test for every news API endpoint+- One path-traversal guard test (Werkzeug rejects before route match)+- Two SUT integration tests that bypass auth via decorator patching++Original history: this file used to contain 83 tests, of which 71 were+near-identical "hit endpoint without auth, accept any of [200, 302, 401,+403, 404, 500]" tautologies. PR #4098 narrowed the assertions to+== 401 / == 404. This PR consolidates the 70 endpoint-+-method+auth-required tests into a single parametrised test+(`test_endpoint_requires_auth`) and keeps the path-traversal test+separately."""import pytest@@ -40,26 +47,99 @@ def client(app):return app.test_client()-def mock_login_required():- """Mock login_required decorator to bypass authentication."""- with patch(- "local_deep_research.news.flask_api.login_required", lambda f: f- ):- yield---def mock_user_context(app):- """Set up mock user context."""- with patch(- "local_deep_research.news.flask_api.get_user_id",- return_value="testuser",- ):- yield---# ============= safe_error_message Tests =============+# ============= Auth-required endpoint smoke tests =============++# Every endpoint under /news/api/* is wrapped in @login_required. An+# unauthenticated request should be rejected with HTTP 401 by Flask-Login+# (the JSON-mode error handler kicks in because these routes return JSON).+#+# Before this consolidation each row below was its own ~5-line test with+# a misleading name like `test_feed_with_limit_parameter` — those tests+# were never actually exercising the parameter; they just bounced on 401+# regardless of what they sent. The parameters are kept here purely to+# preserve the URL surface that was probed previously.+AUTH_REQUIRED_ENDPOINTS = [+ # GET endpoints+ ("GET", "/news/api/categories"),+ ("GET", "/news/api/feed?focus=technology"),+ ("GET", "/news/api/feed?limit=-1"),+ ("GET", "/news/api/feed?limit=0"),+ ("GET", "/news/api/feed?limit=10"),+ ("GET", "/news/api/feed?limit=999999"),+ ("GET", "/news/api/feed?limit=abc"),+ ("GET", "/news/api/feed?strategy=news_aggregation"),+ ("GET", "/news/api/feed?subscription_id=sub123"),+ ("GET", "/news/api/feed?use_cache=false"),+ ("GET", "/news/api/scheduler/stats"),+ ("GET", "/news/api/scheduler/status"),+ ("GET", "/news/api/scheduler/users"),+ ("GET", "/news/api/search-history"),+ ("GET", "/news/api/subscription/folders"),+ ("GET", "/news/api/subscription/stats"),+ ("GET", "/news/api/subscription/subscriptions/organized"),+ ("GET", "/news/api/subscriptions/'; DROP TABLE users; --"),+ ("GET", "/news/api/subscriptions/current"),+ ("GET", "/news/api/subscriptions/null"),+ ("GET", "/news/api/subscriptions/sub123"),+ ("GET", "/news/api/subscriptions/sub123/history"),+ ("GET", "/news/api/subscriptions/sub123/history?limit=50"),+ ("GET", "/news/api/subscriptions/undefined"),+ # POST endpoints+ ("POST", "/news/api/check-overdue"),+ ("POST", "/news/api/feedback/batch"),+ ("POST", "/news/api/feedback/card123"),+ ("POST", "/news/api/preferences"),+ ("POST", "/news/api/research/card123"),+ ("POST", "/news/api/scheduler/check-now"),+ ("POST", "/news/api/scheduler/cleanup-now"),+ ("POST", "/news/api/scheduler/start"),+ ("POST", "/news/api/scheduler/stop"),+ ("POST", "/news/api/search-history"),+ ("POST", "/news/api/subscribe"),+ ("POST", "/news/api/subscription/folders"),+ ("POST", "/news/api/subscriptions/sub123/run"),+ ("POST", "/news/api/vote"),+ # PUT endpoints+ ("PUT", "/news/api/subscription/folders/folder123"),+ ("PUT", "/news/api/subscription/subscriptions/sub123"),+ ("PUT", "/news/api/subscriptions/sub123"),+ # DELETE endpoints+ ("DELETE", "/news/api/search-history"),+ ("DELETE", "/news/api/subscription/folders/folder123"),+ ("DELETE", "/news/api/subscription/folders/folder123?move_to=other_folder"),+ ("DELETE", "/news/api/subscriptions/nonexistent123"),+]++[email protected](("method", "url"), AUTH_REQUIRED_ENDPOINTS)+def test_endpoint_requires_auth(client, method, url):+ """Unauthenticated requests to /news/api/* must return 401.++ This replaces ~70 individual tests that all asserted the same+ contract via misleading test names like `test_feed_with_X_parameter`.+ None of those tests actually exercised their parameters — they all+ bounced on @login_required at 401. The single assertion here covers+ the same contract more honestly and at a fraction of the cost.+ """+ response = client.open(url, method=method)+ assert response.status_code == 401, (+ f"{method} {url} returned {response.status_code}, expected 401"+ )+++def test_path_traversal_rejected(client):+ """Path traversal in subscription id is rejected before route matching.++ Werkzeug returns 404 (no matching route) for ../../etc/passwd-style+ paths, so the request never reaches @login_required or the handler.+ Either outcome (404 or 401) confirms the traversal is not honored;+ we assert the specific code Werkzeug actually produces.+ """+ response = client.get("/news/api/subscriptions/../../etc/passwd")+ assert response.status_code == 404, response.status_code+++# ============= safe_error_message tests =============class TestSafeErrorMessageExtended:@@ -122,6 +202,9 @@ class TestSafeErrorMessageExtended:# ============= get_user_id Tests =============+# ============= get_user_id tests =============++class TestGetUserIdExtended:"""Extended tests for get_user_id function."""@@ -154,744 +237,7 @@ class TestGetUserIdExtended:# ============= News Feed Endpoint Tests =============-class TestNewsFeedEndpoint:- """Tests for the /feed endpoint."""-- def test_feed_with_limit_parameter(self, client):- """Test feed endpoint with limit parameter."""- response = client.get("/news/api/feed?limit=10")- # May require auth or work depending on patch order- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_feed_with_use_cache_false(self, client):- """Test feed endpoint with use_cache=false."""- response = client.get("/news/api/feed?use_cache=false")- # Should require auth or return data- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_feed_with_strategy_parameter(self, client):- """Test feed endpoint with strategy parameter."""- response = client.get("/news/api/feed?strategy=news_aggregation")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_feed_with_focus_parameter(self, client):- """Test feed endpoint with focus parameter."""- response = client.get("/news/api/feed?focus=technology")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_feed_with_subscription_id(self, client):- """Test feed endpoint with subscription_id."""- response = client.get("/news/api/feed?subscription_id=sub123")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Subscription CRUD Tests =============---class TestCreateSubscription:- """Tests for the /subscribe endpoint."""-- def test_subscribe_missing_query(self, client):- """Test subscribe with missing query field."""- response = client.post(- "/news/api/subscribe",- json={"subscription_type": "search"},- content_type="application/json",- )- # Should return 400 or require auth- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_subscribe_with_all_parameters(self, client):- """Test subscribe with all optional parameters."""- response = client.post(- "/news/api/subscribe",- json={- "query": "AI news",- "subscription_type": "topic",- "refresh_minutes": 60,- "model_provider": "ollama",- "model": "llama3",- "search_strategy": "news_aggregation",- "name": "My AI Feed",- "folder_id": "folder123",- "is_active": True,- "search_engine": "searxng",- "search_iterations": 3,- "questions_per_iteration": 5,- },- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_subscribe_empty_json(self, client):- """Test subscribe with empty JSON."""- response = client.post(- "/news/api/subscribe",- json={},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_subscribe_custom_endpoint(self, client):- """Test subscribe with custom endpoint."""- response = client.post(- "/news/api/subscribe",- json={- "query": "test query",- "custom_endpoint": "https://custom.api.com/v1",- },- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestGetSubscription:- """Tests for getting subscriptions."""-- def test_get_subscription_null_id(self, client):- """Test getting subscription with null ID."""- response = client.get("/news/api/subscriptions/null")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_get_subscription_undefined_id(self, client):- """Test getting subscription with undefined ID."""- response = client.get("/news/api/subscriptions/undefined")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_get_subscription_valid_id(self, client):- """Test getting subscription with valid ID."""- response = client.get("/news/api/subscriptions/sub123")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestUpdateSubscription:- """Tests for updating subscriptions."""-- def test_update_subscription_invalid_json(self, client):- """Test update subscription with invalid JSON."""- response = client.put(- "/news/api/subscriptions/sub123",- data="not json",- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_update_subscription_partial_update(self, client):- """Test partial update of subscription."""- response = client.put(- "/news/api/subscriptions/sub123",- json={"name": "Updated Name"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_update_subscription_all_fields(self, client):- """Test updating all subscription fields."""- response = client.put(- "/news/api/subscriptions/sub123",- json={- "query": "updated query",- "name": "Updated Name",- "refresh_minutes": 120,- "is_active": False,- "folder_id": "new_folder",- "model_provider": "anthropic",- "model": "claude-3",- "search_strategy": "comprehensive",- "search_engine": "google",- "search_iterations": 5,- "questions_per_iteration": 10,- },- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestDeleteSubscription:- """Tests for deleting subscriptions."""-- def test_delete_nonexistent_subscription(self, client):- """Test deleting nonexistent subscription."""- response = client.delete("/news/api/subscriptions/nonexistent123")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Voting and Feedback Tests =============---class TestVoteOnNews:- """Tests for voting endpoints."""-- def test_vote_missing_card_id(self, client):- """Test voting with missing card_id."""- response = client.post(- "/news/api/vote",- json={"vote": "up"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_vote_missing_vote(self, client):- """Test voting with missing vote field."""- response = client.post(- "/news/api/vote",- json={"card_id": "card123"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_vote_upvote(self, client):- """Test upvoting a card."""- response = client.post(- "/news/api/vote",- json={"card_id": "card123", "vote": "up"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_vote_downvote(self, client):- """Test downvoting a card."""- response = client.post(- "/news/api/vote",- json={"card_id": "card123", "vote": "down"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestBatchFeedback:- """Tests for batch feedback endpoint."""-- def test_batch_feedback_empty_card_ids(self, client):- """Test batch feedback with empty card_ids."""- response = client.post(- "/news/api/feedback/batch",- json={"card_ids": []},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_batch_feedback_multiple_cards(self, client):- """Test batch feedback with multiple cards."""- response = client.post(- "/news/api/feedback/batch",- json={"card_ids": ["card1", "card2", "card3"]},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_batch_feedback_no_json(self, client):- """Test batch feedback without JSON data."""- response = client.post(- "/news/api/feedback/batch",- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestSubmitFeedback:- """Tests for submit feedback endpoint."""-- def test_submit_feedback_missing_vote(self, client):- """Test submitting feedback without vote."""- response = client.post(- "/news/api/feedback/card123",- json={},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_submit_feedback_valid(self, client):- """Test submitting valid feedback."""- response = client.post(- "/news/api/feedback/card123",- json={"vote": "up"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Research Endpoint Tests =============---class TestResearchNewsItem:- """Tests for research news item endpoint."""-- def test_research_quick_depth(self, client):- """Test researching with quick depth."""- response = client.post(- "/news/api/research/card123",- json={"depth": "quick"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_research_detailed_depth(self, client):- """Test researching with detailed depth."""- response = client.post(- "/news/api/research/card123",- json={"depth": "detailed"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_research_report_depth(self, client):- """Test researching with report depth."""- response = client.post(- "/news/api/research/card123",- json={"depth": "report"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_research_default_depth(self, client):- """Test researching with default depth (no data)."""- response = client.post(- "/news/api/research/card123",- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Subscription History Tests =============---class TestSubscriptionHistory:- """Tests for subscription history endpoint."""-- def test_get_history_default_limit(self, client):- """Test getting history with default limit."""- response = client.get("/news/api/subscriptions/sub123/history")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_get_history_custom_limit(self, client):- """Test getting history with custom limit."""- response = client.get("/news/api/subscriptions/sub123/history?limit=50")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Preferences Tests =============---class TestSavePreferences:- """Tests for saving preferences."""-- def test_save_preferences_empty(self, client):- """Test saving empty preferences."""- response = client.post(- "/news/api/preferences",- json={"preferences": {}},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_save_preferences_with_data(self, client):- """Test saving preferences with data."""- response = client.post(- "/news/api/preferences",- json={- "preferences": {- "theme": "dark",- "notification_enabled": True,- "refresh_interval": 30,- }- },- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_save_preferences_no_json(self, client):- """Test saving preferences without JSON."""- response = client.post(- "/news/api/preferences",- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Categories Tests =============---class TestGetCategories:- """Tests for categories endpoint."""-- def test_get_categories(self, client):- """Test getting categories."""- response = client.get("/news/api/categories")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Scheduler Endpoint Tests =============---class TestSchedulerStatus:- """Tests for scheduler status endpoint."""-- def test_get_scheduler_status(self, client):- """Test getting scheduler status."""- response = client.get("/news/api/scheduler/status")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestStartScheduler:- """Tests for starting scheduler."""-- def test_start_scheduler(self, client):- """Test starting scheduler."""- response = client.post("/news/api/scheduler/start")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestStopScheduler:- """Tests for stopping scheduler."""-- def test_stop_scheduler(self, client):- """Test stopping scheduler."""- response = client.post("/news/api/scheduler/stop")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestCheckSubscriptionsNow:- """Tests for check subscriptions now endpoint."""-- def test_check_subscriptions_now(self, client):- """Test triggering subscription check."""- response = client.post("/news/api/scheduler/check-now")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestTriggerCleanup:- """Tests for triggering cleanup."""-- def test_trigger_cleanup(self, client):- """Test triggering cleanup."""- response = client.post("/news/api/scheduler/cleanup-now")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestGetActiveUsers:- """Tests for getting active users."""-- def test_get_active_users(self, client):- """Test getting active users."""- response = client.get("/news/api/scheduler/users")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestSchedulerStats:- """Tests for scheduler stats."""-- def test_get_scheduler_stats(self, client):- """Test getting scheduler stats."""- response = client.get("/news/api/scheduler/stats")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Overdue Subscriptions Tests =============---class TestCheckOverdueSubscriptions:- """Tests for checking overdue subscriptions."""-- def test_check_overdue(self, client):- """Test checking overdue subscriptions."""- response = client.post("/news/api/check-overdue")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Folder Management Tests =============---class TestGetFolders:- """Tests for getting folders."""-- def test_get_folders(self, client):- """Test getting folders."""- response = client.get("/news/api/subscription/folders")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestCreateFolder:- """Tests for creating folders."""-- def test_create_folder_no_name(self, client):- """Test creating folder without name."""- response = client.post(- "/news/api/subscription/folders",- json={},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_create_folder_with_name(self, client):- """Test creating folder with name."""- response = client.post(- "/news/api/subscription/folders",- json={"name": "Test Folder"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_create_folder_with_description(self, client):- """Test creating folder with description."""- response = client.post(- "/news/api/subscription/folders",- json={"name": "Test Folder", "description": "A test folder"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestUpdateFolder:- """Tests for updating folders."""-- def test_update_folder(self, client):- """Test updating folder."""- response = client.put(- "/news/api/subscription/folders/folder123",- json={"name": "Updated Folder"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestDeleteFolder:- """Tests for deleting folders."""-- def test_delete_folder(self, client):- """Test deleting folder."""- response = client.delete("/news/api/subscription/folders/folder123")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_delete_folder_with_move_to(self, client):- """Test deleting folder with move_to parameter."""- response = client.delete(- "/news/api/subscription/folders/folder123?move_to=other_folder"- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Organized Subscriptions Tests =============---class TestGetSubscriptionsOrganized:- """Tests for getting organized subscriptions."""-- def test_get_subscriptions_organized(self, client):- """Test getting subscriptions organized by folder."""- response = client.get("/news/api/subscription/subscriptions/organized")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestUpdateSubscriptionFolder:- """Tests for updating subscription folder assignment."""-- def test_update_subscription_folder(self, client):- """Test updating subscription folder."""- response = client.put(- "/news/api/subscription/subscriptions/sub123",- json={"folder_id": "new_folder"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_update_subscription_refresh_interval(self, client):- """Test updating subscription refresh interval."""- response = client.put(- "/news/api/subscription/subscriptions/sub123",- json={"refresh_interval_minutes": 60},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Subscription Stats Tests =============---class TestGetSubscriptionStats:- """Tests for getting subscription stats."""-- def test_get_subscription_stats(self, client):- """Test getting subscription stats."""- response = client.get("/news/api/subscription/stats")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Search History Tests =============---class TestGetSearchHistory:- """Tests for getting search history."""-- def test_get_search_history(self, client):- """Test getting search history."""- response = client.get("/news/api/search-history")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestAddSearchHistory:- """Tests for adding search history."""-- def test_add_search_history_no_query(self, client):- """Test adding search history without query."""- response = client.post(- "/news/api/search-history",- json={},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_add_search_history_valid(self, client):- """Test adding valid search history."""- response = client.post(- "/news/api/search-history",- json={- "query": "test search",- "type": "filter",- "resultCount": 10,- },- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_add_search_history_minimal(self, client):- """Test adding minimal search history."""- response = client.post(- "/news/api/search-history",- json={"query": "test search"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---class TestClearSearchHistory:- """Tests for clearing search history."""-- def test_clear_search_history(self, client):- """Test clearing search history."""- response = client.delete("/news/api/search-history")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Error Handler Tests =============+# ============= Error handler tests =============class TestErrorHandlers:@@ -920,32 +266,7 @@ class TestErrorHandlers:# ============= Run Subscription Now Tests =============-class TestRunSubscriptionNow:- """Tests for running subscription immediately."""-- def test_run_subscription_now(self, client):- """Test running subscription immediately."""- response = client.post("/news/api/subscriptions/sub123/run")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Current User Subscriptions Tests =============---class TestGetCurrentUserSubscriptions:- """Tests for getting current user subscriptions."""-- def test_get_current_user_subscriptions(self, client):- """Test getting current user subscriptions."""- response = client.get("/news/api/subscriptions/current")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Integration Tests with Mocking =============+# ============= SUT integration tests (mock auth + mock backend) =============class TestNewsFeedWithMocks:@@ -1025,111 +346,3 @@ class TestSubscriptionWithMocks:403,500,]---class TestSchedulerWithMocks:- """Integration tests for scheduler endpoints with mocking."""-- def test_scheduler_status_returns_data(self, app):- """Test scheduler status returns proper data structure."""- with app.test_client() as client:- with patch(- "local_deep_research.scheduler.background.get_background_job_scheduler"- ) as mock_get_scheduler:- mock_scheduler = MagicMock()- mock_scheduler.is_running = True- mock_scheduler.config = {"check_interval": 60}- mock_scheduler.user_sessions = {"user1": {}}- mock_scheduler.scheduler = MagicMock()- mock_scheduler.scheduler.get_jobs.return_value = []- mock_get_scheduler.return_value = mock_scheduler-- response = client.get("/news/api/scheduler/status")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401---# ============= Edge Cases =============---class TestEdgeCases:- """Tests for edge cases and boundary conditions."""-- def test_very_long_query(self, client):- """Test subscription with very long query."""- long_query = "a" * 10000- response = client.post(- "/news/api/subscribe",- json={"query": long_query},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_special_characters_in_query(self, client):- """Test subscription with special characters."""- response = client.post(- "/news/api/subscribe",- json={"query": "test <script>alert('xss')</script>"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_unicode_in_query(self, client):- """Test subscription with unicode characters."""- response = client.post(- "/news/api/subscribe",- json={"query": "测试 тест テスト"},- content_type="application/json",- )- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_negative_limit(self, client):- """Test feed with negative limit."""- response = client.get("/news/api/feed?limit=-1")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_zero_limit(self, client):- """Test feed with zero limit."""- response = client.get("/news/api/feed?limit=0")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_very_large_limit(self, client):- """Test feed with very large limit."""- response = client.get("/news/api/feed?limit=999999")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_non_integer_limit(self, client):- """Test feed with non-integer limit."""- response = client.get("/news/api/feed?limit=abc")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_sql_injection_attempt(self, client):- """Test subscription ID with SQL injection attempt."""- response = client.get("/news/api/subscriptions/'; DROP TABLE users; --")- assert response.status_code == 401, (- response.status_code- ) # @login_required: unauthenticated request returns 401-- def test_path_traversal_attempt(self, client):- """Test subscription ID with path traversal attempt."""- response = client.get("/news/api/subscriptions/../../etc/passwd")- # Werkzeug rejects the path traversal attempt before the route matches,- # so we get 404 (no matching route) rather than 401 from @login_required.- # Either way, the traversal never reaches a handler — which is what- # this test exists to verify.- assert response.status_code == 404, response.status_code