feature/login #11
@@ -4,7 +4,6 @@ from django.utils import timezone
|
|||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
from dokumente.models import Dokument, Vorgabe, VorgabeKurztext, VorgabeLangtext, Geltungsbereich, Dokumententyp, Thema
|
from dokumente.models import Dokument, Vorgabe, VorgabeKurztext, VorgabeLangtext, Geltungsbereich, Dokumententyp, Thema
|
||||||
from stichworte.models import Stichwort
|
from stichworte.models import Stichwort
|
||||||
from unittest.mock import patch
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
@@ -67,24 +66,24 @@ class SearchViewTest(TestCase):
|
|||||||
"""Test POST request with valid search term"""
|
"""Test POST request with valid search term"""
|
||||||
response = self.client.post('/search/', {'q': 'Test'})
|
response = self.client.post('/search/', {'q': 'Test'})
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertContains(response, 'Suchresultate für Test')
|
self.assertContains(response, 'Suchergebnisse')
|
||||||
|
|
||||||
def test_search_case_insensitive(self):
|
def test_search_case_insensitive(self):
|
||||||
"""Test that search is case insensitive"""
|
"""Test that search is case insensitive"""
|
||||||
# Search for lowercase
|
# Search for lowercase
|
||||||
response = self.client.post('/search/', {'q': 'test'})
|
response = self.client.post('/search/', {'q': 'test'})
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertContains(response, 'Suchresultate für test')
|
self.assertContains(response, 'Suchergebnisse für "test"')
|
||||||
|
|
||||||
# Search for uppercase
|
# Search for uppercase
|
||||||
response = self.client.post('/search/', {'q': 'TEST'})
|
response = self.client.post('/search/', {'q': 'TEST'})
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertContains(response, 'Suchresultate für TEST')
|
self.assertContains(response, 'Suchergebnisse für "TEST"')
|
||||||
|
|
||||||
# Search for mixed case
|
# Search for mixed case
|
||||||
response = self.client.post('/search/', {'q': 'TeSt'})
|
response = self.client.post('/search/', {'q': 'TeSt'})
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertContains(response, 'Suchresultate für TeSt')
|
self.assertContains(response, 'Suchergebnisse für "TeSt"')
|
||||||
|
|
||||||
def test_search_in_kurztext(self):
|
def test_search_in_kurztext(self):
|
||||||
"""Test search in Kurztext content"""
|
"""Test search in Kurztext content"""
|
||||||
@@ -114,7 +113,7 @@ class SearchViewTest(TestCase):
|
|||||||
"""Test search with no results"""
|
"""Test search with no results"""
|
||||||
response = self.client.post('/search/', {'q': 'NichtVorhanden'})
|
response = self.client.post('/search/', {'q': 'NichtVorhanden'})
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertContains(response, 'Keine Resultate für "NichtVorhanden"')
|
self.assertContains(response, 'Keine Ergebnisse gefunden')
|
||||||
|
|
||||||
def test_search_expired_vorgabe_not_included(self):
|
def test_search_expired_vorgabe_not_included(self):
|
||||||
"""Test that expired Vorgaben are not included in results"""
|
"""Test that expired Vorgaben are not included in results"""
|
||||||
@@ -160,8 +159,8 @@ class SearchViewTest(TestCase):
|
|||||||
"""Test that HTML tags are stripped from search input"""
|
"""Test that HTML tags are stripped from search input"""
|
||||||
response = self.client.post('/search/', {'q': '<script>alert("xss")</script>Test'})
|
response = self.client.post('/search/', {'q': '<script>alert("xss")</script>Test'})
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
# Should search for "alert('xss')Test" after HTML tag removal
|
# Should search for "alert("xss")Test" after HTML tag removal
|
||||||
self.assertContains(response, 'Suchresultate für alert("xss")Test')
|
self.assertContains(response, 'Suchergebnisse für "alert')
|
||||||
|
|
||||||
def test_search_invalid_characters_validation(self):
|
def test_search_invalid_characters_validation(self):
|
||||||
"""Test validation for invalid characters"""
|
"""Test validation for invalid characters"""
|
||||||
@@ -206,7 +205,7 @@ class SearchViewTest(TestCase):
|
|||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
# The input should be preserved (escaped) in the form
|
# The input should be preserved (escaped) in the form
|
||||||
# Since HTML tags are stripped, we expect "Test" to be searched
|
# Since HTML tags are stripped, we expect "Test" to be searched
|
||||||
self.assertContains(response, 'Suchresultate für Test')
|
self.assertContains(response, 'Suchergebnisse für "Test"')
|
||||||
|
|
||||||
def test_search_xss_prevention_in_results(self):
|
def test_search_xss_prevention_in_results(self):
|
||||||
"""Test that search terms are escaped in results to prevent XSS"""
|
"""Test that search terms are escaped in results to prevent XSS"""
|
||||||
@@ -218,15 +217,14 @@ class SearchViewTest(TestCase):
|
|||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
# The script tag should be escaped in the output
|
# The script tag should be escaped in the output
|
||||||
# Note: This depends on how the template renders the content
|
# Note: This depends on how the template renders the content
|
||||||
self.assertContains(response, 'Suchresultate für term')
|
self.assertContains(response, 'Suchergebnisse für "term"')
|
||||||
|
|
||||||
@patch('pages.views.pprint.pp')
|
def test_search_result_structure(self):
|
||||||
def test_search_result_logging(self, mock_pprint):
|
"""Test that search results have expected structure"""
|
||||||
"""Test that search results are logged for debugging"""
|
|
||||||
response = self.client.post('/search/', {'q': 'Test'})
|
response = self.client.post('/search/', {'q': 'Test'})
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
# Verify that pprint.pp was called with the result
|
# Verify the results page is rendered with correct structure
|
||||||
mock_pprint.assert_called_once()
|
self.assertContains(response, 'Suchergebnisse für "Test"')
|
||||||
|
|
||||||
def test_search_multiple_documents(self):
|
def test_search_multiple_documents(self):
|
||||||
"""Test search across multiple documents"""
|
"""Test search across multiple documents"""
|
||||||
|
|||||||
Reference in New Issue
Block a user