Files
gh-christianlouis-docuelevate/tests/test_views_license.py
copilot-swe-agent[bot] e3cc489975 fix(test): fix test_get_lgpl_license_not_found JSONDecodeError
The test had two issues:
1. Too-broad mock: patching pathlib.Path.exists globally broke
   Starlette/FastAPI internals. Now targets the specific module.
2. Wrong assertion: response.json() failed because the custom
   HTTPException handler returns HTML for non-API routes, not JSON.
   Updated to only assert on status code.

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-17 12:01:40 +00:00

39 lines
1.5 KiB
Python

"""Tests for app/views/license_routes.py module."""
from unittest.mock import mock_open, patch
import pytest
@pytest.mark.integration
class TestLicenseViews:
"""Tests for license view routes."""
def test_license_api_endpoint(self, client):
"""Test license API endpoint."""
response = client.get("/api/license")
assert response.status_code in (200, 404)
def test_get_lgpl_license_success(self, client):
"""Test successful LGPL license retrieval."""
# Create a mock license file
license_content = "GNU Lesser General Public License\nVersion 3, 29 June 2007"
with patch("pathlib.Path.exists", return_value=True):
with patch("builtins.open", mock_open(read_data=license_content)):
response = client.get("/licenses/lgpl.txt")
assert response.status_code == 200
assert "GNU Lesser General Public License" in response.text
def test_get_lgpl_license_not_found(self, client):
"""Test LGPL license file not found."""
with patch("app.views.license_routes.Path") as MockPath:
MockPath.return_value.exists.return_value = False
response = client.get("/licenses/lgpl.txt")
assert response.status_code == 404
def test_serve_attribution_page(self, client):
"""Test attribution page is served."""
response = client.get("/attribution")
assert response.status_code in (200, 404, 500) # Allow for missing template