Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions tests/unit/test_rule_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timedelta
from unittest.mock import MagicMock, patch

import pytest
Expand All @@ -8,6 +8,11 @@
from app.service.rule_service import RuleService


@pytest.fixture
def future_date():
return (datetime.now() + timedelta(days=1)).date()


@pytest.fixture(autouse=True)
def mock_log_event():
with patch("app.service.rule_service.log_event") as mock_log:
Expand All @@ -16,7 +21,7 @@ def mock_log_event():


@pytest.fixture
def mock_conn():
def mock_conn(future_date):
mock_db = MagicMock()
mock_rule_collection = MagicMock()
# Crea la lista de reglas de ejemplo
Expand All @@ -25,14 +30,14 @@ def mock_conn():
"_id": ObjectId(),
"title": "Rule 1",
"description": "Desc 1",
"effectiveDate": "2024-01-01",
"effectiveDate": datetime.combine(future_date, datetime.min.time()),
"conditions": [],
},
{
"_id": ObjectId(),
"title": "Rule 2",
"description": "Desc 2",
"effectiveDate": "2024-01-01",
"effectiveDate": datetime.combine(future_date, datetime.min.time()),
"conditions": [],
},
]
Expand All @@ -49,22 +54,23 @@ def mock_conn():


@pytest.fixture
def sample_rule():
def sample_rule(future_date):
return Rule(
title="Test Rule",
description="This is a test rule",
effectiveDate="2024-01-01",
effectiveDate=datetime.combine(future_date, datetime.min.time()),
conditions=[],
)


@pytest.fixture
def sample_rule_dict():
def sample_rule_dict(future_date):
date = (datetime.combine(future_date, datetime.min.time()),)
return {
"_id": ObjectId(),
"title": "Test Rule",
"description": "This is a test rule",
"effectiveDate": "2024-01-01",
"effectiveDate": date,
"conditions": [],
}

Expand Down