Tests for behavior log operations
| 135 | """Tests for behavior log operations""" |
| 136 | |
| 137 | def test_log_behavior(self, test_db_path): |
| 138 | """Test logging user behavior""" |
| 139 | import db_ops |
| 140 | db_ops.DB_PATH = test_db_path |
| 141 | |
| 142 | result = log_behavior( |
| 143 | user_id="test_user", |
| 144 | push_id="push_001", |
| 145 | paper_id=1, |
| 146 | action="selected", |
| 147 | action_type="selected", |
| 148 | category="🔴" |
| 149 | ) |
| 150 | assert result is not None |
| 151 | assert result > 0 |
| 152 | |
| 153 | def test_get_behavior_logs(self, test_db_path): |
| 154 | """Test retrieving behavior logs""" |
| 155 | import db_ops |
| 156 | db_ops.DB_PATH = test_db_path |
| 157 | |
| 158 | # Log some behaviors |
| 159 | log_behavior("test_user", "push_001", 1, "selected", "selected", "🔴") |
| 160 | log_behavior("test_user", "push_001", 2, "skipped", "skipped", "🟡") |
| 161 | |
| 162 | # Retrieve logs |
| 163 | from datetime import datetime, timedelta |
| 164 | end_date = datetime.now().strftime("%Y-%m-%d") |
| 165 | start_date = (datetime.now() - timedelta(days=7)).strftime("%Y-%m-%d") |
| 166 | |
| 167 | logs = get_behavior_logs("test_user", start_date, end_date) |
| 168 | assert len(logs) == 2 |
| 169 | |
| 170 | def test_empty_push_is_returned_as_latest_push(self, test_db_path): |
| 171 | """An empty but completed push should not look like no push exists.""" |
| 172 | import db_ops |
| 173 | db_ops.DB_PATH = test_db_path |
| 174 | |
| 175 | log_behavior( |
| 176 | "test_user", |
| 177 | "push_empty_001", |
| 178 | None, |
| 179 | "push_empty", |
| 180 | "push", |
| 181 | "empty_push", |
| 182 | metadata={ |
| 183 | "paper_count": 0, |
| 184 | "total_fetched": 15, |
| 185 | "reason": "all_candidates_filtered", |
| 186 | }, |
| 187 | ) |
| 188 | |
| 189 | latest = get_latest_push("test_user") |
| 190 | assert latest is not None |
| 191 | assert latest["push_id"] == "push_empty_001" |
| 192 | assert latest["papers"] == [] |
| 193 | assert latest["metadata"]["total_fetched"] == 15 |
| 194 |
nothing calls this directly
no outgoing calls
no test coverage detected