bmc_hub/tests/test_internet_change_case_service.py
Christian 1cfe5aee76 feat(migrations): add AI benchmark and vTiger archive tables
- Created tables for AI benchmark runs and results to facilitate model evaluation.
- Added expected answers column to benchmark results.
- Introduced tables for internet connection change cases and vTiger archive management, including records, relations, and checkpoints.
- Implemented triggers to enforce append-only behavior for vTiger archive records and files.
- Enhanced solution management with soft delete capabilities for sag_solutions and knowledge_articles.

feat(scripts): add CRM benchmarking script for Ollama models

- Developed a Python script to benchmark CRM models exposed through Ollama, including various test cases and scoring mechanisms.

test(tests): add comprehensive tests for new features

- Implemented tests for internet change case service, vTiger archive functionality, and sag solution knowledge management.
- Ensured coverage for edge cases and error handling in the new features.
2026-08-31 13:01:35 +02:00

48 lines
2.1 KiB
Python

import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent))
from app.modules.internet_connections.backend import change_case_service as service
def test_relevant_change_filter_excludes_manual_classification_and_customer():
changes = service.filter_relevant_changes({
'monthly_cost': {'from': 100, 'to': 125},
'customer_id': {'from': None, 'to': 7},
'allocation_model': {'from': 'dedicated', 'to': 'shared'},
'notes': {'from': 'før', 'to': 'efter'},
})
assert changes == {'monthly_cost': {'from': 100, 'to': 125}}
def test_same_import_merges_into_existing_case(monkeypatch):
writes = []
monkeypatch.setattr(service, 'execute_query_single', lambda query, params=None: (
{'id': 4, 'sag_id': 91, 'changes': {'monthly_cost': {'from': 100, 'to': 125}}}
if 'FROM internet_connection_change_cases' in query else None
))
monkeypatch.setattr(service, 'execute_query', lambda query, params=None, fetch=True: writes.append((query, params)))
result = service.ensure_external_change_case(
connection_id=5, source_type='test_import', source_key='same-file',
source_label='Testfil', connection_name='Fiber', reference='NKA-1', provider='Leverandør',
owner_customer_id=7, changes={'speed_mbps': {'from': 100, 'to': 200}},
)
assert result['case_id'] == 91
assert result['created'] is False
assert set(result['changes']) == {'monthly_cost', 'speed_mbps'}
assert any('UPDATE sag_sager' in query for query, _ in writes)
def test_case_failure_is_reported_without_raising(monkeypatch):
monkeypatch.setattr(service, 'execute_query_single', lambda *args, **kwargs: (_ for _ in ()).throw(RuntimeError('database down')))
monkeypatch.setattr(service, 'execute_query', lambda *args, **kwargs: None)
result = service.ensure_external_change_case(
connection_id=5, source_type='test', source_key='run-1', source_label='Test',
changes={'status': {'from': 'active', 'to': 'inactive'}},
)
assert result['case_id'] is None
assert result['error'] == 'database down'