PrashanthB461 commited on
Commit
d3afd25
·
verified ·
1 Parent(s): d4c52fd

Update tests/test_notification.py

Browse files
Files changed (1) hide show
  1. tests/test_notification.py +13 -17
tests/test_notification.py CHANGED
@@ -1,26 +1,22 @@
1
  import pytest
2
- import sys
3
- import os
4
-
5
- # Add the parent directory to the path to import app
6
- sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
7
 
8
  def test_send_alert():
9
  """Test alert sending functionality"""
10
- # Test violation data
11
  violation = {
12
  'violation_type': 'No Helmet',
13
  'severity': 'Critical',
14
- 'timestamp': '2025-01-01T12:00:00+05:30',
15
- 'site_id': 'SITE001'
 
16
  }
17
 
18
- # Since send_alert just logs, we can test that it doesn't raise exceptions
19
- try:
20
- # Simulate the send_alert function
21
- print(f"Alert! {violation['violation_type']} detected. Severity: {violation['severity']}")
22
- alert_sent = True
23
- except Exception:
24
- alert_sent = False
25
-
26
- assert alert_sent, "Alert sending failed"
 
1
  import pytest
2
+ from app import send_alert
3
+ import logging
 
 
 
4
 
5
  def test_send_alert():
6
  """Test alert sending functionality"""
 
7
  violation = {
8
  'violation_type': 'No Helmet',
9
  'severity': 'Critical',
10
+ 'timestamp': '2025-06-07T09:23:00Z',
11
+ 'site_id': 'SITE001',
12
+ 'camera_id': 'CAM001'
13
  }
14
 
15
+ # Capture log output to verify alert was sent
16
+ with pytest.raises(Exception):
17
+ # This should not raise an exception
18
+ send_alert(violation)
19
+ assert True, "Alert should be sent without errors"
20
+ else:
21
+ # If no exception, the test passes
22
+ assert True, "Alert sent successfully"