nordabiz/tests/unit/test_search_service.py
Maciej Pienczyn a57187e05f
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
test: Add comprehensive testing infrastructure
- pytest framework with fixtures for auth (auth_client, admin_client)
- Unit tests for SearchService
- Integration tests for auth flow
- Security tests (OWASP Top 10: SQL injection, XSS, CSRF)
- Smoke tests for production health and backup monitoring
- E2E tests with Playwright (basic structure)
- DR tests for backup/restore procedures
- GitHub Actions CI/CD workflow (.github/workflows/test.yml)
- Coverage configuration (.coveragerc) with 80% minimum
- DR documentation and restore script

Staging environment: VM 248, staging.nordabiznes.pl

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 07:52:34 +01:00

95 lines
2.9 KiB
Python

"""
Unit tests for SearchService
============================
Tests search functionality including synonyms, FTS, and fuzzy matching.
"""
import pytest
# Mark all tests in this module as unit tests
pytestmark = pytest.mark.unit
class TestSearchService:
"""Tests for SearchService class."""
def test_search_returns_list(self, app, db):
"""Search should always return a list."""
from search_service import SearchService
with app.app_context():
service = SearchService(db.session)
results = service.search("IT")
assert isinstance(results, list)
def test_search_empty_query(self, app, db):
"""Empty query should return empty list or all results."""
from search_service import SearchService
with app.app_context():
service = SearchService(db.session)
results = service.search("")
assert isinstance(results, list)
def test_search_special_characters(self, app, db):
"""Search should handle special characters safely."""
from search_service import SearchService
with app.app_context():
service = SearchService(db.session)
# SQL injection attempt
results = service.search("'; DROP TABLE companies; --")
assert isinstance(results, list)
# XSS attempt
results = service.search("<script>alert('xss')</script>")
assert isinstance(results, list)
def test_search_polish_characters(self, app, db):
"""Search should handle Polish characters."""
from search_service import SearchService
with app.app_context():
service = SearchService(db.session)
results = service.search("usługi")
assert isinstance(results, list)
results = service.search("żółć")
assert isinstance(results, list)
def test_search_case_insensitive(self, app, db):
"""Search should be case insensitive."""
from search_service import SearchService
with app.app_context():
service = SearchService(db.session)
results_lower = service.search("it")
results_upper = service.search("IT")
results_mixed = service.search("It")
# All should return results (may not be identical due to ranking)
assert isinstance(results_lower, list)
assert isinstance(results_upper, list)
assert isinstance(results_mixed, list)
class TestSearchSynonyms:
"""Tests for search synonym handling."""
def test_synonym_expansion(self, app, db):
"""Search should expand synonyms."""
from search_service import SearchService
with app.app_context():
service = SearchService(db.session)
# "informatyka" should match "IT" companies
results = service.search("informatyka")
assert isinstance(results, list)