88 lines
2.6 KiB
Python
88 lines
2.6 KiB
Python
# Copyright (c) 2026 Patrick Motsch
|
|
# All rights reserved.
|
|
"""Unit tests for trustee.queryData helpers (pure-logic, no DB required)."""
|
|
|
|
import pytest
|
|
|
|
from modules.workflows.methods.methodTrustee.actions.queryData import (
|
|
_accountMatcher,
|
|
_normalizeText,
|
|
_parseFilterJson,
|
|
_parsePeriod,
|
|
_summarizeAggregate,
|
|
)
|
|
|
|
|
|
class TestNormalize:
|
|
def test_normalizeStripsCaseAndPunctuation(self):
|
|
assert _normalizeText("Müller AG") == "mllerag"
|
|
assert _normalizeText("Mueller, AG") == "muellerag"
|
|
|
|
def test_normalizeHandlesEmpty(self):
|
|
assert _normalizeText("") == ""
|
|
assert _normalizeText(None) == ""
|
|
|
|
|
|
class TestParsePeriod:
|
|
def test_yearOnlyExpandsToFullYear(self):
|
|
assert _parsePeriod("2025") == ("2025-01-01", "2025-12-31")
|
|
|
|
def test_rangeWithSlash(self):
|
|
assert _parsePeriod("2025-01-01/2025-06-30") == ("2025-01-01", "2025-06-30")
|
|
|
|
def test_emptyReturnsNone(self):
|
|
assert _parsePeriod("") == (None, None)
|
|
assert _parsePeriod(None) == (None, None)
|
|
|
|
|
|
class TestAccountMatcher:
|
|
def test_exactMatch(self):
|
|
m = _accountMatcher("6000")
|
|
assert m("6000") is True
|
|
assert m("6001") is False
|
|
|
|
def test_prefixMatch(self):
|
|
m = _accountMatcher("6*")
|
|
assert m("6000") is True
|
|
assert m("6999") is True
|
|
assert m("7000") is False
|
|
|
|
def test_rangeMatch(self):
|
|
m = _accountMatcher("6000-6099")
|
|
assert m("6000") is True
|
|
assert m("6050") is True
|
|
assert m("6099") is True
|
|
assert m("6100") is False
|
|
assert m("not-a-number") is False
|
|
|
|
def test_emptyMatchesAll(self):
|
|
m = _accountMatcher("")
|
|
assert m("anything") is True
|
|
|
|
|
|
class TestParseFilterJson:
|
|
def test_validJson(self):
|
|
assert _parseFilterJson('{"foo": "bar"}') == {"foo": "bar"}
|
|
|
|
def test_dictPassThrough(self):
|
|
assert _parseFilterJson({"a": 1}) == {"a": 1}
|
|
|
|
def test_emptyOrInvalidReturnsEmptyDict(self):
|
|
assert _parseFilterJson("") == {}
|
|
assert _parseFilterJson(None) == {}
|
|
assert _parseFilterJson("not json") == {}
|
|
|
|
|
|
class TestSummarizeAggregate:
|
|
def test_countsByContactType(self):
|
|
records = [
|
|
{"contactType": "customer"},
|
|
{"contactType": "customer"},
|
|
{"contactType": "vendor"},
|
|
]
|
|
summary = _summarizeAggregate(records)
|
|
assert summary["total"] == 3
|
|
assert summary["by_contactType"] == {"customer": 2, "vendor": 1}
|
|
|
|
def test_emptyRecordsReturnsZero(self):
|
|
assert _summarizeAggregate([]) == {"total": 0}
|