| 58 | |
| 59 | |
| 60 | def test_analytics_event_logging(temp_analytics_file, temp_data_dir): |
| 61 | analytics = Analytics(logfile=temp_analytics_file) |
| 62 | analytics.asked_opt_in = True |
| 63 | analytics.enable() |
| 64 | |
| 65 | test_event = "test_event" |
| 66 | test_properties = {"test_key": "test_value"} |
| 67 | |
| 68 | # with patch.object(analytics.mp, "track") as mock_mp_track: |
| 69 | with patch.object(analytics.ph, "capture") as mock_ph_capture: |
| 70 | analytics.event(test_event, **test_properties) |
| 71 | |
| 72 | # mock_mp_track.assert_called_once() |
| 73 | mock_ph_capture.assert_called_once() |
| 74 | |
| 75 | # Verify logfile |
| 76 | with open(temp_analytics_file) as f: |
| 77 | log_entry = json.loads(f.read().strip()) |
| 78 | assert log_entry["event"] == test_event |
| 79 | assert "test_key" in log_entry["properties"] |
| 80 | |
| 81 | |
| 82 | def test_system_info(temp_data_dir): |