|
10 | 10 | from fides.api.models.detection_discovery import (
|
11 | 11 | DiffStatus,
|
12 | 12 | MonitorConfig,
|
| 13 | + MonitorExecution, |
13 | 14 | MonitorFrequency,
|
14 | 15 | StagedResource,
|
15 | 16 | fetch_staged_resources_by_type_query,
|
@@ -633,3 +634,50 @@ def test_update_monitor_config_execution_trigger_logic(
|
633 | 634 | )
|
634 | 635 | assert mc.execution_start_date == expected_date
|
635 | 636 | db.delete(mc)
|
| 637 | + |
| 638 | + |
| 639 | +class TestMonitorExecutionModel: |
| 640 | + """Tests for the MonitorExecution model""" |
| 641 | + |
| 642 | + @pytest.fixture |
| 643 | + def monitor_config_key(self, db: Session, monitor_config) -> str: |
| 644 | + """Returns a monitor config key for testing""" |
| 645 | + return monitor_config.key |
| 646 | + |
| 647 | + def test_started_timestamp_is_set_on_creation( |
| 648 | + self, db: Session, monitor_config_key |
| 649 | + ) -> None: |
| 650 | + """Test that the started timestamp is set correctly when creating a new record""" |
| 651 | + # Create first record |
| 652 | + first_execution = MonitorExecution.create( |
| 653 | + db=db, |
| 654 | + data={ |
| 655 | + "monitor_config_key": monitor_config_key, |
| 656 | + "status": "running", |
| 657 | + }, |
| 658 | + ) |
| 659 | + |
| 660 | + # Small delay to ensure timestamps would be different |
| 661 | + import time |
| 662 | + |
| 663 | + time.sleep(0.1) |
| 664 | + |
| 665 | + # Create second record |
| 666 | + second_execution = MonitorExecution.create( |
| 667 | + db=db, |
| 668 | + data={ |
| 669 | + "monitor_config_key": monitor_config_key, |
| 670 | + "status": "running", |
| 671 | + }, |
| 672 | + ) |
| 673 | + |
| 674 | + # Verify timestamps are different (not a constant default) |
| 675 | + assert first_execution.started != second_execution.started |
| 676 | + |
| 677 | + # Verify timestamps are recent |
| 678 | + now = datetime.now(timezone.utc) |
| 679 | + assert (now - first_execution.started).total_seconds() < 5 |
| 680 | + assert (now - second_execution.started).total_seconds() < 5 |
| 681 | + |
| 682 | + # Verify second timestamp is later than first |
| 683 | + assert second_execution.started > first_execution.started |
0 commit comments