addes folder backup attachments logging
This commit is contained in:
+126
-1
@@ -1,7 +1,14 @@
|
||||
from datetime import datetime, timedelta
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from app.models.db_models import ActionType, ConditionField, MatchType
|
||||
from app.services.filter_engine import evaluate_conditions
|
||||
from app.services.filter_engine import evaluate_conditions as _evaluate_conditions_raw
|
||||
|
||||
|
||||
def evaluate_conditions(mail, conditions):
|
||||
"""Wrapper that returns only the bool result for tests."""
|
||||
matched, details = _evaluate_conditions_raw(mail, conditions)
|
||||
return matched
|
||||
from app.services.imap_client import MailMessage
|
||||
|
||||
|
||||
@@ -22,6 +29,7 @@ def _make_mail(**kwargs):
|
||||
subject=kwargs.get("subject", "Test Subject"),
|
||||
body=kwargs.get("body", "This is the body."),
|
||||
has_attachment=kwargs.get("has_attachment", False),
|
||||
date=kwargs.get("date", None),
|
||||
)
|
||||
|
||||
|
||||
@@ -99,6 +107,123 @@ def test_has_attachment_negate():
|
||||
assert evaluate_conditions(mail, [cond]) is True
|
||||
|
||||
|
||||
# --- Date conditions ---
|
||||
|
||||
|
||||
def test_date_on_date():
|
||||
mail = _make_mail(date=datetime(2025, 3, 15, 10, 30))
|
||||
cond = _make_condition("date", "on_date", "2025-03-15")
|
||||
assert evaluate_conditions(mail, [cond]) is True
|
||||
|
||||
|
||||
def test_date_on_date_no_match():
|
||||
mail = _make_mail(date=datetime(2025, 3, 14, 10, 30))
|
||||
cond = _make_condition("date", "on_date", "2025-03-15")
|
||||
assert evaluate_conditions(mail, [cond]) is False
|
||||
|
||||
|
||||
def test_date_before():
|
||||
mail = _make_mail(date=datetime(2025, 1, 10))
|
||||
cond = _make_condition("date", "before", "2025-02-01")
|
||||
assert evaluate_conditions(mail, [cond]) is True
|
||||
|
||||
|
||||
def test_date_after():
|
||||
mail = _make_mail(date=datetime(2025, 6, 1))
|
||||
cond = _make_condition("date", "after", "2025-03-01")
|
||||
assert evaluate_conditions(mail, [cond]) is True
|
||||
|
||||
|
||||
def test_date_range_inside():
|
||||
mail = _make_mail(date=datetime(2025, 6, 15))
|
||||
cond = _make_condition("date", "date_range", "2025-01-01,2025-12-31")
|
||||
assert evaluate_conditions(mail, [cond]) is True
|
||||
|
||||
|
||||
def test_date_range_outside():
|
||||
mail = _make_mail(date=datetime(2024, 6, 15))
|
||||
cond = _make_condition("date", "date_range", "2025-01-01,2025-12-31")
|
||||
assert evaluate_conditions(mail, [cond]) is False
|
||||
|
||||
|
||||
def test_date_year():
|
||||
mail = _make_mail(date=datetime(2025, 8, 20))
|
||||
cond = _make_condition("date", "year", "2025")
|
||||
assert evaluate_conditions(mail, [cond]) is True
|
||||
|
||||
|
||||
def test_date_year_no_match():
|
||||
mail = _make_mail(date=datetime(2024, 8, 20))
|
||||
cond = _make_condition("date", "year", "2025")
|
||||
assert evaluate_conditions(mail, [cond]) is False
|
||||
|
||||
|
||||
def test_date_last_n_days():
|
||||
mail = _make_mail(date=datetime.utcnow() - timedelta(days=5))
|
||||
cond = _make_condition("date", "last_n_days", "10")
|
||||
assert evaluate_conditions(mail, [cond]) is True
|
||||
|
||||
|
||||
def test_date_last_n_days_too_old():
|
||||
mail = _make_mail(date=datetime.utcnow() - timedelta(days=20))
|
||||
cond = _make_condition("date", "last_n_days", "10")
|
||||
assert evaluate_conditions(mail, [cond]) is False
|
||||
|
||||
|
||||
def test_date_last_n_weeks():
|
||||
mail = _make_mail(date=datetime.utcnow() - timedelta(weeks=1))
|
||||
cond = _make_condition("date", "last_n_weeks", "2")
|
||||
assert evaluate_conditions(mail, [cond]) is True
|
||||
|
||||
|
||||
def test_date_last_n_months():
|
||||
mail = _make_mail(date=datetime.utcnow() - timedelta(days=15))
|
||||
cond = _make_condition("date", "last_n_months", "1")
|
||||
assert evaluate_conditions(mail, [cond]) is True
|
||||
|
||||
|
||||
def test_date_older_than_days():
|
||||
mail = _make_mail(date=datetime.utcnow() - timedelta(days=100))
|
||||
cond = _make_condition("date", "older_than_days", "30")
|
||||
assert evaluate_conditions(mail, [cond]) is True
|
||||
|
||||
|
||||
def test_date_older_than_days_too_recent():
|
||||
mail = _make_mail(date=datetime.utcnow() - timedelta(days=5))
|
||||
cond = _make_condition("date", "older_than_days", "30")
|
||||
assert evaluate_conditions(mail, [cond]) is False
|
||||
|
||||
|
||||
def test_date_older_than_weeks():
|
||||
mail = _make_mail(date=datetime.utcnow() - timedelta(weeks=10))
|
||||
cond = _make_condition("date", "older_than_weeks", "4")
|
||||
assert evaluate_conditions(mail, [cond]) is True
|
||||
|
||||
|
||||
def test_date_older_than_months():
|
||||
mail = _make_mail(date=datetime.utcnow() - timedelta(days=200))
|
||||
cond = _make_condition("date", "older_than_months", "3")
|
||||
assert evaluate_conditions(mail, [cond]) is True
|
||||
|
||||
|
||||
def test_date_no_date_in_mail():
|
||||
mail = _make_mail(date=None)
|
||||
cond = _make_condition("date", "on_date", "2025-03-15")
|
||||
assert evaluate_conditions(mail, [cond]) is False
|
||||
|
||||
|
||||
def test_date_negate():
|
||||
mail = _make_mail(date=datetime(2025, 3, 15))
|
||||
cond = _make_condition("date", "year", "2024", negate=True)
|
||||
assert evaluate_conditions(mail, [cond]) is True
|
||||
|
||||
|
||||
def test_date_german_format():
|
||||
mail = _make_mail(date=datetime(2025, 3, 15))
|
||||
cond = _make_condition("date", "on_date", "15.03.2025")
|
||||
assert evaluate_conditions(mail, [cond]) is True
|
||||
|
||||
|
||||
def test_empty_conditions():
|
||||
mail = _make_mail()
|
||||
assert evaluate_conditions(mail, []) is False
|
||||
|
||||
Reference in New Issue
Block a user